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

Commit e0361336 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Crash when switching to incorrect shades

Reintroduces a protection that we used to have before ag/31525022 that
was based on crashing when switching to scenes or overlays that weren't
in the SceneContainerConfig. This time it's done in the validate
methods.

Flag: com.android.systemui.scene_container
Fix: 394632852
Test: unit tests added
Change-Id: I810abd687d2beb95bf5aae87a76d7db1fc765c93
parent 500edc9e
Loading
Loading
Loading
Loading
+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)
    }

+58 −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,52 @@ 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")
        }
}
+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()
        }

+0 −22
Original line number Diff line number Diff line
@@ -780,28 +780,6 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
            assertThat(currentOverlays).isEmpty()
        }

    @Test
    fun collapseQuickSettingsShadeNotBypassingShade_splitShade_switchesToLockscreen() =
        testScope.runTest {
            kosmos.enableSplitShade()
            val shadeMode by collectLastValue(kosmos.shadeMode)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
            assertThat(shadeMode).isEqualTo(ShadeMode.Split)

            sceneInteractor.changeScene(Scenes.QuickSettings, "reason")
            assertThat(currentScene).isEqualTo(Scenes.QuickSettings)
            assertThat(currentOverlays).isEmpty()

            underTest.collapseQuickSettingsShade(
                loggingReason = "reason",
                bypassNotificationsShade = false,
            )

            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
            assertThat(currentOverlays).isEmpty()
        }

    @Test
    fun collapseQuickSettingsShadeBypassingShade_singleShade_switchesToLockscreen() =
        testScope.runTest {
Loading