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

Commit 9651754a authored by Prince's avatar Prince
Browse files

Created a delay to scene

Test: atest CommunalSceneInteractorTest
Flag: NONE simple change
Fixes: 336641384
Change-Id: I83ef22833ab0771db63398bd8f2eff5dffe4ab6f
parent 9f835c5f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.domain.model.CommunalTransitionProgressModel
import com.android.systemui.communal.shared.model.CommunalScenes
@@ -27,8 +28,10 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
@@ -63,6 +66,21 @@ class CommunalSceneInteractorTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
        }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    fun snapToSceneWithDelay() =
        testScope.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
            underTest.snapToScene(
                CommunalScenes.Communal,
                ActivityTransitionAnimator.TIMINGS.totalDuration
            )
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
            advanceTimeBy(ActivityTransitionAnimator.TIMINGS.totalDuration)
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
        }

    @Test
    fun transitionProgress_fullProgress() =
        testScope.runTest {
+4 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.scene.shared.model.SceneDataSource
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -51,7 +52,7 @@ interface CommunalSceneRepository {
    fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null)

    /** Immediately snaps to the desired scene. */
    fun snapToScene(toScene: SceneKey)
    fun snapToScene(toScene: SceneKey, delayMillis: Long = 0)

    /**
     * Updates the transition state of the hub [SceneTransitionLayout].
@@ -92,10 +93,11 @@ constructor(
        }
    }

    override fun snapToScene(toScene: SceneKey) {
    override fun snapToScene(toScene: SceneKey, delayMillis: Long) {
        applicationScope.launch {
            // SceneTransitionLayout state updates must be triggered on the thread the STL was
            // created on.
            delay(delayMillis)
            sceneDataSource.snapToScene(toScene)
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -53,8 +53,8 @@ constructor(
    }

    /** Immediately snaps to the new scene. */
    fun snapToScene(newScene: SceneKey) {
        communalSceneRepository.snapToScene(newScene)
    fun snapToScene(newScene: SceneKey, delayMillis: Long = 0) {
        communalSceneRepository.snapToScene(newScene, delayMillis)
    }

    /**
+6 −4
Original line number Diff line number Diff line
@@ -555,7 +555,12 @@ constructor(

                override fun onTransitionAnimationStart(isExpandingFullyAbove: Boolean) {
                    super.onTransitionAnimationStart(isExpandingFullyAbove)

                    if (communalHub()) {
                        communalSceneInteractor.snapToScene(
                            CommunalScenes.Blank,
                            ActivityTransitionAnimator.TIMINGS.totalDuration
                        )
                    }
                    // Double check that the keyguard is still showing and not going
                    // away, but if so set the keyguard occluded. Typically, WM will let
                    // KeyguardViewMediator know directly, but we're overriding that to
@@ -581,9 +586,6 @@ constructor(
                    // collapse the shade (or at least run the post collapse runnables)
                    // later on.
                    centralSurfaces?.setIsLaunchingActivityOverLockscreen(false, false)
                    if (communalHub()) {
                        communalSceneInteractor.snapToScene(CommunalScenes.Blank)
                    }
                    delegate.onTransitionAnimationEnd(isExpandingFullyAbove)
                }

+11 −5
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.communal.shared.model.CommunalScenes
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -13,20 +14,25 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/** Fake implementation of [CommunalSceneRepository]. */
@OptIn(ExperimentalCoroutinesApi::class)
class FakeCommunalSceneRepository(
    applicationScope: CoroutineScope,
    private val applicationScope: CoroutineScope,
    override val currentScene: MutableStateFlow<SceneKey> =
        MutableStateFlow(CommunalScenes.Default),
) : CommunalSceneRepository {

    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) =
        snapToScene(toScene)
        snapToScene(toScene, 0)

    override fun snapToScene(toScene: SceneKey) {
        this.currentScene.value = toScene
        this._transitionState.value = flowOf(ObservableTransitionState.Idle(toScene))
    override fun snapToScene(toScene: SceneKey, delayMillis: Long) {
        applicationScope.launch {
            delay(delayMillis)
            currentScene.value = toScene
            _transitionState.value = flowOf(ObservableTransitionState.Idle(toScene))
        }
    }

    private val defaultTransitionState = ObservableTransitionState.Idle(CommunalScenes.Default)