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

Commit 3cfb32b5 authored by William Xiao's avatar William Xiao
Browse files

Only automatically enter hub when exiting dream

The UX specs call for the lockscreen to never show when the hub is
enabled and the device is docked. While this is implemented, we don't
have a custom animation for it and it's new behavior that users may not
expect before we announce it. For now, only automatically switch to hub
when exiting the dream

Bug: 322787129
Bug: 327414957
Test: atest CommunalSceneStartableTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: I3b97b6f7b43fe504edabaf3e588fb93868970d49
parent 62fe64e4
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.setCommunalAvailable
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.dock.DockManager
import com.android.systemui.dock.dockManager
import com.android.systemui.dock.fakeDockManager
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
@@ -40,6 +39,7 @@ import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@@ -92,6 +92,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    fun deviceDocked_forceCommunalScene() =
        with(kosmos) {
@@ -109,6 +110,23 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Test
    fun exitingDream_forceCommunalScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                assertThat(scene).isEqualTo(CommunalScenes.Blank)

                updateDocked(true)
                fakeKeyguardTransitionRepository.sendTransitionSteps(
                    from = KeyguardState.DREAMING,
                    to = KeyguardState.LOCKSCREEN,
                    testScope = this
                )
                assertThat(scene).isEqualTo(CommunalScenes.Communal)
            }
        }

    @Test
    fun deviceDocked_doesNotForceCommunalIfTransitioningFromCommunal() =
        with(kosmos) {
@@ -175,6 +193,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    fun dockingOnLockscreen_forcesCommunal() =
        with(kosmos) {
@@ -196,6 +215,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Ignore("Ignored until custom animations are implemented in b/322787129")
    @Test
    fun dockingOnLockscreen_doesNotForceCommunalIfDreamStarts() =
        with(kosmos) {
@@ -230,7 +250,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        with(kosmos) {
            runCurrent()
            fakeDockManager.setIsDocked(docked)
            fakeDockManager.setDockEvent(DockManager.STATE_DOCKED)
            // TODO(b/322787129): uncomment once custom animations are in place
            // fakeDockManager.setDockEvent(DockManager.STATE_DOCKED)
            runCurrent()
        }

+15 −16
Original line number Diff line number Diff line
@@ -24,18 +24,15 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dock.DockManager
import com.android.systemui.dock.retrieveIsDocked
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.mapLatest
@@ -66,19 +63,21 @@ constructor(
            .onEach { nextScene -> communalInteractor.onSceneChanged(nextScene) }
            .launchIn(applicationScope)

        // TODO(b/322787129): re-enable once custom animations are in place
        // Handle automatically switching to communal when docked.
        dockManager
            .retrieveIsDocked()
            // Allow some time after docking to ensure the dream doesn't start. If the dream
            // starts, then we don't want to automatically transition to glanceable hub.
            .debounce(DOCK_DEBOUNCE_DELAY)
            .sample(keyguardTransitionInteractor.startedKeyguardState, ::Pair)
            .onEach { (docked, lastStartedState) ->
                if (docked && lastStartedState == KeyguardState.LOCKSCREEN) {
                    communalInteractor.onSceneChanged(CommunalScenes.Communal)
                }
            }
            .launchIn(bgScope)
        //        dockManager
        //            .retrieveIsDocked()
        //            // Allow some time after docking to ensure the dream doesn't start. If the
        // dream
        //            // starts, then we don't want to automatically transition to glanceable hub.
        //            .debounce(DOCK_DEBOUNCE_DELAY)
        //            .sample(keyguardTransitionInteractor.startedKeyguardState, ::Pair)
        //            .onEach { (docked, lastStartedState) ->
        //                if (docked && lastStartedState == KeyguardState.LOCKSCREEN) {
        //                    communalInteractor.onSceneChanged(CommunalScenes.Communal)
        //                }
        //            }
        //            .launchIn(bgScope)
    }

    private suspend fun determineSceneAfterTransition(
@@ -89,7 +88,7 @@ constructor(
        val docked = dockManager.isDocked

        return when {
            docked && to == KeyguardState.LOCKSCREEN && from != KeyguardState.GLANCEABLE_HUB -> {
            docked && to == KeyguardState.LOCKSCREEN && from == KeyguardState.DREAMING -> {
                CommunalScenes.Communal
            }
            to == KeyguardState.GONE -> CommunalScenes.Blank