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

Commit 31e50849 authored by Darrell Shi's avatar Darrell Shi
Browse files

Fix dream overlay lifecycle when bouncer is showing in scene container

The DreamOverlayService observes bouncer showing state to update its
lifecycle so touch monitor is correctly started/stopped. This change
makes it so this state is correctly handled when scene container is
enabled.

Test: atest DreamOverlayServiceTest
Test: touch monitor stopped when bouncer is showing over dream when
      scene container is enabled
Fix: 379179472
Flag: com.android.systemui.scene_container
Change-Id: I3d6271c29db5b8059007b77993fd1b1252691edc
parent d51ffdf0
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -1035,6 +1035,7 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.RESUMED)
    }

    @DisableFlags(FLAG_SCENE_CONTAINER)
    @Test
    fun testBouncerShown_setsLifecycleState() {
        val client = client
@@ -1067,6 +1068,39 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.RESUMED)
    }

    @EnableFlags(FLAG_SCENE_CONTAINER)
    @Test
    fun testBouncerShown_withSceneContainer_setsLifecycleState() {
        val client = client

        // Inform the overlay service of dream starting.
        client.startDream(
            mWindowParams,
            mDreamOverlayCallback,
            DREAM_COMPONENT,
            false /*isPreview*/,
            false, /*shouldShowComplication*/
        )
        mMainExecutor.runAllReady()
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.RESUMED)

        // Bouncer shows.
        kosmos.sceneInteractor.changeScene(Scenes.Bouncer, "test")
        testScope.runCurrent()
        mMainExecutor.runAllReady()

        // Lifecycle state goes from resumed back to started when the bouncer shows.
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.STARTED)

        // Bouncer closes.
        kosmos.sceneInteractor.changeScene(Scenes.Dream, "test")
        testScope.runCurrent()
        mMainExecutor.runAllReady()

        // Lifecycle state goes back to RESUMED.
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.RESUMED)
    }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun testCommunalVisible_setsLifecycleState() {
+26 −11
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import androidx.lifecycle.ServiceLifecycleDispatcher;
import androidx.lifecycle.ViewModelStore;

import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.compose.animation.scene.SceneKey;
import com.android.dream.lowlight.dagger.LowLightDreamModule;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
@@ -212,16 +213,14 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    private final Consumer<Boolean> mBouncerShowingConsumer = new Consumer<>() {
        @Override
        public void accept(Boolean bouncerShowing) {
            mExecutor.execute(() -> {
                if (mBouncerShowing == bouncerShowing) {
                    return;
            mExecutor.execute(() -> updateBouncerShowingLocked(bouncerShowing));
        }
    };

                mBouncerShowing = bouncerShowing;

                updateLifecycleStateLocked();
                updateGestureBlockingLocked();
            });
    private final Consumer<SceneKey> mCurrentSceneConsumer = new Consumer<>() {
        @Override
        public void accept(SceneKey currentScene) {
            mExecutor.execute(() -> updateBouncerShowingLocked(currentScene == Scenes.Bouncer));
        }
    };

@@ -425,9 +424,14 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
                mIsCommunalAvailableCallback));
        mFlows.add(collectFlow(getLifecycle(), communalInteractor.isCommunalVisible(),
                mCommunalVisibleConsumer));
        if (SceneContainerFlag.isEnabled()) {
            mFlows.add(collectFlow(getLifecycle(), sceneInteractor.getCurrentScene(),
                    mCurrentSceneConsumer));
        } else {
            mFlows.add(collectFlow(getLifecycle(), keyguardInteractor.primaryBouncerShowing,
                    mBouncerShowingConsumer));
        }
    }

    @NonNull
    @Override
@@ -707,4 +711,15 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
        Log.w(TAG, "Removing dream overlay container view parent!");
        parentView.removeView(containerView);
    }

    private void updateBouncerShowingLocked(boolean bouncerShowing) {
        if (mBouncerShowing == bouncerShowing) {
            return;
        }

        mBouncerShowing = bouncerShowing;

        updateLifecycleStateLocked();
        updateGestureBlockingLocked();
    }
}