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

Commit 60d050d8 authored by burakov's avatar burakov Committed by Danny Burakov
Browse files

[flexiglass] Use LaunchedEffectWithLifecycle to detect ShadeMode changes

With `alwaysCompose` enabled for Quick Settings, the activatable scope
is no longer limited to the Quick Settings shade being shown. Therefore
we switch to LaunchedEffectWithLifecycle instead, to ensure ShadeMode
detection only runs while the shade is expanded.

Fix: 438770974
Test: Updated unit tests.
Test: Manually tested by disabling and re-enabling Dual Shade in the
 Settings app, and observing that Quick Settings no longer unexpectedly
 opens.
Flag: com.android.systemui.scene_container
Change-Id: Ice3a6e830f0d3f759f8edaa3e5d3cbd39c69ce8d
parent faa18036
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@ constructor(
            }
        }

        LaunchedEffectWithLifecycle(key1 = Unit) { viewModel.detectShadeModeChanges() }

        QuickSettingsScene(
            notificationStackScrollView = notificationStackScrollView.get(),
            viewModel = viewModel,
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.UserAction
import com.android.compose.animation.scene.UserActionResult
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.lifecycle.LaunchedEffectWithLifecycle
import com.android.compose.modifiers.thenIf
import com.android.systemui.brightness.ui.compose.BrightnessSliderContainer
import com.android.systemui.brightness.ui.compose.ContainerColors
@@ -148,6 +149,8 @@ constructor(
        // Set the bounds to null when the QuickSettings overlay disappears.
        DisposableEffect(Unit) { onDispose { contentViewModel.onPanelShapeInWindowChanged(null) } }

        LaunchedEffectWithLifecycle(key1 = Unit) { contentViewModel.detectShadeModeChanges() }

        Box(modifier = modifier.graphicsLayer { alpha = contentAlphaFromBrightnessMirror }) {
            OverlayShade(
                panelElement = QuickSettingsShade.Elements.Panel,
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.window.domain.interactor.windowRootViewBlurInteractor
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.launch
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -85,6 +86,7 @@ class QuickSettingsSceneContentViewModelTest : SysuiTestCase() {
                    windowRootViewBlurInteractor = windowRootViewBlurInteractor,
                )
            underTest.activateIn(testScope)
            testScope.backgroundScope.launch { underTest.detectShadeModeChanges() }
            disableDualShade()
        }
    }
+2 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.systemui.statusbar.policy.configurationController
import com.android.systemui.testKosmos
import com.android.systemui.window.data.repository.fakeWindowRootViewBlurRepository
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.launch
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -80,6 +81,7 @@ class QuickSettingsShadeOverlayContentViewModelTest : SysuiTestCase() {
            enableDualShade()
            runCurrent()
            underTest.activateIn(testScope)
            testScope.backgroundScope.launch { underTest.detectShadeModeChanges() }
        }

    @Test
+26 −19
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.withContext

/**
 * Models UI state needed for rendering the content of the quick settings scene.
@@ -94,29 +95,35 @@ constructor(

            launch { qsContainerViewModel.activate() }

            launch(context = mainDispatcher) {
            awaitCancellation()
        }
    }

    /**
     * Monitors changes to the shade mode that would make this scene stale, and snaps to the
     * appropriate scene/overlay instead.
     *
     * This function must only run while the scene is shown. Therefore, it shouldn't be part of
     * [onActivated()] while this scene uses `alwaysCompose`.
     */
    suspend fun detectShadeModeChanges(): Nothing {
        shadeModeInteractor.shadeMode.collect { shadeMode ->
            withContext(mainDispatcher) {
                val loggingReason = "Unfold while on Quick Settings"
                when (shadeMode) {
                        is ShadeMode.Split ->
                            sceneInteractor.snapToScene(
                                Scenes.Shade,
                                loggingReason = "Unfold while on Quick Settings",
                            )
                    is ShadeMode.Split -> sceneInteractor.snapToScene(Scenes.Shade, loggingReason)
                    is ShadeMode.Dual -> {
                            val loggingReason = "Unfold or rotate while on Quick Settings"
                        sceneInteractor.snapToScene(SceneFamilies.Home, loggingReason)
                        sceneInteractor.instantlyShowOverlay(
                            Overlays.QuickSettingsShade,
                            loggingReason,
                        )
                    }

                    else -> Unit
                }
            }
        }

            awaitCancellation()
        }
    }

    @AssistedFactory
Loading