Not bypassing the lockscreen anymore when the user has pulled down

Previously we would bypass the lockscreen even if the user has
already pulled down.

Bug: 134094877
Test: atest SystemUITests
Change-Id: Ic86f345a53da83a111ace2ede86648596c3ad982
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
index aa78a5d..35df7d92 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
@@ -163,6 +163,7 @@
         mHandler = handler;
         mWakeUpDelay = wakeUpDelay;
         mKeyguardBypassController = keyguardBypassController;
+        mKeyguardBypassController.setUnlockController(this);
     }
 
     public void setStatusBarKeyguardViewManager(
@@ -234,6 +235,14 @@
         }
         mMetricsLogger.write(new LogMaker(MetricsEvent.BIOMETRIC_AUTH)
                 .setType(MetricsEvent.TYPE_SUCCESS).setSubtype(toSubtype(biometricSourceType)));
+        boolean unlockAllowed = mKeyguardBypassController.onBiometricAuthenticated(
+                biometricSourceType);
+        if (unlockAllowed) {
+            startWakeAndUnlock(biometricSourceType);
+        }
+    }
+
+    private void startWakeAndUnlock(BiometricSourceType biometricSourceType) {
         startWakeAndUnlock(calculateMode(biometricSourceType));
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
index 9cdb2cd..b6ba369 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
@@ -16,8 +16,6 @@
 
 package com.android.systemui.statusbar.phone;
 
-import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
-
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt
index 124206a..9bbe4be 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt
@@ -17,17 +17,22 @@
 package com.android.systemui.statusbar.phone
 
 import android.content.Context
+import android.hardware.biometrics.BiometricSourceType
 import android.hardware.face.FaceManager
 import android.provider.Settings
 import com.android.keyguard.KeyguardUpdateMonitor
+import com.android.systemui.plugins.statusbar.StatusBarStateController
+import com.android.systemui.statusbar.StatusBarState
 import com.android.systemui.tuner.TunerService
-
 import javax.inject.Inject
 import javax.inject.Singleton
 
 @Singleton
 class KeyguardBypassController {
 
+    private val unlockMethodCache: UnlockMethodCache
+    private val statusBarStateController: StatusBarStateController
+
     /**
      * If face unlock dismisses the lock screen or keeps user on keyguard for the current user.
      */
@@ -35,11 +40,13 @@
         get() = field && unlockMethodCache.isUnlockingWithFacePossible
         private set
 
-    private val unlockMethodCache: UnlockMethodCache
+    lateinit var unlockController: BiometricUnlockController
 
     @Inject
-    constructor(context: Context, tunerService: TunerService) {
+    constructor(context: Context, tunerService: TunerService,
+                statusBarStateController: StatusBarStateController) {
         unlockMethodCache = UnlockMethodCache.getInstance(context)
+        this.statusBarStateController = statusBarStateController
         val faceManager = context.getSystemService(FaceManager::class.java)
         if (faceManager?.isHardwareDetected != true) {
             return
@@ -58,4 +65,18 @@
             }
         }, Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD)
     }
+
+    /**
+     * Notify that the biometric unlock has happened.
+     *
+     * @return false if we can not wake and unlock right now
+     */
+    fun onBiometricAuthenticated(biometricSourceType: BiometricSourceType): Boolean {
+        if (bypassEnabled && statusBarStateController.state != StatusBarState.KEYGUARD) {
+            // We're bypassing but not actually on the lockscreen, the user should decide when
+            // to unlock
+            return false
+        }
+        return true
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
index eb3f56a..3d49d58 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java
@@ -81,6 +81,7 @@
         when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
         when(mUpdateMonitor.isDeviceInteractive()).thenReturn(true);
         when(mUnlockMethodCache.isUnlockingWithFacePossible()).thenReturn(true);
+        when(mKeyguardBypassController.onBiometricAuthenticated(any())).thenReturn(true);
         mContext.addMockSystemService(PowerManager.class, mPowerManager);
         mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager);
         mDependency.injectTestDependency(StatusBarWindowController.class,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
index e92dd4c..747411a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
@@ -112,7 +112,7 @@
         mDependency.injectMockDependency(ConfigurationController.class);
         mDependency.injectMockDependency(ZenModeController.class);
         KeyguardBypassController bypassController = new KeyguardBypassController(mContext,
-                mock(TunerService.class));
+                mock(TunerService.class), mStatusBarStateController);
         NotificationWakeUpCoordinator coordinator =
                 new NotificationWakeUpCoordinator(mContext,
                         mock(HeadsUpManagerPhone.class),