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))); } @@ -828,6 +849,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();