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

Commit a875e432 authored by Alex Johnston's avatar Alex Johnston
Browse files

Modified getActiveAdminsForAffectedUser

* Removed parent parameter from method.
* If user is a managed profile, return active admins for that user.
* If user is not a managed profile, then add all the active admins
  for that user and the parent active admins of managed profiles
  associated with it.

Bug: 149461308
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testAdminConfiguredNetworks
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetCameraDisabledLogged
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testAdminConfiguredNetworks
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testCameraDisabledOnParentLogged

Change-Id: I3a4f9dd9f43c1acd7115aede6d26bb288b110c80
parent 87ef8d49
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -4640,20 +4640,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
     * </ul>
     *
     * @param userHandle the affected user for whom to get the active admins
     * @param parent     whether the parent active admins should be included in the list of active
     *                   admins or not
     * @return the list of active admins for the affected user
     */
    private List<ActiveAdmin> getActiveAdminsForAffectedUser(int userHandle, boolean parent) {
        if (!parent) {
    @GuardedBy("getLockObject()")
    private List<ActiveAdmin> getActiveAdminsForAffectedUserLocked(int userHandle) {
        if (isManagedProfile(userHandle)) {
            return getUserDataUnchecked(userHandle).mAdminList;
        }
        ArrayList<ActiveAdmin> admins = new ArrayList<>();
        for (UserInfo userInfo : mUserManager.getProfiles(userHandle)) {
            DevicePolicyData policy = getUserData(userInfo.id);
            if (!userInfo.isManagedProfile()) {
            DevicePolicyData policy = getUserDataUnchecked(userInfo.id);
            if (userInfo.id == userHandle) {
                admins.addAll(policy.mAdminList);
            } else {
            } else if (userInfo.isManagedProfile()) {
                // For managed profiles, policies set on the parent profile will be included
                for (int i = 0; i < policy.mAdminList.size(); i++) {
                    ActiveAdmin admin = policy.mAdminList.get(i);
@@ -4661,6 +4660,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                        admins.add(admin.getParentActiveAdmin());
                    }
                }
            } else {
                Slog.w(LOG_TAG, "Unknown user type: " + userInfo);
            }
        }
        return admins;
@@ -7640,9 +7641,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                return (admin != null) && admin.disableScreenCapture;
            }
            boolean includeParent = isOrganizationOwnedDeviceWithManagedProfile()
                    && !isManagedProfile(userHandle);
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUser(userHandle, includeParent);
            final int affectedUserId = parent ? getProfileParentId(userHandle) : userHandle;
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUserLocked(affectedUserId);
            for (ActiveAdmin admin: admins) {
                if (admin.disableScreenCapture) {
                    return true;
@@ -8151,8 +8151,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    return true;
                }
            }
            final int affectedUserId = parent ? getProfileParentId(userHandle) : userHandle;
            // Return the strictest policy across all participating admins.
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUser(userHandle, parent);
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUserLocked(affectedUserId);
            // Determine whether or not the device camera is disabled for any active admins.
            for (ActiveAdmin admin: admins) {
                if (admin.disableCamera) {