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

Commit 74085f3c authored by Rafael Prado's avatar Rafael Prado
Browse files

Properly resolve policy in getKeyguardDisabledFeatures

Test: atest android.devicepolicy.cts.KeyguardTest   android.devicepolicy.cts.KeyguardDisabledFeaturesTest
com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetKeyguardDisabledFeaturesLogged com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testSetKeyguardDisabledFeaturesLogged com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetKeyguardDisabledSecureCameraLogged com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testSetKeyguardDisabledSecureCameraLogged with flag on and off.
Flag: android.app.admin.flags.set_keyguard_disabled_features_coexistence
Bug: 385315558
Change-Id: I89f5bac7966cc24f4466488eaef6227fe3c2b134
parent 43703516
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -9628,32 +9628,30 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                }
            }
            // TODO: with a quick glance this logic seems incomplete that it doesn't properly handle
            // the different behaviour between a profile with separate challenge vs a profile with
            // unified challenge, which was part of getActiveAdminsForLockscreenPoliciesLocked()
            // before the migration.
            if (Flags.setKeyguardDisabledFeaturesCoexistence()) {
                Integer features = mDevicePolicyEngine.getResolvedPolicy(
                        PolicyDefinition.KEYGUARD_DISABLED_FEATURES,
                        affectedUserId);
                return Binder.withCleanCallingIdentity(() -> {
                    int combinedFeatures = features == null ? 0 : features;
                    List<UserInfo> profiles = mUserManager.getProfiles(affectedUserId);
                    for (UserInfo profile : profiles) {
                        int profileId = profile.id;
                        if (profileId == affectedUserId) {
                    if (!parent && isManagedProfile(userHandle)) {
                        return mDevicePolicyEngine.getResolvedPolicy(
                                PolicyDefinition.KEYGUARD_DISABLED_FEATURES, userHandle);
                    }
                    int targetUserId = getProfileParentUserIfRequested(userHandle, parent);
                    int combinedPolicy = DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE;
                    for (UserInfo profile : mUserManager.getProfiles(targetUserId)) {
                        if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profile.id)) {
                            continue;
                        }
                        Integer profileFeatures = mDevicePolicyEngine.getResolvedPolicy(
                                PolicyDefinition.KEYGUARD_DISABLED_FEATURES,
                                profileId);
                        if (profileFeatures != null) {
                            combinedFeatures |= (profileFeatures
                                    & PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER);
                        Integer profilePolicy = mDevicePolicyEngine.getResolvedPolicy(
                                PolicyDefinition.KEYGUARD_DISABLED_FEATURES, profile.id);
                        profilePolicy = profilePolicy == null ? 0 : profilePolicy;
                        if (profile.id != userHandle) {
                            profilePolicy &= PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER;
                        }
                        combinedPolicy |= profilePolicy;
                    }
                    return combinedFeatures;
                    return combinedPolicy;
                });
            }