Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06fe82d8 authored by Doug Zongker's avatar Doug Zongker Committed by Android Git Automerger
Browse files

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

* commit '2e6d960c':
  add option to shutdown after factory reset
parents a2a13718 2e6d960c
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
@@ -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());
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -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);