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

Commit 172fc0c4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix dream overlay lifecycle when bouncer is showing in scene container" into main

parents 3e7dcede 31e50849
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();
    }
}