Loading packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt +5 −25 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.systemui.scene.shared.model.SceneDataSource import com.android.systemui.scene.shared.model.SceneDataSourceDelegator import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -40,11 +41,7 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.stateIn /** Encapsulates the state of communal mode. */ interface CommunalSceneRepository { /** * Target scene as requested by the underlying [SceneTransitionLayout] or through [changeScene]. */ val currentScene: StateFlow<SceneKey> interface CommunalSceneRepository : SceneDataSource { /** Exposes the transition state of the communal [SceneTransitionLayout]. */ val transitionState: StateFlow<ObservableTransitionState> Loading @@ -52,12 +49,6 @@ interface CommunalSceneRepository { /** Current orientation of the communal container. */ val communalContainerOrientation: StateFlow<Int> /** Updates the requested scene. */ @MainThread fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) /** Immediately snaps to the desired scene. */ @MainThread fun snapToScene(toScene: SceneKey) /** Shows the hub from a power button press. */ @MainThread fun showHubFromPowerButton() Loading @@ -72,6 +63,7 @@ interface CommunalSceneRepository { fun setCommunalContainerOrientation(orientation: Int) } @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton class CommunalSceneRepositoryImpl @Inject Loading @@ -79,9 +71,7 @@ constructor( @Background backgroundScope: CoroutineScope, @Communal private val sceneDataSource: SceneDataSource, @Communal private val delegator: SceneDataSourceDelegator, ) : CommunalSceneRepository { override val currentScene: StateFlow<SceneKey> = sceneDataSource.currentScene ) : CommunalSceneRepository, SceneDataSource by sceneDataSource { private val defaultTransitionState = ObservableTransitionState.Idle(CommunalScenes.Default) private val _transitionState = MutableStateFlow<Flow<ObservableTransitionState>?>(null) Loading @@ -99,16 +89,6 @@ constructor( override val communalContainerOrientation: StateFlow<Int> = _communalContainerOrientation.asStateFlow() @MainThread override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) { sceneDataSource.changeScene(toScene, transitionKey) } @MainThread override fun snapToScene(toScene: SceneKey) { sceneDataSource.snapToScene(toScene) } override fun setCommunalContainerOrientation(orientation: Int) { _communalContainerOrientation.value = orientation } Loading @@ -135,7 +115,7 @@ constructor( _transitionState.value = transitionState } /** Noop implementation of a scene data source that always returns the initial [SceneKey]. */ /** No-op implementation of a scene data source that always returns the initial [SceneKey]. */ private class NoOpSceneDataSource(initialSceneKey: SceneKey) : SceneDataSource { override val currentScene: StateFlow<SceneKey> = MutableStateFlow(initialSceneKey).asStateFlow() Loading packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt +4 −82 Original line number Diff line number Diff line Loading @@ -18,15 +18,13 @@ package com.android.systemui.scene.data.repository import com.android.compose.animation.scene.ContentKey import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.OverlayKey import com.android.compose.animation.scene.SceneKey import com.android.compose.animation.scene.TransitionKey import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.scene.shared.model.SceneContainerConfig import com.android.systemui.scene.shared.model.SceneDataSource import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -36,6 +34,7 @@ import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.stateIn @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton /** Source of truth for scene framework application state. */ class SceneContainerRepository Loading @@ -44,7 +43,8 @@ constructor( @Application applicationScope: CoroutineScope, config: SceneContainerConfig, private val dataSource: SceneDataSource, ) { ) : SceneDataSource by dataSource { /** * The keys of all scenes and overlays in the container. * Loading @@ -53,16 +53,6 @@ constructor( */ val allContentKeys: List<ContentKey> = config.sceneKeys + config.overlayKeys val currentScene: StateFlow<SceneKey> = dataSource.currentScene /** * The current set of overlays to be shown (may be empty). * * Note that during a transition between overlays, a different set of overlays may be rendered - * but only the ones in this set are considered the current overlays. */ val currentOverlays: StateFlow<Set<OverlayKey>> = dataSource.currentOverlays private val _isVisible = MutableStateFlow(true) val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow() Loading Loading @@ -90,66 +80,6 @@ constructor( /** Number of currently active transition animations. */ val activeTransitionAnimationCount = MutableStateFlow(0) fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) { dataSource.changeScene(toScene = toScene, transitionKey = transitionKey) } fun snapToScene(toScene: SceneKey) { dataSource.snapToScene(toScene = toScene) } /** * Request to show [overlay] so that it animates in from [currentScene] and ends up being * visible on screen. * * 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) { dataSource.showOverlay(overlay = overlay, transitionKey = transitionKey) } /** * Request to hide [overlay] so that it animates out to [currentScene] and ends up *not* being * visible on screen. * * 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) { dataSource.hideOverlay(overlay = overlay, transitionKey = transitionKey) } /** * Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up * being visible. * * This throws if [from] is not currently shown or if [to] is already shown. */ fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey? = null) { 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 Loading @@ -163,12 +93,4 @@ constructor( fun setTransitionState(transitionState: Flow<ObservableTransitionState>?) { _transitionState.value = transitionState } /** * If currently in a transition between contents, cancel that transition and go back to the * pre-transition state. */ fun freezeAndAnimateToCurrentState() { dataSource.freezeAndAnimateToCurrentState() } } packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalSceneRepository.kt +19 −1 Original line number Diff line number Diff line Loading @@ -2,10 +2,12 @@ package com.android.systemui.communal.data.repository import android.content.res.Configuration import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.OverlayKey import com.android.compose.animation.scene.SceneKey import com.android.compose.animation.scene.TransitionKey import com.android.systemui.communal.shared.model.CommunalScenes import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -17,9 +19,12 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch /** Fake implementation of [CommunalSceneRepository]. */ @OptIn(ExperimentalCoroutinesApi::class) class FakeCommunalSceneRepository( private val applicationScope: CoroutineScope, override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default), override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default), override val currentOverlays: StateFlow<Set<OverlayKey>> = MutableStateFlow(emptySet()), ) : CommunalSceneRepository { override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) = Loading @@ -32,6 +37,19 @@ class FakeCommunalSceneRepository( } } override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit override fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit override fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey?) = Unit override fun instantlyShowOverlay(overlay: OverlayKey) = Unit override fun instantlyHideOverlay(overlay: OverlayKey) = Unit override fun freezeAndAnimateToCurrentState() = Unit override fun showHubFromPowerButton() { snapToScene(CommunalScenes.Communal) } Loading Loading
packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSceneRepository.kt +5 −25 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.systemui.scene.shared.model.SceneDataSource import com.android.systemui.scene.shared.model.SceneDataSourceDelegator import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -40,11 +41,7 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.stateIn /** Encapsulates the state of communal mode. */ interface CommunalSceneRepository { /** * Target scene as requested by the underlying [SceneTransitionLayout] or through [changeScene]. */ val currentScene: StateFlow<SceneKey> interface CommunalSceneRepository : SceneDataSource { /** Exposes the transition state of the communal [SceneTransitionLayout]. */ val transitionState: StateFlow<ObservableTransitionState> Loading @@ -52,12 +49,6 @@ interface CommunalSceneRepository { /** Current orientation of the communal container. */ val communalContainerOrientation: StateFlow<Int> /** Updates the requested scene. */ @MainThread fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) /** Immediately snaps to the desired scene. */ @MainThread fun snapToScene(toScene: SceneKey) /** Shows the hub from a power button press. */ @MainThread fun showHubFromPowerButton() Loading @@ -72,6 +63,7 @@ interface CommunalSceneRepository { fun setCommunalContainerOrientation(orientation: Int) } @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton class CommunalSceneRepositoryImpl @Inject Loading @@ -79,9 +71,7 @@ constructor( @Background backgroundScope: CoroutineScope, @Communal private val sceneDataSource: SceneDataSource, @Communal private val delegator: SceneDataSourceDelegator, ) : CommunalSceneRepository { override val currentScene: StateFlow<SceneKey> = sceneDataSource.currentScene ) : CommunalSceneRepository, SceneDataSource by sceneDataSource { private val defaultTransitionState = ObservableTransitionState.Idle(CommunalScenes.Default) private val _transitionState = MutableStateFlow<Flow<ObservableTransitionState>?>(null) Loading @@ -99,16 +89,6 @@ constructor( override val communalContainerOrientation: StateFlow<Int> = _communalContainerOrientation.asStateFlow() @MainThread override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) { sceneDataSource.changeScene(toScene, transitionKey) } @MainThread override fun snapToScene(toScene: SceneKey) { sceneDataSource.snapToScene(toScene) } override fun setCommunalContainerOrientation(orientation: Int) { _communalContainerOrientation.value = orientation } Loading @@ -135,7 +115,7 @@ constructor( _transitionState.value = transitionState } /** Noop implementation of a scene data source that always returns the initial [SceneKey]. */ /** No-op implementation of a scene data source that always returns the initial [SceneKey]. */ private class NoOpSceneDataSource(initialSceneKey: SceneKey) : SceneDataSource { override val currentScene: StateFlow<SceneKey> = MutableStateFlow(initialSceneKey).asStateFlow() Loading
packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt +4 −82 Original line number Diff line number Diff line Loading @@ -18,15 +18,13 @@ package com.android.systemui.scene.data.repository import com.android.compose.animation.scene.ContentKey import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.OverlayKey import com.android.compose.animation.scene.SceneKey import com.android.compose.animation.scene.TransitionKey import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.scene.shared.model.SceneContainerConfig import com.android.systemui.scene.shared.model.SceneDataSource import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -36,6 +34,7 @@ import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.stateIn @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton /** Source of truth for scene framework application state. */ class SceneContainerRepository Loading @@ -44,7 +43,8 @@ constructor( @Application applicationScope: CoroutineScope, config: SceneContainerConfig, private val dataSource: SceneDataSource, ) { ) : SceneDataSource by dataSource { /** * The keys of all scenes and overlays in the container. * Loading @@ -53,16 +53,6 @@ constructor( */ val allContentKeys: List<ContentKey> = config.sceneKeys + config.overlayKeys val currentScene: StateFlow<SceneKey> = dataSource.currentScene /** * The current set of overlays to be shown (may be empty). * * Note that during a transition between overlays, a different set of overlays may be rendered - * but only the ones in this set are considered the current overlays. */ val currentOverlays: StateFlow<Set<OverlayKey>> = dataSource.currentOverlays private val _isVisible = MutableStateFlow(true) val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow() Loading Loading @@ -90,66 +80,6 @@ constructor( /** Number of currently active transition animations. */ val activeTransitionAnimationCount = MutableStateFlow(0) fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) { dataSource.changeScene(toScene = toScene, transitionKey = transitionKey) } fun snapToScene(toScene: SceneKey) { dataSource.snapToScene(toScene = toScene) } /** * Request to show [overlay] so that it animates in from [currentScene] and ends up being * visible on screen. * * 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) { dataSource.showOverlay(overlay = overlay, transitionKey = transitionKey) } /** * Request to hide [overlay] so that it animates out to [currentScene] and ends up *not* being * visible on screen. * * 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) { dataSource.hideOverlay(overlay = overlay, transitionKey = transitionKey) } /** * Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up * being visible. * * This throws if [from] is not currently shown or if [to] is already shown. */ fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey? = null) { 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 Loading @@ -163,12 +93,4 @@ constructor( fun setTransitionState(transitionState: Flow<ObservableTransitionState>?) { _transitionState.value = transitionState } /** * If currently in a transition between contents, cancel that transition and go back to the * pre-transition state. */ fun freezeAndAnimateToCurrentState() { dataSource.freezeAndAnimateToCurrentState() } }
packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalSceneRepository.kt +19 −1 Original line number Diff line number Diff line Loading @@ -2,10 +2,12 @@ package com.android.systemui.communal.data.repository import android.content.res.Configuration import com.android.compose.animation.scene.ObservableTransitionState import com.android.compose.animation.scene.OverlayKey import com.android.compose.animation.scene.SceneKey import com.android.compose.animation.scene.TransitionKey import com.android.systemui.communal.shared.model.CommunalScenes import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted Loading @@ -17,9 +19,12 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch /** Fake implementation of [CommunalSceneRepository]. */ @OptIn(ExperimentalCoroutinesApi::class) class FakeCommunalSceneRepository( private val applicationScope: CoroutineScope, override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default), override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default), override val currentOverlays: StateFlow<Set<OverlayKey>> = MutableStateFlow(emptySet()), ) : CommunalSceneRepository { override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) = Loading @@ -32,6 +37,19 @@ class FakeCommunalSceneRepository( } } override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit override fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit override fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey?) = Unit override fun instantlyShowOverlay(overlay: OverlayKey) = Unit override fun instantlyHideOverlay(overlay: OverlayKey) = Unit override fun freezeAndAnimateToCurrentState() = Unit override fun showHubFromPowerButton() { snapToScene(CommunalScenes.Communal) } Loading