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
This commit is contained in:
Ayush Sharma
2023-03-17 13:59:04 +00:00
parent 89945f54ac
commit eb841fc374

View File

@@ -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 {