am 2e6d960c: am cdf00888: add option to shutdown after factory reset

* commit '2e6d960c85436b46f71a048a825c545a376fbf06':
  add option to shutdown after factory reset
This commit is contained in:
Doug Zongker
2014-03-18 20:54:27 +00:00
committed by Android Git Automerger
2 changed files with 37 additions and 7 deletions

View File

@@ -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());
}
/**

View File

@@ -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);