From d4a0af407c00182bbad7f50fcbe596e85c88ebcf Mon Sep 17 00:00:00 2001 From: Diya Bera Date: Tue, 14 Feb 2023 17:26:35 +0000 Subject: [PATCH] Remove indicator theme for non-device entry activity Test: Manual - Authenticate in keyguard, indicator theme matches dynamic theme Authenticate in biometric prompt, indicator theme does not have dynamic theme Enrollment, indicator theme does not have dynamic theme atest SideFpsControllerTest Fixes: 257824090 Change-Id: Ie706bba14bd9cab2069290ebe370d7fb82b4e4e9 --- .../KeyguardSecurityContainerController.java | 4 +- .../systemui/biometrics/SideFpsController.kt | 90 +++++++++++++++---- ...yguardSecurityContainerControllerTest.java | 30 ++++--- .../biometrics/SideFpsControllerTest.kt | 11 +++ 4 files changed, 103 insertions(+), 32 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 9fcacce311d1b..6fd2171b35ca4 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -33,6 +33,7 @@ import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.content.res.ColorStateList; import android.content.res.Configuration; +import android.hardware.biometrics.BiometricOverlayConstants; import android.hardware.biometrics.BiometricSourceType; import android.metrics.LogMaker; import android.os.UserHandle; @@ -379,7 +380,8 @@ public class KeyguardSecurityContainerController extends ViewController onOrientationChanged(reason) }, + BiometricOverlayConstants.REASON_UNKNOWN + ) + + @VisibleForTesting val orientationListener = orientationReasonListener.orientationListener @VisibleForTesting val overviewProxyListener = @@ -168,7 +174,7 @@ constructor( @BiometricOverlayConstants.ShowReason reason: Int ) = if (reason.isReasonToAutoShow(activityTaskManager)) { - show(SideFpsUiRequestSource.AUTO_SHOW) + show(SideFpsUiRequestSource.AUTO_SHOW, reason) } else { hide(SideFpsUiRequestSource.AUTO_SHOW) } @@ -198,11 +204,14 @@ constructor( } /** Shows the side fps overlay if not already shown. */ - fun show(request: SideFpsUiRequestSource) { + fun show( + request: SideFpsUiRequestSource, + @BiometricOverlayConstants.ShowReason reason: Int = BiometricOverlayConstants.REASON_UNKNOWN + ) { requests.add(request) mainExecutor.execute { if (overlayView == null) { - createOverlayForDisplay() + createOverlayForDisplay(reason) } else { Log.v(TAG, "overlay already shown") } @@ -226,13 +235,13 @@ constructor( } } - private fun onOrientationChanged() { + private fun onOrientationChanged(@BiometricOverlayConstants.ShowReason reason: Int) { if (overlayView != null) { - createOverlayForDisplay() + createOverlayForDisplay(reason) } } - private fun createOverlayForDisplay() { + private fun createOverlayForDisplay(@BiometricOverlayConstants.ShowReason reason: Int) { val view = layoutInflater.inflate(R.layout.sidefps_view, null, false) overlayView = view val display = context.display!! @@ -263,7 +272,8 @@ constructor( updateOverlayParams(display, it.bounds) } } - lottie.addOverlayDynamicColor(context) + orientationReasonListener.reason = reason + lottie.addOverlayDynamicColor(context, reason) /** * Intercepts TYPE_WINDOW_STATE_CHANGED accessibility event, preventing Talkback from @@ -418,17 +428,36 @@ private fun Display.isNaturalOrientation(): Boolean = private fun WindowInsets.hasBigNavigationBar(): Boolean = getInsets(WindowInsets.Type.navigationBars()).bottom >= 70 -private fun LottieAnimationView.addOverlayDynamicColor(context: Context) { +private fun LottieAnimationView.addOverlayDynamicColor( + context: Context, + @BiometricOverlayConstants.ShowReason reason: Int +) { fun update() { val c = context.getColor(R.color.biometric_dialog_accent) val chevronFill = context.getColor(R.color.sfps_chevron_fill) - for (key in listOf(".blue600", ".blue400")) { - addValueCallback(KeyPath(key, "**"), LottieProperty.COLOR_FILTER) { - PorterDuffColorFilter(c, PorterDuff.Mode.SRC_ATOP) + val isKeyguard = reason == REASON_AUTH_KEYGUARD + if (isKeyguard) { + for (key in listOf(".blue600", ".blue400")) { + addValueCallback(KeyPath(key, "**"), LottieProperty.COLOR_FILTER) { + PorterDuffColorFilter(c, PorterDuff.Mode.SRC_ATOP) + } + } + addValueCallback(KeyPath(".black", "**"), LottieProperty.COLOR_FILTER) { + PorterDuffColorFilter(chevronFill, PorterDuff.Mode.SRC_ATOP) + } + } else if (!isDarkMode(context)) { + addValueCallback(KeyPath(".black", "**"), LottieProperty.COLOR_FILTER) { + PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP) + } + } else if (isDarkMode(context)) { + for (key in listOf(".blue600", ".blue400")) { + addValueCallback(KeyPath(key, "**"), LottieProperty.COLOR_FILTER) { + PorterDuffColorFilter( + context.getColor(R.color.settingslib_color_blue400), + PorterDuff.Mode.SRC_ATOP + ) + } } - } - addValueCallback(KeyPath(".black", "**"), LottieProperty.COLOR_FILTER) { - PorterDuffColorFilter(chevronFill, PorterDuff.Mode.SRC_ATOP) } } @@ -439,6 +468,29 @@ private fun LottieAnimationView.addOverlayDynamicColor(context: Context) { } } +private fun isDarkMode(context: Context): Boolean { + val darkMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return darkMode == Configuration.UI_MODE_NIGHT_YES +} + +@VisibleForTesting +class OrientationReasonListener( + context: Context, + displayManager: DisplayManager, + handler: Handler, + sensorProps: FingerprintSensorPropertiesInternal, + onOrientationChanged: (reason: Int) -> Unit, + @BiometricOverlayConstants.ShowReason var reason: Int +) { + val orientationListener = + BiometricDisplayListener( + context, + displayManager, + handler, + BiometricDisplayListener.SensorType.SideFingerprint(sensorProps) + ) { onOrientationChanged(reason) } +} + /** * The source of a request to show the side fps visual indicator. This is distinct from * [BiometricOverlayConstants] which corrresponds with the reason fingerprint authentication is diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java index 075ef9df9664d..76646b3ea0ee9 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.when; import android.content.res.Configuration; import android.content.res.Resources; +import android.hardware.biometrics.BiometricOverlayConstants; import android.hardware.biometrics.BiometricSourceType; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -350,7 +351,8 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); - verify(mSideFpsController).show(SideFpsUiRequestSource.PRIMARY_BOUNCER); + verify(mSideFpsController).show(SideFpsUiRequestSource.PRIMARY_BOUNCER, + BiometricOverlayConstants.REASON_AUTH_KEYGUARD); verify(mSideFpsController, never()).hide(any()); } @@ -363,7 +365,7 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -375,7 +377,7 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -387,7 +389,7 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -395,13 +397,14 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { setupGetSecurityView(); setupConditionsToEnableSideFpsHint(); mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); - verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER); + verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER, + BiometricOverlayConstants.REASON_AUTH_KEYGUARD); reset(mSideFpsController); mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.INVISIBLE); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -416,13 +419,14 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { setupGetSecurityView(); setupConditionsToEnableSideFpsHint(); mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); - verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER); + verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER, + BiometricOverlayConstants.REASON_AUTH_KEYGUARD); reset(mSideFpsController); mKeyguardSecurityContainerController.onStartingToHide(); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -430,13 +434,14 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { setupGetSecurityView(); setupConditionsToEnableSideFpsHint(); mKeyguardSecurityContainerController.onBouncerVisibilityChanged(View.VISIBLE); - verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER); + verify(mSideFpsController, atLeastOnce()).show(SideFpsUiRequestSource.PRIMARY_BOUNCER, + BiometricOverlayConstants.REASON_AUTH_KEYGUARD); reset(mSideFpsController); mKeyguardSecurityContainerController.onPause(); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test @@ -448,7 +453,8 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onResume(0); - verify(mSideFpsController).show(SideFpsUiRequestSource.PRIMARY_BOUNCER); + verify(mSideFpsController).show(SideFpsUiRequestSource.PRIMARY_BOUNCER, + BiometricOverlayConstants.REASON_AUTH_KEYGUARD); verify(mSideFpsController, never()).hide(any()); } @@ -463,7 +469,7 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { mKeyguardSecurityContainerController.onResume(0); verify(mSideFpsController).hide(SideFpsUiRequestSource.PRIMARY_BOUNCER); - verify(mSideFpsController, never()).show(any()); + verify(mSideFpsController, never()).show(any(), anyInt()); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt index 41beada11fa97..612e55732bc12 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt @@ -266,6 +266,17 @@ class SideFpsControllerTest : SysuiTestCase() { verify(displayManager).unregisterDisplayListener(any()) } + @Test + fun testShowOverlayReasonWhenDisplayChanged() = testWithDisplay { + sideFpsController.show(SideFpsUiRequestSource.AUTO_SHOW, REASON_AUTH_KEYGUARD) + executor.runAllReady() + sideFpsController.orientationListener.onDisplayChanged(1 /* displayId */) + executor.runAllReady() + + assertThat(sideFpsController.orientationReasonListener.reason) + .isEqualTo(REASON_AUTH_KEYGUARD) + } + @Test fun testShowsAndHides() = testWithDisplay { overlayController.show(SENSOR_ID, REASON_UNKNOWN)