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

Commit 94e0c730 authored by Matt Pietal's avatar Matt Pietal
Browse files

Consolidate occlusion events into KeyguardStateController

Use KeyguardStateController as the source of truth for occlusion. Make
sure events get triggered when occlusion changes as well as showing
states.

Fixes: 226626262
Test: atest CentralSurfacesTest StatusBarKeyguardViewManagerTest
Change-Id: I01a9e802c8bfffea98df12d6876c536a4f6134aa
parent b24001b1
Loading
Loading
Loading
Loading
+12 −16
Original line number Diff line number Diff line
@@ -359,6 +359,16 @@ public class CentralSurfaces extends CoreStartable implements
    private float mTransitionToFullShadeProgress = 0f;
    private NotificationListContainer mNotifListContainer;

    private final KeyguardStateController.Callback mKeyguardStateControllerCallback =
            new KeyguardStateController.Callback() {
                @Override
                public void onKeyguardShowingChanged() {
                    boolean occluded = mKeyguardStateController.isOccluded();
                    mStatusBarHideIconsForBouncerManager.setIsOccludedAndTriggerUpdate(occluded);
                    mScrimController.setKeyguardOccluded(occluded);
                }
            };

    void onStatusBarWindowStateChanged(@WindowVisibleState int state) {
        updateBubblesVisibility();
        mStatusBarWindowState = state;
@@ -655,7 +665,6 @@ public class CentralSurfaces extends CoreStartable implements
    private int mLastLoggedStateFingerprint;
    private boolean mTopHidesStatusBar;
    private boolean mStatusBarWindowHidden;
    private boolean mIsOccluded;
    private boolean mIsLaunchingActivityOverLockscreen;

    private final UserSwitcherController mUserSwitcherController;
@@ -1002,7 +1011,6 @@ public class CentralSurfaces extends CoreStartable implements
            mCommandQueue.setIcon(result.mIcons.keyAt(i), result.mIcons.valueAt(i));
        }


        if (DEBUG) {
            Log.d(TAG, String.format(
                    "init: icons=%d disabled=0x%08x lights=0x%08x imeButton=0x%08x",
@@ -1036,7 +1044,6 @@ public class CentralSurfaces extends CoreStartable implements
        mKeyguardStateController.addCallback(new KeyguardStateController.Callback() {
            @Override
            public void onUnlockedChanged() {
                updateKeyguardState();
                logStateToEventlog();
            }
        });
@@ -1599,6 +1606,7 @@ public class CentralSurfaces extends CoreStartable implements
                mBiometricUnlockController,
                mStackScroller,
                mKeyguardBypassController);
        mKeyguardStateController.addCallback(mKeyguardStateControllerCallback);
        mKeyguardIndicationController
                .setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
        mBiometricUnlockController.setKeyguardViewController(mStatusBarKeyguardViewManager);
@@ -1853,13 +1861,7 @@ public class CentralSurfaces extends CoreStartable implements
     * @return whether the keyguard is currently occluded
     */
    public boolean isOccluded() {
        return mIsOccluded;
    }

    public void setOccluded(boolean occluded) {
        mIsOccluded = occluded;
        mStatusBarHideIconsForBouncerManager.setIsOccludedAndTriggerUpdate(occluded);
        mScrimController.setKeyguardOccluded(occluded);
        return mKeyguardStateController.isOccluded();
    }

    /** A launch animation was cancelled. */
@@ -3383,11 +3385,6 @@ public class CentralSurfaces extends CoreStartable implements
        return mLightRevealScrim;
    }

    private void updateKeyguardState() {
        mKeyguardStateController.notifyKeyguardState(mStatusBarKeyguardViewManager.isShowing(),
                mStatusBarKeyguardViewManager.isOccluded());
    }

    public void onTrackingStarted() {
        mShadeController.runPostCollapseRunnables();
    }
@@ -4385,7 +4382,6 @@ public class CentralSurfaces extends CoreStartable implements
                    checkBarModes();
                    updateScrimController();
                    mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD);
                    updateKeyguardState();
                    Trace.endSection();
                }

