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

Commit d4f6f5a0 authored by Darrell Shi's avatar Darrell Shi
Browse files

Fix Glanceable Hub timeout with scene container

Also make sure the scene container doesn't change scene if the device is
locked while on dream or communal scene.

Additionally, SceneInteractor#changeScene and
SceneInteractor#snapToScene should be called on the main thread, so make
sure of that in the CommunalSceneInteractor.

Test: atest CommunalSceneStartableTest
Test: atest CommunalSceneInteractorTest
Fix: 365598818
Flag: com.android.systemui.scene_container
Change-Id: I3e476192d0563fc408a02b85c3306897b5c9591f
parent 4acfb49a
Loading
Loading
Loading
Loading
+200 −19
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ package com.android.systemui.communal
import android.os.UserHandle
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.logging.uiEventLogger
import com.android.internal.logging.uiEventLoggerFake
import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
import com.android.systemui.Flags.FLAG_COMMUNAL_SCENE_KTF_REFACTOR
import com.android.systemui.Flags.FLAG_SCENE_CONTAINER
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
@@ -38,6 +38,7 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.dock.dockManager
import com.android.systemui.dock.fakeDockManager
import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
@@ -47,6 +48,8 @@ import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.notificationShadeWindowController
import com.android.systemui.statusbar.phone.centralSurfaces
import com.android.systemui.statusbar.phone.centralSurfacesOptional
@@ -65,12 +68,29 @@ import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.whenever
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWith(ParameterizedAndroidJunit4::class)
@EnableFlags(FLAG_COMMUNAL_HUB)
class CommunalSceneStartableTest : SysuiTestCase() {
class CommunalSceneStartableTest(flags: FlagsParameterization) : SysuiTestCase() {

    companion object {
        private const val SCREEN_TIMEOUT = 1000

        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf().andSceneContainer()
        }
    }

    init {
        mSetFlagsRule.setFlagsParameterization(flags)
    }

    private val kosmos = testKosmos()

