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

Commit 617b9833 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge changes I3e476192,I60645079 into main

* changes:
  Fix Glanceable Hub timeout with scene container
  Remove SceneFamilies reference from dream user actions
parents 05d69398 d4f6f5a0
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
    }
}
+0 −7
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.SceneFamilies
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.TransitionKeys.ToSplitShade
import com.android.systemui.shade.data.repository.fakeShadeRepository
@@ -83,7 +82,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {
                shadeMode = ShadeMode.Single,
            )
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Bouncer))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(UserActionResult(Scenes.Shade, isIrreversible = true))
@@ -101,7 +99,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {
                shadeMode = ShadeMode.Single,
            )
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Gone))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(UserActionResult(Scenes.Shade, isIrreversible = true))
@@ -119,7 +116,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {
                shadeMode = ShadeMode.Split,
            )
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Bouncer))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(UserActionResult(Scenes.Shade, ToSplitShade, isIrreversible = true))
@@ -137,7 +133,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {
                shadeMode = ShadeMode.Split,
            )
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Gone))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(UserActionResult(Scenes.Shade, ToSplitShade, isIrreversible = true))
@@ -155,7 +150,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {
                shadeMode = ShadeMode.Dual,
            )
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Bouncer))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(
@@ -171,7 +165,6 @@ class DreamUserActionsViewModelTest : SysuiTestCase() {

            setUpState(isShadeTouchable = true, isDeviceUnlocked = true, shadeMode = ShadeMode.Dual)
            assertThat(actions).isNotEmpty()
            assertThat(actions?.get(Swipe.End)).isEqualTo(UserActionResult(SceneFamilies.Home))
            assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Gone))
            assertThat(actions?.get(Swipe.Down))
                .isEqualTo(
+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

File changed.

Preview size limit exceeded, changes collapsed.

Loading