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

Commit 4510a9d3 authored by Azhara Assanova's avatar Azhara Assanova
Browse files

Update the hierarchy of enforcing admins in DPMS

Supervision should always be higher than DPC.

Tests will be added in a follow up change once the supervision role can
be mocked in tests.

Bug: 392057517
Test: presubmit
Flag: EXEMPT bug fix
Change-Id: Ia734c8085470a384233d30e895476163037315b8
parent 2afd4e3a
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -275,6 +275,7 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STR
import static com.android.server.SystemTimeZone.TIME_ZONE_CONFIDENCE_HIGH;
import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS;
import static com.android.server.devicepolicy.DevicePolicyEngine.DEFAULT_POLICY_SIZE_LIMIT;
import static com.android.server.devicepolicy.DevicePolicyEngine.SYSTEM_SUPERVISION_ROLE;
import static com.android.server.devicepolicy.DevicePolicyStatsLog.DEVICE_POLICY_MANAGEMENT_MODE;
import static com.android.server.devicepolicy.DevicePolicyStatsLog.DEVICE_POLICY_MANAGEMENT_MODE__MANAGEMENT_MODE__COPE;
import static com.android.server.devicepolicy.DevicePolicyStatsLog.DEVICE_POLICY_MANAGEMENT_MODE__MANAGEMENT_MODE__DEVICE_OWNER;
@@ -16231,6 +16232,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        return null;
    }
    /**
     * When multiple admins enforce a policy, this method returns an admin according to this order:
     * 1. Supervision
     * 2. DPC
     *
     * Otherwise, it returns any other admin.
     */
    private android.app.admin.EnforcingAdmin getEnforcingAdminInternal(int userId,
            String identifier) {
        Objects.requireNonNull(identifier);
@@ -16239,16 +16247,22 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        if (admins.isEmpty()) {
            return null;
        }
        final EnforcingAdmin admin;
        if (admins.size() == 1) {
            admin = admins.iterator().next();
        } else {
            return admins.iterator().next().getParcelableAdmin();
        }
        Optional<EnforcingAdmin> supervision = admins.stream()
                .filter(a -> a.hasAuthority(
                        EnforcingAdmin.getRoleAuthorityOf(SYSTEM_SUPERVISION_ROLE)))
                .findFirst();
        if (supervision.isPresent()) {
            return supervision.get().getParcelableAdmin();
        }
        Optional<EnforcingAdmin> dpc = admins.stream()
                .filter(a -> a.hasAuthority(EnforcingAdmin.DPC_AUTHORITY)).findFirst();
            admin = dpc.orElseGet(() -> admins.stream().findFirst().get());
        if (dpc.isPresent()) {
            return dpc.get().getParcelableAdmin();
        }
        return admin == null ? null : admin.getParcelableAdmin();
        return admins.iterator().next().getParcelableAdmin();
    }
    private <V> Set<EnforcingAdmin> getEnforcingAdminsForIdentifier(int userId, String identifier) {