Transitions - Support OCCLUDED -> GONE

If an occluded app is launched over a lockscreen that is dimissable,
then when the app is closed it should go to GONE state, and not back
to LOCKSCREEN.

Fixes: 270554348
Test: atest KeyguardTransitionScenariosTest
Change-Id: I3c62d4aefa1037fdfa573db82918d4bc65bb6968
This commit is contained in:
Matt Pietal
2023-02-24 19:04:06 +00:00
parent 1112655d12
commit 45bea395d5
2 changed files with 133 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ constructor(
override fun start() {
listenForOccludedToLockscreen()
listenForOccludedToGone()
listenForOccludedToDreaming()
listenForOccludedToAodOrDozing()
}
@@ -72,11 +73,22 @@ constructor(
private fun listenForOccludedToLockscreen() {
scope.launch {
keyguardInteractor.isKeyguardOccluded
.sample(keyguardTransitionInteractor.startedKeyguardTransitionStep, ::Pair)
.collect { (isOccluded, lastStartedKeyguardState) ->
.sample(
combine(
keyguardInteractor.isKeyguardShowing,
keyguardTransitionInteractor.startedKeyguardTransitionStep,
::Pair
),
::toTriple
)
.collect { (isOccluded, isShowing, lastStartedKeyguardState) ->
// Occlusion signals come from the framework, and should interrupt any
// existing transition
if (!isOccluded && lastStartedKeyguardState.to == KeyguardState.OCCLUDED) {
if (
!isOccluded &&
isShowing &&
lastStartedKeyguardState.to == KeyguardState.OCCLUDED
) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
@@ -90,6 +102,38 @@ constructor(
}
}
private fun listenForOccludedToGone() {
scope.launch {
keyguardInteractor.isKeyguardOccluded
.sample(
combine(
keyguardInteractor.isKeyguardShowing,
keyguardTransitionInteractor.startedKeyguardTransitionStep,
::Pair
),
::toTriple
)
.collect { (isOccluded, isShowing, lastStartedKeyguardState) ->
// Occlusion signals come from the framework, and should interrupt any
// existing transition
if (
!isOccluded &&
!isShowing &&
lastStartedKeyguardState.to == KeyguardState.OCCLUDED
) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
KeyguardState.OCCLUDED,
KeyguardState.GONE,
getAnimator(),
)
)
}
}
}
}
private fun listenForOccludedToAodOrDozing() {
scope.launch {
keyguardInteractor.wakefulnessModel

View File

@@ -357,6 +357,92 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
coroutineContext.cancelChildren()
}
@Test
fun `OCCLUDED to GONE`() =
testScope.runTest {
// GIVEN a device on lockscreen
keyguardRepository.setKeyguardShowing(true)
runCurrent()
// GIVEN a prior transition has run to OCCLUDED
runner.startTransition(
testScope,
TransitionInfo(
ownerName = "",
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.OCCLUDED,
animator =
ValueAnimator().apply {
duration = 10
interpolator = Interpolators.LINEAR
},
)
)
keyguardRepository.setKeyguardOccluded(true)
runCurrent()
reset(mockTransitionRepository)
// WHEN keyguard goes away
keyguardRepository.setKeyguardShowing(false)
// AND occlusion ends
keyguardRepository.setKeyguardOccluded(false)
runCurrent()
val info =
withArgCaptor<TransitionInfo> {
verify(mockTransitionRepository).startTransition(capture(), anyBoolean())
}
// THEN a transition to GONE should occur
assertThat(info.ownerName).isEqualTo("FromOccludedTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.OCCLUDED)
assertThat(info.to).isEqualTo(KeyguardState.GONE)
assertThat(info.animator).isNotNull()
coroutineContext.cancelChildren()
}
@Test
fun `OCCLUDED to LOCKSCREEN`() =
testScope.runTest {
// GIVEN a device on lockscreen
keyguardRepository.setKeyguardShowing(true)
runCurrent()
// GIVEN a prior transition has run to OCCLUDED
runner.startTransition(
testScope,
TransitionInfo(
ownerName = "",
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.OCCLUDED,
animator =
ValueAnimator().apply {
duration = 10
interpolator = Interpolators.LINEAR
},
)
)
keyguardRepository.setKeyguardOccluded(true)
runCurrent()
reset(mockTransitionRepository)
// WHEN occlusion ends
keyguardRepository.setKeyguardOccluded(false)
runCurrent()
val info =
withArgCaptor<TransitionInfo> {
verify(mockTransitionRepository).startTransition(capture(), anyBoolean())
}
// THEN a transition to LOCKSCREEN should occur
assertThat(info.ownerName).isEqualTo("FromOccludedTransitionInteractor")
assertThat(info.from).isEqualTo(KeyguardState.OCCLUDED)
assertThat(info.to).isEqualTo(KeyguardState.LOCKSCREEN)
assertThat(info.animator).isNotNull()
coroutineContext.cancelChildren()
}
@Test
fun `LOCKSCREEN to DOZING`() =
testScope.runTest {