[flexiglass] SceneDataSource.

In order to support the new TransitionKey API in SceneTransitionLayout
(STL), we must switch from using HoistedSceneTransitionLayoutState to
using MutableSceneTransitionLayoutState.

Unlike HoistedSceneTransitionLayoutState, the MutableSceneTransitionLayoutState keeps the source of truth of the
current scene within itself, forcing us to change our architecture in
order to source the state of the current scene from
MutableSceneTransitionLayoutState and not from our own repository.

This is the first CL in a chain. Here we introduce the SceneDataSource
interface which, in the next CL, will be used by our
SceneContainerRepository as the new source of truth.

Complicating matters is the fact that MutableSceneTransitionLayoutState
is a Compose-aware construct that must be instantiated (and bound to)
within an @Composable function. Therefore, we introduce both
SceneTransitionLayoutDataSource (a MutableSceneTransitionLayoutState
based implementation of SceneDataSource) and SceneDataSourceDelegator
which also implements SceneDataSource and can be provided into our
Dagger graph as a normal dependency in build-time but can receive a
SceneDataSource as a delegate, during runtime. By doing that, we allow
our code in the data layer (the repository) depend on an object provided
from the UI layer (the composable) without breaking the Clean Architecture
Dependency Rule and without adding a dependency on Jetpack Compose from
a part of the codebase that's not yet allowed to do that.

