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

Commit 64bca52b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] validateSceneChange returns false when from == to" into main

parents bc69f41a bed0d988
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteract
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
@@ -60,6 +61,10 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -713,4 +718,43 @@ class SceneInteractorTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(originalScene)
            assertThat(currentOverlays).isEmpty()
        }

    @Test
    fun changeScene_notifiesAboutToChangeListener() =
        kosmos.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            // Unlock so transitioning to the Gone scene becomes possible.
            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            runCurrent()
            underTest.changeScene(toScene = Scenes.Gone, loggingReason = "")
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Gone)

            val processor = mock<SceneInteractor.OnSceneAboutToChangeListener>()
            underTest.registerSceneStateProcessor(processor)

            underTest.changeScene(
                toScene = Scenes.Lockscreen,
                sceneState = KeyguardState.AOD,
                loggingReason = "",
            )
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

            verify(processor).onSceneAboutToChange(Scenes.Lockscreen, KeyguardState.AOD)
        }

    @Test
    fun changeScene_noOp_whenFromAndToAreTheSame() =
        kosmos.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            val processor = mock<SceneInteractor.OnSceneAboutToChangeListener>()
            underTest.registerSceneStateProcessor(processor)

            underTest.changeScene(toScene = checkNotNull(currentScene), loggingReason = "")

            verify(processor, never()).onSceneAboutToChange(any(), any())
        }
}
+20 −3
Original line number Diff line number Diff line
@@ -240,7 +240,13 @@ constructor(
    ) {
        val currentSceneKey = currentScene.value
        val resolvedScene = sceneFamilyResolvers.get()[toScene]?.resolvedScene?.value ?: toScene
        if (!validateSceneChange(to = resolvedScene, loggingReason = loggingReason)) {
        if (
            !validateSceneChange(
                from = currentSceneKey,
                to = resolvedScene,
                loggingReason = loggingReason,
            )
        ) {
            return
        }

@@ -273,7 +279,13 @@ constructor(
                    familyResolver.resolvedScene.value
                }
            } ?: toScene
        if (!validateSceneChange(to = resolvedScene, loggingReason = loggingReason)) {
        if (
            !validateSceneChange(
                from = currentSceneKey,
                to = resolvedScene,
                loggingReason = loggingReason,
            )
        ) {
            return
        }

@@ -491,11 +503,12 @@ constructor(
     * Will throw a runtime exception for illegal states (for example, attempting to change to a
     * scene that's not part of the current scene framework configuration).
     *
     * @param from The current scene being transitioned away from
     * @param to The desired destination scene to transition to
     * @param loggingReason The reason why the transition is requested, for logging purposes
     * @return `true` if the scene change is valid; `false` if it shouldn't happen
     */
    private fun validateSceneChange(to: SceneKey, loggingReason: String): Boolean {
    private fun validateSceneChange(from: SceneKey, to: SceneKey, loggingReason: String): Boolean {
        check(
            !shadeModeInteractor.isDualShade || (to != Scenes.Shade && to != Scenes.QuickSettings)
        ) {
@@ -505,6 +518,10 @@ constructor(
            "Can't change scene to ${to.debugName} in split shade mode!"
        }

        if (from == to) {
            return false
        }

        if (to !in repository.allContentKeys) {
            return false
        }