From 7598b91303d1085ad72eccbe04f8b68adf29f240 Mon Sep 17 00:00:00 2001 From: lbill Date: Tue, 5 Jul 2022 20:37:29 +0000 Subject: [PATCH] Set FLAG_DIM_BEHIND for Bidics Prompt window Biometric prompt used to set a background color biometric_dialog_dim_color for dim effect, however the dim background did not cover the statusbar and navigationbar regions. Use window manager approach for dim effect: - Set FLAG_DIM_BEHIND for window layout params - Set 0.5f dimAmount - Transit dimAmount when animate away Test: atest SystemUITests Test: atest com.android.systemui.biometrics.AuthContainerViewTest Test: enroll FPS, long press wifi hotsopt QS tile, then tap "Share" affordance with the QR code icon to bring up the biometric prompt Bug: 237047065 Change-Id: Icbb68406357a000a61752bd03d9337acf0eb6276 --- .../SystemUI/res/layout/auth_container_view.xml | 1 - packages/SystemUI/res/values/colors.xml | 1 - .../systemui/biometrics/AuthContainerView.java | 16 +++++++++++++++- .../systemui/biometrics/AuthContainerViewTest.kt | 10 ++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res/layout/auth_container_view.xml b/packages/SystemUI/res/layout/auth_container_view.xml index 3db01a4e7f3aa..2bd2e640127e9 100644 --- a/packages/SystemUI/res/layout/auth_container_view.xml +++ b/packages/SystemUI/res/layout/auth_container_view.xml @@ -23,7 +23,6 @@ android:id="@+id/background" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/biometric_dialog_dim_color" android:contentDescription="@string/biometric_dialog_empty_space_description"/> @*android:color/accent_device_default - #80000000 #ff757575 @color/material_dynamic_primary40 #ffd93025 diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java index bc1c5f4baceb7..c9cc3e29f68e2 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java @@ -90,6 +90,8 @@ public class AuthContainerView extends LinearLayout private static final int STATE_ANIMATING_OUT = 4; private static final int STATE_GONE = 5; + private static final float BACKGROUND_DIM_AMOUNT = 0.5f; + /** Shows biometric prompt dialog animation. */ private static final String SHOW = "show"; /** Dismiss biometric prompt dialog animation. */ @@ -754,6 +756,16 @@ public class AuthContainerView extends LinearLayout .setDuration(animateDuration) .setInterpolator(mLinearOutSlowIn) .setListener(getJankListener(this, DISMISS, animateDuration)) + .setUpdateListener(animation -> { + if (mWindowManager == null || getViewRootImpl() == null) { + Log.w(TAG, "skip updateViewLayout() for dim animation."); + return; + } + final WindowManager.LayoutParams lp = getViewRootImpl().mWindowAttributes; + lp.dimAmount = (1.0f - (Float) animation.getAnimatedValue()) + * BACKGROUND_DIM_AMOUNT; + mWindowManager.updateViewLayout(this, lp); + }) .withLayer() .start(); }); @@ -800,7 +812,8 @@ public class AuthContainerView extends LinearLayout @VisibleForTesting static WindowManager.LayoutParams getLayoutParams(IBinder windowToken, CharSequence title) { final int windowFlags = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED - | WindowManager.LayoutParams.FLAG_SECURE; + | WindowManager.LayoutParams.FLAG_SECURE + | WindowManager.LayoutParams.FLAG_DIM_BEHIND; final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, @@ -811,6 +824,7 @@ public class AuthContainerView extends LinearLayout lp.setFitInsetsTypes(lp.getFitInsetsTypes() & ~WindowInsets.Type.ime()); lp.setTitle("BiometricPrompt"); lp.accessibilityTitle = title; + lp.dimAmount = BACKGROUND_DIM_AMOUNT; lp.token = windowToken; return lp; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt index bc5a4d3d274ec..bc0d76e4a1017 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt @@ -296,6 +296,16 @@ class AuthContainerViewTest : SysuiTestCase() { assertThat((layoutParams.flags and WindowManager.LayoutParams.FLAG_SECURE) != 0).isTrue() } + @Test + fun testLayoutParams_hasDimbehindWindowFlag() { + val layoutParams = AuthContainerView.getLayoutParams(windowToken, "") + val lpFlags = layoutParams.flags + val lpDimAmount = layoutParams.dimAmount + + assertThat((lpFlags and WindowManager.LayoutParams.FLAG_DIM_BEHIND) != 0).isTrue() + assertThat(lpDimAmount).isGreaterThan(0f) + } + @Test fun testLayoutParams_excludesImeInsets() { val layoutParams = AuthContainerView.getLayoutParams(windowToken, "")