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

Commit 6bd3e660 authored by Tom Marshall's avatar Tom Marshall Committed by Steve Kondik
Browse files

Factory reset: Allow passing wipe_media to recovery

- Add plumbing pieces in target services

Change-Id: I3b6e224064055b2eef8c2909c7d36f9a76014d70
parent 6861146d
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -354,18 +354,18 @@ public class RecoverySystem {
     * @throws SecurityException if the current user is not allowed to wipe data.
     */
    public static void rebootWipeUserData(Context context) throws IOException {
        rebootWipeUserData(context, false, context.getPackageName());
        rebootWipeUserData(context, false, context.getPackageName(), false);
    }

    /** {@hide} */
    public static void rebootWipeUserData(Context context, String reason) throws IOException {
        rebootWipeUserData(context, false, reason);
        rebootWipeUserData(context, false, reason, false);
    }

    /** {@hide} */
    public static void rebootWipeUserData(Context context, boolean shutdown)
            throws IOException {
        rebootWipeUserData(context, shutdown, context.getPackageName());
        rebootWipeUserData(context, shutdown, context.getPackageName(), false);
    }

   /**
@@ -386,8 +386,8 @@ public class RecoverySystem {
     *
     * @hide
     */
    public static void rebootWipeUserData(Context context, boolean shutdown, String reason)
            throws IOException {
    public static void rebootWipeUserData(Context context, boolean shutdown, String reason,
            boolean wipeMedia) throws IOException {
        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        if (um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
            throw new SecurityException("Wiping data is not allowed for this user.");
@@ -419,7 +419,13 @@ public class RecoverySystem {
        }

        final String localeArg = "--locale=" + Locale.getDefault().toString();
        bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg);

        String cmd = "--wipe_data\n";
        if (wipeMedia) {
            cmd += "--wipe_media\n";
        }

        bootCommand(context, shutdownArg, cmd, reasonArg, localeArg);
    }

    /**
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ import java.io.IOException;
public class MasterClearReceiver extends BroadcastReceiver {
    private static final String TAG = "MasterClear";

    /* {@hide} */
    public static final String EXTRA_WIPE_MEDIA = "wipe_media";

    @Override
    public void onReceive(final Context context, final Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_REMOTE_INTENT)) {
@@ -46,7 +49,8 @@ public class MasterClearReceiver extends BroadcastReceiver {
            @Override
            public void run() {
                try {
                    RecoverySystem.rebootWipeUserData(context, shutdown, reason);
                    boolean wipeMedia = intent.getBooleanExtra(EXTRA_WIPE_MEDIA, false);
                    RecoverySystem.rebootWipeUserData(context, shutdown, reason, wipeMedia);
                    Log.wtf(TAG, "Still running after master clear?!");
                } catch (IOException e) {
                    Slog.e(TAG, "Can't perform master clear/factory reset", e);