Transitions - Make them cancelable

Data layer - Add 'isKeyguardGoingAway' information, allow transitions
to be cancelable and add in Cancel state.

Domain layer - Listen for state transitions and then attempt to
cancel/interrupt them under the right circumstances, such as when the
power button is pressed in the middle of an aod -> lockscreen
transition.

Bouncer fixes - hide() was never called when using the back gesture,
resulting in incorrect bouncer state.

Test: atest KeyguardTransitionRepositoryTest
KeyguardRepositoryImplTest KeyguardBouncerTest BouncerInteractorTest
Bug: 195430376

Change-Id: Id1b79253ab6334e8e5941c89e94e267126b08ecb
This commit is contained in:
Matt Pietal
2022-11-07 12:49:43 +00:00
parent 8d6647d473
commit d3783f7bac
20 changed files with 369 additions and 71 deletions

View File

@@ -69,6 +69,9 @@ interface KeyguardRepository {
*/
val isKeyguardShowing: Flow<Boolean>
/** Observable for the signal that keyguard is about to go away. */
val isKeyguardGoingAway: Flow<Boolean>
/** Observable for whether the bouncer is showing. */
val isBouncerShowing: Flow<Boolean>
@@ -176,6 +179,29 @@ constructor(
awaitClose { keyguardStateController.removeCallback(callback) }
}
override val isKeyguardGoingAway: Flow<Boolean> = conflatedCallbackFlow {
val callback =
object : KeyguardStateController.Callback {
override fun onKeyguardGoingAwayChanged() {
trySendWithFailureLogging(
keyguardStateController.isKeyguardGoingAway,
TAG,
"updated isKeyguardGoingAway"
)
}
}
keyguardStateController.addCallback(callback)
// Adding the callback does not send an initial update.
trySendWithFailureLogging(
keyguardStateController.isKeyguardGoingAway,
TAG,
"initial isKeyguardGoingAway"
)
awaitClose { keyguardStateController.removeCallback(callback) }
}
override val isBouncerShowing: Flow<Boolean> = conflatedCallbackFlow {
val callback =
object : KeyguardStateController.Callback {

View File

@@ -94,11 +94,13 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio
*/
private val _transitions =
MutableSharedFlow<TransitionStep>(
replay = 2,
extraBufferCapacity = 10,
onBufferOverflow = BufferOverflow.DROP_OLDEST
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)
override val transitions = _transitions.asSharedFlow().distinctUntilChanged()
private var lastStep: TransitionStep = TransitionStep()
private var lastAnimator: ValueAnimator? = null
/*
* When manual control of the transition is requested, a unique [UUID] is used as the handle
@@ -106,19 +108,39 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio
*/
private var updateTransitionId: UUID? = null
init {
// Seed with transitions signaling a boot into lockscreen state
emitTransition(
TransitionStep(
KeyguardState.NONE,
KeyguardState.LOCKSCREEN,
0f,
TransitionState.STARTED,
)
)
emitTransition(
TransitionStep(
KeyguardState.NONE,
KeyguardState.LOCKSCREEN,
1f,
TransitionState.FINISHED,
)
)
}
override fun startTransition(info: TransitionInfo): UUID? {
if (lastStep.transitionState != TransitionState.FINISHED) {
// Open questions:
// * Queue of transitions? buffer of 1?
// * Are transitions cancellable if a new one is triggered?
// * What validation does this need to do?
Log.wtf(TAG, "Transition still active: $lastStep")
return null
Log.i(TAG, "Transition still active: $lastStep, canceling")
}
val startingValue = 1f - lastStep.value
lastAnimator?.cancel()
lastAnimator = info.animator
info.animator?.let { animator ->
// An animator was provided, so use it to run the transition
animator.setFloatValues(0f, 1f)
animator.setFloatValues(startingValue, 1f)
animator.duration = ((1f - startingValue) * animator.duration).toLong()
val updateListener =
object : AnimatorUpdateListener {
override fun onAnimationUpdate(animation: ValueAnimator) {
@@ -134,15 +156,24 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio
val adapter =
object : AnimatorListenerAdapter() {
override fun onAnimationStart(animation: Animator) {
emitTransition(TransitionStep(info, 0f, TransitionState.STARTED))
emitTransition(TransitionStep(info, startingValue, TransitionState.STARTED))
}
override fun onAnimationCancel(animation: Animator) {
Log.i(TAG, "Cancelling transition: $info")
endAnimation(animation, lastStep.value, TransitionState.CANCELED)
}
override fun onAnimationEnd(animation: Animator) {
emitTransition(TransitionStep(info, 1f, TransitionState.FINISHED))
endAnimation(animation, 1f, TransitionState.FINISHED)
}
private fun endAnimation(
animation: Animator,
value: Float,
state: TransitionState
) {
emitTransition(TransitionStep(info, value, state))
animator.removeListener(this)
animator.removeUpdateListener(updateListener)
lastAnimator = null
}
}
animator.addListener(adapter)

View File

@@ -20,10 +20,11 @@ import android.animation.ValueAnimator
import com.android.systemui.animation.Interpolators
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.KeyguardRepository
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.keyguard.shared.model.WakefulnessModel.Companion.isSleepingOrStartingToSleep
import com.android.systemui.keyguard.shared.model.WakefulnessModel.Companion.isWakingOrStartingToWake
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -35,18 +36,30 @@ class AodLockscreenTransitionInteractor
@Inject
constructor(
@Application private val scope: CoroutineScope,
private val keyguardRepository: KeyguardRepository,
private val keyguardInteractor: KeyguardInteractor,
private val keyguardTransitionRepository: KeyguardTransitionRepository,
private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
) : TransitionInteractor("AOD<->LOCKSCREEN") {
override fun start() {
scope.launch {
keyguardRepository.isDozing
.sample(keyguardTransitionInteractor.finishedKeyguardState, { a, b -> Pair(a, b) })
/*
* Listening to the startedKeyguardTransitionStep (last started step) allows this code
* to interrupt an active transition, as long as they were either going to LOCKSCREEN or
* AOD state. One example is when the user presses the power button in the middle of an
* active transition.
*/
keyguardInteractor.wakefulnessState
.sample(
keyguardTransitionInteractor.startedKeyguardTransitionStep,
{ a, b -> Pair(a, b) }
)
.collect { pair ->
val (isDozing, keyguardState) = pair
if (isDozing && keyguardState == KeyguardState.LOCKSCREEN) {
val (wakefulnessState, lastStartedStep) = pair
if (
isSleepingOrStartingToSleep(wakefulnessState) &&
lastStartedStep.to == KeyguardState.LOCKSCREEN
) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
@@ -55,7 +68,10 @@ constructor(
getAnimator(),
)
)
} else if (!isDozing && keyguardState == KeyguardState.AOD) {
} else if (
isWakingOrStartingToWake(wakefulnessState) &&
lastStartedStep.to == KeyguardState.AOD
) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.systemui.keyguard.domain.interactor
import android.animation.ValueAnimator
import com.android.systemui.animation.Interpolators
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.shade.data.repository.ShadeRepository
import com.android.systemui.util.kotlin.sample
import java.util.UUID
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@SysUISingleton
class BouncerToGoneTransitionInteractor
@Inject
constructor(
@Application private val scope: CoroutineScope,
private val keyguardInteractor: KeyguardInteractor,
private val shadeRepository: ShadeRepository,
private val keyguardTransitionRepository: KeyguardTransitionRepository,
private val keyguardTransitionInteractor: KeyguardTransitionInteractor
) : TransitionInteractor("BOUNCER->GONE") {
private var transitionId: UUID? = null
override fun start() {
listenForKeyguardGoingAway()
}
private fun listenForKeyguardGoingAway() {
scope.launch {
keyguardInteractor.isKeyguardGoingAway
.sample(keyguardTransitionInteractor.finishedKeyguardState, { a, b -> Pair(a, b) })
.collect { pair ->
val (isKeyguardGoingAway, keyguardState) = pair
if (isKeyguardGoingAway && keyguardState == KeyguardState.BOUNCER) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
ownerName = name,
from = KeyguardState.BOUNCER,
to = KeyguardState.GONE,
animator = getAnimator(),
)
)
}
}
}
}
private fun getAnimator(): ValueAnimator {
return ValueAnimator().apply {
setInterpolator(Interpolators.LINEAR)
setDuration(TRANSITION_DURATION_MS)
}
}
companion object {
private const val TRANSITION_DURATION_MS = 300L
}
}

View File

@@ -43,6 +43,8 @@ constructor(
val isDozing: Flow<Boolean> = repository.isDozing
/** Whether the keyguard is showing or not. */
val isKeyguardShowing: Flow<Boolean> = repository.isKeyguardShowing
/** Whether the keyguard is going away. */
val isKeyguardGoingAway: Flow<Boolean> = repository.isKeyguardGoingAway
/** Whether the bouncer is showing or not. */
val isBouncerShowing: Flow<Boolean> = repository.isBouncerShowing
/** The device wake/sleep state */

View File

@@ -40,12 +40,24 @@ constructor(
keyguardInteractor.wakefulnessState.collect { logger.v("WakefulnessState", it) }
}
scope.launch {
keyguardInteractor.isBouncerShowing.collect { logger.v("Bouncer showing", it) }
}
scope.launch { keyguardInteractor.isDozing.collect { logger.v("isDozing", it) } }
scope.launch {
interactor.finishedKeyguardTransitionStep.collect {
logger.i("Finished transition", it)
}
}
scope.launch {
interactor.canceledKeyguardTransitionStep.collect {
logger.i("Canceled transition", it)
}
}
scope.launch {
interactor.startedKeyguardTransitionStep.collect { logger.i("Started transition", it) }
}

View File

@@ -42,6 +42,7 @@ constructor(
is GoneAodTransitionInteractor -> Log.d(TAG, "Started $it")
is LockscreenGoneTransitionInteractor -> Log.d(TAG, "Started $it")
is AodToGoneTransitionInteractor -> Log.d(TAG, "Started $it")
is BouncerToGoneTransitionInteractor -> Log.d(TAG, "Started $it")
}
it.start()
}

View File

@@ -57,6 +57,14 @@ constructor(
lockscreenToAodTransition,
)
/* The last [TransitionStep] with a [TransitionState] of STARTED */
val startedKeyguardTransitionStep: Flow<TransitionStep> =
repository.transitions.filter { step -> step.transitionState == TransitionState.STARTED }
/* The last [TransitionStep] with a [TransitionState] of CANCELED */
val canceledKeyguardTransitionStep: Flow<TransitionStep> =
repository.transitions.filter { step -> step.transitionState == TransitionState.CANCELED }
/* The last [TransitionStep] with a [TransitionState] of FINISHED */
val finishedKeyguardTransitionStep: Flow<TransitionStep> =
repository.transitions.filter { step -> step.transitionState == TransitionState.FINISHED }
@@ -64,8 +72,4 @@ constructor(
/* The last completed [KeyguardState] transition */
val finishedKeyguardState: Flow<KeyguardState> =
finishedKeyguardTransitionStep.map { step -> step.to }
/* The last [TransitionStep] with a [TransitionState] of STARTED */
val startedKeyguardTransitionStep: Flow<TransitionStep> =
repository.transitions.filter { step -> step.transitionState == TransitionState.STARTED }
}

View File

@@ -56,10 +56,20 @@ constructor(
private fun listenForBouncerHiding() {
scope.launch {
keyguardInteractor.isBouncerShowing
.sample(keyguardInteractor.wakefulnessState, { a, b -> Pair(a, b) })
.collect { pair ->
val (isBouncerShowing, wakefulnessState) = pair
if (!isBouncerShowing) {
.sample(
combine(
keyguardInteractor.wakefulnessState,
keyguardTransitionInteractor.startedKeyguardTransitionStep,
) { a, b ->
Pair(a, b)
},
{ a, bc -> Triple(a, bc.first, bc.second) }
)
.collect { triple ->
val (isBouncerShowing, wakefulnessState, lastStartedTransitionStep) = triple
if (
!isBouncerShowing && lastStartedTransitionStep.to == KeyguardState.BOUNCER
) {
val to =
if (
wakefulnessState == WakefulnessModel.STARTING_TO_SLEEP ||
@@ -90,10 +100,10 @@ constructor(
combine(
keyguardTransitionInteractor.finishedKeyguardState,
keyguardInteractor.statusBarState,
) { keyguardState, statusBarState ->
Pair(keyguardState, statusBarState)
) { a, b ->
Pair(a, b)
},
{ shadeModel, pair -> Triple(shadeModel, pair.first, pair.second) }
{ a, bc -> Triple(a, bc.first, bc.second) }
)
.collect { triple ->
val (shadeModel, keyguardState, statusBarState) = triple
@@ -116,8 +126,7 @@ constructor(
)
} else {
// TODO (b/251849525): Remove statusbarstate check when that state is
// integrated
// into KeyguardTransitionRepository
// integrated into KeyguardTransitionRepository
if (
keyguardState == KeyguardState.LOCKSCREEN &&
shadeModel.isUserDragging &&

View File

@@ -23,6 +23,7 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collect
@@ -34,23 +35,27 @@ class LockscreenGoneTransitionInteractor
constructor(
@Application private val scope: CoroutineScope,
private val keyguardInteractor: KeyguardInteractor,
private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
private val keyguardTransitionRepository: KeyguardTransitionRepository,
) : TransitionInteractor("LOCKSCREEN->GONE") {
override fun start() {
scope.launch {
keyguardInteractor.isKeyguardShowing.collect { isShowing ->
if (!isShowing) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
KeyguardState.LOCKSCREEN,
KeyguardState.GONE,
getAnimator(),
keyguardInteractor.isKeyguardGoingAway
.sample(keyguardTransitionInteractor.finishedKeyguardState, { a, b -> Pair(a, b) })
.collect { pair ->
val (isKeyguardGoingAway, keyguardState) = pair
if (!isKeyguardGoingAway && keyguardState == KeyguardState.LOCKSCREEN) {
keyguardTransitionRepository.startTransition(
TransitionInfo(
name,
KeyguardState.LOCKSCREEN,
KeyguardState.GONE,
getAnimator(),
)
)
)
}
}
}
}
}

View File

@@ -210,9 +210,12 @@ constructor(
expansion == KeyguardBouncer.EXPANSION_HIDDEN &&
oldExpansion != KeyguardBouncer.EXPANSION_HIDDEN
) {
repository.setPrimaryVisible(false)
repository.setPrimaryShow(null)
falsingCollector.onBouncerHidden()
/*
* There are cases where #hide() was not invoked, such as when
* NotificationPanelViewController controls the hide animation. Make sure the state gets
* updated by calling #hide() directly.
*/
hide()
DejankUtils.postAfterTraversal { primaryBouncerCallbackInteractor.dispatchReset() }
primaryBouncerCallbackInteractor.dispatchFullyHidden()
} else if (

View File

@@ -44,6 +44,10 @@ abstract class StartKeyguardTransitionModule {
@Binds @IntoSet abstract fun aodGone(impl: AodToGoneTransitionInteractor): TransitionInteractor
@Binds
@IntoSet
abstract fun bouncerGone(impl: BouncerToGoneTransitionInteractor): TransitionInteractor
@Binds
@IntoSet
abstract fun lockscreenGone(impl: LockscreenGoneTransitionInteractor): TransitionInteractor

View File

@@ -17,7 +17,12 @@ package com.android.systemui.keyguard.shared.model
/** Possible states for a running transition between [State] */
enum class TransitionState {
/* Transition has begun. */
STARTED,
/* Transition is actively running. */
RUNNING,
FINISHED
/* Transition has completed successfully. */
FINISHED,
/* Transition has been interrupted, and not completed successfully. */
CANCELED,
}

View File

@@ -24,5 +24,15 @@ enum class WakefulnessModel {
/** Device is now fully awake and interactive. */
AWAKE,
/** Signal that the device is now going to sleep. */
STARTING_TO_SLEEP,
STARTING_TO_SLEEP;
companion object {
fun isSleepingOrStartingToSleep(model: WakefulnessModel): Boolean {
return model == ASLEEP || model == STARTING_TO_SLEEP
}
fun isWakingOrStartingToWake(model: WakefulnessModel): Boolean {
return model == AWAKE || model == STARTING_TO_WAKE
}
}
}

View File

@@ -279,10 +279,7 @@ public class KeyguardBouncer {
* @see #onFullyShown()
*/
private void onFullyHidden() {
cancelShowRunnable();
setVisibility(View.INVISIBLE);
mFalsingCollector.onBouncerHidden();
DejankUtils.postAfterTraversal(mResetRunnable);
}
private void setVisibility(@View.Visibility int visibility) {
@@ -459,7 +456,13 @@ public class KeyguardBouncer {
onFullyShown();
dispatchFullyShown();
} else if (fraction == EXPANSION_HIDDEN && oldExpansion != EXPANSION_HIDDEN) {
onFullyHidden();
DejankUtils.postAfterTraversal(mResetRunnable);
/*
* There are cases where #hide() was not invoked, such as when
* NotificationPanelViewController controls the hide animation. Make sure the state gets
* updated by calling #hide() directly.
*/
hide(false /* destroyView */);
dispatchFullyHidden();
} else if (fraction != EXPANSION_VISIBLE && oldExpansion == EXPANSION_VISIBLE) {
dispatchStartingToHide();

View File

@@ -165,6 +165,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
@Override
public void onFullyHidden() {
mPrimaryBouncerAnimating = false;
updateStates();
}
@Override
@@ -1184,12 +1185,16 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
updateNavigationBarVisibility(navBarVisible);
}
if (primaryBouncerShowing != mLastPrimaryBouncerShowing || mFirstUpdate) {
boolean isPrimaryBouncerShowingChanged =
primaryBouncerShowing != mLastPrimaryBouncerShowing;
mLastPrimaryBouncerShowing = primaryBouncerShowing;
if (isPrimaryBouncerShowingChanged || mFirstUpdate) {
mNotificationShadeWindowController.setBouncerShowing(primaryBouncerShowing);
mCentralSurfaces.setBouncerShowing(primaryBouncerShowing);
}
if (primaryBouncerIsOrWillBeShowing != mLastPrimaryBouncerIsOrWillBeShowing || mFirstUpdate
|| primaryBouncerShowing != mLastPrimaryBouncerShowing) {
|| isPrimaryBouncerShowingChanged) {
mKeyguardUpdateManager.sendPrimaryBouncerChanged(primaryBouncerIsOrWillBeShowing,
primaryBouncerShowing);
}
@@ -1198,7 +1203,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mLastShowing = showing;
mLastGlobalActionsVisible = mGlobalActionsVisible;
mLastOccluded = occluded;
mLastPrimaryBouncerShowing = primaryBouncerShowing;
mLastPrimaryBouncerIsOrWillBeShowing = primaryBouncerIsOrWillBeShowing;
mLastBouncerDismissible = primaryBouncerDismissible;
mLastRemoteInputActive = remoteInputActive;

View File

@@ -256,6 +256,28 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
job.cancel()
}
@Test
fun isKeyguardGoingAway() = runBlockingTest {
whenever(keyguardStateController.isKeyguardGoingAway).thenReturn(false)
var latest: Boolean? = null
val job = underTest.isKeyguardGoingAway.onEach { latest = it }.launchIn(this)
assertThat(latest).isFalse()
val captor = argumentCaptor<KeyguardStateController.Callback>()
verify(keyguardStateController).addCallback(captor.capture())
whenever(keyguardStateController.isKeyguardGoingAway).thenReturn(true)
captor.value.onKeyguardGoingAwayChanged()
assertThat(latest).isTrue()
whenever(keyguardStateController.isKeyguardGoingAway).thenReturn(false)
captor.value.onKeyguardGoingAwayChanged()
assertThat(latest).isFalse()
job.cancel()
}
@Test
fun biometricUnlockState() = runBlockingTest {
val values = mutableListOf<BiometricUnlockModel>()

View File

@@ -25,8 +25,8 @@ import android.view.Choreographer.FrameCallback
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Interpolators
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.AOD
import com.android.systemui.keyguard.shared.model.KeyguardState.BOUNCER
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.keyguard.shared.model.TransitionState
@@ -38,7 +38,6 @@ import java.util.UUID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.launchIn
@@ -91,18 +90,51 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
}
}
assertSteps(steps, listWithStep(BigDecimal(.1)))
assertSteps(steps, listWithStep(BigDecimal(.1)), AOD, LOCKSCREEN)
job.cancel()
provider.stop()
}
@Test
fun `startTransition called during another transition fails`() {
underTest.startTransition(TransitionInfo(OWNER_NAME, AOD, LOCKSCREEN, null))
underTest.startTransition(TransitionInfo(OWNER_NAME, LOCKSCREEN, BOUNCER, null))
fun `starting second transition will cancel the first transition`() {
runBlocking(IMMEDIATE) {
val (animator, provider) = setupAnimator(this)
assertThat(wtfHandler.failed).isTrue()
val steps = mutableListOf<TransitionStep>()
val job = underTest.transition(AOD, LOCKSCREEN).onEach { steps.add(it) }.launchIn(this)
underTest.startTransition(TransitionInfo(OWNER_NAME, AOD, LOCKSCREEN, animator))
// 3 yields(), alternating with the animator, results in a value 0.1, which can be
// canceled and tested against
yield()
yield()
yield()
// Now start 2nd transition, which will interrupt the first
val job2 = underTest.transition(LOCKSCREEN, AOD).onEach { steps.add(it) }.launchIn(this)
val (animator2, provider2) = setupAnimator(this)
underTest.startTransition(TransitionInfo(OWNER_NAME, LOCKSCREEN, AOD, animator2))
val startTime = System.currentTimeMillis()
while (animator2.isRunning()) {
yield()
if (System.currentTimeMillis() - startTime > MAX_TEST_DURATION) {
fail("Failed test due to excessive runtime of: $MAX_TEST_DURATION")
}
}
val firstTransitionSteps = listWithStep(step = BigDecimal(.1), stop = BigDecimal(.1))
assertSteps(steps.subList(0, 4), firstTransitionSteps, AOD, LOCKSCREEN)
val secondTransitionSteps = listWithStep(step = BigDecimal(.1), start = BigDecimal(.9))
assertSteps(steps.subList(4, steps.size), secondTransitionSteps, LOCKSCREEN, AOD)
job.cancel()
job2.cancel()
provider.stop()
provider2.stop()
}
}
@Test
@@ -165,11 +197,15 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
assertThat(wtfHandler.failed).isTrue()
}
private fun listWithStep(step: BigDecimal): List<BigDecimal> {
private fun listWithStep(
step: BigDecimal,
start: BigDecimal = BigDecimal.ZERO,
stop: BigDecimal = BigDecimal.ONE,
): List<BigDecimal> {
val steps = mutableListOf<BigDecimal>()
var i = BigDecimal.ZERO
while (i.compareTo(BigDecimal.ONE) <= 0) {
var i = start
while (i.compareTo(stop) <= 0) {
steps.add(i)
i = (i + step).setScale(2, RoundingMode.HALF_UP)
}
@@ -177,23 +213,43 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
return steps
}
private fun assertSteps(steps: List<TransitionStep>, fractions: List<BigDecimal>) {
private fun assertSteps(
steps: List<TransitionStep>,
fractions: List<BigDecimal>,
from: KeyguardState,
to: KeyguardState,
) {
assertThat(steps[0])
.isEqualTo(TransitionStep(AOD, LOCKSCREEN, 0f, TransitionState.STARTED, OWNER_NAME))
.isEqualTo(
TransitionStep(
from,
to,
fractions[0].toFloat(),
TransitionState.STARTED,
OWNER_NAME
)
)
fractions.forEachIndexed { index, fraction ->
assertThat(steps[index + 1])
.isEqualTo(
TransitionStep(
AOD,
LOCKSCREEN,
from,
to,
fraction.toFloat(),
TransitionState.RUNNING,
OWNER_NAME
)
)
}
val lastValue = fractions[fractions.size - 1].toFloat()
val status =
if (lastValue < 1f) {
TransitionState.CANCELED
} else {
TransitionState.FINISHED
}
assertThat(steps[steps.size - 1])
.isEqualTo(TransitionStep(AOD, LOCKSCREEN, 1f, TransitionState.FINISHED, OWNER_NAME))
.isEqualTo(TransitionStep(from, to, lastValue, status, OWNER_NAME))
assertThat(wtfHandler.failed).isFalse()
}
@@ -230,7 +286,7 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
scope.launch {
frames.collect {
// Delay is required for AnimationHandler to properly register a callback
delay(1)
yield()
val (frameNumber, callback) = it
callback?.doFrame(frameNumber)
}
@@ -243,7 +299,7 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
}
override fun postFrameCallback(cb: FrameCallback) {
frames.value = Pair(++frameCount, cb)
frames.value = Pair(frameCount++, cb)
}
override fun postCommitCallback(runnable: Runnable) {}
override fun getFrameTime() = frameCount

View File

@@ -155,6 +155,7 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() {
mPrimaryBouncerInteractor.setPanelExpansion(EXPANSION_HIDDEN)
verify(repository).setPrimaryVisible(false)
verify(repository).setPrimaryShow(null)
verify(repository).setPrimaryHide(true)
verify(falsingCollector).onBouncerHidden()
verify(mPrimaryBouncerCallbackInteractor).dispatchReset()
verify(mPrimaryBouncerCallbackInteractor).dispatchFullyHidden()

View File

@@ -58,6 +58,9 @@ class FakeKeyguardRepository : KeyguardRepository {
private val _isBouncerShowing = MutableStateFlow(false)
override val isBouncerShowing: Flow<Boolean> = _isBouncerShowing
private val _isKeyguardGoingAway = MutableStateFlow(false)
override val isKeyguardGoingAway: Flow<Boolean> = _isKeyguardGoingAway
private val _biometricUnlockState = MutableStateFlow(BiometricUnlockModel.NONE)
override val biometricUnlockState: Flow<BiometricUnlockModel> = _biometricUnlockState