Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f21e41e1 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Fix policy transparency for user restrictions

Fixes: 270576347
Test: atest MixedManagedProfileOwnerTest#testPackageInstallUserRestrictions
Change-Id: Iba6946296035e4c35efb5e50b34348916a8460da
parent 9622d179
Loading
Loading
Loading
Loading
+7 −19
Original line number Original line Diff line number Diff line
@@ -16111,6 +16111,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        } else {
        } else {
            long ident = mInjector.binderClearCallingIdentity();
            long ident = mInjector.binderClearCallingIdentity();
            try {
            try {
                // TODO(b/277908283): check in the policy engine instead of calling user manager.
                List<UserManager.EnforcingUser> sources = mUserManager
                List<UserManager.EnforcingUser> sources = mUserManager
                        .getUserRestrictionSources(restriction, UserHandle.of(userId));
                        .getUserRestrictionSources(restriction, UserHandle.of(userId));
                if (sources == null) {
                if (sources == null) {
@@ -16142,27 +16143,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                }
                }
                final UserManager.EnforcingUser enforcingUser = sources.get(0);
                final UserManager.EnforcingUser enforcingUser = sources.get(0);
                final int sourceType = enforcingUser.getUserRestrictionSource();
                final int sourceType = enforcingUser.getUserRestrictionSource();
                final int enforcingUserId = enforcingUser.getUserHandle().getIdentifier();
                if (sourceType == UserManager.RESTRICTION_SOURCE_PROFILE_OWNER
                if (sourceType == UserManager.RESTRICTION_SOURCE_PROFILE_OWNER) {
                        || sourceType == UserManager.RESTRICTION_SOURCE_DEVICE_OWNER ) {
                    // Restriction was enforced by PO
                    ActiveAdmin admin = getMostProbableDPCAdminForLocalPolicy(userId);
                    final ComponentName profileOwner = mOwners.getProfileOwnerComponent(
                    if (admin != null) {
                            enforcingUserId);
                    if (profileOwner != null) {
                        result = new Bundle();
                        result.putInt(Intent.EXTRA_USER_ID, enforcingUserId);
                        result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                                profileOwner);
                        return result;
                    }
                } else if (sourceType == UserManager.RESTRICTION_SOURCE_DEVICE_OWNER) {
                    // Restriction was enforced by DO
                    final Pair<Integer, ComponentName> deviceOwner =
                            mOwners.getDeviceOwnerUserIdAndComponent();
                    if (deviceOwner != null) {
                        result = new Bundle();
                        result = new Bundle();
                        result.putInt(Intent.EXTRA_USER_ID, deviceOwner.first);
                        result.putInt(Intent.EXTRA_USER_ID, admin.getUserHandle().getIdentifier());
                        result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                        result.putParcelable(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                                deviceOwner.second);
                                admin.info.getComponent());
                        return result;
                        return result;
                    }
                    }
                } else if (sourceType == UserManager.RESTRICTION_SOURCE_SYSTEM) {
                } else if (sourceType == UserManager.RESTRICTION_SOURCE_SYSTEM) {