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

Commit 18c4b17d authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Fabián Kozynski
Browse files

Make Edit mode internal in QuickSettingsScene

This removes the top level QSEditMode scene and replaces it with an
internal STL in QuickSettingsScene. Also, adds the appropriate
transitions.

Issues:
 * when swiping up from the bottom of edit mode, to dismiss to Gone, it
   dismisses correctly, but after performing this dismiss, next time QS
   is opened, it will crash (b/437886576)

Test: manual
Bug: 420960164
Bug: 437886576
Flag: com.android.systemui.scene_container
Change-Id: Ife70fae89919326a255a1e4ed3de89a4f3a1a19b
parent 21e7eb73
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.scene

import com.android.systemui.qs.ui.composable.EditModeScene
import com.android.systemui.scene.ui.composable.Scene
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoSet

@Module
interface EditSceneModule {
    @Binds @IntoSet fun editModeScene(scene: EditModeScene): Scene
}
+0 −87
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.ui.composable

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.UserAction
import com.android.compose.animation.scene.UserActionResult
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.lifecycle.rememberViewModel
import com.android.systemui.qs.panels.ui.compose.EditMode
import com.android.systemui.qs.ui.viewmodel.EditModeSceneActionsViewModel
import com.android.systemui.qs.ui.viewmodel.EditModeSceneContentViewModel
import com.android.systemui.res.R
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.ui.composable.Scene
import com.android.systemui.shade.ui.composable.Shade
import com.android.systemui.shade.ui.composable.ShadeHeader
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

