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

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

Merge "[Dual Shade] Fix shade interactor's `isQsFullscreen` in Dual Shade." into main

parents 85dde963 a9279f45
Loading
Loading
Loading
Loading
+79 −4
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.shade.shared.model.ShadeMode
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.TestScope
@@ -43,6 +44,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@EnableSceneContainer
@@ -114,7 +116,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
        }

    @Test
    fun qsFullscreen_falseWhenTransitioning() =
    fun qsFullscreen_singleShade_falseWhenTransitioning() =
        testScope.runTest {
            val actual by collectLastValue(underTest.isQsFullscreen)

@@ -139,7 +141,36 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
        }

    @Test
    fun qsFullscreen_falseWhenIdleNotQS() =
    fun qsFullscreen_dualShade_falseWhenTransitioning() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = false)
            val actual by collectLastValue(underTest.isQsFullscreen)

            // WHEN overlay transition active
            keyguardRepository.setStatusBarState(StatusBarState.SHADE)
            sceneInteractor.setTransitionState(
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition.ReplaceOverlay(
                        fromOverlay = Overlays.QuickSettingsShade,
                        toOverlay = Overlays.NotificationsShade,
                        currentScene = Scenes.Gone,
                        currentOverlays = flowOf(setOf(Overlays.QuickSettingsShade)),
                        progress = MutableStateFlow(.3f),
                        isInitiatedByUserInput = false,
                        isUserInputOngoing = flowOf(false),
                        previewProgress = flowOf(0f),
                        isInPreviewStage = flowOf(false),
                    )
                )
            )
            runCurrent()

            // THEN QS is not fullscreen
            assertThat(actual).isFalse()
        }

    @Test
    fun qsFullscreen_falseWhenIdleNotQs() =
        testScope.runTest {
            val actual by collectLastValue(underTest.isQsFullscreen)

@@ -157,7 +188,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
        }

    @Test
    fun qsFullscreen_falseWhenIdleSplitShadeQs() =
    fun qsFullscreen_splitShade_falseWhenIdleQs() =
        testScope.runTest {
            val actual by collectLastValue(underTest.isQsFullscreen)

@@ -176,7 +207,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
        }

    @Test
    fun qsFullscreen_trueWhenIdleQS() =
    fun qsFullscreen_singleShade_trueWhenIdleQs() =
        testScope.runTest {
            val actual by collectLastValue(underTest.isQsFullscreen)

@@ -193,6 +224,50 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() {
            assertThat(actual).isTrue()
        }

    @Test
    fun qsFullscreen_dualShade_trueWhenIdleQs() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = false)
            val actual by collectLastValue(underTest.isQsFullscreen)

            // WHEN Idle on QuickSettingsShade overlay
            keyguardRepository.setStatusBarState(StatusBarState.SHADE)
            sceneInteractor.setTransitionState(
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(
                        currentScene = Scenes.Gone,
                        currentOverlays = setOf(Overlays.QuickSettingsShade),
                    )
                )
            )
            runCurrent()

            // THEN QS is fullscreen
            assertThat(actual).isTrue()
        }

    @Test
    fun qsFullscreen_dualShadeWide_falseWhenIdleQs() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = true)
            val actual by collectLastValue(underTest.isQsFullscreen)

            // WHEN Idle on QuickSettingsShade overlay
            keyguardRepository.setStatusBarState(StatusBarState.SHADE)
            sceneInteractor.setTransitionState(
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(
                        currentScene = Scenes.Gone,
                        currentOverlays = setOf(Overlays.QuickSettingsShade),
                    )
                )
            )
            runCurrent()

            // THEN QS is fullscreen
            assertThat(actual).isFalse()
        }

    @Test
    fun lockscreenShadeExpansion_idle_onScene() =
        testScope.runTest {
+26 −11
Original line number Diff line number Diff line
@@ -95,18 +95,16 @@ constructor(
        shadeModeInteractor.shadeMode
            .flatMapLatest { shadeMode ->
                when (shadeMode) {
                    ShadeMode.Single ->
                        sceneInteractor.transitionState
                            .map { state ->
                                when (state) {
                                    is ObservableTransitionState.Idle ->
                                        state.currentScene == Scenes.QuickSettings
                                    is ObservableTransitionState.Transition -> false
                    ShadeMode.Single -> Scenes.QuickSettings.isShownAndIdle
                    ShadeMode.Split -> flowOf(false)
                    ShadeMode.Dual ->
                        shadeModeInteractor.isShadeLayoutWide.flatMapLatest { isShadeLayoutWide ->
                            if (isShadeLayoutWide) {
                                flowOf(false)
                            } else {
                                Overlays.QuickSettingsShade.isShownAndIdle
                            }
                        }
                            .distinctUntilChanged()
                    ShadeMode.Split,
                    ShadeMode.Dual -> flowOf(false)
                }
            }
            .distinctUntilChanged()
@@ -368,6 +366,23 @@ constructor(
            }
            .distinctUntilChanged()

    /** Whether this content key is currently shown and in idle transition state. */
    private val ContentKey.isShownAndIdle: Flow<Boolean>
        get() {
            return sceneInteractor.transitionState
                .map { state ->
                    when (state) {
                        is ObservableTransitionState.Idle ->
                            when (this) {
                                is SceneKey -> this == state.currentScene
                                is OverlayKey -> this in state.currentOverlays
                            }
                        is ObservableTransitionState.Transition -> false
                    }
                }
                .distinctUntilChanged()
        }

    private val ShadeMode.notificationsContentKey: ContentKey
        get() {
            return when (this) {