Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19b19cd4 authored by Beverly's avatar Beverly
Browse files

Always go through StatusBarKeyguardViewManager for altBouncer updates

So the correct state is retained and propagated

Test: atest StatusBarKeyguardViewManagerTest
Fixes: 276873785
Change-Id: Iaea44ead007fcc6237c47b47d6a3d484b38ce943
parent e691f596
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -41,17 +41,6 @@ constructor(
    var receivedDownTouch = false
    val isVisible: Flow<Boolean> = 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 {
+10 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
    private final DreamOverlayStateController mDreamOverlayStateController;
    @Nullable
    private final FoldAodAnimationController mFoldAodAnimationController;
    private KeyguardMessageAreaController<AuthKeyguardMessageArea> mKeyguardMessageAreaController;
    KeyguardMessageAreaController<AuthKeyguardMessageArea> 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.
+26 −1
Original line number Diff line number Diff line
@@ -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<OnBackInvokedCallback> mBackCallbackCaptor;
    @Captor
    private ArgumentCaptor<KeyguardStateController.Callback> 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(""));
    }
}