summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
diff options
context:
space:
mode:
authorEran Messeri <eranm@google.com>2020-11-13 13:45:49 +0000
committerEran Messeri <eranm@google.com>2020-11-30 22:28:06 +0000
commit9afde363ccae30700d679fb0147b970fe33ad12a (patch)
tree95c5a79e43e0108539a37466c48312e1f8a9f19f /packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
parent0a993aac9ad03628d0efcf47fb702c230caee93a (diff)
DPMS: Enforce password complexity in lockscreen setting
Enforce a lock screen that adheres with the required complexity set by the admin. To do this, provide a method to let the Settings code query the DevicePolicyManager for the effective password complexities that applies to a user. Bug: 165573442 Test: Manually, set complexity using TestDPC. Test: m RunSettingsRoboTests Change-Id: Ia03aebb725cacc7104d7fd765ae6ab53456e33e0
Diffstat (limited to 'packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
index 9f16d033aea5..ac20ee14ced2 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
@@ -408,7 +408,8 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
}
/**
- * Checks if an admin has enforced minimum password quality requirements on the given user.
+ * Checks if an admin has enforced minimum password quality or complexity requirements on the
+ * given user.
*
* @return EnforcedAdmin Object containing the enforced admin component and admin user details,
* or {@code null} if no quality requirements are set. If the requirements are set by
@@ -428,6 +429,30 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
}
LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
+ final int aggregatedComplexity = dpm.getAggregatedPasswordComplexityForUser(userId);
+ if (aggregatedComplexity > DevicePolicyManager.PASSWORD_COMPLEXITY_NONE) {
+ // First, check if there's a Device Owner. If so, then only it can apply password
+ // complexity requiremnts (there can be no secondary profiles).
+ final UserHandle deviceOwnerUser = dpm.getDeviceOwnerUser();
+ if (deviceOwnerUser != null) {
+ return new EnforcedAdmin(dpm.getDeviceOwnerComponentOnAnyUser(), deviceOwnerUser);
+ }
+
+ // The complexity could be enforced by a Profile Owner - either in the current user
+ // or the current user is the parent user that is affected by the profile owner.
+ for (UserInfo userInfo : UserManager.get(context).getProfiles(userId)) {
+ final ComponentName profileOwnerComponent = dpm.getProfileOwnerAsUser(userInfo.id);
+ if (profileOwnerComponent != null) {
+ return new EnforcedAdmin(profileOwnerComponent, getUserHandleOf(userInfo.id));
+ }
+ }
+
+ // Should not get here: A Device Owner or Profile Owner should be found.
+ throw new IllegalStateException(
+ String.format("Could not find admin enforcing complexity %d for user %d",
+ aggregatedComplexity, userId));
+ }
+
if (sProxy.isSeparateProfileChallengeEnabled(lockPatternUtils, userId)) {
// userId is managed profile and has a separate challenge, only consider
// the admins in that user.