不积跬步无以至千里
之前也是比较发闷儿,密码解锁后清楚指纹识别的次数是在哪里处理的,今天正好查找一个问题正好发现,记录下来
1.调用密码验证流程
代码路径:frameworks/base/services/core/java/com/android/server/locksettings/LockSettingsService.java
/**
* Verify user credential and unlock the user. Fix pattern bug by deprecating the old base zero
* format.
*/
private VerifyCredentialResponse doVerifyCredential(String credential, int credentialType,
boolean hasChallenge, long challenge, int userId,
ICheckCredentialProgressCallback progressCallback) throws RemoteException {
if (TextUtils.isEmpty(credential)) {
throw new IllegalArgumentException("Credential can't be null or empty");
}
...
response = verifyCredential(userId, storedHash, credentialToVerify,
hasChallenge, challenge, progressCallback);
if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_OK) {
mStrongAuth.reportSuccessfulStrongAuthUnlock(userId);
if (shouldReEnrollBaseZero) {
setLockCredentialInternal(credential, storedHash.type, credentialToVerify,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
}
}
return response;
}
这里是通过密码验证的流程中,当验证成功了VerifyCredentialResponse.RESPONSE_OK,调用了reportSuccessfulStrongAuthUnlock.
2.上报强解锁成功
代码路径:frameworks/base/services/core/java/com/android/server/locksettings/LockSettingsStrongAuth.java
public void reportSuccessfulStrongAuthUnlock(int userId) {
if (mFingerprintManager != null) {
byte[] token = null; /* TODO: pass real auth token once fp HAL supports it */
mFingerprintManager.resetTimeout(token);
}
final int argNotUsed = 0;
mHandler.obtainMessage(MSG_SCHEDULE_STRONG_AUTH_TIMEOUT, userId, argNotUsed).sendToTarget();
}
这里调用了mFingerprintManager.resetTimeout(token);
3.指纹识别外部接口
代码路径:frameworks/base/core/java/android/hardware/fingerprint/FingerprintManager.java
/**
* Reset the lockout timer when asked to do so by keyguard.
*
* @param token an opaque token returned by password confirmation.
*
* @hide
*/
public void resetTimeout(byte[] token) {
if (mService != null) {
try {
mService.resetTimeout(token);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} else {
Log.w(TAG, "resetTimeout(): Service not connected!");
}
}
4.去重置指纹解锁次数
代码路径:frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java
这里调用了mService.resetTimeout(token);
@Override // Binder call
public void resetTimeout(byte [] token) {
checkPermission(RESET_FINGERPRINT_LOCKOUT);
// TODO: confirm security token when we move timeout management into the HAL layer.
mHandler.post(mResetFailedAttemptsRunnable);
}
所对应的Runnable
private final Runnable mResetFailedAttemptsRunnable = new Runnable() {
@Override
public void run() {
resetFailedAttempts(true /* clearAttemptCounter */);
}
};
清除指纹失败的尝试次数
// attempt counter should only be cleared when Keyguard goes away or when
// a fingerprint is successfully authenticated
protected void resetFailedAttempts(boolean clearAttemptCounter) {
if (DEBUG && getLockoutMode() != AuthenticationClient.LOCKOUT_NONE) {
Slog.v(TAG, "Reset fingerprint lockout, clearAttemptCounter=" + clearAttemptCounter);
}
if (clearAttemptCounter) {
mFailedAttempts = 0;
}
mTimedLockoutCleared = true;
// If we're asked to reset failed attempts externally (i.e. from Keyguard),
// the alarm might still be pending; remove it.
cancelLockoutReset();
notifyLockoutResetMonitors();
}
这次就知道了.
话外篇:(封装指纹清楚次数方法)
所以咱们也可以在KeyguardUpdateMonitor中封装一个清楚指纹次数的方法,因为指纹的更新认证状态都是在这个类里实现的,因此封装成此方法,如下(自测有效):
public void reportSuccessfulFingerprintAttempt() {
if (mFpm != null) {
byte[] token = null; /* TODO: pass real auth token once fp HAL supports it */
mFpm.resetTimeout(token);
}
}