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

Commit 3e5348bd authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge "Convert KeyguardlessScene into using SceneContainerStartable." into main

parents 12753147 f0d8808f
Loading
Loading
Loading
Loading
+48 −7
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.sceneContainerRepository
import com.android.systemui.scene.sceneContainerConfig
import com.android.systemui.scene.sceneKeys
import com.android.systemui.scene.shared.model.SceneContainerConfig
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.fakeSceneDataSource
import com.android.systemui.testKosmos
@@ -39,7 +40,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -54,19 +54,46 @@ class SceneInteractorTest : SysuiTestCase() {

    private lateinit var underTest: SceneInteractor

    @Before
    fun setUp() {
    @Test
    fun allSceneKeys() {
        underTest = kosmos.sceneInteractor
        assertThat(underTest.allSceneKeys()).isEqualTo(kosmos.sceneKeys)
    }

    @Test
    fun allSceneKeys() {
        assertThat(underTest.allSceneKeys()).isEqualTo(kosmos.sceneKeys)
    fun changeScene_toUnknownScene_doesNothing() =
        testScope.runTest {
            val sceneKeys =
                listOf(
                    Scenes.QuickSettings,
                    Scenes.Shade,
                    Scenes.Lockscreen,
                    Scenes.Gone,
                    Scenes.Communal,
                )
            val navigationDistances =
                mapOf(
                    Scenes.Gone to 0,
                    Scenes.Lockscreen to 0,
                    Scenes.Communal to 1,
                    Scenes.Shade to 2,
                    Scenes.QuickSettings to 3,
                )
            kosmos.sceneContainerConfig =
                SceneContainerConfig(sceneKeys, Scenes.Lockscreen, navigationDistances)
            underTest = kosmos.sceneInteractor
            val currentScene by collectLastValue(underTest.currentScene)
            val previousScene = currentScene
            assertThat(previousScene).isNotEqualTo(Scenes.Bouncer)
            underTest.changeScene(Scenes.Bouncer, "reason")
            assertThat(currentScene).isEqualTo(previousScene)
        }

    @Test
    fun changeScene() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor

            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

@@ -77,6 +104,8 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun changeScene_toGoneWhenUnl_doesNotThrow() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor

            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

@@ -91,11 +120,15 @@ class SceneInteractorTest : SysuiTestCase() {

    @Test(expected = IllegalStateException::class)
    fun changeScene_toGoneWhenStillLocked_throws() =
        testScope.runTest { underTest.changeScene(Scenes.Gone, "reason") }
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            underTest.changeScene(Scenes.Gone, "reason")
        }

    @Test
    fun sceneChanged_inDataSource() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

@@ -107,6 +140,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun transitionState() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val underTest = kosmos.sceneContainerRepository
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
@@ -143,6 +177,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun transitioningTo() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(underTest.currentScene.value)
@@ -179,6 +214,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isTransitionUserInputOngoing_idle_false() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(Scenes.Shade)
@@ -193,6 +229,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isTransitionUserInputOngoing_transition_true() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
@@ -213,6 +250,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isTransitionUserInputOngoing_updateMidTransition_false() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
@@ -244,6 +282,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isTransitionUserInputOngoing_updateOnIdle_false() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
@@ -268,6 +307,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isVisible() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            val isVisible by collectLastValue(underTest.isVisible)
            assertThat(isVisible).isTrue()

@@ -281,6 +321,7 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun isVisible_duringRemoteUserInteraction_forcedVisible() =
        testScope.runTest {
            underTest = kosmos.sceneInteractor
            underTest.setVisible(false, "reason")
            val isVisible by collectLastValue(underTest.isVisible)
            assertThat(isVisible).isFalse()
+40 −21
Original line number Diff line number Diff line
@@ -16,10 +16,16 @@

package com.android.systemui.scene

import com.android.systemui.CoreStartable
import com.android.systemui.scene.domain.interactor.WindowRootViewVisibilityInteractor
import com.android.systemui.scene.domain.startable.SceneContainerStartable
import com.android.systemui.scene.shared.model.SceneContainerConfig
import com.android.systemui.scene.shared.model.Scenes
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap

/** Scene framework Dagger module suitable for variants that want to exclude "keyguard" scenes. */
@Module(
@@ -31,9 +37,21 @@ import dagger.Provides
            ShadeSceneModule::class,
        ],
)
object KeyguardlessSceneContainerFrameworkModule {
interface KeyguardlessSceneContainerFrameworkModule {

    // TODO(b/298234162): provide a SceneContainerStartable without lockscreen and bouncer.
    @Binds
    @IntoMap
    @ClassKey(SceneContainerStartable::class)
    fun containerStartable(impl: SceneContainerStartable): CoreStartable

    @Binds
    @IntoMap
    @ClassKey(WindowRootViewVisibilityInteractor::class)
    fun bindWindowRootViewVisibilityInteractor(
        impl: WindowRootViewVisibilityInteractor
    ): CoreStartable

    companion object {

        @Provides
        fun containerConfig(): SceneContainerConfig {
@@ -56,3 +74,4 @@ object KeyguardlessSceneContainerFrameworkModule {
            )
        }
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -81,14 +81,6 @@ constructor(
        toScene: SceneKey,
        transitionKey: TransitionKey? = null,
    ) {
        check(allSceneKeys().contains(toScene)) {
            """
                Cannot set the desired scene key to "$toScene". The configuration does not
                contain a scene with that key.
            """
                .trimIndent()
        }

        dataSource.changeScene(
            toScene = toScene,
            transitionKey = transitionKey,
+4 −0
Original line number Diff line number Diff line
@@ -162,6 +162,10 @@ constructor(
        loggingReason: String,
        transitionKey: TransitionKey? = null,
    ) {
        if (!repository.allSceneKeys().contains(toScene)) {
            return
        }

        check(
            toScene != Scenes.Gone || deviceUnlockedInteractor.deviceUnlockStatus.value.isUnlocked
        ) {
+6 −2
Original line number Diff line number Diff line
@@ -57,12 +57,14 @@ import com.android.systemui.statusbar.notification.domain.interactor.HeadsUpNoti
import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.statusbar.policy.domain.interactor.DeviceProvisioningInteractor
import com.android.systemui.util.asIndenting
import com.android.systemui.util.kotlin.getOrNull
import com.android.systemui.util.kotlin.pairwise
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.printSection
import com.android.systemui.util.println
import dagger.Lazy
import java.io.PrintWriter
import java.util.Optional
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -107,7 +109,7 @@ constructor(
    private val authenticationInteractor: Lazy<AuthenticationInteractor>,
    private val windowController: NotificationShadeWindowController,
    private val deviceProvisioningInteractor: DeviceProvisioningInteractor,
    private val centralSurfaces: CentralSurfaces,
    private val centralSurfacesOptLazy: Lazy<Optional<CentralSurfaces>>,
    private val headsUpInteractor: HeadsUpNotificationInteractor,
    private val occlusionInteractor: SceneContainerOcclusionInteractor,
    private val faceUnlockInteractor: DeviceEntryFaceAuthInteractor,
@@ -115,6 +117,8 @@ constructor(
    private val uiEventLogger: UiEventLogger,
    private val sceneBackInteractor: SceneBackInteractor,
) : CoreStartable {
    private val centralSurfaces: CentralSurfaces?
        get() = centralSurfacesOptLazy.get().getOrNull()

    override fun start() {
        if (SceneContainerFlag.isEnabled) {
@@ -542,7 +546,7 @@ constructor(
                }
                .collect { isInteractingOrNull ->
                    isInteractingOrNull?.let { isInteracting ->
                        centralSurfaces.setInteracting(
                        centralSurfaces?.setInteracting(
                            StatusBarManager.WINDOW_STATUS_BAR,
                            isInteracting,
                        )
Loading