Fixed a bug where a fingerprint animation was not running

Previously the fingerprint animation would not run
when we successfully unlocked with the fingerprint,
because we were checking for the wrong state.

Bug: 22483380
Change-Id: I8d3ec303a43323431b8866df29ddd6d668edc1ed
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java
index 23bd238..85da298 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -308,7 +308,8 @@
     boolean showNextSecurityScreenOrFinish(boolean authenticated) {
         if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
         boolean finish = false;
-        if (mUpdateMonitor.getUserHasTrust(KeyguardUpdateMonitor.getCurrentUser())) {
+        if (mUpdateMonitor.getUserCanSkipBouncer(
+                KeyguardUpdateMonitor.getCurrentUser())) {
             finish = true;
         } else if (SecurityMode.None == mCurrentSecuritySelection) {
             SecurityMode securityMode = mSecurityModel.getSecurityMode();
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
index 6574e4e..9e5644e 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -455,9 +455,12 @@
                     & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0;
     }
 
+    public boolean getUserCanSkipBouncer(int userId) {
+        return getUserHasTrust(userId) || mUserFingerprintAuthenticated.get(userId);
+    }
+
     public boolean getUserHasTrust(int userId) {
-        return !isTrustDisabled(userId) && mUserHasTrust.get(userId)
-                || mUserFingerprintAuthenticated.get(userId);
+        return !isTrustDisabled(userId) && mUserHasTrust.get(userId);
     }
 
     public boolean getUserTrustIsManaged(int userId) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java
index 937615a..61695b2 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/CastTile.java
@@ -92,7 +92,8 @@
 
     @Override
     protected void handleUpdateState(BooleanState state, Object arg) {
-        state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing() && !mKeyguard.isTrusted());
+        state.visible = !mKeyguard.isSecure() || !mKeyguard.isShowing()
+                || mKeyguard.canSkipBouncer();
         state.label = mContext.getString(R.string.quick_settings_cast_title);
         state.value = false;
         state.autoMirrorDrawable = false;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index 815e123..91adc460 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -18,7 +18,6 @@
 
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
-import android.app.Application;
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
@@ -30,8 +29,6 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Configuration;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.InsetDrawable;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.IBinder;
@@ -255,10 +252,10 @@
 
     private Intent getCameraIntent() {
         KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
-        boolean currentUserHasTrust = updateMonitor.getUserHasTrust(
+        boolean canSkipBouncer = updateMonitor.getUserCanSkipBouncer(
                 KeyguardUpdateMonitor.getCurrentUser());
         boolean secure = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser());
-        return (secure && !currentUserHasTrust) ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
+        return (secure && !canSkipBouncer) ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
     }
 
     private void updateCameraVisibility() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
index 6bcb766..9e2ce15 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java
@@ -214,7 +214,7 @@
         } else if (oldState == STATE_FINGERPRINT_ERROR && newState == STATE_FINGERPRINT) {
             return R.drawable.lockscreen_fingerprint_error_state_to_fp_animation;
         } else if (oldState == STATE_FINGERPRINT && newState == STATE_LOCK_OPEN
-                && !mUnlockMethodCache.isCurrentlyInsecure()) {
+                && !mUnlockMethodCache.isTrusted()) {
             return R.drawable.lockscreen_fingerprint_draw_off_animation;
         } else if (newState == STATE_FINGERPRINT && !oldScreenOn && screenOn) {
             return R.drawable.lockscreen_fingerprint_draw_on_animation;
@@ -226,7 +226,7 @@
     private int getState() {
         boolean fingerprintRunning =
                 KeyguardUpdateMonitor.getInstance(mContext).isFingerprintDetectionRunning();
-        if (mUnlockMethodCache.isCurrentlyInsecure()) {
+        if (mUnlockMethodCache.canSkipBouncer()) {
             return STATE_LOCK_OPEN;
         } else if (mTransientFpError) {
             return STATE_FINGERPRINT_ERROR;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 88aa071..cc71aeb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -2001,7 +2001,7 @@
     }
 
     public boolean isKeyguardCurrentlySecure() {
-        return !mUnlockMethodCache.isCurrentlyInsecure();
+        return !mUnlockMethodCache.canSkipBouncer();
     }
 
     public void setPanelExpanded(boolean isExpanded) {
@@ -3051,20 +3051,20 @@
         boolean isOccluded = mStatusBarKeyguardViewManager.isOccluded();
         boolean isBouncerShowing = mStatusBarKeyguardViewManager.isBouncerShowing();
         boolean isSecure = mUnlockMethodCache.isMethodSecure();
-        boolean isCurrentlyInsecure = mUnlockMethodCache.isCurrentlyInsecure();
+        boolean canSkipBouncer = mUnlockMethodCache.canSkipBouncer();
         int stateFingerprint = getLoggingFingerprint(mState,
                 isShowing,
                 isOccluded,
                 isBouncerShowing,
                 isSecure,
-                isCurrentlyInsecure);
+                canSkipBouncer);
         if (stateFingerprint != mLastLoggedStateFingerprint) {
             EventLogTags.writeSysuiStatusBarState(mState,
                     isShowing ? 1 : 0,
                     isOccluded ? 1 : 0,
                     isBouncerShowing ? 1 : 0,
                     isSecure ? 1 : 0,
-                    isCurrentlyInsecure ? 1 : 0);
+                    canSkipBouncer ? 1 : 0);
             mLastLoggedStateFingerprint = stateFingerprint;
         }
     }
@@ -3668,7 +3668,7 @@
 
     public void onTrackingStopped(boolean expand) {
         if (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED) {
-            if (!expand && !mUnlockMethodCache.isCurrentlyInsecure()) {
+            if (!expand && !mUnlockMethodCache.canSkipBouncer()) {
                 showBouncer();
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index bacf890..6816399 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -105,7 +105,7 @@
 
     public void onTrackingStarted() {
         mExpanding = true;
-        mDarkenWhileDragging = !mUnlockMethodCache.isCurrentlyInsecure();
+        mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer();
     }
 
     public void onExpandingFinished() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
index 66d71f6..6fc15a8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java
@@ -39,9 +39,10 @@
     /** Whether the user configured a secure unlock method (PIN, password, etc.) */
     private boolean mSecure;
     /** Whether the unlock method is currently insecure (insecure method or trusted environment) */
-    private boolean mCurrentlyInsecure;
+    private boolean mCanSkipBouncer;
     private boolean mTrustManaged;
     private boolean mFaceUnlockRunning;
+    private boolean mTrusted;
 
     private UnlockMethodCache(Context ctx) {
         mLockPatternUtils = new LockPatternUtils(ctx);
@@ -64,11 +65,15 @@
         return mSecure;
     }
 
+    public boolean isTrusted() {
+        return mTrusted;
+    }
+
     /**
-     * @return whether the lockscreen is currently insecure, i. e. the bouncer won't be shown
+     * @return whether the lockscreen is currently insecure, and the bouncer won't be shown
      */
-    public boolean isCurrentlyInsecure() {
-        return mCurrentlyInsecure;
+    public boolean canSkipBouncer() {
+        return mCanSkipBouncer;
     }
 
     public void addListener(OnUnlockMethodChangedListener listener) {
@@ -82,15 +87,17 @@
     private void update(boolean updateAlways) {
         int user = KeyguardUpdateMonitor.getCurrentUser();
         boolean secure = mLockPatternUtils.isSecure(user);
-        boolean currentlyInsecure = !secure ||  mKeyguardUpdateMonitor.getUserHasTrust(user);
+        boolean canSkipBouncer = !secure ||  mKeyguardUpdateMonitor.getUserCanSkipBouncer(user);
         boolean trustManaged = mKeyguardUpdateMonitor.getUserTrustIsManaged(user);
+        boolean trusted = mKeyguardUpdateMonitor.getUserHasTrust(user);
         boolean faceUnlockRunning = mKeyguardUpdateMonitor.isFaceUnlockRunning(user)
                 && trustManaged;
-        boolean changed = secure != mSecure || currentlyInsecure != mCurrentlyInsecure ||
+        boolean changed = secure != mSecure || canSkipBouncer != mCanSkipBouncer ||
                 trustManaged != mTrustManaged  || faceUnlockRunning != mFaceUnlockRunning;
         if (changed || updateAlways) {
             mSecure = secure;
-            mCurrentlyInsecure = currentlyInsecure;
+            mCanSkipBouncer = canSkipBouncer;
+            mTrusted = trusted;
             mTrustManaged = trustManaged;
             mFaceUnlockRunning = faceUnlockRunning;
             notifyListeners();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java
index d4eb553..d907b00 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java
@@ -36,7 +36,7 @@
     private int mCurrentUser;
     private boolean mShowing;
     private boolean mSecure;
-    private boolean mTrusted;
+    private boolean mCanSkipBouncer;
 
     private boolean mListening;
 
@@ -47,7 +47,7 @@
             @Override
             public void onUserSwitched(int newUserId) {
                 mCurrentUser = newUserId;
-                updateTrustedState();
+                updateCanSkipBouncerState();
             }
         };
     }
@@ -57,7 +57,7 @@
         if (mCallbacks.size() != 0 && !mListening) {
             mListening = true;
             mCurrentUser = ActivityManager.getCurrentUser();
-            updateTrustedState();
+            updateCanSkipBouncerState();
             mKeyguardUpdateMonitor.registerCallback(this);
             mUserTracker.startTracking();
         }
@@ -79,8 +79,8 @@
         return mSecure;
     }
 
-    public boolean isTrusted() {
-        return mTrusted;
+    public boolean canSkipBouncer() {
+        return mCanSkipBouncer;
     }
 
     public void notifyKeyguardState(boolean showing, boolean secure) {
@@ -92,12 +92,12 @@
 
     @Override
     public void onTrustChanged(int userId) {
-        updateTrustedState();
+        updateCanSkipBouncerState();
         notifyKeyguardChanged();
     }
 
-    private void updateTrustedState() {
-        mTrusted = mKeyguardUpdateMonitor.getUserHasTrust(mCurrentUser);
+    private void updateCanSkipBouncerState() {
+        mCanSkipBouncer = mKeyguardUpdateMonitor.getUserCanSkipBouncer(mCurrentUser);
     }
 
     private void notifyKeyguardChanged() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
index 41fc967..6fabe9b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
@@ -412,7 +412,7 @@
         public int getCount() {
             boolean secureKeyguardShowing = mController.mKeyguardMonitor.isShowing()
                     && mController.mKeyguardMonitor.isSecure()
-                    && !mController.mKeyguardMonitor.isTrusted();
+                    && !mController.mKeyguardMonitor.canSkipBouncer();
             if (!secureKeyguardShowing) {
                 return mController.mUsers.size();
             }