Support AOD => occluded and Dozing => occluded transitions

The device can wake up to an occluded state.

Test: launch the camera activity, then press the power button to turn
off the screen and then quickly press the power button to turn back
on the screen & check the keyguard state
Test: atest KeyguardTransitionScenariosTest
Bug: 292506244

Change-Id: I37cb6933e4020b203137d832fe8b9fe0314fbb32
This commit is contained in:
Beverly
2023-07-25 20:55:47 +00:00
parent b60c36e01d
commit ec54c93ef6
3 changed files with 88 additions and 12 deletions

View File

@@ -24,9 +24,11 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.util.kotlin.Utils.Companion.toTriple
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
@SysUISingleton
@@ -43,19 +45,27 @@ constructor(
) {
override fun start() {
listenForAodToLockscreen()
listenForAodToLockscreenOrOccluded()
listenForAodToGone()
}
private fun listenForAodToLockscreen() {
private fun listenForAodToLockscreenOrOccluded() {
scope.launch {
keyguardInteractor
.dozeTransitionTo(DozeStateModel.FINISH)
.sample(transitionInteractor.startedKeyguardTransitionStep, ::Pair)
.collect { pair ->
val (dozeToAod, lastStartedStep) = pair
.sample(
combine(
transitionInteractor.startedKeyguardTransitionStep,
keyguardInteractor.isKeyguardOccluded,
::Pair
),
::toTriple
)
.collect { (_, lastStartedStep, occluded) ->
if (lastStartedStep.to == KeyguardState.AOD) {
startTransitionTo(KeyguardState.LOCKSCREEN)
startTransitionTo(
if (occluded) KeyguardState.OCCLUDED else KeyguardState.LOCKSCREEN
)
}
}
}

View File

@@ -23,10 +23,12 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.util.kotlin.Utils.Companion.toTriple
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
@SysUISingleton
@@ -43,20 +45,29 @@ constructor(
) {
override fun start() {
listenForDozingToLockscreen()
listenForDozingToLockscreenOrOccluded()
listenForDozingToGone()
}
private fun listenForDozingToLockscreen() {
private fun listenForDozingToLockscreenOrOccluded() {
scope.launch {
keyguardInteractor.wakefulnessModel
.sample(transitionInteractor.startedKeyguardTransitionStep, ::Pair)
.collect { (wakefulnessModel, lastStartedTransition) ->
.sample(
combine(
transitionInteractor.startedKeyguardTransitionStep,
keyguardInteractor.isKeyguardOccluded,
::Pair
),
::toTriple
)
.collect { (wakefulnessModel, lastStartedTransition, occluded) ->
if (
wakefulnessModel.isStartingToWakeOrAwake() &&
lastStartedTransition.to == KeyguardState.DOZING
) {
startTransitionTo(KeyguardState.LOCKSCREEN)
startTransitionTo(
if (occluded) KeyguardState.OCCLUDED else KeyguardState.LOCKSCREEN
)
}
}
}

View File

@@ -831,7 +831,7 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
withArgCaptor<TransitionInfo> {
verify(transitionRepository).startTransition(capture(), anyBoolean())
}
// THEN a transition to AlternateBouncer should occur
// THEN a transition to OCCLUDED should occur
assertThat(info.ownerName).isEqualTo("FromPrimaryBouncerTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.PRIMARY_BOUNCER)
assertThat(info.to).isEqualTo(KeyguardState.OCCLUDED)
@@ -840,6 +840,61 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
coroutineContext.cancelChildren()
}
@Test
fun dozingToOccluded() =
testScope.runTest {
// GIVEN a prior transition has run to DOZING
runTransition(KeyguardState.LOCKSCREEN, KeyguardState.DOZING)
runCurrent()
// WHEN the keyguard is occluded and device wakes up
keyguardRepository.setKeyguardOccluded(true)
keyguardRepository.setWakefulnessModel(startingToWake())
runCurrent()
val info =
withArgCaptor<TransitionInfo> {
verify(transitionRepository).startTransition(capture(), anyBoolean())
}
// THEN a transition to OCCLUDED should occur
assertThat(info.ownerName).isEqualTo("FromDozingTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.DOZING)
assertThat(info.to).isEqualTo(KeyguardState.OCCLUDED)
assertThat(info.animator).isNotNull()
coroutineContext.cancelChildren()
}
@Test
fun aodToOccluded() =
testScope.runTest {
// GIVEN a prior transition has run to AOD
runTransition(KeyguardState.LOCKSCREEN, KeyguardState.AOD)
runCurrent()
// WHEN the keyguard is occluded and aod ends
keyguardRepository.setKeyguardOccluded(true)
keyguardRepository.setDozeTransitionModel(
DozeTransitionModel(
from = DozeStateModel.DOZE_AOD,
to = DozeStateModel.FINISH,
)
)
runCurrent()
val info =
withArgCaptor<TransitionInfo> {
verify(transitionRepository).startTransition(capture(), anyBoolean())
}
// THEN a transition to OCCLUDED should occur
assertThat(info.ownerName).isEqualTo("FromAodTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.AOD)
assertThat(info.to).isEqualTo(KeyguardState.OCCLUDED)
assertThat(info.animator).isNotNull()
coroutineContext.cancelChildren()
}
private fun startingToWake() =
WakefulnessModel(
WakefulnessState.STARTING_TO_WAKE,