    private lateinit var underTest: CommunalSceneStartable
@@ -95,7 +115,6 @@ class CommunalSceneStartableTest : SysuiTestCase() {
                        keyguardInteractor = keyguardInteractor,
                        systemSettings = fakeSettings,
                        notificationShadeWindowController = notificationShadeWindowController,
                        featureFlagsClassic = kosmos.fakeFeatureFlagsClassic,
                        applicationScope = applicationCoroutineScope,
                        bgScope = applicationCoroutineScope,
                        mainDispatcher = testDispatcher,
@@ -114,7 +133,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun keyguardGoesAway_whenLaunchingEditMode_doNotForceBlankScene() =
        with(kosmos) {
            testScope.runTest {
@@ -135,7 +154,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun keyguardGoesAway_whenLaunchingWidget_doNotForceBlankScene() =
        with(kosmos) {
            testScope.runTest {
@@ -156,7 +175,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun keyguardGoesAway_whenNotLaunchingWidget_forceBlankScene() =
        with(kosmos) {
            testScope.runTest {
@@ -177,7 +196,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun keyguardGoesAway_whenInEditMode_doesNotChangeScene() =
        with(kosmos) {
            testScope.runTest {
@@ -198,6 +217,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun deviceDocked_forceCommunalScene() =
        with(kosmos) {
            testScope.runTest {
@@ -215,7 +235,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun occluded_forceBlankScene() =
        with(kosmos) {
            testScope.runTest {
@@ -235,7 +255,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun occluded_doesNotForceBlankSceneIfLaunchingActivityOverLockscreen() =
        with(kosmos) {
            testScope.runTest {
@@ -255,7 +275,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun deviceDocked_doesNotForceCommunalIfTransitioningFromCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -273,7 +293,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun deviceAsleep_forceBlankSceneAfterTimeout() =
        with(kosmos) {
            testScope.runTest {
@@ -295,7 +315,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun deviceAsleep_wakesUpBeforeTimeout_noChangeInScene() =
        with(kosmos) {
            testScope.runTest {
@@ -325,6 +345,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun dockingOnLockscreen_forcesCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -347,6 +368,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun dockingOnLockscreen_doesNotForceCommunalIfDreamStarts() =
        with(kosmos) {
            testScope.runTest {
@@ -377,6 +399,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_whenDreaming_goesToBlank() =
        with(kosmos) {
            testScope.runTest {
@@ -394,6 +417,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_notDreaming_staysOnCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -409,6 +433,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_dreamStopped_staysOnCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -432,6 +457,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_dreamStartedHalfway_goesToCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -454,6 +480,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_dreamAfterInitialTimeout_goesToBlank() =
        with(kosmos) {
            testScope.runTest {
@@ -474,6 +501,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_userActivityTriggered_resetsTimeout() =
        with(kosmos) {
            testScope.runTest {
@@ -501,6 +529,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_screenTimeoutChanged() =
        with(kosmos) {
            testScope.runTest {
@@ -526,7 +555,163 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_whenDreaming_goesToBlank() =
        with(kosmos) {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Scene times out back to blank after the screen timeout.
                advanceTimeBy(SCREEN_TIMEOUT.milliseconds)
                assertThat(scene).isEqualTo(Scenes.Dream)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_notDreaming_staysOnCommunal() =
        with(kosmos) {
            testScope.runTest {
                // Device is not dreaming and on communal.
                updateDreaming(false)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                // Scene stays as Communal
                advanceTimeBy(SCREEN_TIMEOUT.milliseconds)
                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_dreamStopped_staysOnCommunal() =
        with(kosmos) {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Wait a bit, but not long enough to timeout.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Dream stops, timeout is cancelled and device stays on hub, because the regular
                // screen timeout will take effect at this point.
                updateDreaming(false)
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                assertThat(scene).isEqualTo(Scenes.Communal)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_dreamStartedHalfway_goesToCommunal() =
        with(kosmos) {
            testScope.runTest {
                // Device is on communal, but not dreaming.
                updateDreaming(false)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Wait a bit, but not long enough to timeout, then start dreaming.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                updateDreaming(true)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Device times out after one screen timeout interval, dream doesn't reset timeout.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                assertThat(scene).isEqualTo(Scenes.Dream)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_dreamAfterInitialTimeout_goesToBlank() =
        with(kosmos) {
            testScope.runTest {
                // Device is on communal.
                sceneInteractor.changeScene(Scenes.Communal, "test")

                // Device stays on the hub after the timeout since we're not dreaming.
                advanceTimeBy(SCREEN_TIMEOUT.milliseconds * 2)
                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Start dreaming.
                updateDreaming(true)

                // Hub times out immediately.
                assertThat(scene).isEqualTo(Scenes.Dream)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_userActivityTriggered_resetsTimeout() =
        with(kosmos) {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Wait a bit, but not long enough to timeout.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)

                // Send user interaction to reset timeout.
                communalInteractor.signalUserInteraction()

                // If user activity didn't reset timeout, we would have gone back to Blank by now.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Timeout happens one interval after the user interaction.
                advanceTimeBy((SCREEN_TIMEOUT / 2).milliseconds)
                assertThat(scene).isEqualTo(Scenes.Dream)
            }
        }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun hubTimeout_withSceneContainer_screenTimeoutChanged() =
        with(kosmos) {
            testScope.runTest {
                fakeSettings.putInt(Settings.System.SCREEN_OFF_TIMEOUT, SCREEN_TIMEOUT * 2)

                // Device is dreaming and on communal.
                updateDreaming(true)
                sceneInteractor.changeScene(Scenes.Communal, "test")

                val scene by collectLastValue(sceneInteractor.currentScene)
                assertThat(scene).isEqualTo(Scenes.Communal)

                // Scene times out back to blank after the screen timeout.
                advanceTimeBy(SCREEN_TIMEOUT.milliseconds)
                assertThat(scene).isEqualTo(Scenes.Communal)

                advanceTimeBy(SCREEN_TIMEOUT.milliseconds)
                assertThat(scene).isEqualTo(Scenes.Dream)
                assertThat(uiEventLoggerFake.logs.first().eventId)
                    .isEqualTo(CommunalUiEvent.COMMUNAL_HUB_TIMEOUT.id)
                assertThat(uiEventLoggerFake.numLogs()).isEqualTo(1)
            }
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_SCENE_CONTAINER)
    fun transitionFromDozingToGlanceableHub_forcesCommunal() =
        with(kosmos) {
            testScope.runTest {
@@ -558,8 +743,4 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            fakeKeyguardRepository.setDreaming(dreaming)
            runCurrent()
        }

    companion object {
        private const val SCREEN_TIMEOUT = 1000
    }
}
+83 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepositor
import com.android.systemui.deviceentry.domain.interactor.deviceEntryHapticsInteractor
import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.deviceentry.shared.model.DeviceUnlockStatus
import com.android.systemui.deviceentry.shared.model.FailedFaceAuthenticationStatus
import com.android.systemui.deviceentry.shared.model.SuccessFaceAuthenticationStatus
import com.android.systemui.flags.EnableSceneContainer
@@ -2532,6 +2533,88 @@ class SceneContainerStartableTest : SysuiTestCase() {
            assertThat(isAlternateBouncerVisible).isFalse()
        }

    @Test
    fun handleDeviceUnlockStatus_deviceLockedWhileOnDream_stayOnDream() =
        testScope.runTest {
            val transitionState =
                prepareState(
                    isDeviceUnlocked = false,
                    initialSceneKey = Scenes.Lockscreen,
                    authenticationMethod = AuthenticationMethodModel.Pin,
                )
            underTest.start()

            val isUnlocked by
                collectLastValue(
                    kosmos.deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked }
                )
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            assertThat(isUnlocked).isFalse()
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

            // Unlock device.
            kosmos.deviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            assertThat(isUnlocked).isTrue()
            assertThat(currentScene).isEqualTo(Scenes.Gone)

            // Change to Dream.
            sceneInteractor.changeScene(Scenes.Dream, "test")
            transitionState.value = ObservableTransitionState.Idle(Scenes.Dream)
            runCurrent()
            assertThat(isUnlocked).isTrue()
            assertThat(currentScene).isEqualTo(Scenes.Dream)

            // Lock device, and verify stay on dream.
            kosmos.fakeDeviceEntryRepository.deviceUnlockStatus.value =
                DeviceUnlockStatus(isUnlocked = false, deviceUnlockSource = null)
            runCurrent()
            assertThat(isUnlocked).isFalse()
            assertThat(currentScene).isEqualTo(Scenes.Dream)
        }

    @Test
    fun handleDeviceUnlockStatus_deviceLockedWhileOnCommunal_stayOnCommunal() =
        testScope.runTest {
            val transitionState =
                prepareState(
                    isDeviceUnlocked = false,
                    initialSceneKey = Scenes.Lockscreen,
                    authenticationMethod = AuthenticationMethodModel.Pin,
                )
            underTest.start()

            val isUnlocked by
                collectLastValue(
                    kosmos.deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked }
                )
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            assertThat(isUnlocked).isFalse()
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

            // Unlock device.
            kosmos.deviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            assertThat(isUnlocked).isTrue()
            assertThat(currentScene).isEqualTo(Scenes.Gone)

            // Change to Communal.
            sceneInteractor.changeScene(Scenes.Communal, "test")
            transitionState.value = ObservableTransitionState.Idle(Scenes.Communal)
            runCurrent()
            assertThat(isUnlocked).isTrue()
            assertThat(currentScene).isEqualTo(Scenes.Communal)

            // Lock device, and verify stay on Communal.
            kosmos.fakeDeviceEntryRepository.deviceUnlockStatus.value =
                DeviceUnlockStatus(isUnlocked = false, deviceUnlockSource = null)
            runCurrent()
            assertThat(isUnlocked).isFalse()
            assertThat(currentScene).isEqualTo(Scenes.Communal)
        }

    @Test
    fun replacesLockscreenSceneOnBackStack_whenFaceUnlocked_fromShade_noAlternateBouncer() =
        testScope.runTest {
+4 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.communal

import android.os.UserHandle
import android.provider.Settings
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.TransitionKey
import com.android.internal.logging.UiEventLogger
@@ -28,6 +29,7 @@ import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalScenes.isCommunal
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
import com.android.systemui.communal.shared.model.EditModeState
import com.android.systemui.dagger.SysUISingleton
@@ -35,7 +37,6 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dock.DockManager
import com.android.systemui.flags.FeatureFlagsClassic
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -62,7 +63,6 @@ import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import com.android.app.tracing.coroutines.launchTraced as launch
import kotlinx.coroutines.withContext

/**
@@ -83,7 +83,6 @@ constructor(
    private val systemSettings: SystemSettings,
    centralSurfacesOpt: Optional<CentralSurfaces>,
    private val notificationShadeWindowController: NotificationShadeWindowController,
    private val featureFlagsClassic: FeatureFlagsClassic,
    @Application private val applicationScope: CoroutineScope,
    @Background private val bgScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
@@ -168,7 +167,7 @@ constructor(
                    communalInteractor.userActivity.emitOnStart(),
                ) { scene, _ ->
                    // Only timeout if we're on the hub is open.
                    scene == CommunalScenes.Communal
                    scene.isCommunal()
                }
                .collectLatest { shouldTimeout ->
                    cancelHubTimeout()
@@ -182,7 +181,7 @@ constructor(
                .sample(communalSceneInteractor.currentScene, ::Pair)
                .collectLatest { (isDreaming, scene) ->
                    this@CommunalSceneStartable.isDreaming = isDreaming
                    if (scene == CommunalScenes.Communal && isDreaming && timeoutJob == null) {
                    if (scene.isCommunal() && isDreaming && timeoutJob == null) {
                        // If dreaming starts after timeout has expired, ex. if dream restarts under
                        // the hub, just close the hub immediately.
                        communalSceneInteractor.changeScene(
+20 −21
Original line number Diff line number Diff line
@@ -98,16 +98,17 @@ constructor(
        transitionKey: TransitionKey? = null,
        keyguardState: KeyguardState? = null,
    ) {
        applicationScope.launch("$TAG#changeScene") {
            if (SceneContainerFlag.isEnabled) {
            return sceneInteractor.changeScene(
                sceneInteractor.changeScene(
                    toScene = newScene.toSceneContainerSceneKey(),
                    loggingReason = loggingReason,
                    transitionKey = transitionKey,
                    sceneState = keyguardState,
                )
                return@launch
            }

        applicationScope.launch("$TAG#changeScene") {
            if (currentScene.value == newScene) return@launch
            logger.logSceneChangeRequested(
                from = currentScene.value,
@@ -125,16 +126,17 @@ constructor(
        newScene: SceneKey,
        loggingReason: String,
        delayMillis: Long = 0,
        keyguardState: KeyguardState? = null
        keyguardState: KeyguardState? = null,
    ) {
        applicationScope.launch("$TAG#snapToScene") {
            if (SceneContainerFlag.isEnabled) {
            return sceneInteractor.snapToScene(
                sceneInteractor.snapToScene(
                    toScene = newScene.toSceneContainerSceneKey(),
                    loggingReason = loggingReason,
                )
                return@launch
            }

        applicationScope.launch("$TAG#snapToScene") {
            delay(delayMillis)
            if (currentScene.value == newScene) return@launch
            logger.logSceneChangeRequested(
@@ -161,10 +163,7 @@ constructor(
        } else {
            repository.currentScene
                .pairwiseBy(initialValue = repository.currentScene.value) { from, to ->
                    logger.logSceneChangeCommitted(
                        from = from,
                        to = to,
                    )
                    logger.logSceneChangeCommitted(from = from, to = to)
                    to
                }
                .stateIn(
+15 −4

File changed.

Preview size limit exceeded, changes collapsed.

Loading