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 Original line Diff line number Diff line
@@ -178,6 +178,7 @@ constructor(
        smallClockOnAttachStateChangeListener =
        smallClockOnAttachStateChangeListener =
            object : OnAttachStateChangeListener {
            object : OnAttachStateChangeListener {
                var pastVisibility: Int? = null
                var pastVisibility: Int? = null

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

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


    var smallRegionSampler: RegionSampler? = null
    var smallRegionSampler: RegionSampler? = null
        private set
        private set

    var largeRegionSampler: RegionSampler? = null
    var largeRegionSampler: RegionSampler? = null
        private set
        private set

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


+0 −4
Original line number Original line Diff line number Diff line
@@ -413,10 +413,6 @@ constructor(
    /** Whether we've currently STARTED a transition and haven't yet FINISHED it. */
    /** Whether we've currently STARTED a transition and haven't yet FINISHED it. */
    val isInTransitionToAnyState = isInTransitionWhere({ true }, { true })
    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
     * Called to start a transition that will ultimately dismiss the keyguard from the current
     * state.
     * state.
+1 −1
Original line number Original line Diff line number Diff line
@@ -441,7 +441,7 @@ constructor(
                    anyOf(
                    anyOf(
                            *toFlowArray(statesForHiddenKeyguard) { state ->
                            *toFlowArray(statesForHiddenKeyguard) { state ->
                                keyguardTransitionInteractor
                                keyguardTransitionInteractor
                                    .transitionStepsToState(state)
                                    .transition(Edge.create(to = state))
                                    .map { it.value > 0f && it.transitionState == RUNNING }
                                    .map { it.value > 0f && it.transitionState == RUNNING }
                                    .onStart { emit(false) }
                                    .onStart { emit(false) }
                            }
                            }
+10 −5
Original line number Original line Diff line number Diff line
@@ -348,7 +348,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    fun listenForTransitionToAodFromGone_updatesClockDozeAmountToOne() =
    fun listenForTransitionToAodFromGone_updatesClockDozeAmountToOne() =
        runBlocking(IMMEDIATE) {
        runBlocking(IMMEDIATE) {
            val transitionStep = MutableStateFlow(TransitionStep())
            val transitionStep = MutableStateFlow(TransitionStep())
            whenever(keyguardTransitionInteractor.transitionStepsToState(AOD))
            whenever(keyguardTransitionInteractor
                .transition(Edge.create(to = AOD)))
                .thenReturn(transitionStep)
                .thenReturn(transitionStep)


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


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


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


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


            val job = underTest.listenForAnyStateToDozingTransition(this)
            val job = underTest.listenForAnyStateToDozingTransition(this)