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

Commit 471e5a31 authored by William Xiao's avatar William Xiao
Browse files

Don't keep dream alive under hub with hub v2

With hub v2, there is no longer a swipe to/from the hub to the dream so
there's no need to keep the dream alive. While this is not directly
needed for hub v2, this improves the hub's performance and reduces the
complexity of the hub interaction model and shade/bouncer/scrim
handling logic.

Bug: 389108560
Test: atest CommunalDreamStartableTest DreamOverlayServiceTest
Flag: com.android.systemui.glanceable_hub_v2
Change-Id: I59ce39214a8471526abb929e10767e16eb1da75c
parent e32d6120
Loading
Loading
Loading
Loading
+61 −13
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package com.android.systemui.communal

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.service.dream.dreamManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.interactor.setCommunalV2Enabled
import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
@@ -48,12 +51,14 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@EnableFlags(Flags.FLAG_COMMUNAL_HUB)
@RunWith(AndroidJUnit4::class)
class CommunalDreamStartableTest : SysuiTestCase() {
@RunWith(ParameterizedAndroidJunit4::class)
class CommunalDreamStartableTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

@@ -63,6 +68,10 @@ class CommunalDreamStartableTest : SysuiTestCase() {
    private val keyguardRepository by lazy { kosmos.fakeKeyguardRepository }
    private val powerRepository by lazy { kosmos.fakePowerRepository }

    init {
        mSetFlagsRule.setFlagsParameterization(flags)
    }

    @Before
    fun setUp() {
        kosmos.fakeFeatureFlagsClassic.set(COMMUNAL_SERVICE_ENABLED, true)
@@ -77,12 +86,32 @@ class CommunalDreamStartableTest : SysuiTestCase() {
                communalSceneInteractor = kosmos.communalSceneInteractor,
                bgScope = kosmos.applicationCoroutineScope,
            )
                .apply { start() }
    }

    @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun dreamNotStartedWhenTransitioningToHub() =
        testScope.runTest {
            // Enable v2 flag and recreate + rerun start method.
            kosmos.setCommunalV2Enabled(true)
            underTest.start()

            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
            runCurrent()

            transition(from = KeyguardState.DREAMING, to = KeyguardState.GLANCEABLE_HUB)

            verify(dreamManager, never()).startDream()
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun startDreamWhenTransitioningToHub() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
@@ -100,6 +129,7 @@ class CommunalDreamStartableTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_RESTART_DREAM_ON_UNOCCLUDE)
    fun restartDreamingWhenTransitioningFromDreamingToOccludedToDreaming() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
@@ -122,9 +152,11 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            verify(dreamManager).startDream()
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun shouldNotStartDreamWhenIneligibleToDream() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            // Not eligible to dream
@@ -134,9 +166,11 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            verify(dreamManager, never()).startDream()
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun shouldNotStartDreamIfAlreadyDreaming() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setDreaming(true)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
@@ -145,9 +179,11 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            verify(dreamManager, never()).startDream()
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun shouldNotStartDreamForInvalidTransition() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setDreaming(true)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
@@ -160,9 +196,11 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            }
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun shouldNotStartDreamWhenLaunchingWidget() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
@@ -175,9 +213,11 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            verify(dreamManager, never()).startDream()
        }

    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Test
    fun shouldNotStartDreamWhenOccluded() =
        testScope.runTest {
            underTest.start()
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
@@ -194,8 +234,16 @@ class CommunalDreamStartableTest : SysuiTestCase() {
        kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
            from = from,
            to = to,
            testScope = this
            testScope = this,
        )
        runCurrent()
    }

    companion object {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf(FLAG_GLANCEABLE_HUB_V2)
        }
    }
}
+30 −2
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.interactor.setCommunalAvailable
import com.android.systemui.communal.domain.interactor.setCommunalV2ConfigEnabled
import com.android.systemui.communal.domain.interactor.setCommunalV2Enabled
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.complication.ComplicationHostViewController
@@ -747,7 +748,7 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_COMMUNAL_HUB)
    @DisableFlags(FLAG_SCENE_CONTAINER)
    @DisableFlags(FLAG_SCENE_CONTAINER, FLAG_GLANCEABLE_HUB_V2)
    @kotlin.Throws(RemoteException::class)
    fun testTransitionToGlanceableHub() =
        testScope.runTest {
@@ -774,6 +775,7 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_SCENE_CONTAINER, FLAG_COMMUNAL_HUB)
    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @kotlin.Throws(RemoteException::class)
    fun testTransitionToGlanceableHub_sceneContainer() =
        testScope.runTest {
@@ -801,8 +803,30 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
            verify(mUiEventLogger).log(CommunalUiEvent.DREAM_TO_COMMUNAL_HUB_DREAM_AWAKE_START)
        }

    @Test
    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_COMMUNAL_HUB, FLAG_GLANCEABLE_HUB_V2)
    @Throws(RemoteException::class)
    fun testRedirect_v2Enabled_notTriggered() =
        testScope.runTest {
            kosmos.setCommunalV2Enabled(true)
            // Inform the overlay service of dream starting. Do not show dream complications.
            client.startDream(
                mWindowParams,
                mDreamOverlayCallback,
                DREAM_COMPONENT,
                false /*isPreview*/,
                false, /*shouldShowComplication*/
            )
            // Set communal available, verify that onRedirectWake is never called.
            kosmos.setCommunalAvailable(true)
            mMainExecutor.runAllReady()
            runCurrent()
            verify(mDreamOverlayCallback, never()).onRedirectWake(any())
        }

    @Test
    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_COMMUNAL_HUB)
    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @Throws(RemoteException::class)
    fun testRedirectExit() =
        testScope.runTest {
@@ -1347,7 +1371,11 @@ class DreamOverlayServiceTest(flags: FlagsParameterization?) : SysuiTestCase() {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf(FLAG_COMMUNAL_HUB).andSceneContainer()
            return FlagsParameterization.allCombinationsOf(
                    FLAG_COMMUNAL_HUB,
                    FLAG_GLANCEABLE_HUB_V2,
                )
                .andSceneContainer()
        }
    }
}
+14 −8
Original line number Diff line number Diff line
@@ -91,13 +91,19 @@ constructor(
                .launchIn(bgScope)
        }

        // Restart the dream underneath the hub in order to support the ability to swipe
        // away the hub to enter the dream.
        // With hub v2, we no longer need to keep the dream running underneath the hub as there is
        // no more swipe between the hub and dream. We can just start the dream on-demand when the
        // user presses the dream coin.
        if (!communalSettingsInteractor.isV2FlagEnabled()) {
            // Restart the dream underneath the hub in order to support the ability to swipe away
            // the hub to enter the dream.
            startDream
                .sampleFilter(powerInteractor.isAwake) { isAwake ->
                !glanceableHubAllowKeyguardWhenDreaming() && dreamManager.canStartDreaming(isAwake)
                    !glanceableHubAllowKeyguardWhenDreaming() &&
                        dreamManager.canStartDreaming(isAwake)
                }
                .onEach { dreamManager.startDream() }
                .launchIn(bgScope)
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -562,6 +562,13 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            return;
        }

        if (mCommunalSettingsInteractor.isV2FlagEnabled()) {
            // Dream wake redirect is not needed in V2 as we do not need to keep the dream awake
            // underneath the hub anymore as there is no more swipe between the dream and hub. SysUI
            // will automatically transition to the hub when the dream wakes.
            return;
        }

        redirectWake(mCommunalAvailable && !glanceableHubAllowKeyguardWhenDreaming());
    }