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

Commit fd59bd3d authored by Lucas Silva's avatar Lucas Silva
Browse files

Remove references to deprecated methods

Removes usage of deprecated methods in CommunalSceneStartable and
CommunalViewModel, as there is now a standalone interactor for
scene-related logic.

Test: atest SystemUiRoboTests
Flag: com.android.systemui.glanceable_hub
Bug: 331591373
Change-Id: I75097a1fc9be9aae5164a7ccb5fa5d3469c49a77
parent 5df44e99
Loading
Loading
Loading
Loading
+32 −36
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.setCommunalAvailable
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.coroutines.collectLastValue
@@ -70,6 +71,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
                CommunalSceneStartable(
                        dockManager = dockManager,
                        communalInteractor = communalInteractor,
                        communalSceneInteractor = communalSceneInteractor,
                        keyguardTransitionInteractor = keyguardTransitionInteractor,
                        keyguardInteractor = keyguardInteractor,
                        systemSettings = fakeSettings,
@@ -94,9 +96,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun keyguardGoesAway_forceBlankScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)

                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                fakeKeyguardTransitionRepository.sendTransitionSteps(
@@ -114,7 +116,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun deviceDocked_forceCommunalScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Blank)

                updateDocked(true)
@@ -132,8 +134,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        with(kosmos) {
            testScope.runTest {
                whenever(centralSurfaces.isLaunchingActivityOverLockscreen).thenReturn(false)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                updateDocked(true)
@@ -151,8 +153,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        with(kosmos) {
            testScope.runTest {
                whenever(centralSurfaces.isLaunchingActivityOverLockscreen).thenReturn(true)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                updateDocked(true)
@@ -169,7 +171,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun deviceDocked_doesNotForceCommunalIfTransitioningFromCommunal() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Blank)

                updateDocked(true)
@@ -186,8 +188,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun deviceAsleep_forceBlankSceneAfterTimeout() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                fakeKeyguardTransitionRepository.sendTransitionSteps(
@@ -207,8 +209,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun deviceAsleep_wakesUpBeforeTimeout_noChangeInScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                fakeKeyguardTransitionRepository.sendTransitionSteps(
@@ -236,8 +238,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun dockingOnLockscreen_forcesCommunal() =
        with(kosmos) {
            testScope.runTest {
                communalInteractor.changeScene(CommunalScenes.Blank)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalSceneInteractor.changeScene(CommunalScenes.Blank)
                val scene by collectLastValue(communalSceneInteractor.currentScene)

                // device is docked while on the lockscreen
                fakeKeyguardTransitionRepository.sendTransitionSteps(
@@ -258,8 +260,8 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun dockingOnLockscreen_doesNotForceCommunalIfDreamStarts() =
        with(kosmos) {
            testScope.runTest {
                communalInteractor.changeScene(CommunalScenes.Blank)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalSceneInteractor.changeScene(CommunalScenes.Blank)
                val scene by collectLastValue(communalSceneInteractor.currentScene)

                // device is docked while on the lockscreen
                fakeKeyguardTransitionRepository.sendTransitionSteps(
@@ -290,9 +292,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                // Scene times out back to blank after the screen timeout.
@@ -307,11 +309,11 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            testScope.runTest {
                // Device is not dreaming and on communal.
                updateDreaming(false)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                // Scene stays as Communal
                advanceTimeBy(SCREEN_TIMEOUT.milliseconds)
                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)
            }
        }
@@ -322,9 +324,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                // Wait a bit, but not long enough to timeout.
@@ -345,9 +347,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            testScope.runTest {
                // Device is on communal, but not dreaming.
                updateDreaming(false)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                // Wait a bit, but not long enough to timeout, then start dreaming.
@@ -366,11 +368,11 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        with(kosmos) {
            testScope.runTest {
                // Device is on communal.
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

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

                // Start dreaming.
@@ -387,9 +389,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            testScope.runTest {
                // Device is dreaming and on communal.
                updateDreaming(true)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                // Wait a bit, but not long enough to timeout.
@@ -416,9 +418,9 @@ class CommunalSceneStartableTest : SysuiTestCase() {

                // Device is dreaming and on communal.
                updateDreaming(true)
                communalInteractor.changeScene(CommunalScenes.Communal)
                communalSceneInteractor.changeScene(CommunalScenes.Communal)

                val scene by collectLastValue(communalInteractor.desiredScene)
                val scene by collectLastValue(communalSceneInteractor.currentScene)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                // Scene times out back to blank after the screen timeout.
@@ -445,12 +447,6 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            runCurrent()
        }

    private suspend fun TestScope.enableCommunal() =
        with(kosmos) {
            setCommunalAvailable(true)
            runCurrent()
        }

    companion object {
        private const val SCREEN_TIMEOUT = 1000
    }
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.communal.data.repository.fakeCommunalMediaRepository
import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository
import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalUiEvent
@@ -106,6 +107,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {

        underTest =
            CommunalEditModeViewModel(
                kosmos.communalSceneInteractor,
                kosmos.communalInteractor,
                kosmos.communalSettingsInteractor,
                mediaHost,
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.communal.data.repository.fakeCommunalRepository
import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository
import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalTutorialInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.model.CommunalScenes
@@ -143,6 +144,7 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                context.resources,
                kosmos.keyguardTransitionInteractor,
                kosmos.keyguardInteractor,
                kosmos.communalSceneInteractor,
                kosmos.communalInteractor,
                kosmos.communalTutorialInteractor,
                kosmos.shadeInteractor,
+8 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.provider.Settings
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.CoreStartable
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
import com.android.systemui.dagger.SysUISingleton
@@ -67,6 +68,7 @@ class CommunalSceneStartable
constructor(
    private val dockManager: DockManager,
    private val communalInteractor: CommunalInteractor,
    private val communalSceneInteractor: CommunalSceneInteractor,
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    private val systemSettings: SystemSettings,
@@ -90,7 +92,7 @@ constructor(
            .mapLatest(::determineSceneAfterTransition)
            .filterNotNull()
            .onEach { nextScene ->
                communalInteractor.changeScene(nextScene, CommunalTransitionKeys.SimpleFade)
                communalSceneInteractor.changeScene(nextScene, CommunalTransitionKeys.SimpleFade)
            }
            .launchIn(applicationScope)

@@ -130,7 +132,7 @@ constructor(
        // app is updated by the Play store, a new timeout should be started.
        bgScope.launch {
            combine(
                    communalInteractor.desiredScene,
                    communalSceneInteractor.currentScene,
                    // Emit a value on start so the combine starts.
                    communalInteractor.userActivity.emitOnStart()
                ) { scene, _ ->
@@ -146,19 +148,19 @@ constructor(
        }
        bgScope.launch {
            keyguardInteractor.isDreaming
                .sample(communalInteractor.desiredScene, ::Pair)
                .sample(communalSceneInteractor.currentScene, ::Pair)
                .collectLatest { (isDreaming, scene) ->
                    this@CommunalSceneStartable.isDreaming = isDreaming
                    if (scene == CommunalScenes.Communal && isDreaming && timeoutJob == null) {
                        // If dreaming starts after timeout has expired, ex. if dream restarts under
                        // the hub, just close the hub immediately.
                        communalInteractor.changeScene(CommunalScenes.Blank)
                        communalSceneInteractor.changeScene(CommunalScenes.Blank)
                    }
                }
        }

        bgScope.launch {
            communalInteractor.isIdleOnCommunal.collectLatest {
            communalSceneInteractor.isIdleOnCommunal.collectLatest {
                withContext(mainDispatcher) {
                    notificationShadeWindowController.setGlanceableHubShowing(it)
                }
@@ -177,7 +179,7 @@ constructor(
                bgScope.launch {
                    delay(screenTimeout.milliseconds)
                    if (isDreaming) {
                        communalInteractor.changeScene(CommunalScenes.Blank)
                        communalSceneInteractor.changeScene(CommunalScenes.Blank)
                    }
                    timeoutJob = null
                }
+5 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.widgets.WidgetConfigurator
import com.android.systemui.media.controls.ui.view.MediaHost
@@ -33,10 +34,11 @@ import kotlinx.coroutines.flow.flowOf

/** The base view model for the communal hub. */
abstract class BaseCommunalViewModel(
    private val communalSceneInteractor: CommunalSceneInteractor,
    private val communalInteractor: CommunalInteractor,
    val mediaHost: MediaHost,
) {
    val currentScene: Flow<SceneKey> = communalInteractor.desiredScene
    val currentScene: Flow<SceneKey> = communalSceneInteractor.currentScene

    /** Whether communal hub should be focused by accessibility tools. */
    open val isFocusable: Flow<Boolean> = MutableStateFlow(false)
@@ -58,7 +60,7 @@ abstract class BaseCommunalViewModel(
    }

    fun changeScene(scene: SceneKey, transitionKey: TransitionKey? = null) {
        communalInteractor.changeScene(scene, transitionKey)
        communalSceneInteractor.changeScene(scene, transitionKey)
    }

    /**
@@ -67,7 +69,7 @@ abstract class BaseCommunalViewModel(
     * Note that you must call is with `null` when the UI is done or risk a memory leak.
     */
    fun setTransitionState(transitionState: Flow<ObservableTransitionState>?) {
        communalInteractor.setTransitionState(transitionState)
        communalSceneInteractor.setTransitionState(transitionState)
    }

    /**
Loading