在我的设备中,我已经设置了设备的密码,现在我安装了由设备策略管理器管理的应用程序。现在,当我调用此方法时
int currentPolicy = devicePolicyManager.getPasswordQuality(demoDeviceAdmin);
if(currentPolicy==262144)passwordType="Alphabetic";
else if(currentPolicy==327680)passwordType="Alphanumeric";
else if(currentPolicy==131072)passwordType="Numeric";
//if(currentPolicy==196608)passwordType="PASSWORD_QUALITY_NUMERIC_COMPLEX";
else if(currentPolicy==393216)passwordType="Complex";
else if(currentPolicy==196608)passwordType="Pattern";
else if(currentPolicy==0)passwordType="None"; 它给我的密码类型是none。现在,如果我在应用程序中通过设备策略管理器设置密码,如下所示
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);现在,如果再次获得密码质量,它会给出正确的值。第一次我认为设备策略管理器没有或存储旧的密码类型。
所以我的问题是,在通过设备策略管理器从我的应用程序设置密码之前,如何获得密码质量。
谢谢
发布于 2016-01-16 05:56:05
getPasswordQuality不会报告当前密码的质量,它只报告最低允许密码质量的策略设置。
基本上,getPasswordQuality返回使用管理员的setPasswordQuality设置的值,如果有多个管理员处于活动状态,则返回聚合值。
管理员可以通过调用DevicePolicyManager.isActivePasswordSufficient().来检查当前密码是否足够好
Keyguard使用隐藏方法setActivePasswordState将当前密码状态报告给DevicePolicyManager。
据我所知,此信息对第三方管理应用程序不可用。
如果输入的密码不正确,keyguard会调用DevicePolicyManager.reportFailedPasswordAttempt,在多次尝试失败的情况下启动出厂重置。
希望这能有所帮助。
/Marek Pola (索尼移动员工)
发布于 2016-10-26 16:16:40
对于Android6(独占)之前的设备,可以通过调用LockPatternUtils类中的隐藏函数getActivePasswordQuality()获取解锁方法类型(可以通过Java反射调用该函数)。但是对于Android6和更高版本,我还没有想出如何获得解锁方法类型。
/**
* Determine authentication method type (DAS, PIN, Password or Biometric)
*/
private String getAuthenticationMethodType(){
String LOCK_PATTERN_UTILS="com.android.internal.widget.LockPatternUtils";
String ACTIVE_PASSWORD_QUALITY="getActivePasswordQuality";
int lockProtectionLevel=0;
try{
Class <?> lockPatternUtilsClass=Class.forName(LOCK_PATTERN_UTILS);
Object lockPatternUtils=lockPatternUtilsClass.getConstructor(Context.class).newInstance(this);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
// Have not figured out how to get the unlocking method type for Android 6 and above devices. The same method will not work on Android 6. See detailed explanation below.
}else {
Method method = lockPatternUtilsClass.getMethod(ACTIVE_PASSWORD_QUALITY);
lockProtectionLevel=Integer.valueOf(String.valueOf(method.invoke(lockPatternUtils,null)));
}
}catch (Exception e){
e.printStackTrace();
}
switch (lockProtectionLevel){
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
return "PIN";
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
return "Password";
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
return "DAS";
case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
return "Biometric";
default:return "None";
}
}对于Android6,经过我到目前为止的所有测试,我发现如果我们仍然想通过getActivePasswordQuality(int userId)函数获得解锁方法,应用程序必须有权限android.permission.ACCESS_KEYGUARD_SECURE_STORAGE才能读取lockscreen.password_type,并获得解锁方法。但是,权限ACCESS_KEYGUARD_SECURE_STORAGE是一个签名权限,这意味着我们需要用厂商用来给系统签名的密钥(或者说权限)对应用进行签名,这样才能成功地将签名权限授予应用。
希望这能有所帮助。
https://stackoverflow.com/questions/34786483
复制相似问题