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

Commit 0e4a1bed authored by brycelee's avatar brycelee
Browse files

DreamOverlayService: Reduce scope where shade affects gesture blocking.

Currently shade expansion affects gesture blocking and is active during
the lifetime of the DreamOverlayService. Since a service can be reused
by multiple dream instances, it is better for this listener to be
scoped to the dream lifetime, rather than the overlay service.
Additionally, the callback for handling changes fires on an executor. As
a result, it might be executed after the dream has ended. This
changelists adds a scoped execution method which checks the dream
status before executing the Runnable.

Fixes: 432039567
Test: atest DreamOverlayServiceTest
Flag: EXEMPT bugfix
Change-Id: I82e20461a27956513aa5076bc003c636cfa30a2c
parent 859c6c2c
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.navigationbar.gestural.data.gestureRepository
import com.android.systemui.navigationbar.gestural.domain.GestureInteractor
import com.android.systemui.navigationbar.gestural.domain.TaskInfo
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.data.repository.sceneContainerRepository
@@ -156,6 +157,8 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {

    private lateinit var mService: DreamOverlayService

    private lateinit var mGestureInteractor: GestureInteractor

    private class EnvironmentComponents(
        val dreamsComplicationComponent: DreamComplicationComponent,
        val dreamOverlayComponent: DreamOverlayComponent,
@@ -245,6 +248,7 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
        Dispatchers.setMain(kosmos.testDispatcher)
        onTeardown { Dispatchers.resetMain() }
        with(kosmos) {
            mGestureInteractor = spy(gestureInteractor)
            mService =
                DreamOverlayService(
                    mContext,
@@ -269,7 +273,7 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
                    HOME_CONTROL_PANEL_DREAM_COMPONENT,
                    mDreamOverlayCallbackController,
                    keyguardInteractor,
                    gestureInteractor,
                    mGestureInteractor,
                    wakeGestureMonitor,
                    powerInteractor,
                    WINDOW_NAME,
@@ -1345,6 +1349,32 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
            assertThat(gestureRepository.gestureBlockedMatchers.value).isEmpty()
        }

    @Test
    fun testShadeExpansionNoEffectAfterEndDream() =
        kosmos.runTest {
            val client = client

            // Inform the overlay service of dream starting.
            client.startDream(
                mWindowParams,
                mDreamOverlayCallback,
                DREAM_COMPONENT,
                false /*isPreview*/,
                false, /*shouldShowComplication*/
            )
            mMainExecutor.runAllReady()

            val callbackCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
            verify(mKeyguardUpdateMonitor).registerCallback(callbackCaptor.capture())
            callbackCaptor.lastValue.onShadeExpandedChanged(true)
            client.endDream()
            mMainExecutor.runAllReady()
            clearInvocations(mGestureInteractor)
            callbackCaptor.lastValue.onShadeExpandedChanged(false)
            mMainExecutor.runAllReady()
            verifyNoMoreInteractions(mGestureInteractor)
        }

    @Test
    fun testDreamActivityGesturesNotBlockedDreamEndedBeforeKeyguardStateChanged() =
        kosmos.runTest {
+27 −24
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            new KeyguardUpdateMonitorCallback() {
                @Override
                public void onShadeExpandedChanged(boolean expanded) {
                    mExecutor.execute(() -> {
                    dreamScopedExecute(() -> {
                        if (mShadeExpanded == expanded) {
                            return;
                        }
@@ -217,7 +217,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ

                        updateLifecycleStateLocked();
                        updateGestureBlockingLocked();
                    });
                    }, "shade expanded changed");
                }
            };

@@ -236,20 +236,14 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        }
    };

    private final Consumer<Boolean> mBouncerShowingConsumer = new Consumer<>() {
        @Override
        public void accept(Boolean bouncerShowing) {
            mExecutor.execute(() -> updateBouncerShowingLocked(bouncerShowing));
        }
    };
    private final Consumer<Boolean> mBouncerShowingConsumer = bouncerShowing ->
            dreamScopedExecute(() -> updateBouncerShowingLocked(bouncerShowing),
            "bouncer showing changed");

    private final Consumer<Set<OverlayKey>> mCurrentOverlaysConsumer = new Consumer<>() {
        @Override
        public void accept(Set<OverlayKey> currentOverlays) {
            mExecutor.execute(() ->
                    updateBouncerShowingLocked(currentOverlays.contains(Overlays.Bouncer)));
        }
    };
    private final Consumer<Set<OverlayKey>> mCurrentOverlaysConsumer =
            currentOverlays -> dreamScopedExecute(() ->
                    updateBouncerShowingLocked(currentOverlays.contains(Overlays.Bouncer)),
                    "overlays changed");

    private final Consumer<Unit> mPickupConsumer = new Consumer<>() {
        @Override
@@ -260,12 +254,9 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        }
    };

    private final Consumer<Boolean> mBiometricPromptShowingConsumer = new Consumer<>() {
        @Override
        public void accept(Boolean showing) {
            mExecutor.execute(() -> updateBiometricPromptShowingLocked(showing));
        }
    };
    private final Consumer<Boolean> mBiometricPromptShowingConsumer =
            showing -> dreamScopedExecute(() -> updateBiometricPromptShowingLocked(showing),
            "update biometric prompt showing");

    /**
     * {@link ResetHandler} protects resetting {@link DreamOverlayService} by making sure reset
@@ -360,6 +351,8 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            mGestureInteractor.removeGestureBlockedMatcher(DREAM_TYPE_MATCHER,
                    GestureInteractor.Scope.Global);

            mKeyguardUpdateMonitor.removeCallback(mKeyguardCallback);

            mStarted = false;
        }

@@ -447,7 +440,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        mBouncerScrimController = bouncerScrimController;
        mLowLightDreamComponent = lowLightDreamComponent;
        mHomeControlPanelDreamComponent = homeControlPanelDreamComponent;
        mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);
        mStateController = stateController;
        mUiEventLogger = uiEventLogger;
        mComplicationComponentFactory = complicationComponentFactory;
@@ -512,8 +504,6 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ

    @Override
    public void onDestroy() {
        mKeyguardUpdateMonitor.removeCallback(mKeyguardCallback);

        for (Job job : mFlows) {
            job.cancel(new CancellationException());
        }
@@ -614,6 +604,8 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        mDreamOverlayCallbackController.onStartDream();
        mStarted = true;

        mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);

        updateRedirectWakeup();
        updateGestureBlockingLocked();
    }
@@ -815,4 +807,15 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        updateLifecycleStateLocked();
        updateGestureBlockingLocked();
    }

    private void dreamScopedExecute(Runnable runnable, String description) {
        mExecutor.execute(() -> {
            if (!mStarted) {
                Log.d(TAG, "could not execute when not dreaming:" + description);
                return;
            }

            runnable.run();
        });
    }
}