Transitions - Add GONE->LOCKSCREEN support

Primarily used when the device goes into immediate lockdown. Also,
increase the timeout to see if it reduces flakiness.

Fixes: 266192407
Test: atest KeyguardTransitionScenariosTest
Change-Id: I1e99ab8fa081c23943f319982c5730644680bd9c
This commit is contained in:
Matt Pietal
2023-01-20 14:35:21 +00:00
parent 7da4acbb93
commit aa2fabb937
3 changed files with 60 additions and 2 deletions

View File

@@ -45,6 +45,27 @@ constructor(
override fun start() {
listenForGoneToAodOrDozing()
listenForGoneToDreaming()
listenForGoneToLockscreen()
}
// Primarily for when the user chooses to lock down the device
private fun listenForGoneToLockscreen() {
scope.launch {
keyguardInteractor.isKeyguardShowing
.sample(keyguardTransitionInteractor.startedKeyguardTransitionStep, ::Pair)
.collect { (isKeyguardShowing, lastStartedStep) ->
if (isKeyguardShowing && lastStartedStep.to == KeyguardState.GONE) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
KeyguardState.GONE,
KeyguardState.LOCKSCREEN,
getAnimator(),
)
)
}
}
}
}
private fun listenForGoneToDreaming() {

View File

@@ -518,6 +518,43 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
coroutineContext.cancelChildren()
}
@Test
fun `GONE to LOCKSREEN`() =
testScope.runTest {
// GIVEN a prior transition has run to GONE
runner.startTransition(
testScope,
TransitionInfo(
ownerName = "",
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.GONE,
animator =
ValueAnimator().apply {
duration = 10
interpolator = Interpolators.LINEAR
},
)
)
runCurrent()
reset(mockTransitionRepository)
// WHEN the keyguard starts to show
keyguardRepository.setKeyguardShowing(true)
runCurrent()
val info =
withArgCaptor<TransitionInfo> {
verify(mockTransitionRepository).startTransition(capture())
}
// THEN a transition to AOD should occur
assertThat(info.ownerName).isEqualTo("FromGoneTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.GONE)
assertThat(info.to).isEqualTo(KeyguardState.LOCKSCREEN)
assertThat(info.animator).isNotNull()
coroutineContext.cancelChildren()
}
@Test
fun `GONE to DREAMING`() =
testScope.runTest {

View File

@@ -71,7 +71,7 @@ class KeyguardTransitionRunner(
waitUntilComplete(info.animator!!)
}
suspend private fun waitUntilComplete(animator: ValueAnimator) {
private suspend fun waitUntilComplete(animator: ValueAnimator) {
withContext(Dispatchers.Main) {
val startTime = System.currentTimeMillis()
while (!isTerminated && animator.isRunning()) {
@@ -96,6 +96,6 @@ class KeyguardTransitionRunner(
override fun setFrameDelay(delay: Long) {}
companion object {
private const val MAX_TEST_DURATION = 100L
private const val MAX_TEST_DURATION = 200L
}
}