Bug: 323173116
Test: unit test included
Test: unit tests updated in following CL(s)
Test: manual verification done with following CL(s)
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: Ic1aa6aafb6bc8b7d8a133e441a782d377b1ff4e4
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeAwareExtensions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeAwareExtensions.kt
new file mode 100644
index 0000000..a7de1ee
--- /dev/null
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeAwareExtensions.kt
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2024 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.ui.composable
+
+import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.IntSize
+import com.android.compose.animation.scene.Back
+import com.android.compose.animation.scene.Edge as ComposeAwareEdge
+import com.android.compose.animation.scene.SceneKey as ComposeAwareSceneKey
+import com.android.compose.animation.scene.Swipe
+import com.android.compose.animation.scene.SwipeDirection
+import com.android.compose.animation.scene.TransitionKey as ComposeAwareTransitionKey
+import com.android.compose.animation.scene.UserAction as ComposeAwareUserAction
+import com.android.compose.animation.scene.UserActionDistance as ComposeAwareUserActionDistance
+import com.android.compose.animation.scene.UserActionResult as ComposeAwareUserActionResult
+import com.android.systemui.scene.shared.model.Direction
+import com.android.systemui.scene.shared.model.Edge
+import com.android.systemui.scene.shared.model.SceneKey
+import com.android.systemui.scene.shared.model.TransitionKey
+import com.android.systemui.scene.shared.model.UserAction
+import com.android.systemui.scene.shared.model.UserActionDistance
+import com.android.systemui.scene.shared.model.UserActionResult
+
+// TODO(b/293899074): remove this file once we can use the types from SceneTransitionLayout.
+
+fun SceneKey.asComposeAware(): ComposeAwareSceneKey {
+    return ComposeAwareSceneKey(
+        debugName = toString(),
+        identity = this,
+    )
+}
+
+fun TransitionKey.asComposeAware(): ComposeAwareTransitionKey {
+    return ComposeAwareTransitionKey(
+        debugName = debugName,
+        identity = this,
+    )
+}
+
+fun UserAction.asComposeAware(): ComposeAwareUserAction {
+    return when (this) {
+        is UserAction.Swipe ->
+            Swipe(
+                pointerCount = pointerCount,
+                fromSource =
+                    when (this.fromEdge) {
+                        null -> null
+                        Edge.LEFT -> ComposeAwareEdge.Left
+                        Edge.TOP -> ComposeAwareEdge.Top
+                        Edge.RIGHT -> ComposeAwareEdge.Right
+                        Edge.BOTTOM -> ComposeAwareEdge.Bottom
+                    },
+                direction =
+                    when (this.direction) {
+                        Direction.LEFT -> SwipeDirection.Left
+                        Direction.UP -> SwipeDirection.Up
+                        Direction.RIGHT -> SwipeDirection.Right
+                        Direction.DOWN -> SwipeDirection.Down
+                    }
+            )
+        is UserAction.Back -> Back
+    }
+}
+
+fun UserActionResult.asComposeAware(): ComposeAwareUserActionResult {
+    val composeUnaware = this
+    return ComposeAwareUserActionResult(
+        toScene = composeUnaware.toScene.asComposeAware(),
+        transitionKey = composeUnaware.transitionKey?.asComposeAware(),
+        distance = composeUnaware.distance?.asComposeAware(),
+    )
+}
+
+fun UserActionDistance.asComposeAware(): ComposeAwareUserActionDistance {
+    val composeUnware = this
+    return object : ComposeAwareUserActionDistance {
+        override fun Density.absoluteDistance(
+            fromSceneSize: IntSize,
+            orientation: Orientation,
+        ): Float {
+            return composeUnware.absoluteDistance(
+                fromSceneWidth = fromSceneSize.width,
+                fromSceneHeight = fromSceneSize.height,
+                isHorizontal = orientation == Orientation.Horizontal,
+            )
+        }
+    }
+}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeUnawareExtensions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeUnawareExtensions.kt
new file mode 100644
index 0000000..4c03664
--- /dev/null
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/ComposeUnawareExtensions.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2024 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.ui.composable
+
+import com.android.compose.animation.scene.ObservableTransitionState as ComposeAwareObservableTransitionState
+import com.android.compose.animation.scene.SceneKey as ComposeAwareSceneKey
+import com.android.systemui.scene.shared.model.ObservableTransitionState
+import com.android.systemui.scene.shared.model.SceneKey
+
+fun ComposeAwareSceneKey.asComposeUnaware(): SceneKey {
+    return this.identity as SceneKey
+}
+
+fun ComposeAwareObservableTransitionState.asComposeUnaware(): ObservableTransitionState {
+    return when (this) {
+        is ComposeAwareObservableTransitionState.Idle ->
+            ObservableTransitionState.Idle(scene.asComposeUnaware())
+        is ComposeAwareObservableTransitionState.Transition ->
+            ObservableTransitionState.Transition(
+                fromScene = fromScene.asComposeUnaware(),
+                toScene = toScene.asComposeUnaware(),
+                progress = progress,
+                isInitiatedByUserInput = isInitiatedByUserInput,
+                isUserInputOngoing = isUserInputOngoing,
+            )
+    }
+}
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
new file mode 100644
index 0000000..60c0b77
--- /dev/null
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.scene.ui.composable
+
+import com.android.compose.animation.scene.MutableSceneTransitionLayoutState
+import com.android.compose.animation.scene.ObservableTransitionState
+import com.android.compose.animation.scene.observableTransitionState
+import com.android.systemui.scene.shared.model.SceneDataSource
+import com.android.systemui.scene.shared.model.SceneKey
+import com.android.systemui.scene.shared.model.TransitionKey
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
+
+/**
+ * An implementation of [SceneDataSource] that's backed by a [MutableSceneTransitionLayoutState].
+ */
+class SceneTransitionLayoutDataSource(
+    private val state: MutableSceneTransitionLayoutState,
+
+    /**
+     * The [CoroutineScope] of the @Composable that's using this, it's critical that this is *not*
+     * the application scope.
+     */
+    private val coroutineScope: CoroutineScope,
+) : SceneDataSource {
+    override val currentScene: StateFlow<SceneKey> =
+        state
+            .observableTransitionState()
+            .flatMapLatest { observableTransitionState ->
+                when (observableTransitionState) {
+                    is ObservableTransitionState.Idle -> flowOf(observableTransitionState.scene)
+                    is ObservableTransitionState.Transition ->
+                        observableTransitionState.isUserInputOngoing.map { isUserInputOngoing ->
+                            if (isUserInputOngoing) {
+                                observableTransitionState.fromScene
+                            } else {
+                                observableTransitionState.toScene
+                            }
+                        }
+                }
+            }
+            .map { it.asComposeUnaware() }
+            .stateIn(
+                scope = coroutineScope,
+                started = SharingStarted.WhileSubscribed(),
+                initialValue = state.transitionState.currentScene.asComposeUnaware(),
+            )
+
+    override fun changeScene(
+        toScene: SceneKey,
+        transitionKey: TransitionKey?,
+    ) {
+        state.setTargetScene(
+            targetScene = toScene.asComposeAware(),
+            transitionKey = transitionKey?.asComposeAware(),
+            coroutineScope = coroutineScope,
+        )
+    }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegatorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegatorTest.kt
new file mode 100644
index 0000000..ed4b1e6
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegatorTest.kt
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.scene.initialSceneKey
+import com.android.systemui.testKosmos
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class SceneDataSourceDelegatorTest : SysuiTestCase() {
+
+    private val kosmos = testKosmos()
+    private val testScope = kosmos.testScope
+    private val initialSceneKey = kosmos.initialSceneKey
+    private val fakeSceneDataSource = kosmos.fakeSceneDataSource
+
+    private val underTest = kosmos.sceneDataSourceDelegator
+
+    @Test
+    fun currentScene_withoutDelegate_startsWithInitialScene() =
+        testScope.runTest {
+            val currentScene by collectLastValue(underTest.currentScene)
+            underTest.setDelegate(null)
+
+            assertThat(currentScene).isEqualTo(initialSceneKey)
+        }
+
+    @Test
+    fun currentScene_withoutDelegate_doesNothing() =
+        testScope.runTest {
+            val currentScene by collectLastValue(underTest.currentScene)
+            underTest.setDelegate(null)
+            assertThat(currentScene).isNotEqualTo(SceneKey.Bouncer)
+
+            underTest.changeScene(toScene = SceneKey.Bouncer)
+
+            assertThat(currentScene).isEqualTo(initialSceneKey)
+        }
+
+    @Test
+    fun currentScene_withDelegate_startsWithInitialScene() =
+        testScope.runTest {
+            val currentScene by collectLastValue(underTest.currentScene)
+            assertThat(currentScene).isEqualTo(initialSceneKey)
+        }
+
+    @Test
+    fun currentScene_withDelegate_changesScenes() =
+        testScope.runTest {
+            val currentScene by collectLastValue(underTest.currentScene)
+            assertThat(currentScene).isNotEqualTo(SceneKey.Bouncer)
+
+            underTest.changeScene(toScene = SceneKey.Bouncer)
+
+            assertThat(currentScene).isEqualTo(SceneKey.Bouncer)
+        }
+
+    @Test
+    fun currentScene_reflectsDelegate() =
+        testScope.runTest {
+            val currentScene by collectLastValue(underTest.currentScene)
+
+            fakeSceneDataSource.changeScene(toScene = SceneKey.Bouncer)
+
+            assertThat(currentScene).isEqualTo(SceneKey.Bouncer)
+        }
+}
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
new file mode 100644
index 0000000..f7b45e5
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSource.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+import kotlinx.coroutines.flow.StateFlow
+
+/** Defines interface for classes that provide access to scene state. */
+interface SceneDataSource {
+
+    /**
+     * The current scene, as seen by the real data source in the UI layer.
+     *
+     * During a transition between two scenes, the original scene will still be reflected in
+     * [currentScene] until a time when the UI layer decides to commit the change, which is when
+     * [currentScene] will have the value of the target/new scene.
+     */
+    val currentScene: StateFlow<SceneKey>
+
+    /**
+     * 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,
+    )
+}
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
new file mode 100644
index 0000000..a50830c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/SceneDataSourceDelegator.kt
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.scene.shared.model
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
+import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.stateIn
+
+/**
+ * Delegates calls to a runtime-provided [SceneDataSource] or to a no-op implementation if a
+ * delegate isn't set.
+ */
+@SysUISingleton
+class SceneDataSourceDelegator
+@Inject
+constructor(
+    @Application private val applicationScope: CoroutineScope,
+    config: SceneContainerConfig,
+) : SceneDataSource {
+
+    private val noOpDelegate = NoOpSceneDataSource(config.initialSceneKey)
+    private val delegateMutable = MutableStateFlow<SceneDataSource>(noOpDelegate)
+
+    override val currentScene: StateFlow<SceneKey> =
+        delegateMutable
+            .flatMapLatest { delegate -> delegate.currentScene }
+            .stateIn(
+                scope = applicationScope,
+                started = SharingStarted.WhileSubscribed(),
+                initialValue = config.initialSceneKey,
+            )
+
+    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
+        delegateMutable.value.changeScene(
+            toScene = toScene,
+            transitionKey = transitionKey,
+        )
+    }
+
+    /**
+     * Binds the current, dependency injection provided [SceneDataSource] to the given object.
+     *
+     * In other words: once this is invoked, the state and functionality of the [SceneDataSource]
+     * will be served by the given [delegate].
+     *
+     * If `null` is passed in, the delegator will use a no-op implementation of [SceneDataSource].
+     *
+     * This removes any previously set delegate.
+     */
+    fun setDelegate(delegate: SceneDataSource?) {
+        delegateMutable.value = delegate ?: noOpDelegate
+    }
+
+    private class NoOpSceneDataSource(
+        initialSceneKey: SceneKey,
+    ) : SceneDataSource {
+        override val currentScene: StateFlow<SceneKey> =
+            MutableStateFlow(initialSceneKey).asStateFlow()
+        override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) = Unit
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKey.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKey.kt
new file mode 100644
index 0000000..87332ae
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/TransitionKey.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+/**
+ * Key for a transition. This can be used to specify which transition spec should be used when
+ * starting the transition between two scenes.
+ */
+data class TransitionKey(
+    val debugName: String,
+    val identity: Any = Object(),
+)
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionDistance.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionDistance.kt
new file mode 100644
index 0000000..b93f837
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionDistance.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+interface UserActionDistance {
+
+    /**
+     * Return the **absolute** distance of the user action (in pixels) given the size of the scene
+     * we are animating from and the orientation.
+     */
+    fun absoluteDistance(fromSceneWidth: Int, fromSceneHeight: Int, isHorizontal: Boolean): Float
+}
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionResult.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionResult.kt
new file mode 100644
index 0000000..e1b96e4
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/model/UserActionResult.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+data class UserActionResult(
+
+    /** The scene we should be transitioning due to the [UserAction]. */
+    val toScene: SceneKey,
+
+    /**
+     * The distance the action takes to animate from 0% to 100%.
+     *
+     * If `null`, a default distance will be used depending on the [UserAction] performed.
+     */
+    val distance: UserActionDistance? = null,
+
+    /**
+     * The key of the transition that should be used, if a specific one should be used.
+     *
+     * If `null`, the transition used will be the corresponding transition from the collection
+     * passed into the UI layer.
+     */
+    val transitionKey: TransitionKey? = null,
+)
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
new file mode 100644
index 0000000..c208aad
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/FakeSceneDataSource.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+
+class FakeSceneDataSource(
+    initialSceneKey: SceneKey,
+) : SceneDataSource {
+
+    private val _currentScene = MutableStateFlow(initialSceneKey)
+    override val currentScene: StateFlow<SceneKey> = _currentScene.asStateFlow()
+
+    var isPaused = false
+        private set
+    var pendingScene: SceneKey? = null
+        private set
+
+    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
+        if (isPaused) {
+            pendingScene = toScene
+        } else {
+            _currentScene.value = toScene
+        }
+    }
+
+    /**
+     * Pauses scene changes.
+     *
+     * Any following calls to [changeScene] will be conflated and the last one will be remembered.
+     */
+    fun pause() {
+        check(!isPaused) { "Can't pause what's already paused!" }
+
+        isPaused = true
+    }
+
+    /**
+     * Unpauses scene changes.
+     *
+     * If there were any calls to [changeScene] since [pause] was called, the latest of the bunch
+     * will be replayed.
+     *
+     * If [force] is `true`, there will be no check that [isPaused] is true.
+     *
+     * If [expectedScene] is provided, will assert that it's indeed the latest called.
+     */
+    fun unpause(
+        force: Boolean = false,
+        expectedScene: SceneKey? = null,
+    ) {
+        check(force || isPaused) { "Can't unpause what's already not paused!" }
+
+        isPaused = false
+        pendingScene?.let { _currentScene.value = it }
+        pendingScene = null
+
+        check(expectedScene == null || currentScene.value == expectedScene) {
+            """
+                Unexpected scene while unpausing.
+                Expected $expectedScene but was $currentScene.
+            """
+                .trimIndent()
+        }
+    }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/SceneDataSourceKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/SceneDataSourceKosmos.kt
new file mode 100644
index 0000000..f519686
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/shared/model/SceneDataSourceKosmos.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2024 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.shared.model
+
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.Kosmos.Fixture
+import com.android.systemui.kosmos.applicationCoroutineScope
+import com.android.systemui.scene.initialSceneKey
+import com.android.systemui.scene.sceneContainerConfig
+
+val Kosmos.fakeSceneDataSource by Fixture {
+    FakeSceneDataSource(
+        initialSceneKey = initialSceneKey,
+    )
+}
+
+val Kosmos.sceneDataSourceDelegator by Fixture {
+    SceneDataSourceDelegator(
+            applicationScope = applicationCoroutineScope,
+            config = sceneContainerConfig,
+        )
+        .apply { setDelegate(fakeSceneDataSource) }
+}
+
+val Kosmos.sceneDataSource by Fixture { sceneDataSourceDelegator }