diff options
6 files changed, 83 insertions, 36 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt index addbdb664c77..7906a8244c5d 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt @@ -27,6 +27,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.bouncer.data.repository.keyguardBouncerRepository import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.coroutines.collectValues import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.keyguard.data.repository.fakeCommandQueue import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository @@ -191,6 +192,7 @@ class KeyguardInteractorTest : SysuiTestCase() { fun dismissAlpha() = testScope.runTest { val dismissAlpha by collectLastValue(underTest.dismissAlpha) + assertThat(dismissAlpha).isEqualTo(1f) keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.AOD, @@ -202,9 +204,9 @@ class KeyguardInteractorTest : SysuiTestCase() { // User begins to swipe up shadeRepository.setLegacyShadeExpansion(0.99f) - // When not dismissable, no alpha value (null) should emit + // When not dismissable, the last alpha value should still be present repository.setKeyguardDismissible(false) - assertThat(dismissAlpha).isNull() + assertThat(dismissAlpha).isEqualTo(1f) repository.setKeyguardDismissible(true) shadeRepository.setLegacyShadeExpansion(0.98f) @@ -212,9 +214,11 @@ class KeyguardInteractorTest : SysuiTestCase() { } @Test - fun dismissAlpha_whenShadeIsExpandedEmitsNull() = + fun dismissAlpha_whenShadeResetsEmitsOne() = testScope.runTest { - val dismissAlpha by collectLastValue(underTest.dismissAlpha) + val dismissAlpha by collectValues(underTest.dismissAlpha) + assertThat(dismissAlpha[0]).isEqualTo(1f) + assertThat(dismissAlpha.size).isEqualTo(1) keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.AOD, @@ -222,14 +226,50 @@ class KeyguardInteractorTest : SysuiTestCase() { testScope, ) - repository.setStatusBarState(StatusBarState.SHADE_LOCKED) - shadeRepository.setQsExpansion(1f) + // User begins to swipe up + repository.setStatusBarState(StatusBarState.KEYGUARD) + repository.setKeyguardDismissible(true) + shadeRepository.setLegacyShadeExpansion(0.98f) - repository.setKeyguardDismissible(false) - assertThat(dismissAlpha).isNull() + assertThat(dismissAlpha[1]).isGreaterThan(0.5f) + assertThat(dismissAlpha[1]).isLessThan(1f) + assertThat(dismissAlpha.size).isEqualTo(2) + + // Now reset the shade + shadeRepository.setLegacyShadeExpansion(1f) + assertThat(dismissAlpha[2]).isEqualTo(1f) + assertThat(dismissAlpha.size).isEqualTo(3) + } + + @Test + fun dismissAlpha_doesNotEmitWhileTransitioning() = + testScope.runTest { + val dismissAlpha by collectLastValue(underTest.dismissAlpha) + assertThat(dismissAlpha).isEqualTo(1f) + + keyguardTransitionRepository.sendTransitionSteps( + listOf( + TransitionStep( + from = KeyguardState.AOD, + to = KeyguardState.GONE, + value = 0f, + transitionState = TransitionState.STARTED, + ), + TransitionStep( + from = KeyguardState.AOD, + to = KeyguardState.GONE, + value = 0.1f, + transitionState = TransitionState.RUNNING, + ), + ), + testScope, + ) repository.setKeyguardDismissible(true) - assertThat(dismissAlpha).isNull() + shadeRepository.setLegacyShadeExpansion(0.98f) + + // Should still be one + assertThat(dismissAlpha).isEqualTo(1f) } @Test diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt index 48660f25907a..c13781de1a33 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt @@ -50,6 +50,7 @@ import com.android.systemui.shade.data.repository.ShadeRepository import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.notification.NotificationUtils.interpolate import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor +import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine import com.android.systemui.util.kotlin.Utils.Companion.sampleFilter import com.android.systemui.util.kotlin.pairwise import com.android.systemui.util.kotlin.sample @@ -77,7 +78,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn -import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine +import kotlinx.coroutines.flow.transform /** * Encapsulates business-logic related to the keyguard but not to a more specific part within it. @@ -327,28 +328,35 @@ constructor( * This uses legacyShadeExpansion to process swipe up events. In the future, the touch input * signal should be sent directly to transitions. */ - val dismissAlpha: Flow<Float?> = + val dismissAlpha: Flow<Float> = shadeRepository.legacyShadeExpansion - .filter { it < 1f } .sampleCombine( statusBarState, keyguardTransitionInteractor.currentKeyguardState, + keyguardTransitionInteractor.transitionState, isKeyguardDismissible, ) - .map { - (legacyShadeExpansion, statusBarState, currentKeyguardState, isKeyguardDismissible) - -> + .filter { (_, _, _, step, _) -> !step.transitionState.isTransitioning() } + .transform { + ( + legacyShadeExpansion, + statusBarState, + currentKeyguardState, + step, + isKeyguardDismissible) -> if ( statusBarState == StatusBarState.KEYGUARD && isKeyguardDismissible && - currentKeyguardState == LOCKSCREEN + currentKeyguardState == LOCKSCREEN && + legacyShadeExpansion != 1f ) { - MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, legacyShadeExpansion) - } else { - null + emit(MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, legacyShadeExpansion)) + } else if (legacyShadeExpansion == 0f || legacyShadeExpansion == 1f) { + // Resets alpha state + emit(1f) } } - .onStart { emit(null) } + .onStart { emit(1f) } .distinctUntilChanged() val keyguardTranslationY: Flow<Float> = diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt index 5027524e7a4b..aefff7d0f79b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt @@ -66,7 +66,6 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combineTransform import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter -import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart @@ -236,7 +235,7 @@ constructor( // value emitted by any of them. Do not add flows that cannot make this guarantee. merge( alphaOnShadeExpansion, - keyguardInteractor.dismissAlpha.filterNotNull(), + keyguardInteractor.dismissAlpha, alternateBouncerToGoneTransitionViewModel.lockscreenAlpha(viewState), aodToGoneTransitionViewModel.lockscreenAlpha(viewState), aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt index 6a8c43a077a6..b13630fa302a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt @@ -53,6 +53,7 @@ import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTrans import com.android.systemui.keyguard.ui.viewmodel.GoneToAodTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.GoneToDozingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.GoneToDreamingTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.GoneToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGoneTransitionViewModel @@ -120,6 +121,7 @@ constructor( private val goneToAodTransitionViewModel: GoneToAodTransitionViewModel, private val goneToDozingTransitionViewModel: GoneToDozingTransitionViewModel, private val goneToDreamingTransitionViewModel: GoneToDreamingTransitionViewModel, + private val goneToLockscreenTransitionViewModel: GoneToLockscreenTransitionViewModel, private val lockscreenToDreamingTransitionViewModel: LockscreenToDreamingTransitionViewModel, private val lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel, @@ -472,6 +474,9 @@ constructor( // All transition view models are mututally exclusive, and safe to merge val alphaTransitions = merge( + keyguardInteractor.dismissAlpha.dumpWhileCollecting( + "keyguardInteractor.dismissAlpha" + ), alternateBouncerToGoneTransitionViewModel.notificationAlpha(viewState), aodToGoneTransitionViewModel.notificationAlpha(viewState), aodToLockscreenTransitionViewModel.notificationAlpha, @@ -482,6 +487,7 @@ constructor( goneToAodTransitionViewModel.notificationAlpha, goneToDreamingTransitionViewModel.lockscreenAlpha, goneToDozingTransitionViewModel.lockscreenAlpha, + goneToLockscreenTransitionViewModel.lockscreenAlpha, lockscreenToDreamingTransitionViewModel.lockscreenAlpha, lockscreenToGoneTransitionViewModel.notificationAlpha(viewState), lockscreenToOccludedTransitionViewModel.lockscreenAlpha, @@ -498,24 +504,12 @@ constructor( // These remaining cases handle alpha changes within an existing state, such as // shade expansion or swipe to dismiss combineTransform( - isOnLockscreenWithoutShade, isTransitioningToHiddenKeyguard, - shadeCollapseFadeIn, alphaForShadeAndQsExpansion, - keyguardInteractor.dismissAlpha.dumpWhileCollecting( - "keyguardInteractor.keyguardAlpha" - ), ) { - isOnLockscreenWithoutShade, isTransitioningToHiddenKeyguard, - shadeCollapseFadeIn, - alphaForShadeAndQsExpansion, - dismissAlpha -> - if (isOnLockscreenWithoutShade) { - if (!shadeCollapseFadeIn && dismissAlpha != null) { - emit(dismissAlpha) - } - } else if (!isTransitioningToHiddenKeyguard) { + alphaForShadeAndQsExpansion -> + if (!isTransitioningToHiddenKeyguard) { emit(alphaForShadeAndQsExpansion) } }, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorFactory.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorFactory.kt index 02842cc3f56b..b5ca964d6968 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorFactory.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorFactory.kt @@ -24,6 +24,7 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.keyguard.data.repository.FakeCommandQueue import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.keyguard.shared.model.KeyguardState +import com.android.systemui.keyguard.shared.model.TransitionStep import com.android.systemui.power.domain.interactor.PowerInteractor import com.android.systemui.power.domain.interactor.PowerInteractorFactory import com.android.systemui.scene.domain.interactor.SceneInteractor @@ -34,6 +35,7 @@ import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.TestScope /** @@ -60,9 +62,11 @@ object KeyguardInteractorFactory { ): WithDependencies { // Mock these until they are replaced by kosmos val currentKeyguardStateFlow = MutableSharedFlow<KeyguardState>() + val transitionStateFlow = MutableStateFlow(TransitionStep()) val keyguardTransitionInteractor = mock<KeyguardTransitionInteractor>().also { whenever(it.currentKeyguardState).thenReturn(currentKeyguardStateFlow) + whenever(it.transitionState).thenReturn(transitionStateFlow) } val configurationDimensionFlow = MutableSharedFlow<ConfigurationBasedDimensions>() configurationDimensionFlow.tryEmit( diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt index d00eedf22efc..299486fc8ef4 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt @@ -31,6 +31,7 @@ import com.android.systemui.keyguard.ui.viewmodel.glanceableHubToLockscreenTrans import com.android.systemui.keyguard.ui.viewmodel.goneToAodTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.goneToDozingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.goneToDreamingTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.goneToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGlanceableHubTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGoneTransitionViewModel @@ -70,6 +71,7 @@ val Kosmos.sharedNotificationContainerViewModel by Fixture { goneToAodTransitionViewModel = goneToAodTransitionViewModel, goneToDozingTransitionViewModel = goneToDozingTransitionViewModel, goneToDreamingTransitionViewModel = goneToDreamingTransitionViewModel, + goneToLockscreenTransitionViewModel = goneToLockscreenTransitionViewModel, glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, lockscreenToDreamingTransitionViewModel = lockscreenToDreamingTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel = lockscreenToGlanceableHubTransitionViewModel, |