+10 −11
Original line number Diff line number Diff line
@@ -659,12 +659,14 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb

    @Override
    public void setOccluded(boolean occluded, boolean animate) {
        mCentralSurfaces.setOccluded(occluded);
        if (occluded && !mOccluded && mShowing) {
        final boolean isOccluding = !mOccluded && occluded;
        final boolean isUnOccluding = mOccluded && !occluded;
        setOccludedAndUpdateStates(occluded);

        if (mShowing && isOccluding) {
            SysUiStatsLog.write(SysUiStatsLog.KEYGUARD_STATE_CHANGED,
                    SysUiStatsLog.KEYGUARD_STATE_CHANGED__STATE__OCCLUDED);
            if (mCentralSurfaces.isInLaunchTransition()) {
                setOccludedAndUpdateStates(true);
                final Runnable endRunnable = new Runnable() {
                    @Override
                    public void run() {
@@ -680,8 +682,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
            }

            if (mCentralSurfaces.isLaunchingActivityOverLockscreen()) {
                setOccludedAndUpdateStates(true);

                // When isLaunchingActivityOverLockscreen() is true, we know for sure that the post
                // collapse runnables will be run.
                mShadeController.get().addPostCollapseAction(() -> {
@@ -690,16 +690,14 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
                });
                return;
            }
        } else if (!occluded && mOccluded && mShowing) {
        } else if (mShowing && isUnOccluding) {
            SysUiStatsLog.write(SysUiStatsLog.KEYGUARD_STATE_CHANGED,
                    SysUiStatsLog.KEYGUARD_STATE_CHANGED__STATE__SHOWN);
        }
        boolean isOccluding = !mOccluded && occluded;
        setOccludedAndUpdateStates(occluded);
        if (mShowing) {
            mMediaManager.updateMediaMetaData(false, animate && !occluded);
            mMediaManager.updateMediaMetaData(false, animate && !mOccluded);
        }
        mNotificationShadeWindowController.setKeyguardOccluded(occluded);
        mNotificationShadeWindowController.setKeyguardOccluded(mOccluded);

        // setDozing(false) will call reset once we stop dozing.
        if (!mDozing) {
@@ -707,7 +705,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
            // by a FLAG_DISMISS_KEYGUARD_ACTIVITY.
            reset(isOccluding /* hideBouncerWhenShowing*/);
        }
        if (animate && !occluded && mShowing && !mBouncer.isShowing()) {
        if (animate && !mOccluded && mShowing && !mBouncer.isShowing()) {
            mCentralSurfaces.animateKeyguardUnoccluding();
        }
    }
@@ -1041,6 +1039,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb

        if (occluded != mLastOccluded || mFirstUpdate) {
            mKeyguardUpdateManager.onKeyguardOccludedChanged(occluded);
            mKeyguardStateController.notifyKeyguardState(showing, occluded);
        }
        if ((showing && !occluded) != (mLastShowing && !mLastOccluded) || mFirstUpdate) {
            mKeyguardUpdateManager.onKeyguardVisibilityChanged(showing && !occluded);
+8 −2
Original line number Diff line number Diff line
@@ -861,11 +861,17 @@ public class CentralSurfacesTest extends SysuiTestCase {

    @Test
    public void testSetOccluded_propagatesToScrimController() {
        mCentralSurfaces.setOccluded(true);
        ArgumentCaptor<KeyguardStateController.Callback> callbackCaptor =
                ArgumentCaptor.forClass(KeyguardStateController.Callback.class);
        verify(mKeyguardStateController).addCallback(callbackCaptor.capture());

        when(mKeyguardStateController.isOccluded()).thenReturn(true);
        callbackCaptor.getValue().onKeyguardShowingChanged();
        verify(mScrimController).setKeyguardOccluded(eq(true));

        reset(mScrimController);
        mCentralSurfaces.setOccluded(false);
        when(mKeyguardStateController.isOccluded()).thenReturn(false);
        callbackCaptor.getValue().onKeyguardShowingChanged();
        verify(mScrimController).setKeyguardOccluded(eq(false));
    }

+10 −3
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
                mBiometricUnlockController,
                mNotificationContainer,
                mBypassController);
        when(mKeyguardStateController.isOccluded()).thenReturn(false);
        mStatusBarKeyguardViewManager.show(null);
    }

@@ -286,23 +287,27 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {

    @Test
    public void setOccluded_onKeyguardOccludedChangedCalledCorrectly() {
        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor).onKeyguardOccludedChanged(false);

        clearInvocations(mKeyguardStateController);
        clearInvocations(mKeyguardUpdateMonitor);

        // Should be false to start, so no invocations
        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor, never()).onKeyguardOccludedChanged(anyBoolean());
        verify(mKeyguardStateController, never()).notifyKeyguardState(anyBoolean(), anyBoolean());

        clearInvocations(mKeyguardUpdateMonitor);
        clearInvocations(mKeyguardStateController);

        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor).onKeyguardOccludedChanged(true);
        verify(mKeyguardStateController).notifyKeyguardState(true, true);

        clearInvocations(mKeyguardUpdateMonitor);
        clearInvocations(mKeyguardStateController);

        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor, never()).onKeyguardOccludedChanged(anyBoolean());
        verify(mKeyguardStateController, never()).notifyKeyguardState(anyBoolean(), anyBoolean());
    }

    @Test
@@ -312,6 +317,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {

        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor).onKeyguardOccludedChanged(true);
        verify(mKeyguardStateController).notifyKeyguardState(true, true);
    }

    @Test
@@ -321,6 +327,7 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {

        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
        verify(mKeyguardUpdateMonitor).onKeyguardOccludedChanged(true);
        verify(mKeyguardStateController).notifyKeyguardState(true, true);
    }

    @Test