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

Commit 5c6d6941 authored by Tom Marshall's avatar Tom Marshall
Browse files

Factory reset: Allow passing wipe_media to recovery

Change-Id: I3b6e224064055b2eef8c2909c7d36f9a76014d70
parent eecc15fa
Loading
Loading
Loading
Loading
+41 −2
Original line number Diff line number Diff line
@@ -348,8 +348,10 @@ public class RecoverySystem {
     *
     * @throws IOException  if writing the recovery command file
     * fails, or if the reboot itself fails.
     *
     * @hide
     */
    public static void rebootWipeUserData(Context context) throws IOException {
    private static void doRebootWipeUserData(Context context, boolean wipeMedia) throws IOException {
        final ConditionVariable condition = new ConditionVariable();

        Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
@@ -365,7 +367,44 @@ public class RecoverySystem {
        // Block until the ordered broadcast has completed.
        condition.block();

        bootCommand(context, "--wipe_data\n--locale=" + Locale.getDefault().toString());
        String cmd = "--wipe_data\n";
        if (wipeMedia) {
            cmd += "--wipe_media\n";
        }
        cmd += "--locale=" + Locale.getDefault().toString();

        bootCommand(context, cmd);
    }

    /**
     * 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.
     *
     * @param context  the Context to use
     *
     * @throws IOException  if writing the recovery command file
     * fails, or if the reboot itself fails.
     */
    public static void rebootWipeUserData(Context context) throws IOException {
        doRebootWipeUserData(context, false);
    }

    /**
     * Reboots the device and formats the user data partition.  This is
     * like rebootWipeUserData except that it forces the data partition
     * to be formatted on datamedia devices.
     * Requires the {@link android.Manifest.permission#REBOOT} permission.
     *
     * @param context  the Context to use
     *
     * @throws IOException  if writing the recovery command file
     * fails, or if the reboot itself fails.
     */
    public static void rebootFormatUserData(Context context) throws IOException {
        doRebootWipeUserData(context, true);
    }

    /**
+8 −1
Original line number Diff line number Diff line
@@ -37,13 +37,20 @@ public class MasterClearReceiver extends BroadcastReceiver {
            }
        }

        final boolean wipeMedia = intent.getBooleanExtra("wipe_media", 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 {
                    if (wipeMedia) {
                        RecoverySystem.rebootFormatUserData(context);
                    }
                    else {
                        RecoverySystem.rebootWipeUserData(context);
                    }
                    Log.wtf(TAG, "Still running after master clear?!");
                } catch (IOException e) {
                    Slog.e(TAG, "Can't perform master clear/factory reset", e);