Fix device not locking properly on power press

A recent change to start listening for fingerprint auth sooner when the
device is going to sleep caused an issue with the device not locking
properly in some cases when the power/lock button is pressed. This
commit fixes that issue and updates the unit test to check for the
offending method call.

Test: atest KeyguardViewMediatorTest
Test: Unlock phone, press power, verify device is always locked
Test: Press power to lock, quickly touch sensor, verify device unlocks

Change-Id: I11b388b16184a6903ba7f4f5cf977e91d79efd90
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 5e38f2e..411bf9a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -833,8 +833,10 @@
             mDeviceInteractive = false;
             mGoingToSleep = true;
 
-            // Reset keyguard going away state so we can start listening for biometric auth
-            setKeyguardGoingAway(false);
+            // Reset keyguard going away state so we can start listening for fingerprint. We
+            // explicitly DO NOT want to call mStatusBarWindowController.setKeyguardGoingAway(false)
+            // here, since that will mess with the device lock state.
+            mUpdateMonitor.setKeyguardGoingAway(false);
 
             // Lock immediately based on setting if secure (user has a pin/pattern/password).
             // This also "locks" the device when not secure to provide easy access to the
@@ -1814,7 +1816,8 @@
             mHideAnimationRun = false;
             adjustStatusBarLocked();
             userActivity();
-            setKeyguardGoingAway(false);
+            mUpdateMonitor.setKeyguardGoingAway(false);
+            mStatusBarWindowController.setKeyguardGoingAway(false);
             mShowKeyguardWakeLock.release();
         }
         mKeyguardDisplayManager.show();
@@ -1846,7 +1849,8 @@
                         .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS;
             }
 
-            setKeyguardGoingAway(true);
+            mUpdateMonitor.setKeyguardGoingAway(true);
+            mStatusBarWindowController.setKeyguardGoingAway(true);
 
             // Don't actually hide the Keyguard at the moment, wait for window
             // manager until it tells us it's safe to do so with
@@ -2081,11 +2085,6 @@
         mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
     }
 
-    private void setKeyguardGoingAway(boolean goingAway) {
-        mUpdateMonitor.setKeyguardGoingAway(goingAway);
-        mStatusBarWindowController.setKeyguardGoingAway(goingAway);
-    }
-
     @Override
     public void onBootCompleted() {
         mUpdateMonitor.dispatchBootCompleted();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
index c385e8f..9312ed2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -19,6 +19,8 @@
 import static android.view.WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -88,6 +90,6 @@
         mViewMediator.start();
         mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
         verify(mUpdateMonitor).setKeyguardGoingAway(false);
-        verify(mStatusBarWindowController).setKeyguardGoingAway(false);
+        verify(mStatusBarWindowController, never()).setKeyguardGoingAway(anyBoolean());
     }
 }