Merge "Fix biometric prompt appearing above shade" into main
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
index 1ee4908..177aad9 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
@@ -552,8 +552,6 @@
         }
 
         mWakefulnessLifecycle.addObserver(this);
-        mPanelInteractionDetector.enable(
-                () -> animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED));
         if (constraintBp()) {
             // Do nothing on attachment with constraintLayout
         } else if (mPromptViewModel.getPromptKind().getValue().isBiometric()) {
@@ -566,6 +564,8 @@
         }
 
         if (!constraintBp()) {
+            mPanelInteractionDetector.enable(
+                    () -> animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED));
             updatePositionByCapability(false /* invalidate */);
         }
 
@@ -977,7 +977,7 @@
         final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT,
                 ViewGroup.LayoutParams.MATCH_PARENT,
-                WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG,
+                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                 windowFlags,
                 PixelFormat.TRANSLUCENT);
         lp.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
index fb718d3..85b5faf 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
@@ -34,6 +34,7 @@
 import android.content.IntentFilter;
 import android.graphics.Rect;
 import android.hardware.biometrics.BiometricFingerprintConstants;
+import android.hardware.biometrics.BiometricPrompt;
 import android.hardware.biometrics.SensorProperties;
 import android.hardware.display.DisplayManager;
 import android.hardware.fingerprint.FingerprintManager;
@@ -43,7 +44,9 @@
 import android.hardware.fingerprint.IUdfpsOverlayControllerCallback;
 import android.hardware.input.InputManager;
 import android.os.Build;
+import android.os.CancellationSignal;
 import android.os.Handler;
+import android.os.Looper;
 import android.os.PowerManager;
 import android.os.Trace;
 import android.os.VibrationAttributes;
@@ -382,6 +385,26 @@
             UdfpsController.this.mFingerprintManager.onUdfpsUiEvent(
                     FingerprintManager.UDFPS_UI_READY, requestId, sensorId);
         }
+
+        /**
+         * Debug to show biometric prompt
+         */
+        public void debugBiometricPrompt() {
+            final BiometricPrompt.AuthenticationCallback authenticationCallback =
+                    new BiometricPrompt.AuthenticationCallback() {
+                    };
+
+            final BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(mContext)
+                    .setTitle("Test")
+                    .setDeviceCredentialAllowed(true)
+                    .setAllowBackgroundAuthentication(true)
+                    .build();
+            final Handler handler = new Handler(Looper.getMainLooper());
+            biometricPrompt.authenticate(
+                    new CancellationSignal(),
+                    handler::post,
+                    authenticationCallback);
+        }
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsShell.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsShell.kt
index 88b9e1b..f5e3d29 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsShell.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsShell.kt
@@ -45,16 +45,13 @@
 private const val MINOR = 10F
 private const val MAJOR = 10F
 
-/**
- * Used to show and hide the UDFPS overlay with statusbar commands.
- */
+/** Used to show and hide the UDFPS overlay with statusbar commands. */
 @SysUISingleton
