OSDN Git Service

Don't call authenticate immediately after getting valid fingerprint
authorJorim Jaggi <jjaggi@google.com>
Wed, 19 Aug 2015 02:49:04 +0000 (19:49 -0700)
committerJorim Jaggi <jjaggi@google.com>
Thu, 20 Aug 2015 00:06:29 +0000 (17:06 -0700)
After gettin a callback onAuthenticationSucceded we set the
fingerprint listening state to false. However, when waking up, we
immediately started listening again because the state was false.
Protect against that by only calling authenticate only once, except
when the unlock doesn't go through because unlocking with fingerprint
is not allowed.

Also fixes some animation "jank" because of the state messup.

Bug: 23304421
Change-Id: Ic83ac0f1590dd4f8017bb55dca9e19a60cfdf99f

packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java

index 4eb6f88..40dcd0d 100644 (file)
@@ -147,6 +147,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
     private int mRingMode;
     private int mPhoneState;
     private boolean mKeyguardIsVisible;
+
+    /**
+     * If true, fingerprint was already authenticated and we don't need to start listening again
+     * until the Keyguard has been dismissed.
+     */
+    private boolean mFingerprintAlreadyAuthenticated;
     private boolean mBouncer;
     private boolean mBootCompleted;
     private boolean mUserHasAuthenticatedSinceBoot;
@@ -373,6 +379,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
 
     private void onFingerprintAuthenticated(int userId) {
         mUserFingerprintAuthenticated.put(userId, true);
+
+        // If fingerprint unlocking is allowed, this event will lead to a Keyguard dismiss or to a
+        // wake-up (if Keyguard is not showing), so we don't need to listen until Keyguard is
+        // fully gone.
+        mFingerprintAlreadyAuthenticated = isUnlockingWithFingerprintAllowed();
         for (int i = 0; i < mCallbacks.size(); i++) {
             KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
             if (cb != null) {
@@ -818,6 +829,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
                 cb.onFinishedGoingToSleep(arg1);
             }
         }
+        mFingerprintAlreadyAuthenticated = false;
         updateFingerprintListeningState();
     }
 
@@ -951,13 +963,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
     }
 
     private boolean shouldListenForFingerprint() {
-        return (mKeyguardIsVisible || !mDeviceInteractive) && !mSwitchingUser;
+        return (mKeyguardIsVisible || !mDeviceInteractive) && !mSwitchingUser
+                && !mFingerprintAlreadyAuthenticated;
     }
 
     private void startListeningForFingerprint() {
         if (DEBUG) Log.v(TAG, "startListeningForFingerprint()");
         int userId = ActivityManager.getCurrentUser();
-        if (!mFingerprintDetectionRunning && isUnlockWithFingerprintPossible(userId)) {
+        if (isUnlockWithFingerprintPossible(userId)) {
             mUserHasAuthenticatedSinceBoot = mTrustManager.hasUserAuthenticatedSinceBoot(
                     ActivityManager.getCurrentUser());
             if (mFingerprintCancelSignal != null) {
@@ -1249,6 +1262,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
                 cb.onKeyguardVisibilityChangedRaw(isShowing);
             }
         }
+        if (!isShowing) {
+            mFingerprintAlreadyAuthenticated = false;
+        }
         updateFingerprintListeningState();
     }