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

Commit d4a19fea authored by Eran Messeri's avatar Eran Messeri
Browse files

DPM: Allow Device Admin targeting P to set quality

If the caller is a Device Admin and it's targeting API level 28,
let it call setPasswordQuality.

Bug: 174672085
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.DeviceAdminHostSideTestApi24#testRunDeviceAdminTest
Change-Id: Ib5b8db0079f1989918e5460495cdd5a69fb106d8
parent 7bd311cf
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -3353,6 +3353,18 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                PREVENT_SETTING_PASSWORD_QUALITY_ON_PARENT, packageName, userId);
                PREVENT_SETTING_PASSWORD_QUALITY_ON_PARENT, packageName, userId);
    }
    }
    private boolean isPasswordLimitingAdminTargetingP(CallerIdentity caller) {
        if (!caller.hasAdminComponent()) {
            return false;
        }
        synchronized (getLockObject()) {
            return getActiveAdminWithPolicyForUidLocked(
                    caller.getComponentName(), DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD,
                    caller.getUid()) != null;
        }
    }
    @Override
    @Override
    public void setPasswordQuality(ComponentName who, int quality, boolean parent) {
    public void setPasswordQuality(ComponentName who, int quality, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature) {
@@ -3363,7 +3375,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        final CallerIdentity caller = getCallerIdentity(who);
        final CallerIdentity caller = getCallerIdentity(who);
        Preconditions.checkCallAuthorization(
        Preconditions.checkCallAuthorization(
                isProfileOwner(caller) || isDeviceOwner(caller) || isSystemUid(caller));
                isProfileOwner(caller) || isDeviceOwner(caller) || isSystemUid(caller)
                || isPasswordLimitingAdminTargetingP(caller));
        final boolean qualityMayApplyToParent =
        final boolean qualityMayApplyToParent =
                canSetPasswordQualityOnParent(who.getPackageName(), caller.getUserId());
                canSetPasswordQualityOnParent(who.getPackageName(), caller.getUserId());