Transitions - Handle cancel of bouncer swipe
When swipe up is followed by a swipe down, issue a call to cancel the current transition and then immediately go back to the prior state. This was impacting dream transitions. Test: atest KeyguardTransitionRepositoryTest Bug: 260637747 Change-Id: I6509e0377e58971c09ddd0ee971c31fce615e542
This commit is contained in:
@@ -209,7 +209,7 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio
|
||||
return
|
||||
}
|
||||
|
||||
if (state == TransitionState.FINISHED) {
|
||||
if (state == TransitionState.FINISHED || state == TransitionState.CANCELED) {
|
||||
updateTransitionId = null
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,6 @@ constructor(
|
||||
private val keyguardTransitionRepository: KeyguardTransitionRepository,
|
||||
) : TransitionInteractor(FromLockscreenTransitionInteractor::class.simpleName!!) {
|
||||
|
||||
private var transitionId: UUID? = null
|
||||
|
||||
override fun start() {
|
||||
listenForLockscreenToGone()
|
||||
listenForLockscreenToOccluded()
|
||||
@@ -104,6 +102,7 @@ constructor(
|
||||
|
||||
/* Starts transitions when manually dragging up the bouncer from the lockscreen. */
|
||||
private fun listenForLockscreenToBouncerDragging() {
|
||||
var transitionId: UUID? = null
|
||||
scope.launch {
|
||||
shadeRepository.shadeModel
|
||||
.sample(
|
||||
@@ -114,25 +113,43 @@ constructor(
|
||||
),
|
||||
::toTriple
|
||||
)
|
||||
.collect { triple ->
|
||||
val (shadeModel, keyguardState, statusBarState) = triple
|
||||
|
||||
.collect { (shadeModel, keyguardState, statusBarState) ->
|
||||
val id = transitionId
|
||||
if (id != null) {
|
||||
// An existing `id` means a transition is started, and calls to
|
||||
// `updateTransition` will control it until FINISHED
|
||||
keyguardTransitionRepository.updateTransition(
|
||||
id,
|
||||
1f - shadeModel.expansionAmount,
|
||||
if (
|
||||
shadeModel.expansionAmount == 0f || shadeModel.expansionAmount == 1f
|
||||
) {
|
||||
transitionId = null
|
||||
// `updateTransition` will control it until FINISHED or CANCELED
|
||||
var nextState =
|
||||
if (shadeModel.expansionAmount == 0f) {
|
||||
TransitionState.FINISHED
|
||||
} else if (shadeModel.expansionAmount == 1f) {
|
||||
TransitionState.CANCELED
|
||||
} else {
|
||||
TransitionState.RUNNING
|
||||
}
|
||||
keyguardTransitionRepository.updateTransition(
|
||||
id,
|
||||
1f - shadeModel.expansionAmount,
|
||||
nextState,
|
||||
)
|
||||
|
||||
if (
|
||||
nextState == TransitionState.CANCELED ||
|
||||
nextState == TransitionState.FINISHED
|
||||
) {
|
||||
transitionId = null
|
||||
}
|
||||
|
||||
// If canceled, just put the state back
|
||||
if (nextState == TransitionState.CANCELED) {
|
||||
keyguardTransitionRepository.startTransition(
|
||||
TransitionInfo(
|
||||
ownerName = name,
|
||||
from = KeyguardState.BOUNCER,
|
||||
to = KeyguardState.LOCKSCREEN,
|
||||
animator = getAnimator(0.milliseconds)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// TODO (b/251849525): Remove statusbarstate check when that state is
|
||||
// integrated into KeyguardTransitionRepository
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
|
||||
import com.android.systemui.keyguard.shared.model.AnimationParams
|
||||
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.DREAMING
|
||||
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
|
||||
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
|
||||
@@ -30,9 +31,9 @@ import com.android.systemui.keyguard.shared.model.TransitionState
|
||||
import com.android.systemui.keyguard.shared.model.TransitionState.STARTED
|
||||
import com.android.systemui.keyguard.shared.model.TransitionStep
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.time.Duration
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -62,6 +63,10 @@ constructor(
|
||||
/** LOCKSCREEN->AOD transition information. */
|
||||
val lockscreenToAodTransition: Flow<TransitionStep> = repository.transition(LOCKSCREEN, AOD)
|
||||
|
||||
/** LOCKSCREEN->BOUNCER transition information. */
|
||||
val lockscreenToBouncerTransition: Flow<TransitionStep> =
|
||||
repository.transition(LOCKSCREEN, BOUNCER)
|
||||
|
||||
/** LOCKSCREEN->DREAMING transition information. */
|
||||
val lockscreenToDreamingTransition: Flow<TransitionStep> =
|
||||
repository.transition(LOCKSCREEN, DREAMING)
|
||||
|
||||
@@ -168,6 +168,25 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
|
||||
assertThat(wtfHandler.failed).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Attempt to manually update transition after CANCELED state throws exception`() {
|
||||
val uuid =
|
||||
underTest.startTransition(
|
||||
TransitionInfo(
|
||||
ownerName = OWNER_NAME,
|
||||
from = AOD,
|
||||
to = LOCKSCREEN,
|
||||
animator = null,
|
||||
)
|
||||
)
|
||||
|
||||
checkNotNull(uuid).let {
|
||||
underTest.updateTransition(it, 0.2f, TransitionState.CANCELED)
|
||||
underTest.updateTransition(it, 0.5f, TransitionState.RUNNING)
|
||||
}
|
||||
assertThat(wtfHandler.failed).isTrue()
|
||||
}
|
||||
|
||||
private fun listWithStep(
|
||||
step: BigDecimal,
|
||||
start: BigDecimal = BigDecimal.ZERO,
|
||||
|
||||
Reference in New Issue
Block a user