SystemUI密碼解鎖後指紋識別清除次數

不積跬步無以至千里

之前也是比較發悶兒,密碼解鎖後清楚指紋識別的次數是在哪裏處理的,今天正好查找一個問題正好發現,記錄下來

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);
        }
    }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章