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

Commit f42fdc79 authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Make started/finished states SharedFlows.

Bug: 278086361
Test: atest SystemUITests
Flag: NA
Change-Id: I9e7aea0cef3bdc1fc85ef6861f05f97e74604322
parent 4624eedc
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -54,7 +54,10 @@ constructor(

    fun startToLockscreenTransition() {
        scope.launch {
            if (transitionInteractor.startedKeyguardState.value == KeyguardState.DREAMING) {
            if (
                transitionInteractor.startedKeyguardState.replayCache.last() ==
                    KeyguardState.DREAMING
            ) {
                startTransitionTo(KeyguardState.LOCKSCREEN)
            }
        }
+13 −10
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
@@ -40,7 +41,8 @@ constructor(

    @OptIn(ExperimentalCoroutinesApi::class)
    val viewParams: Flow<KeyguardSurfaceBehindModel> =
        transitionInteractor.isInTransitionToAnyState.flatMapLatest { isInTransition ->
        transitionInteractor.isInTransitionToAnyState
            .flatMapLatest { isInTransition ->
                if (!isInTransition) {
                    defaultParams
                } else {
@@ -52,6 +54,7 @@ constructor(
                    }
                }
            }
            .distinctUntilChanged()

    val isAnimatingSurface = repository.isAnimatingSurface

+8 −9
Original line number Diff line number Diff line
@@ -37,14 +37,14 @@ import com.android.systemui.keyguard.shared.model.TransitionStep
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.shareIn

/** Encapsulates business-logic related to the keyguard transitions. */
@SysUISingleton
@@ -171,16 +171,16 @@ constructor(
        repository.transitions.filter { step -> step.transitionState == TransitionState.FINISHED }

    /** The destination state of the last started transition. */
    val startedKeyguardState: StateFlow<KeyguardState> =
    val startedKeyguardState: SharedFlow<KeyguardState> =
        startedKeyguardTransitionStep
            .map { step -> step.to }
            .stateIn(scope, SharingStarted.Eagerly, OFF)
            .shareIn(scope, SharingStarted.Eagerly, replay = 1)

    /** The last completed [KeyguardState] transition */
    val finishedKeyguardState: StateFlow<KeyguardState> =
    val finishedKeyguardState: SharedFlow<KeyguardState> =
        finishedKeyguardTransitionStep
            .map { step -> step.to }
            .stateIn(scope, SharingStarted.Eagerly, LOCKSCREEN)
            .shareIn(scope, SharingStarted.Eagerly, replay = 1)

    /**
     * Whether we're currently in a transition to a new [KeyguardState] and haven't yet completed
@@ -227,14 +227,13 @@ constructor(
     * state.
     */
    fun startDismissKeyguardTransition() {
        when (startedKeyguardState.value) {
        when (val startedState = startedKeyguardState.replayCache.last()) {
            LOCKSCREEN -> fromLockscreenTransitionInteractor.get().dismissKeyguard()
            PRIMARY_BOUNCER -> fromPrimaryBouncerTransitionInteractor.get().dismissPrimaryBouncer()
            else ->
                Log.e(
                    "KeyguardTransitionInteractor",
                    "We don't know how to dismiss keyguard from state " +
                        "${startedKeyguardState.value}"
                    "We don't know how to dismiss keyguard from state $startedState."
                )
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -53,16 +53,16 @@ sealed class TransitionInteractor(
        modeOnCanceled: TransitionModeOnCanceled = TransitionModeOnCanceled.LAST_VALUE
    ): UUID? {
        if (
            fromState != transitionInteractor.startedKeyguardState.value &&
                fromState != transitionInteractor.finishedKeyguardState.value
            fromState != transitionInteractor.startedKeyguardState.replayCache.last() &&
                fromState != transitionInteractor.finishedKeyguardState.replayCache.last()
        ) {
            Log.e(
                name,
                "startTransition: We were asked to transition from " +
                    "$fromState to $toState, however we last finished a transition to " +
                    "${transitionInteractor.finishedKeyguardState.value}, " +
                    "${transitionInteractor.finishedKeyguardState.replayCache.last()}, " +
                    "and last started a transition to " +
                    "${transitionInteractor.startedKeyguardState.value}. " +
                    "${transitionInteractor.startedKeyguardState.replayCache.last()}. " +
                    "Ignoring startTransition, but this should never happen."
            )
            return null
+7 −0
Original line number Diff line number Diff line
@@ -411,6 +411,13 @@ class InWindowLauncherUnlockAnimationInteractorTest : SysuiTestCase() {
                    to = KeyguardState.GONE,
                )
            )
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.CANCELED,
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                )
            )
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
Loading