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

Commit d19a9fdf authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge changes I1e598720,I72b6a583 into main

* changes:
  Dispatch scene changes on immediate dispatcher
  Listen to transition animation progress on immediate dispatcher
parents f6ab114d aa09e1ba
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.backgroundScope
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
@@ -49,7 +48,6 @@ class CommunalSceneRepositoryImplTest : SysuiTestCase() {
    private val Kosmos.underTest by
        Kosmos.Fixture {
            CommunalSceneRepositoryImpl(
                applicationScope = applicationCoroutineScope,
                backgroundScope = backgroundScope,
                sceneDataSource = delegator,
                delegator = delegator,
+10 −17
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui.communal.data.repository

import android.content.res.Configuration
import com.android.app.tracing.coroutines.launchTraced as launch
import androidx.annotation.MainThread
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
@@ -25,7 +25,6 @@ import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.communal.dagger.Communal
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.scene.shared.model.SceneDataSource
import com.android.systemui.scene.shared.model.SceneDataSourceDelegator
@@ -54,13 +53,13 @@ interface CommunalSceneRepository {
    val communalContainerOrientation: StateFlow<Int>

    /** Updates the requested scene. */
    fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null)
    @MainThread fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null)

    /** Immediately snaps to the desired scene. */
    fun snapToScene(toScene: SceneKey)
    @MainThread fun snapToScene(toScene: SceneKey)

    /** Shows the hub from a power button press. */
    suspend fun showHubFromPowerButton()
    @MainThread fun showHubFromPowerButton()

    /**
     * Updates the transition state of the hub [SceneTransitionLayout].
@@ -77,7 +76,6 @@ interface CommunalSceneRepository {
class CommunalSceneRepositoryImpl
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Background backgroundScope: CoroutineScope,
    @Communal private val sceneDataSource: SceneDataSource,
    @Communal private val delegator: SceneDataSourceDelegator,
@@ -101,27 +99,22 @@ constructor(
    override val communalContainerOrientation: StateFlow<Int> =
        _communalContainerOrientation.asStateFlow()

    @MainThread
    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
        applicationScope.launch {
            // SceneTransitionLayout state updates must be triggered on the thread the STL was
            // created on.
        sceneDataSource.changeScene(toScene, transitionKey)
    }
    }

    @MainThread
    override fun snapToScene(toScene: SceneKey) {
        applicationScope.launch {
            // SceneTransitionLayout state updates must be triggered on the thread the STL was
            // created on.
        sceneDataSource.snapToScene(toScene)
    }
    }

    override fun setCommunalContainerOrientation(orientation: Int) {
        _communalContainerOrientation.value = orientation
    }

    override suspend fun showHubFromPowerButton() {
    @MainThread
    override fun showHubFromPowerButton() {
        // If keyguard is not showing yet, the hub view is not ready and the
        // [SceneDataSourceDelegator] will still be using the default [NoOpSceneDataSource]
        // and initial key, which is Blank. This means that when the hub container loads, it
+6 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.communal.shared.model.CommunalScenes.toSceneContaine
import com.android.systemui.communal.shared.model.EditModeState
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
@@ -37,6 +38,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf
import com.android.systemui.util.kotlin.pairwiseBy
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
@@ -57,6 +59,7 @@ class CommunalSceneInteractor
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainImmediateDispatcher: CoroutineDispatcher,
    private val repository: CommunalSceneRepository,
    private val logger: CommunalSceneLogger,
    private val sceneInteractor: SceneInteractor,
@@ -123,7 +126,7 @@ constructor(
        transitionKey: TransitionKey? = null,
        keyguardState: KeyguardState? = null,
    ) {
        applicationScope.launch("$TAG#changeScene") {
        applicationScope.launch("$TAG#changeScene", mainImmediateDispatcher) {
            if (SceneContainerFlag.isEnabled) {
                sceneInteractor.changeScene(
                    toScene = newScene.toSceneContainerSceneKey(),
@@ -153,7 +156,7 @@ constructor(
        delayMillis: Long = 0,
        keyguardState: KeyguardState? = null,
    ) {
        applicationScope.launch("$TAG#snapToScene") {
        applicationScope.launch("$TAG#snapToScene", mainImmediateDispatcher) {
            if (SceneContainerFlag.isEnabled) {
                sceneInteractor.snapToScene(
                    toScene = newScene.toSceneContainerSceneKey(),
@@ -177,7 +180,7 @@ constructor(

    fun showHubFromPowerButton() {
        val loggingReason = "showing hub from power button"
        applicationScope.launch("$TAG#showHubFromPowerButton") {
        applicationScope.launch("$TAG#showHubFromPowerButton", mainImmediateDispatcher) {
            if (SceneContainerFlag.isEnabled) {
                sceneInteractor.changeScene(
                    toScene = CommunalScenes.Communal.toSceneContainerSceneKey(),
+12 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.communal.data.repository.CommunalSceneTransitionRepo
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.domain.interactor.InternalKeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
@@ -37,6 +38,7 @@ import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.util.kotlin.pairwise
import java.util.UUID
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.SharingStarted
@@ -64,6 +66,7 @@ constructor(
    val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
    private val settingsInteractor: CommunalSettingsInteractor,
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainImmediateDispatcher: CoroutineDispatcher,
    private val sceneInteractor: CommunalSceneInteractor,
    private val repository: CommunalSceneTransitionRepository,
    private val powerInteractor: PowerInteractor,
@@ -143,7 +146,7 @@ constructor(

    /** Monitors [SceneTransitionLayout] state and updates KTF state accordingly. */
    private fun listenForSceneTransitionProgress() {
        applicationScope.launch {
        applicationScope.launch("$TAG#listenForSceneTransitionProgress", mainImmediateDispatcher) {
            sceneInteractor.transitionState
                .pairwise(ObservableTransitionState.Idle(CommunalScenes.Blank))
                .collect { (prevTransition, transition) ->
@@ -256,7 +259,10 @@ constructor(

    private fun collectProgress(transition: ObservableTransitionState.Transition) {
        progressJob?.cancel()
        progressJob = applicationScope.launch { transition.progress.collect { updateProgress(it) } }
        progressJob =
            applicationScope.launch("$TAG#collectProgress", mainImmediateDispatcher) {
                transition.progress.collect { updateProgress(it) }
            }
    }

    private suspend fun startTransitionFromGlanceableHub() {
@@ -300,4 +306,8 @@ constructor(
            TransitionState.RUNNING,
        )
    }

    private companion object {
        const val TAG = "CommunalSceneTransitionInteractor"
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class FakeCommunalSceneRepository(
        }
    }

    override suspend fun showHubFromPowerButton() {
    override fun showHubFromPowerButton() {
        snapToScene(CommunalScenes.Communal)
    }

Loading