Loading core/java/android/os/RecoverySystem.java +34 −6 Original line number Diff line number Diff line Loading @@ -338,11 +338,11 @@ public class RecoverySystem { } /** * Reboots the device and wipes the user data partition. This is * sometimes called a "factory reset", which is something of a * misnomer because the system partition is not restored to its * factory state. * Requires the {@link android.Manifest.permission#REBOOT} permission. * Reboots the device and wipes the user data and cache * partitions. This is sometimes called a "factory reset", which * is something of a misnomer because the system partition is not * restored to its factory state. Requires the * {@link android.Manifest.permission#REBOOT} permission. * * @param context the Context to use * Loading @@ -350,6 +350,28 @@ public class RecoverySystem { * fails, or if the reboot itself fails. */ public static void rebootWipeUserData(Context context) throws IOException { rebootWipeUserData(context, false); } /** * Reboots the device and wipes the user data and cache * partitions. This is sometimes called a "factory reset", which * is something of a misnomer because the system partition is not * restored to its factory state. Requires the * {@link android.Manifest.permission#REBOOT} permission. * * @param context the Context to use * @param shutdown if true, the device will be powered down after * the wipe completes, rather than being rebooted * back to the regular system. * * @throws IOException if writing the recovery command file * fails, or if the reboot itself fails. * * @hide */ public static void rebootWipeUserData(Context context, boolean shutdown) throws IOException { final ConditionVariable condition = new ConditionVariable(); Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION"); Loading @@ -365,7 +387,13 @@ public class RecoverySystem { // Block until the ordered broadcast has completed. condition.block(); bootCommand(context, "--wipe_data\n--locale=" + Locale.getDefault().toString()); String shutdownArg = ""; if (shutdown) { shutdownArg = "--shutdown_after\n"; } bootCommand(context, shutdownArg + "--wipe_data\n--locale=" + Locale.getDefault().toString()); } /** Loading services/core/java/com/android/server/MasterClearReceiver.java +3 −1 Original line number Diff line number Diff line Loading @@ -37,13 +37,15 @@ public class MasterClearReceiver extends BroadcastReceiver { } } final boolean shutdown = intent.getBooleanExtra("shutdown", false); Slog.w(TAG, "!!! FACTORY RESET !!!"); // The reboot call is blocking, so we need to do it on another thread. Thread thr = new Thread("Reboot") { @Override public void run() { try { RecoverySystem.rebootWipeUserData(context); RecoverySystem.rebootWipeUserData(context, shutdown); Log.wtf(TAG, "Still running after master clear?!"); } catch (IOException e) { Slog.e(TAG, "Can't perform master clear/factory reset", e); Loading Loading
core/java/android/os/RecoverySystem.java +34 −6 Original line number Diff line number Diff line Loading @@ -338,11 +338,11 @@ public class RecoverySystem { } /** * Reboots the device and wipes the user data partition. This is * sometimes called a "factory reset", which is something of a * misnomer because the system partition is not restored to its * factory state. * Requires the {@link android.Manifest.permission#REBOOT} permission. * Reboots the device and wipes the user data and cache * partitions. This is sometimes called a "factory reset", which * is something of a misnomer because the system partition is not * restored to its factory state. Requires the * {@link android.Manifest.permission#REBOOT} permission. * * @param context the Context to use * Loading @@ -350,6 +350,28 @@ public class RecoverySystem { * fails, or if the reboot itself fails. */ public static void rebootWipeUserData(Context context) throws IOException { rebootWipeUserData(context, false); } /** * Reboots the device and wipes the user data and cache * partitions. This is sometimes called a "factory reset", which * is something of a misnomer because the system partition is not * restored to its factory state. Requires the * {@link android.Manifest.permission#REBOOT} permission. * * @param context the Context to use * @param shutdown if true, the device will be powered down after * the wipe completes, rather than being rebooted * back to the regular system. * * @throws IOException if writing the recovery command file * fails, or if the reboot itself fails. * * @hide */ public static void rebootWipeUserData(Context context, boolean shutdown) throws IOException { final ConditionVariable condition = new ConditionVariable(); Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION"); Loading @@ -365,7 +387,13 @@ public class RecoverySystem { // Block until the ordered broadcast has completed. condition.block(); bootCommand(context, "--wipe_data\n--locale=" + Locale.getDefault().toString()); String shutdownArg = ""; if (shutdown) { shutdownArg = "--shutdown_after\n"; } bootCommand(context, shutdownArg + "--wipe_data\n--locale=" + Locale.getDefault().toString()); } /** Loading
services/core/java/com/android/server/MasterClearReceiver.java +3 −1 Original line number Diff line number Diff line Loading @@ -37,13 +37,15 @@ public class MasterClearReceiver extends BroadcastReceiver { } } final boolean shutdown = intent.getBooleanExtra("shutdown", false); Slog.w(TAG, "!!! FACTORY RESET !!!"); // The reboot call is blocking, so we need to do it on another thread. Thread thr = new Thread("Reboot") { @Override public void run() { try { RecoverySystem.rebootWipeUserData(context); RecoverySystem.rebootWipeUserData(context, shutdown); Log.wtf(TAG, "Still running after master clear?!"); } catch (IOException e) { Slog.e(TAG, "Can't perform master clear/factory reset", e); Loading