@SysUISingleton
class EditModeScene
@Inject
constructor(
    private val contentViewModelFactory: EditModeSceneContentViewModel.Factory,
    private val actionsViewModelFactory: EditModeSceneActionsViewModel.Factory,
) : ExclusiveActivatable(), Scene {
    override val key = Scenes.QSEditMode

    private val actionsViewModel: EditModeSceneActionsViewModel by lazy {
        actionsViewModelFactory.create()
    }

    override suspend fun onActivated() {
        actionsViewModel.activate()
    }

    override val userActions: Flow<Map<UserAction, UserActionResult>> = actionsViewModel.actions

    override val alwaysCompose: Boolean = false

    @Composable
    override fun ContentScope.Content(modifier: Modifier) {
        val viewModel =
            rememberViewModel("edit_mode_scene_view_model") { contentViewModelFactory.create() }

        Box(modifier = modifier.fillMaxSize()) {
            Box(
                modifier =
                    Modifier.fillMaxSize()
                        .element(Shade.Elements.BackgroundScrim)
                        .background(colorResource(R.color.shade_scrim_background_dark))
            )

            EditMode(
                viewModel.editModeViewModel,
                Modifier.fillMaxSize()
                    .testTag("edit_mode_scene")
                    .padding(horizontal = QuickSettingsShade.Dimensions.Padding)
                    .padding(top = ShadeHeader.Dimensions.StatusBarHeight),
            )
        }
    }
}
+121 −16
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs.ui.composable

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.clipScrollableContainer
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
@@ -38,11 +39,12 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -50,16 +52,21 @@ import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.UserAction
import com.android.compose.animation.scene.UserActionResult
import com.android.compose.animation.scene.animateContentFloatAsState
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.rememberMutableSceneTransitionLayoutState
import com.android.compose.animation.scene.transitions
import com.android.compose.lifecycle.DisposableEffectWithLifecycle
import com.android.compose.lifecycle.LaunchedEffectWithLifecycle
import com.android.compose.modifiers.thenIf
import com.android.compose.windowsizeclass.LocalWindowSizeClass
@@ -78,8 +85,11 @@ import com.android.systemui.notifications.ui.composable.HeadsUpNotificationSpace
import com.android.systemui.notifications.ui.composable.NotificationScrollingStack
import com.android.systemui.qs.composefragment.ui.GridAnchor
import com.android.systemui.qs.footer.ui.compose.FooterActionsWithAnimatedVisibility
import com.android.systemui.qs.panels.ui.compose.EditMode
import com.android.systemui.qs.panels.ui.compose.TileGrid
import com.android.systemui.qs.shared.ui.ElementKeys
import com.android.systemui.qs.ui.composable.QuickSettingsScene.Companion.InternalScenes.Edit
import com.android.systemui.qs.ui.composable.QuickSettingsScene.Companion.InternalScenes.QS
import com.android.systemui.qs.ui.viewmodel.QuickSettingsContainerViewModel
import com.android.systemui.qs.ui.viewmodel.QuickSettingsSceneContentViewModel
import com.android.systemui.qs.ui.viewmodel.QuickSettingsUserActionsViewModel
@@ -89,6 +99,7 @@ import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.ui.composable.Scene
import com.android.systemui.shade.ui.composable.CollapsedShadeHeader
import com.android.systemui.shade.ui.composable.ExpandedShadeHeader
import com.android.systemui.shade.ui.composable.ShadeHeader
import com.android.systemui.shade.ui.composable.ShadePanelScrim
import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
import com.android.systemui.statusbar.notification.stack.ui.view.NotificationScrollView
@@ -132,16 +143,51 @@ constructor(
            rememberViewModel("QuickSettingsScene-notifPlaceholderViewModel") {
                notificationsPlaceholderViewModelFactory.create()
            }

        val brightnessMirrorShowing =
            viewModel.qsContainerViewModel.brightnessSliderViewModel.showMirror
        val contentAlpha by
            animateFloatAsState(
                targetValue = if (brightnessMirrorShowing) 0f else 1f,
                label = "alphaAnimationBrightnessMirrorContentHiding",
            )

        LaunchedEffectWithLifecycle(key1 = Unit) {
            try {
                snapshotFlow { contentAlpha }
                    .collect { notificationsPlaceholderViewModel.setAlphaForBrightnessMirror(it) }
            } finally {
                notificationsPlaceholderViewModel.setAlphaForBrightnessMirror(1f)
            }
        }

        QuickSettingsScene(
            notificationStackScrollView = notificationStackScrollView.get(),
            viewModel = viewModel,
            headerViewModel = viewModel.qsContainerViewModel.shadeHeaderViewModel,
            notificationsPlaceholderViewModel = notificationsPlaceholderViewModel,
            modifier = modifier,
            modifier = modifier.graphicsLayer { alpha = contentAlpha },
            shadeSession = shadeSession,
            jankMonitor = jankMonitor,
        )
    }

    companion object {
        object InternalScenes {
            val QS = SceneKey("QuickSettingsMainPanel")
            val Edit = SceneKey("QuickSettingsEditPanel")

            private const val EDIT_MODE_TIME_MILLIS = 500

            val transitions = transitions {
                from(QS, Edit) {
                    spec = tween(durationMillis = EDIT_MODE_TIME_MILLIS)
                    fractionRange(start = 0.5f) { fade(Edit.rootElementKey) }
                    fractionRange(end = 0.5f) { fade(QS.rootElementKey) }
                }
            }
        }
    }
}

