From eb841fc37461a324c3ab44d52e61ca163f2d34af Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Fri, 17 Mar 2023 13:59:04 +0000 Subject: [PATCH] Avoid hardcoding SYSTEM_USER to support HSUM In case of headless system user mode, first human user would not be SYSTEM_USER(user 0), so avoid harcoding for SYSTEM_USER. Bug: 265281464 Test: atest android.devicepolicy.cts.ManagedSubscriptionsPolicyTest Change-Id: I261867048a2a5b44d19ba5b34537b8d5201e4534 --- .../server/devicepolicy/DevicePolicyManagerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 782711fb4a0b2..6cfca3e1979a4 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -22741,9 +22741,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { "This policy can only be set by a profile owner on an organization-owned " + "device."); + int parentUserId = getProfileParentId(caller.getUserId()); synchronized (getLockObject()) { final ActiveAdmin admin = getProfileOwnerLocked(caller.getUserId()); - if (hasUserSetupCompleted(UserHandle.USER_SYSTEM) && !isAdminTestOnlyLocked( + if (hasUserSetupCompleted(parentUserId) && !isAdminTestOnlyLocked( admin.info.getComponent(), caller.getUserId())) { throw new IllegalStateException("Not allowed to apply this policy after setup"); } @@ -22765,7 +22766,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (policyType == ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) { final long id = mInjector.binderClearCallingIdentity(); try { - int parentUserId = getProfileParentId(caller.getUserId()); installOemDefaultDialerAndSmsApp(caller.getUserId()); updateTelephonyCrossProfileIntentFilters(parentUserId, caller.getUserId(), true); } finally {