diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 8b9a65103c6db..24f73c3ac54cf 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -8903,17 +8903,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } @Override - public ComponentName getProfileOwnerAsUser(int userHandle) { + public ComponentName getProfileOwnerAsUser(int userId) { if (!mHasFeature) { return null; } - Preconditions.checkArgumentNonnegative(userHandle, "Invalid userId"); + Preconditions.checkArgumentNonnegative(userId, "Invalid userId"); - final CallerIdentity caller = getCallerIdentity(); - Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userHandle)); + CallerIdentity caller = getCallerIdentity(); + Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userId)); synchronized (getLockObject()) { - return mOwners.getProfileOwnerComponent(userHandle); + return mOwners.getProfileOwnerComponent(userId); } } @@ -9357,19 +9357,20 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { public List listForegroundAffiliatedUsers() { checkIsDeviceOwner(getCallerIdentity()); - int userId = mInjector.binderWithCleanCallingIdentity(() -> getCurrentForegroundUserId()); + return mInjector.binderWithCleanCallingIdentity(() -> { + int userId = getCurrentForegroundUserId(); + boolean isAffiliated; + synchronized (getLockObject()) { + isAffiliated = isUserAffiliatedWithDeviceLocked(userId); + } - boolean isAffiliated; - synchronized (getLockObject()) { - isAffiliated = isUserAffiliatedWithDeviceLocked(userId); - } + if (!isAffiliated) return Collections.emptyList(); - if (!isAffiliated) return Collections.emptyList(); + List users = new ArrayList<>(1); + users.add(UserHandle.of(userId)); - List users = new ArrayList<>(1); - users.add(UserHandle.of(userId)); - - return users; + return users; + }); } protected int getProfileParentId(int userHandle) { @@ -14129,7 +14130,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } - private boolean isUserAffiliatedWithDeviceLocked(int userId) { + private boolean isUserAffiliatedWithDeviceLocked(@UserIdInt int userId) { if (!mOwners.hasDeviceOwner()) { return false; }