Enforce password complexity in lockscreen setting
Enforce a lock screen that adheres with the required complexity set by the admin. This is done by querying the DevicePolicyManager for the complexity set for the given user, and merging it with the complexity from the "change lock screen" intent (if any). If the admin sets a higher complexity requirement than the app triggering the lock screen change request, then the admin-set complexity is enforced and the user is not shown information about the requesting app. Bug: 165573442 Test: Manually, set complexity using TestDPC and see it applies. Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.password.ChooseLockGenericTest Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.password.ChooseLockPasswordTest Change-Id: If3f24f7430bdcbcd34265339f7d2a1ff82a44fc1
This commit is contained in:
@@ -18,19 +18,31 @@ package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.LockscreenCredential;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Implements(LockPatternUtils.class)
|
||||
public class ShadowLockPatternUtils {
|
||||
|
||||
private static boolean sDeviceEncryptionEnabled;
|
||||
private static Map<Integer, Integer> sUserToComplexityMap = new HashMap<>();
|
||||
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sUserToComplexityMap.clear();
|
||||
sDeviceEncryptionEnabled = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected boolean hasSecureLockScreen() {
|
||||
@@ -76,4 +88,18 @@ public class ShadowLockPatternUtils {
|
||||
protected boolean checkPasswordHistory(byte[] passwordToCheck, byte[] hashFactor, int userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public @DevicePolicyManager.PasswordComplexity int getRequestedPasswordComplexity(int userId) {
|
||||
return sUserToComplexityMap.getOrDefault(userId,
|
||||
DevicePolicyManager.PASSWORD_COMPLEXITY_NONE);
|
||||
}
|
||||
|
||||
public static void setRequiredPasswordComplexity(int userId, int complexity) {
|
||||
sUserToComplexityMap.put(userId, complexity);
|
||||
}
|
||||
|
||||
public static void setRequiredPasswordComplexity(int complexity) {
|
||||
setRequiredPasswordComplexity(UserHandle.myUserId(), complexity);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user