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

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

Move changeScene calls to the application scope

SceneTransitionLayout now enforces that state changes are done on the
same thread the STL was made on, which in our case is just the main
thread.

Move our calls to the main thread to fix timeout and potentially other
places where we go to/from the glanceable hub from breaking.

Bug: 342470602
Fix: 342470602
Test: manually verified that hub times out successfully
Flag: com.android.systemui.glanceable_hub
Change-Id: I980a314f3198f04611a0e9e979326ba0d2db34e7
parent 6ed86daa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ class CommunalRepositoryImplTest : SysuiTestCase() {
    private val testScope = kosmos.testScope
    private val underTest by lazy {
        CommunalSceneRepositoryImpl(
            kosmos.applicationCoroutineScope,
            kosmos.applicationCoroutineScope,
            kosmos.sceneDataSource,
        )
+13 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.communal.dagger.Communal
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.scene.shared.model.SceneDataSource
import javax.inject.Inject
@@ -34,6 +35,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/** Encapsulates the state of communal mode. */
interface CommunalSceneRepository {
@@ -64,6 +66,7 @@ interface CommunalSceneRepository {
class CommunalSceneRepositoryImpl
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Background backgroundScope: CoroutineScope,
    @Communal private val sceneDataSource: SceneDataSource,
) : CommunalSceneRepository {
@@ -82,12 +85,20 @@ constructor(
            )

    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
        applicationScope.launch {
            // SceneTransitionLayout state updates must be triggered on the thread the STL was
            // created on.
            sceneDataSource.changeScene(toScene, transitionKey)
        }
    }

    override fun snapToScene(toScene: SceneKey) {
        applicationScope.launch {
            // SceneTransitionLayout state updates must be triggered on the thread the STL was
            // created on.
            sceneDataSource.snapToScene(toScene)
        }
    }

    /**
     * Updates the transition state of the hub [SceneTransitionLayout].