Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does system broadcasts any intents during factory reset and system updates?

how to find factory reset is called in android

like image 518
Vishal Pawar Avatar asked Feb 29 '12 11:02

Vishal Pawar


1 Answers

Old topic but maybe will help someone.

There is not any official event which states that Factory Data Reset will be performed. However for Android <= 22 (Lollipop) there is unofficial (hidden in the code) broadcast intent android.intent.action.MASTER_CLEAR which is fired when External Storage will be formatted. If you click factory reset for Android Settings then MASTER_CLEAR intent is fired, in the result you can state that there will be factory reset.

Sample code:

// Class Member 
private BroadcastReceiver receiver;
.
.
.

// In some method, e.g. onCreate()
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.ACTION_SHUTDOWN");
filter.addAction("android.intent.action.MASTER_CLEAR");

receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
                    Intent.ACTION_SHUTDOWN)) {
                Log.d(TAG, "SHUTDOWN")
            }

            if (intent.getAction().equals("android.intent.action.MASTER_CLEAR")) {
                Log.d(TAG, "FACTORY DATA RESET")
            }
        };

registerReceiver(receiver, filter);

If there will be factory reset then you will see MASTER_CLEAR action followed by SHUTDOWN action. I tested on Nexus 5 and Androids 4.4.4, 5.0, 6.0, 6.0.1 and works.

like image 72
MikePtr Avatar answered Oct 23 '22 03:10

MikePtr