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.

Test: Manually tested wipeData() with ApiDemos, both on 1) the primary user,
2) a secondary user and 3) work profile.

Test: adb shell am instrument -e class com.android.server.devicepolicy.DevicePolicyManagerTest -w com.android.frameworks.servicestests

Bug 30681079

Change-Id: Ia832bed0f22396998d6307ab46e262dae9463838
Merged-in: Ia832bed0f22396998d6307ab46e262dae9463838
(cherry picked from commit efdec8f568)
This commit is contained in:
Makoto Onuki
2017-01-04 14:36:59 -08:00
committed by Suprabh Shukla
parent f98ed6863a
commit 2317451acc

View File

@ -4536,7 +4536,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
} }
private void wipeDataLocked(boolean wipeExtRequested, String reason) { private void wipeDataNoLock(boolean wipeExtRequested, String reason) {
if (wipeExtRequested) { if (wipeExtRequested) {
StorageManager sm = (StorageManager) mContext.getSystemService( StorageManager sm = (StorageManager) mContext.getSystemService(
Context.STORAGE_SERVICE); Context.STORAGE_SERVICE);
@ -4556,13 +4556,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
final int userHandle = mInjector.userHandleGetCallingUserId(); final int userHandle = mInjector.userHandleGetCallingUserId();
enforceFullCrossUsersPermission(userHandle); enforceFullCrossUsersPermission(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);
source = admin.info.getComponent().flattenToShortString();
final String source = admin.info.getComponent().flattenToShortString();
long ident = mInjector.binderClearCallingIdentity(); long ident = mInjector.binderClearCallingIdentity();
try { try {
@ -4577,18 +4578,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
manager.wipe(); manager.wipe();
} }
} }
boolean wipeExtRequested = (flags & WIPE_EXTERNAL_STORAGE) != 0;
wipeDeviceOrUserLocked(wipeExtRequested, userHandle,
"DevicePolicyManager.wipeData() from " + source);
} finally { } finally {
mInjector.binderRestoreCallingIdentity(ident); mInjector.binderRestoreCallingIdentity(ident);
} }
} }
final boolean wipeExtRequested = (flags & WIPE_EXTERNAL_STORAGE) != 0;
wipeDeviceNoLock(wipeExtRequested, userHandle,
"DevicePolicyManager.wipeData() from " + source);
} }
private void wipeDeviceOrUserLocked(boolean wipeExtRequested, final int userHandle, String reason) { private void wipeDeviceNoLock(boolean wipeExtRequested, final int userHandle, String reason) {
final long ident = mInjector.binderClearCallingIdentity();
try {
if (userHandle == UserHandle.USER_SYSTEM) { if (userHandle == UserHandle.USER_SYSTEM) {
wipeDataLocked(wipeExtRequested, reason); wipeDataNoLock(wipeExtRequested, reason);
} else { } else {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
@ -4611,6 +4614,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
}); });
} }
} finally {
mInjector.binderRestoreCallingIdentity(ident);
}
} }
private void sendWipeProfileNotification() { private void sendWipeProfileNotification() {
@ -4789,7 +4795,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
if (wipeData) { if (wipeData) {
// Call without holding lock. // Call without holding lock.
wipeDeviceOrUserLocked(false, identifier, wipeDeviceNoLock(false, identifier,
"reportFailedPasswordAttempt()"); "reportFailedPasswordAttempt()");
} }
} finally { } finally {