Add getProfileOwnerNameUnchecked private method and use in manageUserUnchecked

Skip check for canManageUser.

Test: manual: download and install TestDPC
adb unroot && adb shell dpm set-device-owner --user 0 com.afwsamples.testdpc/.DeviceAdminReceiver
Fixes: 176107119

Change-Id: Ic00afaffc58a567490fa8fb3b8c66a9569e6333b
This commit is contained in:
Yan Zhu
2021-01-07 20:28:43 -08:00
parent dd0180a142
commit 63f7e2883b

View File

@@ -8401,7 +8401,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return null;
}
Preconditions.checkCallAuthorization(canManageUsers(getCallerIdentity()));
return getProfileOwnerNameUnchecked(userHandle);
}
private String getProfileOwnerNameUnchecked(int userHandle) {
ComponentName profileOwner = getProfileOwnerAsUser(userHandle);
if (profileOwner == null) {
return null;
@@ -9707,7 +9710,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
// Set admin.
setActiveAdmin(profileOwner, /* refreshing= */ true, userId);
final String ownerName = getProfileOwnerName(Process.myUserHandle().getIdentifier());
final String ownerName = getProfileOwnerNameUnchecked(
Process.myUserHandle().getIdentifier());
setProfileOwner(profileOwner, ownerName, userId);
synchronized (getLockObject()) {