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

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

Merge changes Ifba461b2,I810abd68 into main

* changes:
  [flexiglass] Adds instantly(Show|Hide)Overlay to SceneInteractor
  [flexiglass] Crash when switching to incorrect shades
parents 913d4058 198ac2da
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -59,10 +59,7 @@ class SceneTransitionLayoutDataSource(
                initialValue = emptySet(),
            )

    override fun changeScene(
        toScene: SceneKey,
        transitionKey: TransitionKey?,
    ) {
    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
        state.setTargetScene(
            targetScene = toScene,
            transitionKey = transitionKey,
@@ -71,9 +68,7 @@ class SceneTransitionLayoutDataSource(
    }

    override fun snapToScene(toScene: SceneKey) {
        state.snapToScene(
            scene = toScene,
        )
        state.snapToScene(scene = toScene)
    }

    override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) {
@@ -100,4 +95,18 @@ class SceneTransitionLayoutDataSource(
            transitionKey = transitionKey,
        )
    }

    override fun instantlyShowOverlay(overlay: OverlayKey) {
        state.snapToScene(
            scene = state.transitionState.currentScene,
            currentOverlays = state.currentOverlays + overlay,
        )
    }

    override fun instantlyHideOverlay(overlay: OverlayKey) {
        state.snapToScene(
            scene = state.transitionState.currentScene,
            currentOverlays = state.currentOverlays - overlay,
        )
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.authentication.domain.interactor.AuthenticationResul
import com.android.systemui.authentication.domain.interactor.authenticationInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.testScope
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
@@ -65,6 +66,7 @@ class NotificationsShadeOverlayContentViewModelTest : SysuiTestCase() {
    fun setUp() {
        kosmos.sceneContainerStartable.start()
        kosmos.enableDualShade()
        kosmos.runCurrent()
        underTest.activateIn(testScope)
    }

+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.authentication.domain.interactor.AuthenticationResul
import com.android.systemui.authentication.domain.interactor.authenticationInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.testScope
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
@@ -68,6 +69,7 @@ class QuickSettingsShadeOverlayContentViewModelTest : SysuiTestCase() {
    fun setUp() {
        kosmos.sceneContainerStartable.start()
        kosmos.enableDualShade()
        kosmos.runCurrent()
        underTest.activateIn(testScope)
    }

+96 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintA
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.Idle
@@ -44,6 +45,8 @@ import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.SceneFamilies
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.fakeSceneDataSource
import com.android.systemui.shade.domain.interactor.disableDualShade
import com.android.systemui.shade.domain.interactor.enableDualShade
import com.android.systemui.statusbar.disableflags.data.repository.fakeDisableFlagsRepository
import com.android.systemui.statusbar.disableflags.shared.model.DisableFlagsModel
import com.android.systemui.testKosmos
@@ -298,7 +301,9 @@ class SceneInteractorTest : SysuiTestCase() {

    @Test
    fun transitioningTo_overlayChange() =
        testScope.runTest {
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(underTest.currentScene.value)
@@ -529,6 +534,8 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun showOverlay_overlayDisabled_doesNothing() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val disabledOverlay = Overlays.QuickSettingsShade
            fakeDisableFlagsRepository.disableFlags.value =
@@ -544,6 +551,8 @@ class SceneInteractorTest : SysuiTestCase() {
    @Test
    fun replaceOverlay_withDisabledOverlay_doesNothing() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val showingOverlay = Overlays.NotificationsShade
            underTest.showOverlay(showingOverlay, "reason")
@@ -618,4 +627,90 @@ class SceneInteractorTest : SysuiTestCase() {
            // No more active animations, not forced visible.
            assertThat(isVisible).isFalse()
        }

    @Test(expected = IllegalStateException::class)
    fun changeScene_toIncorrectShade_crashes() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            underTest.changeScene(Scenes.Shade, "reason")
        }

    @Test(expected = IllegalStateException::class)
    fun changeScene_toIncorrectQuickSettings_crashes() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            underTest.changeScene(Scenes.QuickSettings, "reason")
        }

    @Test(expected = IllegalStateException::class)
    fun snapToScene_toIncorrectShade_crashes() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            underTest.snapToScene(Scenes.Shade, "reason")
        }

    @Test(expected = IllegalStateException::class)
    fun snapToScene_toIncorrectQuickSettings_crashes() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            underTest.changeScene(Scenes.QuickSettings, "reason")
        }

    @Test(expected = IllegalStateException::class)
    fun showOverlay_incorrectShadeOverlay_crashes() =
        kosmos.runTest {
            disableDualShade()
            runCurrent()
            underTest.showOverlay(Overlays.NotificationsShade, "reason")
        }

    @Test(expected = IllegalStateException::class)
    fun showOverlay_incorrectQuickSettingsOverlay_crashes() =
        kosmos.runTest {
            disableDualShade()
            runCurrent()
            underTest.showOverlay(Overlays.QuickSettingsShade, "reason")
        }

    @Test
    fun instantlyShowOverlay() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentScene by collectLastValue(underTest.currentScene)
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val originalScene = currentScene
            assertThat(currentOverlays).isEmpty()

            val overlay = Overlays.NotificationsShade
            underTest.instantlyShowOverlay(overlay, "reason")
            runCurrent()

            assertThat(currentScene).isEqualTo(originalScene)
            assertThat(currentOverlays).contains(overlay)
        }

    @Test
    fun instantlyHideOverlay() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentScene by collectLastValue(underTest.currentScene)
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val overlay = Overlays.QuickSettingsShade
            underTest.showOverlay(overlay, "reason")
            runCurrent()
            val originalScene = currentScene
            assertThat(currentOverlays).contains(overlay)

            underTest.instantlyHideOverlay(overlay, "reason")
            runCurrent()

            assertThat(currentScene).isEqualTo(originalScene)
            assertThat(currentOverlays).isEmpty()
        }
}
+22 −8
Original line number Diff line number Diff line
@@ -2049,9 +2049,9 @@ class SceneContainerStartableTest : SysuiTestCase() {
            )

            clearInvocations(centralSurfaces)
            emulateSceneTransition(
            emulateOverlayTransition(
                transitionStateFlow = transitionStateFlow,
                toScene = Scenes.Shade,
                toOverlay = Overlays.NotificationsShade,
                verifyBeforeTransition = {
                    verify(centralSurfaces, never()).setInteracting(anyInt(), anyBoolean())
                },
@@ -2079,9 +2079,9 @@ class SceneContainerStartableTest : SysuiTestCase() {
            )

            clearInvocations(centralSurfaces)
            emulateSceneTransition(
            emulateOverlayTransition(
                transitionStateFlow = transitionStateFlow,
                toScene = Scenes.QuickSettings,
                toOverlay = Overlays.QuickSettingsShade,
                verifyBeforeTransition = {
                    verify(centralSurfaces, never()).setInteracting(anyInt(), anyBoolean())
                },
@@ -2654,22 +2654,36 @@ class SceneContainerStartableTest : SysuiTestCase() {
        }

    @Test
    fun handleDisableFlags() =
    fun handleDisableFlags_singleShade() =
        kosmos.runTest {
            underTest.start()
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
            disableDualShade()
            runCurrent()
            sceneInteractor.changeScene(Scenes.Shade, "reason")
            sceneInteractor.showOverlay(Overlays.NotificationsShade, "reason")
            assertThat(currentScene).isEqualTo(Scenes.Shade)
            assertThat(currentOverlays).contains(Overlays.NotificationsShade)

            fakeDisableFlagsRepository.disableFlags.value =
                DisableFlagsModel(disable2 = StatusBarManager.DISABLE2_NOTIFICATION_SHADE)
            runCurrent()

            assertThat(currentScene).isNotEqualTo(Scenes.Shade)
        }

    @Test
    fun handleDisableFlags_dualShade() =
        kosmos.runTest {
            underTest.start()
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
            enableDualShade()
            runCurrent()
            sceneInteractor.showOverlay(Overlays.NotificationsShade, "reason")
            assertThat(currentOverlays).contains(Overlays.NotificationsShade)

            fakeDisableFlagsRepository.disableFlags.value =
                DisableFlagsModel(disable2 = StatusBarManager.DISABLE2_NOTIFICATION_SHADE)
            runCurrent()

            assertThat(currentOverlays).isEmpty()
        }

Loading