diff options
3 files changed, 86 insertions, 24 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorTest.kt index 1ec78742f0dd..4d81317b7755 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractorTest.kt @@ -30,6 +30,7 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository import com.android.systemui.keyguard.shared.model.KeyguardState +import com.android.systemui.keyguard.shared.model.StatusBarState.KEYGUARD import com.android.systemui.keyguard.shared.model.TransitionState import com.android.systemui.keyguard.shared.model.TransitionStep import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat as assertThatRepository @@ -81,7 +82,7 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() { assertThat(values) .containsExactly( - null, // LOCKSCREEN -> AOD does not have any specific surface visibility. + null // LOCKSCREEN -> AOD does not have any specific surface visibility. ) transitionRepository.sendTransitionStep( @@ -118,6 +119,53 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() { } @Test + fun draggingToPrimaryBouncerUpdateIsSent() = + testScope.runTest { + underTest.start() + transitionRepository.sendTransitionSteps( + from = KeyguardState.OFF, + to = KeyguardState.LOCKSCREEN, + testScope, + ) + + val steps by collectValues(transitionRepository.transitions) + + shadeRepository.setLegacyShadeExpansion(0f) + shadeRepository.setLegacyShadeTracking(true) + keyguardRepository.setKeyguardDismissible(false) + keyguardRepository.setStatusBarState(KEYGUARD) + runCurrent() + + // User starts dragging up + shadeRepository.setLegacyShadeExpansion(0.1f) + runCurrent() + + assertThatRepository(transitionRepository) + .startedTransition( + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.PRIMARY_BOUNCER, + ) + + // FakeKeyguardRepository doesn't send the step, so do that + transitionRepository.sendTransitionStep( + TransitionStep( + transitionState = TransitionState.STARTED, + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.PRIMARY_BOUNCER, + value = 0f, + ) + ) + runCurrent() + + // Update is sent + shadeRepository.setLegacyShadeExpansion(0.2f) + runCurrent() + + assertThatRepository(transitionRepository) + .updatedTransition(value = 1f, state = TransitionState.RUNNING) + } + + @Test @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR) fun testTransitionsToGone_whenDismissFlingWhileDismissable_flagEnabled() = testScope.runTest { @@ -132,10 +180,7 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() { runCurrent() assertThatRepository(transitionRepository) - .startedTransition( - from = KeyguardState.LOCKSCREEN, - to = KeyguardState.GONE, - ) + .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.GONE) } @Test @@ -184,15 +229,12 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() { true, ActivityManager.RunningTaskInfo().apply { topActivityType = WindowConfiguration.ACTIVITY_TYPE_STANDARD - } + }, ) runCurrent() assertThatRepository(transitionRepository) - .startedTransition( - from = KeyguardState.LOCKSCREEN, - to = KeyguardState.OCCLUDED, - ) + .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.OCCLUDED) } @Test @@ -207,14 +249,11 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() { true, ActivityManager.RunningTaskInfo().apply { topActivityType = WindowConfiguration.ACTIVITY_TYPE_DREAM - } + }, ) runCurrent() assertThatRepository(transitionRepository) - .startedTransition( - from = KeyguardState.LOCKSCREEN, - to = KeyguardState.DREAMING, - ) + .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.DREAMING) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt index cd5daf9a99f0..1e9541e1923e 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt @@ -210,13 +210,18 @@ constructor( } else { TransitionState.RUNNING } - transitionRepository.updateTransition( - id, - // This maps the shadeExpansion to a much faster curve, to match - // the existing logic - 1f - MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion), - nextState, - ) + + // startTransition below will issue the CANCELED directly + if (nextState != TransitionState.CANCELED) { + transitionRepository.updateTransition( + id, + // This maps the shadeExpansion to a much faster curve, to match + // the existing logic + 1f - + MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion), + nextState, + ) + } if ( nextState == TransitionState.CANCELED || @@ -234,11 +239,12 @@ constructor( ownerName = name, from = KeyguardState.PRIMARY_BOUNCER, to = KeyguardState.LOCKSCREEN, + modeOnCanceled = TransitionModeOnCanceled.REVERSE, animator = getDefaultAnimatorForTransitionsToState( KeyguardState.LOCKSCREEN ) - .apply { duration = 0 }, + .apply { duration = 100L }, ) ) } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/util/KeyguardTransitionRepositorySpySubject.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/util/KeyguardTransitionRepositorySpySubject.kt index 450f08f1fe3f..11f0c19ffa67 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/util/KeyguardTransitionRepositorySpySubject.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/util/KeyguardTransitionRepositorySpySubject.kt @@ -21,17 +21,20 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.model.TransitionInfo import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled -import com.android.systemui.util.mockito.any +import com.android.systemui.keyguard.shared.model.TransitionState import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.FailureMetadata import com.google.common.truth.Subject import com.google.common.truth.Truth import com.google.common.truth.Truth.assertAbout +import com.google.common.truth.Truth.assertThat import junit.framework.Assert.assertEquals import org.junit.Assert.fail import org.mockito.Mockito import org.mockito.Mockito.never import org.mockito.Mockito.verify +import org.mockito.kotlin.any +import org.mockito.kotlin.argumentCaptor /** [Subject] used to make assertions about a [Mockito.spy] KeyguardTransitionRepository. */ class KeyguardTransitionRepositorySpySubject @@ -89,6 +92,20 @@ private constructor( } } + /** + * Asserts that we started a transition to the given state, optionally verifying additional + * params. + */ + suspend fun updatedTransition(value: Float, state: TransitionState) { + val valueCaptor = argumentCaptor<Float>() + val stateCaptor = argumentCaptor<TransitionState>() + + verify(repository).updateTransition(any(), valueCaptor.capture(), stateCaptor.capture()) + + assertThat(value).isEqualTo(valueCaptor.firstValue) + assertThat(state).isEqualTo(stateCaptor.firstValue) + } + /** Verifies that [KeyguardTransitionRepository.startTransition] was never called. */ suspend fun noTransitionsStarted() { verify(repository, never()).startTransition(any()) |