From 19b19cd47b5be6579bc88e43f95e39a0f742ed47 Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 21 Apr 2023 18:18:16 +0000 Subject: Always go through StatusBarKeyguardViewManager for altBouncer updates So the correct state is retained and propagated Test: atest StatusBarKeyguardViewManagerTest Fixes: 276873785 Change-Id: Iaea44ead007fcc6237c47b47d6a3d484b38ce943 --- .../interactor/AlternateBouncerInteractor.kt | 24 ++++++++----------- .../phone/StatusBarKeyguardViewManager.java | 11 ++++++++- .../phone/StatusBarKeyguardViewManagerTest.java | 27 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt index 9b94cdbfe8dc..148d4255636c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt @@ -41,17 +41,6 @@ constructor( var receivedDownTouch = false val isVisible: Flow = bouncerRepository.alternateBouncerVisible - private val keyguardStateControllerCallback: KeyguardStateController.Callback = - object : KeyguardStateController.Callback { - override fun onUnlockedChanged() { - maybeHide() - } - } - - init { - keyguardStateController.addCallback(keyguardStateControllerCallback) - } - /** * Sets the correct bouncer states to show the alternate bouncer if it can show. * @@ -102,11 +91,18 @@ constructor( return (systemClock.uptimeMillis() - bouncerRepository.lastAlternateBouncerVisibleTime) > MIN_VISIBILITY_DURATION_UNTIL_TOUCHES_DISMISS_ALTERNATE_BOUNCER_MS } - - private fun maybeHide() { + /** + * Should only be called through StatusBarKeyguardViewManager which propagates the source of + * truth to other concerned controllers. Will hide the alternate bouncer if it's no longer + * allowed to show. + * + * @return true if the alternate bouncer was newly hidden, else false. + */ + fun maybeHide(): Boolean { if (isVisibleState() && !canShowAlternateBouncerForFingerprint()) { - hide() + return hide() } + return false } companion object { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index f7646d718dc6..e2c7b580bd1f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -135,7 +135,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb private final DreamOverlayStateController mDreamOverlayStateController; @Nullable private final FoldAodAnimationController mFoldAodAnimationController; - private KeyguardMessageAreaController mKeyguardMessageAreaController; + KeyguardMessageAreaController mKeyguardMessageAreaController; private final PrimaryBouncerCallbackInteractor mPrimaryBouncerCallbackInteractor; private final PrimaryBouncerInteractor mPrimaryBouncerInteractor; private final AlternateBouncerInteractor mAlternateBouncerInteractor; @@ -426,6 +426,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mDockManager.addListener(mDockEventListener); mIsDocked = mDockManager.isDocked(); } + mKeyguardStateController.addCallback(mKeyguardStateControllerCallback); } /** Register a callback, to be invoked by the Predictive Back system. */ @@ -1554,6 +1555,14 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb || mode == KeyguardSecurityModel.SecurityMode.SimPuk; } + private KeyguardStateController.Callback mKeyguardStateControllerCallback = + new KeyguardStateController.Callback() { + @Override + public void onUnlockedChanged() { + updateAlternateBouncerShowing(mAlternateBouncerInteractor.maybeHide()); + } + }; + /** * Delegate used to send show and hide events to an alternate authentication method instead of * the regular pin/pattern/password bouncer. diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java index 4ff225cc7f3f..3fb816abf760 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java @@ -83,6 +83,7 @@ import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.SysuiStatusBarStateController; import com.android.systemui.statusbar.policy.ConfigurationController; +import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.unfold.SysUIUnfoldComponent; import com.google.common.truth.Truth; @@ -149,13 +150,15 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { private WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher; @Captor private ArgumentCaptor mBackCallbackCaptor; + @Captor + private ArgumentCaptor mKeyguardStateControllerCallback; @Before public void setUp() { MockitoAnnotations.initMocks(this); when(mContainer.findViewById(anyInt())).thenReturn(mKeyguardMessageArea); - when(mKeyguardMessageAreaFactory.create(any(KeyguardMessageArea.class))) + when(mKeyguardMessageAreaFactory.create(any())) .thenReturn(mKeyguardMessageAreaController); when(mBouncerView.getDelegate()).thenReturn(mBouncerViewDelegate); when(mBouncerViewDelegate.getBackCallback()).thenReturn(mBouncerViewDelegateBackCallback); @@ -905,4 +908,26 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { // THEN the alternateBouncer doesn't hide verify(mAlternateBouncerInteractor, never()).hide(); } + + @Test + public void onDeviceUnlocked_hideAlternateBouncerAndClearMessageArea() { + reset(mKeyguardUpdateMonitor); + reset(mKeyguardMessageAreaController); + + // GIVEN keyguard state controller callback is registered + verify(mKeyguardStateController).addCallback(mKeyguardStateControllerCallback.capture()); + + // GIVEN alternate bouncer state = not visible + when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(false); + + // WHEN the device is unlocked + mKeyguardStateControllerCallback.getValue().onUnlockedChanged(); + + // THEN the false visibility state is propagated to the keyguardUpdateMonitor + verify(mKeyguardUpdateMonitor).setAlternateBouncerShowing(eq(false)); + + // THEN message area visibility updated to FALSE with empty message + verify(mKeyguardMessageAreaController).setIsVisible(eq(false)); + verify(mKeyguardMessageAreaController).setMessage(eq("")); + } } -- cgit v1.2.3-59-g8ed1b