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

Commit 14ed6119 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

DO NOT MERGE Do not call RecoverySystem with DPMS lock held

Note DPM.wipeData() on a secondary user is now blocking, just like
it's been always blocking on the primary user.

Bug 30681079

Change-Id: Ia832bed0f22396998d6307ab46e262dae9463838
Merged-In: Ia832bed0f22396998d6307ab46e262dae9463838
parent 0a8978f0
Loading
Loading
Loading
Loading
+12 −13
Original line number Original line Diff line number Diff line
@@ -2894,7 +2894,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        return false;
        return false;
    }
    }


    void wipeDataLocked(int flags, String reason) {
    void wipeDataNoLock(int flags, String reason) {
        // If the SD card is encrypted and non-removable, we have to force a wipe.
        // If the SD card is encrypted and non-removable, we have to force a wipe.
        boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted();
        boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted();
        boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0;
        boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0;
@@ -2924,13 +2924,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            return;
            return;
        }
        }
        enforceCrossUserPermission(userHandle);
        enforceCrossUserPermission(userHandle);
        final String source;
        synchronized (this) {
        synchronized (this) {
            // This API can only be called by an active device admin,
            // This API can only be called by an active device admin,
            // so try to retrieve it to check that the caller is one.
            // so try to retrieve it to check that the caller is one.
            final ActiveAdmin admin = getActiveAdminForCallerLocked(null,
            final ActiveAdmin admin = getActiveAdminForCallerLocked(null,
                    DeviceAdminInfo.USES_POLICY_WIPE_DATA);
                    DeviceAdminInfo.USES_POLICY_WIPE_DATA);


            final String source;
            if (admin != null && admin.info != null) {
            if (admin != null && admin.info != null) {
                final ComponentName cname = admin.info.getComponent();
                final ComponentName cname = admin.info.getComponent();
                if (cname != null) {
                if (cname != null) {
@@ -2941,20 +2941,19 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            } else {
            } else {
                source = "?";
                source = "?";
            }
            }

        }
        long ident = Binder.clearCallingIdentity();
        long ident = Binder.clearCallingIdentity();
        try {
        try {
                wipeDeviceOrUserLocked(flags, userHandle,
            wipeDeviceNoLock(flags, userHandle,
                    "DevicePolicyManager.wipeData() from " + source);
                    "DevicePolicyManager.wipeData() from " + source);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(ident);
            Binder.restoreCallingIdentity(ident);
        }
        }
    }
    }
    }


    private void wipeDeviceOrUserLocked(int flags, final int userHandle, String reason) {
    private void wipeDeviceNoLock(int flags, final int userHandle, String reason) {
        if (userHandle == UserHandle.USER_OWNER) {
        if (userHandle == UserHandle.USER_OWNER) {
            wipeDataLocked(flags, reason);
            wipeDataNoLock(flags, reason);
        } else {
        } else {
            mHandler.post(new Runnable() {
            mHandler.post(new Runnable() {
                public void run() {
                public void run() {
@@ -3106,7 +3105,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            }
            }
            if (wipeData) {
            if (wipeData) {
                // Call without holding lock.
                // Call without holding lock.
                wipeDeviceOrUserLocked(0, identifier, "reportFailedPasswordAttempt()");
                wipeDeviceNoLock(0, identifier, "reportFailedPasswordAttempt()");
            }
            }
        } finally {
        } finally {
            Binder.restoreCallingIdentity(ident);
            Binder.restoreCallingIdentity(ident);