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

Commit f0898b11 authored by Andreas Miko's avatar Andreas Miko
Browse files

Transform and consolidate transitionStepsToState callers

Removing transitionStepsToState has two goals:
a. Consolidate the API surface of KeyguardTransitionInteractor
b. transitionStepsFromState could only accept states. Use transition API instead which enables scenes or states as input.

All callers are now transformed to use the right APIs.

Test: None
Bug: b/330311871
Flag: com.android.systemui.scene_container
Change-Id: Iff931ed3eef4bea038a1cf85c55ba6dfbc4e034d
parent 0da20c15
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ constructor(
        smallClockOnAttachStateChangeListener =
            object : OnAttachStateChangeListener {
                var pastVisibility: Int? = null

                override fun onViewAttachedToWindow(view: View) {
                    clock.events.onTimeFormatChanged(DateFormat.is24HourFormat(context))
                    // Match the asing for view.parent's layout classes.
@@ -213,6 +214,7 @@ constructor(
                override fun onViewAttachedToWindow(p0: View) {
                    clock.events.onTimeFormatChanged(DateFormat.is24HourFormat(context))
                }

                override fun onViewDetachedFromWindow(p0: View) {}
            }
        clock.largeClock.view.addOnAttachStateChangeListener(largeClockOnAttachStateChangeListener)
@@ -284,8 +286,10 @@ constructor(

    var smallRegionSampler: RegionSampler? = null
        private set

    var largeRegionSampler: RegionSampler? = null
        private set

    var smallTimeListener: TimeListener? = null
    var largeTimeListener: TimeListener? = null
    val shouldTimeListenerRun: Boolean
@@ -560,7 +564,7 @@ constructor(
    internal fun listenForAnyStateToAodTransition(scope: CoroutineScope): Job {
        return scope.launch {
            keyguardTransitionInteractor
                .transitionStepsToState(AOD)
                .transition(Edge.create(to = AOD))
                .filter { it.transitionState == TransitionState.STARTED }
                .filter { it.from != LOCKSCREEN }
                .collect { handleDoze(1f) }
@@ -571,7 +575,7 @@ constructor(
    internal fun listenForAnyStateToLockscreenTransition(scope: CoroutineScope): Job {
        return scope.launch {
            keyguardTransitionInteractor
                .transitionStepsToState(LOCKSCREEN)
                .transition(Edge.create(to = LOCKSCREEN))
                .filter { it.transitionState == TransitionState.STARTED }
                .filter { it.from != AOD }
                .collect { handleDoze(0f) }
@@ -586,7 +590,7 @@ constructor(
    internal fun listenForAnyStateToDozingTransition(scope: CoroutineScope): Job {
        return scope.launch {
            keyguardTransitionInteractor
                .transitionStepsToState(DOZING)
                .transition(Edge.create(to = DOZING))
                .filter { it.transitionState == TransitionState.FINISHED }
                .collect { handleDoze(1f) }
        }
+2 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
@@ -164,7 +165,7 @@ constructor(
    /** Whether to start dreaming when returning from occluded */
    val dreamFromOccluded: Flow<Boolean> =
        keyguardTransitionInteractor
            .transitionStepsToState(KeyguardState.OCCLUDED)
            .transition(Edge.create(to = KeyguardState.OCCLUDED))
            .map { it.from == KeyguardState.DREAMING }
            .stateIn(scope = applicationScope, SharingStarted.Eagerly, false)

+0 −4
Original line number Diff line number Diff line
@@ -413,10 +413,6 @@ constructor(
    /** Whether we've currently STARTED a transition and haven't yet FINISHED it. */
    val isInTransitionToAnyState = isInTransitionWhere({ true }, { true })

    fun transitionStepsToState(toState: KeyguardState): Flow<TransitionStep> {
        return transition(Edge.create(from = null, to = toState))
    }

    /**
     * Called to start a transition that will ultimately dismiss the keyguard from the current
     * state.
+1 −1
Original line number Diff line number Diff line
@@ -441,7 +441,7 @@ constructor(
                    anyOf(
                            *toFlowArray(statesForHiddenKeyguard) { state ->
                                keyguardTransitionInteractor
                                    .transitionStepsToState(state)
                                    .transition(Edge.create(to = state))
                                    .map { it.value > 0f && it.transitionState == RUNNING }
                                    .onStart { emit(false) }
                            }
+10 −5
Original line number Diff line number Diff line
@@ -348,7 +348,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForTransitionToAodFromGone_updatesClockDozeAmountToOne() =
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(AOD))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = AOD)))
                .thenReturn(transitionStep)

            val job = underTest.listenForAnyStateToAodTransition(this)
@@ -369,7 +370,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForTransitionToLSFromOccluded_updatesClockDozeAmountToZero() =
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(LOCKSCREEN))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = LOCKSCREEN)))
                .thenReturn(transitionStep)

            val job = underTest.listenForAnyStateToLockscreenTransition(this)
@@ -390,7 +392,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForTransitionToAodFromLockscreen_neverUpdatesClockDozeAmount() =
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(AOD))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = AOD)))
                .thenReturn(transitionStep)

            val job = underTest.listenForAnyStateToAodTransition(this)
@@ -411,7 +414,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForAnyStateToLockscreenTransition_neverUpdatesClockDozeAmount() =
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(LOCKSCREEN))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = LOCKSCREEN)))
                .thenReturn(transitionStep)

            val job = underTest.listenForAnyStateToLockscreenTransition(this)
@@ -432,7 +436,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForAnyStateToDozingTransition_UpdatesClockDozeAmountToOne() =
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(DOZING))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = DOZING)))
                .thenReturn(transitionStep)

            val job = underTest.listenForAnyStateToDozingTransition(this)