原理就是创建一个广播接收者,接收到广播执行恢复出厂设置的方法就可以了,以下为创建的广播接收者以及恢复出厂设置的代码:
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/RestoreReceiver.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/RestoreReceiver.java
new file mode 100755
index 00000000000..4f468f80209
--- /dev/null
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/RestoreReceiver.java
@@ -0,0 +1,47 @@
+package com.android.systemui;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.radio.V1_2.CellIdentityOperatorNames;
+import android.media.AudioManager;
+import android.os.PowerManager;
+import android.util.Log;
+
+import android.os.ServiceManager;
+import com.android.internal.statusbar.IStatusBarService;
+import android.os.RemoteException;
+public class RestoreReceiver extends BroadcastReceiver {
+
+ public static String Action_Restore_Setting="action_restore";
+
+ public void regiserRecevier(Context context){
+ IntentFilter filter=new IntentFilter();
+ filter.addAction(Action_Restore_Setting);
+ context.registerReceiver(this,filter);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d("swl","action:"+intent.getAction());
+ if(Action_Restore_Setting.equals(intent.getAction())){
+ master_clear(context);
+ }
+
+ }
+ private void master_clear(Context context) {
+ Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
+ intent.setPackage("android");
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
+ intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, true);
+ context.sendBroadcast(intent);
+
+ }
+
+}
下面是注册广播:
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/SystemUIApplication.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/SystemUIApplication.java
old mode 100644
new mode 100755
index 4ff5c1d7d20..2968c2c677b
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -74,6 +74,9 @@ public class SystemUIApplication extends Application implements
TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
Trace.TRACE_TAG_APP);
log.traceBegin("DependencyInjection");
+ //swl add
+ new RestoreReceiver().regiserRecevier(getApplicationContext());
+ //end
mContextAvailableCallback.onContextAvailable(this);
mRootComponent = SystemUIFactory.getInstance().getRootComponent();
mComponentHelper = mRootComponent.getContextComponentHelper();