@Composable
@@ -154,19 +200,80 @@ private fun ContentScope.QuickSettingsScene(
    shadeSession: SaveableSession,
    jankMonitor: InteractionJankMonitor,
) {
    val cutoutLocation = LocalDisplayCutout.current().location
    val brightnessMirrorShowing =
        viewModel.qsContainerViewModel.brightnessSliderViewModel.showMirror
    val contentAlpha by
        animateFloatAsState(
            targetValue = if (brightnessMirrorShowing) 0f else 1f,
            label = "alphaAnimationBrightnessMirrorContentHiding",
    Box(modifier.fillMaxSize()) {
        // This is the background for the whole scene, as the elements don't necessarily provide
        // a background that extends to the edges.
        ShadePanelScrim(viewModel.isTransparencyEnabled)

        val sceneState =
            rememberMutableSceneTransitionLayoutState(
                initialScene =
                    remember { if (viewModel.qsContainerViewModel.isEditing) Edit else QS },
                transitions = QuickSettingsScene.Companion.InternalScenes.transitions,
            )

    notificationsPlaceholderViewModel.setAlphaForBrightnessMirror(contentAlpha)
    DisposableEffect(Unit) {
        onDispose { notificationsPlaceholderViewModel.setAlphaForBrightnessMirror(1f) }
        val coroutineScope = rememberCoroutineScope()

        DisposableEffectWithLifecycle(key1 = viewModel, key2 = sceneState) {
            onDispose {
                viewModel.qsContainerViewModel.editModeViewModel.stopEditing()
                sceneState.snapTo(QS)
            }
        }

        LaunchedEffectWithLifecycle(
            key1 = sceneState,
            key2 = viewModel.qsContainerViewModel.isEditing,
            key3 = coroutineScope,
        ) {
            if (viewModel.qsContainerViewModel.isEditing) {
                sceneState.setTargetScene(Edit, coroutineScope)
            } else {
                sceneState.setTargetScene(QS, coroutineScope)
            }
        }

        NestedSceneTransitionLayout(state = sceneState, modifier = Modifier.fillMaxSize()) {
            scene(QS) {
                Element(QS.rootElementKey, Modifier) {
                    QuickSettingsContent(
                        notificationsPlaceholderViewModel,
                        Modifier,
                        viewModel,
                        headerViewModel,
                        notificationStackScrollView,
                        shadeSession,
                        jankMonitor,
                    )
                }
            }

            scene(Edit) {
                Element(Edit.rootElementKey, Modifier) {
                    GridAnchor()
                    EditMode(
                        viewModel.qsContainerViewModel.editModeViewModel,
                        Modifier.testTag("edit_mode_scene")
                            .padding(horizontal = QuickSettingsShade.Dimensions.Padding)
                            .padding(top = ShadeHeader.Dimensions.StatusBarHeight),
                    )
                }
            }
        }
    }
}

@Composable
private fun ContentScope.QuickSettingsContent(
    notificationsPlaceholderViewModel: NotificationsPlaceholderViewModel,
    modifier: Modifier,
    viewModel: QuickSettingsSceneContentViewModel,
    headerViewModel: ShadeHeaderViewModel,
    notificationStackScrollView: NotificationScrollView,
    shadeSession: SaveableSession,
    jankMonitor: InteractionJankMonitor,
) {
    val cutoutLocation = LocalDisplayCutout.current().location

    val shadeHorizontalPadding =
        dimensionResource(id = R.dimen.notification_panel_margin_horizontal)
@@ -180,7 +287,6 @@ private fun ContentScope.QuickSettingsScene(
        modifier =
            modifier
                .fillMaxSize()
                .graphicsLayer { alpha = contentAlpha }
                .thenIf(shouldPunchHoleBehindScrim) {
                    // Render the scene to an offscreen buffer so that BlendMode.DstOut only clears
                    // this scene (and not the one under it) during a scene transition.
@@ -223,7 +329,6 @@ private fun ContentScope.QuickSettingsScene(
        // ############# Media ###############
        val mediaInRow = viewModel.qsContainerViewModel.showMediaInRow

        ShadePanelScrim(viewModel.isTransparencyEnabled)
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier =
+8 −0
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import androidx.compose.animation.core.tween
import com.android.compose.animation.scene.Edge
import com.android.compose.animation.scene.TransitionBuilder
import com.android.systemui.notifications.ui.composable.Notifications
import com.android.systemui.qs.shared.ui.ElementKeys
import com.android.systemui.qs.ui.composable.QuickSettings
import com.android.systemui.qs.ui.composable.QuickSettingsScene
import com.android.systemui.shade.ui.composable.ShadeHeader
import kotlin.time.Duration.Companion.milliseconds

@@ -41,8 +43,14 @@ fun TransitionBuilder.toQuickSettingsTransition(durationScale: Double = 1.0) {
        fade(ShadeHeader.Elements.ShadeCarrierGroup)
    }

    fade(Notifications.Elements.HeadsUpNotificationPlaceholder)

    // Old QSSceneAdapter element
    translate(QuickSettings.Elements.Content, y = -ShadeHeader.Dimensions.ExpandedHeight * .66f)
    // New all compose element
    translate(ElementKeys.QuickSettingsContent, y = -ShadeHeader.Dimensions.ExpandedHeight * .66f)
    translate(Notifications.Elements.NotificationScrim, Edge.Top, false)
    translate(QuickSettingsScene.Companion.InternalScenes.Edit.rootElementKey, Edge.Top, true)
}

private val DefaultDuration = 500.milliseconds
+10 −9
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticati
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.qs.panels.ui.viewmodel.editModeViewModel
import com.android.systemui.scene.domain.interactor.sceneBackInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.domain.resolver.homeSceneFamilyResolver
@@ -57,8 +58,8 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val testScope = kosmos.testScope
    private val qsFlexiglassAdapter = kosmos.fakeQsSceneAdapter

    private val editModeViewModel = kosmos.editModeViewModel
    private val sceneInteractor = kosmos.sceneInteractor
    private val sceneBackInteractor = kosmos.sceneBackInteractor
    private val sceneContainerStartable = kosmos.sceneContainerStartable
@@ -70,7 +71,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
        sceneContainerStartable.start()
        underTest =
            QuickSettingsUserActionsViewModel(
                qsSceneAdapter = qsFlexiglassAdapter,
                editModeViewModel = editModeViewModel,
                sceneBackInteractor = sceneBackInteractor,
            )
        underTest.activateIn(testScope)
@@ -82,7 +83,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
            kosmos.enableSingleShade()
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            qsFlexiglassAdapter.setCustomizing(false)
            editModeViewModel.stopEditing()
            kosmos.fakeAuthenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.Pin
            )
@@ -105,7 +106,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
    fun destinations_whenNotCustomizing_withPreviousSceneLockscreen() =
        testScope.runTest {
            kosmos.enableSingleShade()
            qsFlexiglassAdapter.setCustomizing(false)
            editModeViewModel.stopEditing()
            val actions by collectLastValue(underTest.actions)

            val currentScene by collectLastValue(sceneInteractor.currentScene)
@@ -131,7 +132,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
    fun destinations_whenNotCustomizing_withPreviousSceneLockscreen_butLockscreenDisabled() =
        testScope.runTest {
            kosmos.enableSingleShade()
            qsFlexiglassAdapter.setCustomizing(false)
            editModeViewModel.stopEditing()
            val actions by collectLastValue(underTest.actions)

            val currentScene by collectLastValue(sceneInteractor.currentScene)
@@ -161,7 +162,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
            kosmos.enableSingleShade()
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            qsFlexiglassAdapter.setCustomizing(false)
            editModeViewModel.stopEditing()
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
            kosmos.fakeAuthenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.None
@@ -183,7 +184,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
        testScope.runTest {
            kosmos.enableSingleShade()
            val actions by collectLastValue(underTest.actions)
            qsFlexiglassAdapter.setCustomizing(true)
            editModeViewModel.startEditing()

            assertThat(actions)
                .isEqualTo(mapOf(Swipe.Up(fromSource = Edge.Bottom) to SceneFamilies.Home))
@@ -195,7 +196,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
            kosmos.enableSplitShade()
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            qsFlexiglassAdapter.setCustomizing(false)
            editModeViewModel.stopEditing()
            kosmos.fakeAuthenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.Pin
            )
@@ -219,7 +220,7 @@ class QuickSettingsUserActionsViewModelTest : SysuiTestCase() {
        testScope.runTest {
            kosmos.enableSplitShade()
            val actions by collectLastValue(underTest.actions)
            qsFlexiglassAdapter.setCustomizing(true)
            editModeViewModel.startEditing()

            assertThat(actions)
                .isEqualTo(mapOf(Swipe.Up(fromSource = Edge.Bottom) to SceneFamilies.Home))
Loading