summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/os/RecoverySystem.java40
-rw-r--r--services/core/java/com/android/server/MasterClearReceiver.java4
2 files changed, 37 insertions, 7 deletions
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index b692ffdea91c..f671ed955659 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -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
*
@@ -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");
@@ -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());
}
/**
diff --git a/services/core/java/com/android/server/MasterClearReceiver.java b/services/core/java/com/android/server/MasterClearReceiver.java
index 86f57d124868..e570b0bd0978 100644
--- a/services/core/java/com/android/server/MasterClearReceiver.java
+++ b/services/core/java/com/android/server/MasterClearReceiver.java
@@ -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);