From 7aeb56ce6b4090fdc58bf5fc4b22516d53aa003d Mon Sep 17 00:00:00 2001 From: Oleksandr Peletskyi Date: Thu, 10 Mar 2016 11:59:22 +0100 Subject: [PATCH] Block "Screen lock" menu for Work Challenge. For Work Challenge feature "Screen lock" menu item for managed profile is completely disabled in case, if PASSWORD_QUALITY_MANAGED is set and user choose not to use the same lock. BUG: 25549437 Change-Id: I201aecb91ba8c2868e57e2014d125b149aeac377 --- res/xml/security_settings_lockscreen.xml | 2 +- .../security_settings_lockscreen_profile.xml | 2 +- .../security_settings_password_profile.xml | 2 +- res/xml/security_settings_pattern_profile.xml | 2 +- res/xml/security_settings_pin_profile.xml | 2 +- .../android/settings/SecuritySettings.java | 60 ++++++++++++++----- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/res/xml/security_settings_lockscreen.xml b/res/xml/security_settings_lockscreen.xml index a5aa7673fe7..c141fb7c74c 100644 --- a/res/xml/security_settings_lockscreen.xml +++ b/res/xml/security_settings_lockscreen.xml @@ -22,7 +22,7 @@ android:key="security_category" android:title="@string/lock_settings_title"> - - - - - index = new ArrayList(); final LockPatternUtils lockPatternUtils = new LockPatternUtils(context); - final EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet( - context, MY_USER_ID); final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); final UserManager um = UserManager.get(context); + final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID); - if (admin == null || dpm.getPasswordQuality(admin.component) != - DevicePolicyManager.PASSWORD_QUALITY_MANAGED) { + // To add option for unlock screen, user's password must not be managed and + // must not be unified with managed profile, whose password is managed. + if (!isPasswordManaged(MY_USER_ID, context, dpm) + && (profileUserId == UserHandle.USER_NULL + || lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId) + || !isPasswordManaged(profileUserId, context, dpm))) { // Add options for lock/unlock screen final int resId = getResIdForLockUnlockScreen(context, lockPatternUtils, MY_USER_ID); index.add(getSearchResource(context, resId)); } - final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID); if (profileUserId != UserHandle.USER_NULL - && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) { + && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId) + && !isPasswordManaged(profileUserId, context, dpm)) { index.add(getSearchResource(context, getResIdForLockUnlockScreen(context, lockPatternUtils, profileUserId))); } @@ -806,6 +827,13 @@ public class SecuritySettings extends SettingsPreferenceFragment return sir; } + private boolean isPasswordManaged(int userId, Context context, DevicePolicyManager dpm) { + final EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet( + context, userId); + return admin != null && dpm.getPasswordQuality(admin.component, userId) == + DevicePolicyManager.PASSWORD_QUALITY_MANAGED; + } + @Override public List getRawDataToIndex(Context context, boolean enabled) { final List result = new ArrayList();