summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alejandro Nijamkin <nijamkin@google.com> 2025-02-06 11:07:57 -0800
committer Alejandro Nijamkin <nijamkin@google.com> 2025-02-06 13:15:10 -0800
commit198ac2dab2557c53067a041afa36dbe524a8c58e (patch)
tree435e0e429b983f94465aed93001851669ffab989
parente036133690a82557096767c49d07b6f893803094 (diff)
[flexiglass] Adds instantly(Show|Hide)Overlay to SceneInteractor
Fix: 394632852 Test: unit tests added Flag: com.android.systemui.scene_container Change-Id: Ifba461b2149e4125b0e0ea9f178a2e4ad86a93b3
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt23
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt38
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt20
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt32
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt31
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt49
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt8
8 files changed, 150 insertions, 55 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt
index 1423d4acca21..6d906bd4aa66 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt
@@ -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,
+ )
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt
index 02645b70125a..a0d86f27b9b8 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt
@@ -675,4 +675,42 @@ class SceneInteractorTest : SysuiTestCase() {
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()
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt
index 8b6322720118..0a9bd4214a12 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt
@@ -147,5 +147,9 @@ constructor(
to: OverlayKey,
transitionKey: TransitionKey?,
) = Unit
+
+ override fun instantlyShowOverlay(overlay: OverlayKey) = Unit
+
+ override fun instantlyHideOverlay(overlay: OverlayKey) = Unit
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt b/packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt
index 80c7c4a07c1e..caa7bbae0420 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt
@@ -130,6 +130,26 @@ constructor(
dataSource.replaceOverlay(from = from, to = to, transitionKey = transitionKey)
}
+ /**
+ * Instantly shows [overlay].
+ *
+ * The change is instantaneous and not animated; it will be observable in the next frame and
+ * there will be no transition animation.
+ */
+ fun instantlyShowOverlay(overlay: OverlayKey) {
+ dataSource.instantlyShowOverlay(overlay)
+ }
+
+ /**
+ * Instantly hides [overlay].
+ *
+ * The change is instantaneous and not animated; it will be observable in the next frame and
+ * there will be no transition animation.
+ */
+ fun instantlyHideOverlay(overlay: OverlayKey) {
+ dataSource.instantlyHideOverlay(overlay)
+ }
+
/** Sets whether the container is visible. */
fun setVisible(isVisible: Boolean) {
_isVisible.value = isVisible
diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt
index d72a37249004..7a32491c0b67 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt
@@ -339,6 +339,38 @@ constructor(
}
/**
+ * Instantly shows [overlay].
+ *
+ * The change is instantaneous and not animated; it will be observable in the next frame and
+ * there will be no transition animation.
+ */
+ fun instantlyShowOverlay(overlay: OverlayKey, loggingReason: String) {
+ if (!validateOverlayChange(to = overlay, loggingReason = loggingReason)) {
+ return
+ }
+
+ logger.logOverlayChangeRequested(to = overlay, reason = loggingReason)
+
+ repository.instantlyShowOverlay(overlay)
+ }
+
+ /**
+ * Instantly hides [overlay].
+ *
+ * The change is instantaneous and not animated; it will be observable in the next frame and
+ * there will be no transition animation.
+ */
+ fun instantlyHideOverlay(overlay: OverlayKey, loggingReason: String) {
+ if (!validateOverlayChange(from = overlay, loggingReason = loggingReason)) {
+ return
+ }
+
+ logger.logOverlayChangeRequested(from = overlay, reason = loggingReason)
+
+ repository.instantlyHideOverlay(overlay)
+ }
+
+ /**
* Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up
* being visible.
*
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt
index 4538d1ca48f8..daf2d7f698b6 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt
@@ -45,17 +45,12 @@ interface SceneDataSource {
* Asks for an asynchronous scene switch to [toScene], which will use the corresponding
* installed transition or the one specified by [transitionKey], if provided.
*/
- fun changeScene(
- toScene: SceneKey,
- transitionKey: TransitionKey? = null,
- )
+ fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null)
/**
* Asks for an instant scene switch to [toScene], without an animated transition of any kind.
*/
- fun snapToScene(
- toScene: SceneKey,
- )
+ fun snapToScene(toScene: SceneKey)
/**
* Request to show [overlay] so that it animates in from [currentScene] and ends up being
@@ -64,10 +59,7 @@ interface SceneDataSource {
* After this returns, this overlay will be included in [currentOverlays]. This does nothing if
* [overlay] is already shown.
*/
- fun showOverlay(
- overlay: OverlayKey,
- transitionKey: TransitionKey? = null,
- )
+ fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null)
/**
* Request to hide [overlay] so that it animates out to [currentScene] and ends up *not* being
@@ -76,10 +68,7 @@ interface SceneDataSource {
* After this returns, this overlay will not be included in [currentOverlays]. This does nothing
* if [overlay] is already hidden.
*/
- fun hideOverlay(
- overlay: OverlayKey,
- transitionKey: TransitionKey? = null,
- )
+ fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null)
/**
* Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up
@@ -87,9 +76,11 @@ interface SceneDataSource {
*
* This throws if [from] is not currently shown or if [to] is already shown.
*/
- fun replaceOverlay(
- from: OverlayKey,
- to: OverlayKey,
- transitionKey: TransitionKey? = null,
- )
+ fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey? = null)
+
+ /** Asks for [overlay] to be instantly shown, without an animated transition of any kind. */
+ fun instantlyShowOverlay(overlay: OverlayKey)
+
+ /** Asks for [overlay] to be instantly hidden, without an animated transition of any kind. */
+ fun instantlyHideOverlay(overlay: OverlayKey)
}
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt
index 5d0edc504782..dcb699539760 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt
@@ -31,10 +31,8 @@ import kotlinx.coroutines.flow.stateIn
* Delegates calls to a runtime-provided [SceneDataSource] or to a no-op implementation if a
* delegate isn't set.
*/
-class SceneDataSourceDelegator(
- applicationScope: CoroutineScope,
- config: SceneContainerConfig,
-) : SceneDataSource {
+class SceneDataSourceDelegator(applicationScope: CoroutineScope, config: SceneContainerConfig) :
+ SceneDataSource {
private val noOpDelegate = NoOpSceneDataSource(config.initialSceneKey)
private val delegateMutable = MutableStateFlow<SceneDataSource>(noOpDelegate)
@@ -57,38 +55,31 @@ class SceneDataSourceDelegator(
)
override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
- delegateMutable.value.changeScene(
- toScene = toScene,
- transitionKey = transitionKey,
- )
+ delegateMutable.value.changeScene(toScene = toScene, transitionKey = transitionKey)
}
override fun snapToScene(toScene: SceneKey) {
- delegateMutable.value.snapToScene(
- toScene = toScene,
- )
+ delegateMutable.value.snapToScene(toScene = toScene)
}
override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) {
- delegateMutable.value.showOverlay(
- overlay = overlay,
- transitionKey = transitionKey,
- )
+ delegateMutable.value.showOverlay(overlay = overlay, transitionKey = transitionKey)
}
override fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) {
- delegateMutable.value.hideOverlay(
- overlay = overlay,
- transitionKey = transitionKey,
- )
+ delegateMutable.value.hideOverlay(overlay = overlay, transitionKey = transitionKey)
}
override fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey?) {
- delegateMutable.value.replaceOverlay(
- from = from,
- to = to,
- transitionKey = transitionKey,
- )
+ delegateMutable.value.replaceOverlay(from = from, to = to, transitionKey = transitionKey)
+ }
+
+ override fun instantlyShowOverlay(overlay: OverlayKey) {
+ delegateMutable.value.instantlyShowOverlay(overlay)
+ }
+
+ override fun instantlyHideOverlay(overlay: OverlayKey) {
+ delegateMutable.value.instantlyHideOverlay(overlay)
}
/**
@@ -105,9 +96,7 @@ class SceneDataSourceDelegator(
delegateMutable.value = delegate ?: noOpDelegate
}
- private class NoOpSceneDataSource(
- initialSceneKey: SceneKey,
- ) : SceneDataSource {
+ private class NoOpSceneDataSource(initialSceneKey: SceneKey) : SceneDataSource {
override val currentScene: StateFlow<SceneKey> =
MutableStateFlow(initialSceneKey).asStateFlow()
@@ -125,7 +114,11 @@ class SceneDataSourceDelegator(
override fun replaceOverlay(
from: OverlayKey,
to: OverlayKey,
- transitionKey: TransitionKey?
+ transitionKey: TransitionKey?,
) = Unit
+
+ override fun instantlyShowOverlay(overlay: OverlayKey) = Unit
+
+ override fun instantlyHideOverlay(overlay: OverlayKey) = Unit
}
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt
index f5eebb46c2ec..60c0f342b874 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt
@@ -77,6 +77,14 @@ class FakeSceneDataSource(initialSceneKey: SceneKey, val testScope: TestScope) :
showOverlay(to, transitionKey)
}
+ override fun instantlyShowOverlay(overlay: OverlayKey) {
+ showOverlay(overlay)
+ }
+
+ override fun instantlyHideOverlay(overlay: OverlayKey) {
+ hideOverlay(overlay)
+ }
+
/**
* Pauses scene and overlay changes.
*