-class UdfpsShell @Inject constructor(
-    commandRegistry: CommandRegistry
-) : Command {
+class UdfpsShell @Inject constructor(commandRegistry: CommandRegistry) : Command {
 
     /**
      * Set in [UdfpsController.java] constructor, used to show and hide the UDFPS overlay.
+     *
      * TODO: inject after b/229290039 is resolved
      */
     var udfpsOverlayController: UdfpsController.UdfpsOverlayController? = null
@@ -76,6 +73,8 @@
             simFingerDown()
         } else if (args.size == 1 && args[0] == "simFingerUp") {
             simFingerUp()
+        } else if (args.size == 1 && args[0] == "biometricPrompt") {
+            launchBiometricPrompt()
         } else {
             invalidCommand(pw)
         }
@@ -85,8 +84,10 @@
         pw.println("Usage: adb shell cmd statusbar udfps <cmd>")
         pw.println("Supported commands:")
         pw.println("  - show <reason>")
-        pw.println("    -> supported reasons: [enroll-find-sensor, enroll-enrolling, auth-bp, " +
-                            "auth-keyguard, auth-other, auth-settings]")
+        pw.println(
+            "    -> supported reasons: [enroll-find-sensor, enroll-enrolling, auth-bp, " +
+                "auth-keyguard, auth-other, auth-settings]"
+        )
         pw.println("    -> reason otherwise defaults to unknown")
         pw.println("  - hide")
         pw.println("  - onUiReady")
@@ -94,6 +95,8 @@
         pw.println("    -> Simulates onFingerDown on sensor")
         pw.println("  - simFingerUp")
         pw.println("    -> Simulates onFingerUp on sensor")
+        pw.println("  - biometricPrompt")
+        pw.println("    -> Shows Biometric Prompt")
     }
 
     private fun invalidCommand(pw: PrintWriter) {
@@ -115,14 +118,14 @@
 
     private fun showOverlay(reason: Int) {
         udfpsOverlayController?.showUdfpsOverlay(
-                REQUEST_ID,
-                SENSOR_ID,
-                reason,
-                object : IUdfpsOverlayControllerCallback.Stub() {
-                    override fun onUserCanceled() {
-                        Log.e(TAG, "User cancelled")
-                    }
+            REQUEST_ID,
+            SENSOR_ID,
+            reason,
+            object : IUdfpsOverlayControllerCallback.Stub() {
+                override fun onUserCanceled() {
+                    Log.e(TAG, "User cancelled")
                 }
+            }
         )
     }
 
@@ -130,6 +133,9 @@
         udfpsOverlayController?.hideUdfpsOverlay(SENSOR_ID)
     }
 
+    private fun launchBiometricPrompt() {
+        udfpsOverlayController?.debugBiometricPrompt()
+    }
 
     @VisibleForTesting
     fun onUiReady() {
@@ -140,12 +146,24 @@
     fun simFingerDown() {
         val sensorBounds: Rect = udfpsOverlayController!!.sensorBounds
 
-        val downEvent: MotionEvent? = obtainMotionEvent(ACTION_DOWN, sensorBounds.exactCenterX(),
-                sensorBounds.exactCenterY(), MINOR, MAJOR)
+        val downEvent: MotionEvent? =
+            obtainMotionEvent(
+                ACTION_DOWN,
+                sensorBounds.exactCenterX(),
+                sensorBounds.exactCenterY(),
+                MINOR,
+                MAJOR
+            )
         udfpsOverlayController?.debugOnTouch(downEvent)
 
-        val moveEvent: MotionEvent? = obtainMotionEvent(ACTION_MOVE, sensorBounds.exactCenterX(),
-                sensorBounds.exactCenterY(), MINOR, MAJOR)
+        val moveEvent: MotionEvent? =
+            obtainMotionEvent(
+                ACTION_MOVE,
+                sensorBounds.exactCenterX(),
+                sensorBounds.exactCenterY(),
+                MINOR,
+                MAJOR
+            )
         udfpsOverlayController?.debugOnTouch(moveEvent)
 
         downEvent?.recycle()
@@ -156,18 +174,24 @@
     fun simFingerUp() {
         val sensorBounds: Rect = udfpsOverlayController!!.sensorBounds
 
-        val upEvent: MotionEvent? = obtainMotionEvent(ACTION_UP, sensorBounds.exactCenterX(),
-                sensorBounds.exactCenterY(), MINOR, MAJOR)
+        val upEvent: MotionEvent? =
+            obtainMotionEvent(
+                ACTION_UP,
+                sensorBounds.exactCenterX(),
+                sensorBounds.exactCenterY(),
+                MINOR,
+                MAJOR
+            )
         udfpsOverlayController?.debugOnTouch(upEvent)
         upEvent?.recycle()
     }
 
     private fun obtainMotionEvent(
-            action: Int,
-            x: Float,
-            y: Float,
-            minor: Float,
-            major: Float
+        action: Int,
+        x: Float,
+        y: Float,
+        minor: Float,
+        major: Float
     ): MotionEvent? {
         val pp = MotionEvent.PointerProperties()
         pp.id = 1
@@ -176,7 +200,21 @@
         pc.y = y
         pc.touchMinor = minor
         pc.touchMajor = major
-        return MotionEvent.obtain(0, 0, action, 1, arrayOf(pp), arrayOf(pc),
-                0, 0, 1f, 1f, 0, 0, 0, 0)
+        return MotionEvent.obtain(
+            0,
+            0,
+            action,
+            1,
+            arrayOf(pp),
+            arrayOf(pc),
+            0,
+            0,
+            1f,
+            1f,
+            0,
+            0,
+            0,
+            0
+        )
     }
 }