a
判断是否已安装facelock的方法
// Check wheather facelock is installed
public boolean isBiometricWeakInstalled() {
// 1st Have installed app com.android.facelock
PackageManager pm = mContext.getPackageManager();
try {
pm.getPackageInfo("com.android.facelock", PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
// 2nd Hava feature of front camera
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
return false;
}
// 3nd No admin disable camera
if (getDevicePolicyManager().getCameraDisabled(null, getCurrentOrCallingUserId())) {
return false;
}
return true;
}
判断当前锁屏方式是否在使用face lock或者voicd lock(根据数据库中的lockscreen.password_type)
//return true if the lockscreen method is set to biometric weak
public boolean usingBiometricWeak() {
// 数据库中lockscreen.password_type的值是否为PASSWORD_QUALITY_BIOMETRIC_WEAK
int quality = (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
}
public boolean usingVoiceWeak() {
//feature option需要打开
if (FeatureOption.MTK_VOICE_UNLOCK_SUPPORT) {
int quality = (int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
return quality == DevicePolicyManager.PASSWORD_QUALITY_VOICE_WEAK;
} else {
return false;
}
}
判断是否已保存过pattern或者password(根据相关文件是否存在:gesture.key和password.key)
//检查是否存在这个文件:/data/system/gesture.key
public boolean savedPatternExists() {
try {
return getLockSettings().havePattern(getCurrentOrCallingUserId());
} catch (RemoteException re) {
return false;
}
}
//检查是否存在这个文件:/data/system/password.key
public boolean savedPasswordExists() {
try {
return getLockSettings().havePassword(getCurrentOrCallingUserId());
} catch (RemoteException re) {
return false;
}
}
判断图案锁屏是否已开启
public boolean isLockPatternEnabled() {
//lockscreen.password_type_alternate
final boolean backupEnabled = getLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING)
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
//1st gesture.key文件已保存
//2nd lock_pattern_autolock = 1
//3nd lockscreen.password_type = PASSWORD_QUALITY_SOMETHING 或者 正在使用face/voice lock且允许交替
return savedPatternExists()
&& getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false)
&& (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING)
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING ||
((usingBiometricWeak() || usingVoiceWeak()) && backupEnabled)); /// M: VoiceUnlock
}