* commit '06fe82d8e01780b7b6c16364f81f8dd75d467420': add option to shutdown after factory reset
This commit is contained in:
@@ -338,11 +338,11 @@ public class RecoverySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reboots the device and wipes the user data partition. This is
|
* Reboots the device and wipes the user data and cache
|
||||||
* sometimes called a "factory reset", which is something of a
|
* partitions. This is sometimes called a "factory reset", which
|
||||||
* misnomer because the system partition is not restored to its
|
* is something of a misnomer because the system partition is not
|
||||||
* factory state.
|
* restored to its factory state. Requires the
|
||||||
* Requires the {@link android.Manifest.permission#REBOOT} permission.
|
* {@link android.Manifest.permission#REBOOT} permission.
|
||||||
*
|
*
|
||||||
* @param context the Context to use
|
* @param context the Context to use
|
||||||
*
|
*
|
||||||
@@ -350,6 +350,28 @@ public class RecoverySystem {
|
|||||||
* fails, or if the reboot itself fails.
|
* fails, or if the reboot itself fails.
|
||||||
*/
|
*/
|
||||||
public static void rebootWipeUserData(Context context) throws IOException {
|
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();
|
final ConditionVariable condition = new ConditionVariable();
|
||||||
|
|
||||||
Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
|
Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
|
||||||
@@ -365,7 +387,13 @@ public class RecoverySystem {
|
|||||||
// Block until the ordered broadcast has completed.
|
// Block until the ordered broadcast has completed.
|
||||||
condition.block();
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,13 +37,15 @@ public class MasterClearReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean shutdown = intent.getBooleanExtra("shutdown", false);
|
||||||
|
|
||||||
Slog.w(TAG, "!!! FACTORY RESET !!!");
|
Slog.w(TAG, "!!! FACTORY RESET !!!");
|
||||||
// The reboot call is blocking, so we need to do it on another thread.
|
// The reboot call is blocking, so we need to do it on another thread.
|
||||||
Thread thr = new Thread("Reboot") {
|
Thread thr = new Thread("Reboot") {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
RecoverySystem.rebootWipeUserData(context);
|
RecoverySystem.rebootWipeUserData(context, shutdown);
|
||||||
Log.wtf(TAG, "Still running after master clear?!");
|
Log.wtf(TAG, "Still running after master clear?!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Slog.e(TAG, "Can't perform master clear/factory reset", e);
|
Slog.e(TAG, "Can't perform master clear/factory reset", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user