From 3fd0a6705a28cda177b268feb0eea90e9d3bc787 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Thu, 12 Jan 2023 20:24:14 +0000 Subject: [PATCH] Transitions - Allow ->GONE to be canceled Especially for when the user may auth but continue pushing down the power button, allow transitions to GONE to be interrupted by an immediate transition back to any keyguard state. Also, optimization for DREAMING->LOCKSCREEN. Add a slight delay in processing events, because the data source events may come in out of order or with a small gap. Test: existing transition tests cover these small tweaks well Test: atest frameworks/base/packages/SystemUI/tests/src/com/android/systemui/keyguard/ Fixes: 265325414 Change-Id: I07d8b225db2df04453ffe4b694f5124da94ee560 --- .../interactor/FromDreamingTransitionInteractor.kt | 5 +++++ .../interactor/FromGoneTransitionInteractor.kt | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt index 7134ec0d64f01..81a58286aab75 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt @@ -31,8 +31,10 @@ import javax.inject.Inject import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @SysUISingleton @@ -87,6 +89,9 @@ constructor( private fun listenForDreamingToOccluded() { scope.launch { keyguardInteractor.isDreaming + // Add a slight delay, as dreaming and occluded events will arrive with a small gap + // in time. This prevents a transition to OCCLUSION happening prematurely. + .onEach { delay(50) } .sample( combine( keyguardInteractor.isKeyguardOccluded, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt index 9203a9b924a79..14f918d78bc67 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt @@ -50,10 +50,9 @@ constructor( private fun listenForGoneToDreaming() { scope.launch { keyguardInteractor.isAbleToDream - .sample(keyguardTransitionInteractor.finishedKeyguardState, ::Pair) - .collect { pair -> - val (isAbleToDream, keyguardState) = pair - if (isAbleToDream && keyguardState == KeyguardState.GONE) { + .sample(keyguardTransitionInteractor.startedKeyguardTransitionStep, ::Pair) + .collect { (isAbleToDream, lastStartedStep) -> + if (isAbleToDream && lastStartedStep.to == KeyguardState.GONE) { keyguardTransitionRepository.startTransition( TransitionInfo( name, @@ -72,15 +71,15 @@ constructor( keyguardInteractor.wakefulnessModel .sample( combine( - keyguardTransitionInteractor.finishedKeyguardState, + keyguardTransitionInteractor.startedKeyguardTransitionStep, keyguardInteractor.isAodAvailable, ::Pair ), ::toTriple ) - .collect { (wakefulnessState, keyguardState, isAodAvailable) -> + .collect { (wakefulnessState, lastStartedStep, isAodAvailable) -> if ( - keyguardState == KeyguardState.GONE && + lastStartedStep.to == KeyguardState.GONE && wakefulnessState.state == WakefulnessState.STARTING_TO_SLEEP ) { keyguardTransitionRepository.startTransition(