diff options
| author | 2024-02-14 10:52:44 +0000 | |
|---|---|---|
| committer | 2024-02-14 10:52:44 +0000 | |
| commit | b47b88de9a55bf09d7964bfe904e7c212a128abb (patch) | |
| tree | e6dbdcfccc6539e1dd3d8b4c93de0a25fc196e55 | |
| parent | 39087e18f1b1026bff5f98e7dc7f03648b68963f (diff) | |
| parent | 417a78d154149a6e72dbc022941b2dabb555c349 (diff) | |
Merge "Control all transition alpha with TransitionViewModels" into main
37 files changed, 595 insertions, 237 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/modifier/BurnInModifiers.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/modifier/BurnInModifiers.kt index f9dd04b66b1f..0728daf28c25 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/modifier/BurnInModifiers.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/modifier/BurnInModifiers.kt @@ -40,7 +40,6 @@ fun Modifier.burnInAware( ): Modifier { val translationX by viewModel.translationX(params).collectAsState(initial = 0f) val translationY by viewModel.translationY(params).collectAsState(initial = 0f) - val alpha by viewModel.alpha.collectAsState(initial = 1f) val scaleViewModel by viewModel.scale(params).collectAsState(initial = BurnInScaleViewModel()) return this.graphicsLayer { 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 0b320a28b419..ef2b6f0805d6 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,7 +27,10 @@ import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeCommandQueue import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository +import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository import com.android.systemui.keyguard.shared.model.CameraLaunchSourceModel +import com.android.systemui.keyguard.shared.model.KeyguardState +import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.kosmos.testScope import com.android.systemui.power.domain.interactor.PowerInteractorFactory import com.android.systemui.scene.domain.interactor.sceneInteractor @@ -56,11 +59,10 @@ class KeyguardInteractorTest : SysuiTestCase() { private val testScope = kosmos.testScope private val repository by lazy { kosmos.fakeKeyguardRepository } private val sceneInteractor by lazy { kosmos.sceneInteractor } - private val commandQueue by lazy { - FakeCommandQueue() - } + private val commandQueue by lazy { FakeCommandQueue() } private val bouncerRepository = FakeKeyguardBouncerRepository() private val shadeRepository = FakeShadeRepository() + private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository private val transitionState: MutableStateFlow<ObservableTransitionState> = MutableStateFlow(ObservableTransitionState.Idle(SceneKey.Gone)) @@ -73,6 +75,7 @@ class KeyguardInteractorTest : SysuiTestCase() { bouncerRepository = bouncerRepository, configurationInteractor = ConfigurationInteractor(FakeConfigurationRepository()), shadeRepository = shadeRepository, + keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor, sceneInteractorProvider = { sceneInteractor }, ) } @@ -188,6 +191,49 @@ class KeyguardInteractorTest : SysuiTestCase() { } @Test + fun dismissAlpha() = + testScope.runTest { + val dismissAlpha by collectLastValue(underTest.dismissAlpha) + + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.AOD, + to = KeyguardState.LOCKSCREEN, + testScope, + ) + + repository.setStatusBarState(StatusBarState.KEYGUARD) + shadeRepository.setLegacyShadeExpansion(1f) + + // When not dismissable, no alpha value (null) should emit + repository.setKeyguardDismissible(false) + assertThat(dismissAlpha).isNull() + + repository.setKeyguardDismissible(true) + assertThat(dismissAlpha).isGreaterThan(0.95f) + } + + @Test + fun dismissAlpha_whenShadeIsExpandedEmitsNull() = + testScope.runTest { + val dismissAlpha by collectLastValue(underTest.dismissAlpha) + + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.AOD, + to = KeyguardState.LOCKSCREEN, + testScope, + ) + + repository.setStatusBarState(StatusBarState.SHADE_LOCKED) + shadeRepository.setQsExpansion(1f) + + repository.setKeyguardDismissible(false) + assertThat(dismissAlpha).isNull() + + repository.setKeyguardDismissible(true) + assertThat(dismissAlpha).isNull() + } + + @Test fun animationDozingTransitions() = testScope.runTest { kosmos.fakeSceneContainerFlags.enabled = true diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelTest.kt index 83782e214780..837a9db6eea7 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelTest.kt @@ -25,6 +25,8 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository import com.android.systemui.keyguard.shared.model.KeyguardState +import com.android.systemui.keyguard.shared.model.TransitionState +import com.android.systemui.keyguard.shared.model.TransitionStep import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.util.mockito.whenever @@ -42,67 +44,123 @@ import org.mockito.MockitoAnnotations @RunWith(AndroidJUnit4::class) class AodAlphaViewModelTest : SysuiTestCase() { - @Mock - private lateinit var occludedToLockscreenTransitionViewModel: - OccludedToLockscreenTransitionViewModel + @Mock private lateinit var goneToAodTransitionViewModel: GoneToAodTransitionViewModel private val kosmos = testKosmos() private val testScope = kosmos.testScope private val keyguardRepository = kosmos.fakeKeyguardRepository private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository - private val occludedToLockscreenAlpha = MutableStateFlow(0f) private lateinit var underTest: AodAlphaViewModel + private val enterFromTopAnimationAlpha = MutableStateFlow(0f) + @Before fun setUp() { MockitoAnnotations.initMocks(this) - whenever(occludedToLockscreenTransitionViewModel.lockscreenAlpha) - .thenReturn(occludedToLockscreenAlpha) - kosmos.occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel + whenever(goneToAodTransitionViewModel.enterFromTopAnimationAlpha) + .thenReturn(enterFromTopAnimationAlpha) + kosmos.goneToAodTransitionViewModel = goneToAodTransitionViewModel underTest = kosmos.aodAlphaViewModel } @Test - fun alpha() = + fun alpha_WhenGoneToAod() = testScope.runTest { val alpha by collectLastValue(underTest.alpha) keyguardTransitionRepository.sendTransitionSteps( - from = KeyguardState.OFF, - to = KeyguardState.LOCKSCREEN, + from = KeyguardState.AOD, + to = KeyguardState.GONE, testScope = testScope, ) + assertThat(alpha).isEqualTo(0f) - keyguardRepository.setKeyguardAlpha(0.1f) - assertThat(alpha).isEqualTo(0.1f) - keyguardRepository.setKeyguardAlpha(0.5f) + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.GONE, + to = KeyguardState.AOD, + testScope = testScope, + ) + enterFromTopAnimationAlpha.value = 0.5f assertThat(alpha).isEqualTo(0.5f) - keyguardRepository.setKeyguardAlpha(0.2f) - assertThat(alpha).isEqualTo(0.2f) - keyguardRepository.setKeyguardAlpha(0f) - assertThat(alpha).isEqualTo(0f) - occludedToLockscreenAlpha.value = 0.8f - assertThat(alpha).isEqualTo(0.8f) + + enterFromTopAnimationAlpha.value = 1f + assertThat(alpha).isEqualTo(1f) } @Test - fun alpha_whenGone_equalsZero() = + fun alpha_WhenGoneToDozing() = testScope.runTest { val alpha by collectLastValue(underTest.alpha) keyguardTransitionRepository.sendTransitionSteps( - from = KeyguardState.LOCKSCREEN, + from = KeyguardState.AOD, to = KeyguardState.GONE, testScope = testScope, ) - - keyguardRepository.setKeyguardAlpha(0.1f) - assertThat(alpha).isEqualTo(0f) - keyguardRepository.setKeyguardAlpha(0.5f) assertThat(alpha).isEqualTo(0f) - keyguardRepository.setKeyguardAlpha(1f) + + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.GONE, + to = KeyguardState.DOZING, + testScope = testScope, + ) + assertThat(alpha).isEqualTo(1f) + } + + @Test + fun alpha_whenGone_equalsZero() = + testScope.runTest { + val alpha by collectLastValue(underTest.alpha) + + keyguardTransitionRepository.sendTransitionStep( + TransitionStep( + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.GONE, + transitionState = TransitionState.STARTED, + ) + ) + assertThat(alpha).isNull() + + keyguardTransitionRepository.sendTransitionStep( + TransitionStep( + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.GONE, + transitionState = TransitionState.RUNNING, + value = 0.5f, + ) + ) + assertThat(alpha).isNull() + + keyguardTransitionRepository.sendTransitionStep( + TransitionStep( + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.GONE, + transitionState = TransitionState.RUNNING, + value = 1f, + ) + ) assertThat(alpha).isEqualTo(0f) } + + @Test + fun enterFromTopAlpha() = + testScope.runTest { + val alpha by collectLastValue(underTest.alpha) + + keyguardTransitionRepository.sendTransitionStep( + TransitionStep( + from = KeyguardState.GONE, + to = KeyguardState.AOD, + transitionState = TransitionState.STARTED, + ) + ) + + enterFromTopAnimationAlpha.value = 0.2f + assertThat(alpha).isEqualTo(0.2f) + + enterFromTopAnimationAlpha.value = 1f + assertThat(alpha).isEqualTo(1f) + } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModelTest.kt index d52696a0bd87..74fa46519629 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModelTest.kt @@ -65,7 +65,6 @@ class AodBurnInViewModelTest : SysuiTestCase() { clockControllerProvider = { clockController }, ) private val burnInFlow = MutableStateFlow(BurnInModel()) - private val enterFromTopAnimationAlpha = MutableStateFlow(0f) @Before fun setUp() { @@ -74,8 +73,6 @@ class AodBurnInViewModelTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) whenever(burnInInteractor.keyguardBurnIn).thenReturn(burnInFlow) kosmos.burnInInteractor = burnInInteractor - whenever(goneToAodTransitionViewModel.enterFromTopAnimationAlpha) - .thenReturn(enterFromTopAnimationAlpha) whenever(goneToAodTransitionViewModel.enterFromTopTranslationY(anyInt())) .thenReturn(emptyFlow()) kosmos.goneToAodTransitionViewModel = goneToAodTransitionViewModel @@ -278,16 +275,4 @@ class AodBurnInViewModelTest : SysuiTestCase() { assertThat(translationY).isEqualTo(0) assertThat(scale).isEqualTo(BurnInScaleViewModel(scale = 0.5f, scaleClockOnly = false)) } - - @Test - fun alpha() = - testScope.runTest { - val alpha by collectLastValue(underTest.alpha) - - enterFromTopAnimationAlpha.value = 0.2f - assertThat(alpha).isEqualTo(0.2f) - - enterFromTopAnimationAlpha.value = 1f - assertThat(alpha).isEqualTo(1f) - } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt index bf1d76f87f5a..e04cbfd88bb3 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt @@ -255,14 +255,21 @@ class KeyguardRootViewModelTest : SysuiTestCase() { testScope.runTest { val alpha by collectLastValue(underTest.alpha(viewState)) + // Default value check + assertThat(alpha).isEqualTo(1f) + // Hub transition state is idle with hub open. communalRepository.setTransitionState( flowOf(ObservableCommunalTransitionState.Idle(CommunalSceneKey.Communal)) ) runCurrent() - // Set keyguard alpha to 1.0f. - keyguardInteractor.setAlpha(1.0f) + // Run at least 1 transition to make sure value remains at 0 + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.AOD, + to = KeyguardState.LOCKSCREEN, + testScope, + ) // Alpha property remains 0 regardless. assertThat(alpha).isEqualTo(0f) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt index e20f570e6c0a..7593ac252543 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGoneTransitionInteractor.kt @@ -150,6 +150,7 @@ constructor( when (toState) { KeyguardState.DREAMING -> TO_DREAMING_DURATION KeyguardState.AOD -> TO_AOD_DURATION + KeyguardState.DOZING -> TO_DOZING_DURATION KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION else -> DEFAULT_DURATION }.inWholeMilliseconds @@ -160,6 +161,7 @@ constructor( private val DEFAULT_DURATION = 500.milliseconds val TO_DREAMING_DURATION = 933.milliseconds val TO_AOD_DURATION = 1300.milliseconds + val TO_DOZING_DURATION = 933.milliseconds val TO_LOCKSCREEN_DURATION = DEFAULT_DURATION } } 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 1da0a0e5bd8c..57e9ac707965 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 @@ -17,6 +17,7 @@ package com.android.systemui.keyguard.domain.interactor import android.animation.ValueAnimator +import android.util.MathUtils import com.android.app.animation.Interpolators import com.android.systemui.communal.shared.model.CommunalSceneKey import com.android.systemui.dagger.SysUISingleton @@ -208,7 +209,10 @@ constructor( } transitionRepository.updateTransition( id, - 1f - shadeExpansion, + // This maps the shadeExpansion to a much faster curve, to match + // the existing logic + 1f - + MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion), nextState, ) 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 22d11d08054e..405d1d46456c 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 @@ -37,6 +37,7 @@ import com.android.systemui.keyguard.shared.model.CameraLaunchSourceModel import com.android.systemui.keyguard.shared.model.DozeStateModel import com.android.systemui.keyguard.shared.model.DozeStateModel.Companion.isDozeOff import com.android.systemui.keyguard.shared.model.DozeTransitionModel +import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.power.domain.interactor.PowerInteractor import com.android.systemui.res.R @@ -79,6 +80,7 @@ constructor( bouncerRepository: KeyguardBouncerRepository, configurationInteractor: ConfigurationInteractor, shadeRepository: ShadeRepository, + keyguardTransitionInteractor: KeyguardTransitionInteractor, sceneInteractorProvider: Provider<SceneInteractor>, ) { // TODO(b/296118689): move to a repository @@ -233,8 +235,33 @@ constructor( /** The position of the keyguard clock. */ val clockPosition: Flow<Position> = repository.clockPosition + @Deprecated("Use the relevant TransitionViewModel") val keyguardAlpha: Flow<Float> = repository.keyguardAlpha + /** + * When the lockscreen can be dismissed, emit an alpha value as the user swipes up. This is + * useful just before the code commits to moving to GONE. + */ + val dismissAlpha: Flow<Float?> = + combine( + shadeRepository.legacyShadeExpansion, + statusBarState, + keyguardTransitionInteractor.currentKeyguardState, + isKeyguardDismissible, + ) { legacyShadeExpansion, statusBarState, currentKeyguardState, isKeyguardDismissible -> + if ( + statusBarState == StatusBarState.KEYGUARD && + isKeyguardDismissible && + currentKeyguardState == LOCKSCREEN + ) { + MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, legacyShadeExpansion) + } else { + null + } + } + .onStart { emit(null) } + .distinctUntilChanged() + val keyguardTranslationY: Flow<Float> = configurationInteractor .dimensionPixelSize(R.dimen.keyguard_translate_distance_on_swipe_up) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt index 310f13d49e16..d1fd7195d8cc 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt @@ -56,7 +56,6 @@ class KeyguardTransitionInteractor constructor( @Application val scope: CoroutineScope, private val repository: KeyguardTransitionRepository, - private val keyguardInteractor: dagger.Lazy<KeyguardInteractor>, private val fromLockscreenTransitionInteractor: dagger.Lazy<FromLockscreenTransitionInteractor>, private val fromPrimaryBouncerTransitionInteractor: dagger.Lazy<FromPrimaryBouncerTransitionInteractor>, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt index 1b7a50790561..5604ef23a142 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardRootViewBinder.kt @@ -179,7 +179,7 @@ object KeyguardRootViewBinder { } launch { - viewModel.lockscreenStateAlpha.collect { alpha -> + viewModel.lockscreenStateAlpha(viewState).collect { alpha -> childViews[statusViewId]?.alpha = alpha } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModel.kt index d4ea728bbffb..f208e85bde3e 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModel.kt @@ -19,15 +19,15 @@ package com.android.systemui.keyguard.ui.viewmodel import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor -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.DOZING +import com.android.systemui.keyguard.shared.model.KeyguardState.GONE import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.combineTransform import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart /** Models UI state for the alpha of the AOD (always-on display). */ @@ -35,27 +35,28 @@ import kotlinx.coroutines.flow.onStart class AodAlphaViewModel @Inject constructor( - keyguardInteractor: KeyguardInteractor, keyguardTransitionInteractor: KeyguardTransitionInteractor, - occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel, + goneToAodTransitionViewModel: GoneToAodTransitionViewModel, + goneToDozingTransitionViewModel: GoneToDozingTransitionViewModel, ) { /** The alpha level for the entire lockscreen while in AOD. */ val alpha: Flow<Float> = - combine( - keyguardTransitionInteractor.transitionValue(KeyguardState.GONE).onStart { - emit(0f) - }, - merge( - keyguardInteractor.keyguardAlpha, - occludedToLockscreenTransitionViewModel.lockscreenAlpha, - ) - ) { transitionToGone, alpha -> - if (transitionToGone == 1f) { - // Ensures content is not visible when in GONE state - 0f - } else { - alpha + combineTransform( + keyguardTransitionInteractor.transitions, + goneToAodTransitionViewModel.enterFromTopAnimationAlpha.onStart { emit(0f) }, + goneToDozingTransitionViewModel.lockscreenAlpha.onStart { emit(0f) }, + ) { step, goneToAodAlpha, goneToDozingAlpha -> + if (step.to == GONE) { + // When transitioning to GONE, only emit a value when complete as other + // transitions may be controlling the alpha fade + if (step.value == 1f) { + emit(0f) + } + } else if (step.from == GONE && step.to == AOD) { + emit(goneToAodAlpha) + } else if (step.from == GONE && step.to == DOZING) { + emit(goneToDozingAlpha) } } .distinctUntilChanged() diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModel.kt index 8110de23be13..6fcbf48eab82 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodBurnInViewModel.kt @@ -31,6 +31,7 @@ import com.android.systemui.keyguard.shared.model.BurnInModel import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER import com.android.systemui.keyguard.shared.model.KeyguardState.AOD import com.android.systemui.keyguard.shared.model.KeyguardState.GONE +import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER import com.android.systemui.keyguard.shared.model.TransitionState import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING import com.android.systemui.keyguard.shared.model.TransitionState.STARTED @@ -66,9 +67,6 @@ constructor( private val occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel, private val keyguardClockViewModel: KeyguardClockViewModel, ) { - /** Alpha for elements that appear and move during the animation -> AOD */ - val alpha: Flow<Float> = goneToAodTransitionViewModel.enterFromTopAnimationAlpha - /** Horizontal translation for elements that need to apply anti-burn-in tactics. */ fun translationX( params: BurnInParameters, @@ -131,6 +129,9 @@ constructor( return combine( merge( keyguardTransitionInteractor.transition(GONE, AOD).map { it.value }, + keyguardTransitionInteractor.transition(AOD, PRIMARY_BOUNCER).map { + 1f - it.value + }, keyguardTransitionInteractor.transition(ALTERNATE_BOUNCER, AOD).map { it.value }, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModel.kt index 3a98359da2cb..a3888c3341db 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModel.kt @@ -57,21 +57,32 @@ constructor( var startValue = 0f return transitionAnimation.sharedFlowWithState( duration = 500.milliseconds, - onStart = { - startValue = currentTranslationY() ?: 0f - startValue - }, + onStart = { startValue = currentTranslationY() ?: 0f }, onStep = { MathUtils.lerp(startValue, 0f, FAST_OUT_SLOW_IN.getInterpolation(it)) }, ) } /** Ensure alpha is set to be visible */ - val lockscreenAlpha: Flow<Float> = - transitionAnimation.sharedFlow( + fun lockscreenAlpha(viewState: ViewStateAccessor): Flow<Float> { + var startAlpha: Float? = null + return transitionAnimation.sharedFlow( duration = 500.milliseconds, - onStart = { 1f }, - onStep = { 1f }, + onStep = { + if (startAlpha == null) { + startAlpha = viewState.alpha() + } + MathUtils.lerp(startAlpha!!, 1f, it) + }, + onFinish = { + startAlpha = null + 1f + }, + onCancel = { + startAlpha = null + 1f + }, ) + } val shortcutsAlpha: Flow<Float> = transitionAnimation.sharedFlow( @@ -88,5 +99,10 @@ constructor( onFinish = { 1f }, ) - override val deviceEntryParentViewAlpha: Flow<Float> = lockscreenAlpha + override val deviceEntryParentViewAlpha: Flow<Float> = + transitionAnimation.sharedFlow( + duration = 500.milliseconds, + onStart = { 1f }, + onStep = { 1f }, + ) } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DozingToLockscreenTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DozingToLockscreenTransitionViewModel.kt index e4610c15a3d0..f81941bf064b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DozingToLockscreenTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DozingToLockscreenTransitionViewModel.kt @@ -50,6 +50,8 @@ constructor( onCancel = { 0f }, ) + val lockscreenAlpha: Flow<Float> = shortcutsAlpha + override val deviceEntryParentViewAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(1f) } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModel.kt new file mode 100644 index 000000000000..55a289ef890f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModel.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 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.ui.viewmodel + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.keyguard.domain.interactor.FromGoneTransitionInteractor.Companion.TO_DOZING_DURATION +import com.android.systemui.keyguard.shared.model.KeyguardState +import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow +import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.Flow + +/** Breaks down GONE->DOZING transition into discrete steps for corresponding views to consume. */ +@ExperimentalCoroutinesApi +@SysUISingleton +class GoneToDozingTransitionViewModel +@Inject +constructor( + animationFlow: KeyguardTransitionAnimationFlow, +) { + + private val transitionAnimation = + animationFlow.setup( + duration = TO_DOZING_DURATION, + from = KeyguardState.GONE, + to = KeyguardState.DOZING, + ) + + val lockscreenAlpha: Flow<Float> = + transitionAnimation.sharedFlow( + duration = 500.milliseconds, + onStep = { 0f }, + onCancel = { 1f }, + onFinish = { 1f }, + ) +} 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 83be65181bea..f790d356620d 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 @@ -48,6 +48,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine 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 @@ -63,15 +64,25 @@ constructor( private val communalInteractor: CommunalInteractor, keyguardTransitionInteractor: KeyguardTransitionInteractor, private val notificationsKeyguardInteractor: NotificationsKeyguardInteractor, - private val aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel, - private val lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, private val alternateBouncerToGoneTransitionViewModel: AlternateBouncerToGoneTransitionViewModel, - private val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel, - private val lockscreenToGlanceableHubTransitionViewModel: - LockscreenToGlanceableHubTransitionViewModel, + private val aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel, + private val dozingToLockscreenTransitionViewModel: DozingToLockscreenTransitionViewModel, private val glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel, + private val lockscreenToDreamingTransitionViewModel: LockscreenToDreamingTransitionViewModel, + private val lockscreenToGlanceableHubTransitionViewModel: + LockscreenToGlanceableHubTransitionViewModel, + private val lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, + private val lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, + private val lockscreenToPrimaryBouncerTransitionViewModel: + LockscreenToPrimaryBouncerTransitionViewModel, + private val occludedToAodTransitionViewModel: OccludedToAodTransitionViewModel, + private val occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel, + private val primaryBouncerToAodTransitionViewModel: PrimaryBouncerToAodTransitionViewModel, + private val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel, + private val primaryBouncerToLockscreenTransitionViewModel: + PrimaryBouncerToLockscreenTransitionViewModel, private val screenOffAnimationController: ScreenOffAnimationController, private val aodBurnInViewModel: AodBurnInViewModel, private val aodAlphaViewModel: AodAlphaViewModel, @@ -110,13 +121,24 @@ constructor( // The transitions are mutually exclusive, so they are safe to merge to get the last // value emitted by any of them. Do not add flows that cannot make this guarantee. merge( - aodAlphaViewModel.alpha, - lockscreenToGlanceableHubTransitionViewModel.keyguardAlpha, - glanceableHubToLockscreenTransitionViewModel.keyguardAlpha, - lockscreenToGoneTransitionViewModel.lockscreenAlpha(viewState), - primaryBouncerToGoneTransitionViewModel.lockscreenAlpha, - alternateBouncerToGoneTransitionViewModel.lockscreenAlpha, - ) + aodAlphaViewModel.alpha, + keyguardInteractor.dismissAlpha.filterNotNull(), + alternateBouncerToGoneTransitionViewModel.lockscreenAlpha, + aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState), + dozingToLockscreenTransitionViewModel.lockscreenAlpha, + glanceableHubToLockscreenTransitionViewModel.keyguardAlpha, + lockscreenToDreamingTransitionViewModel.lockscreenAlpha, + lockscreenToGlanceableHubTransitionViewModel.keyguardAlpha, + lockscreenToGoneTransitionViewModel.lockscreenAlpha(viewState), + lockscreenToOccludedTransitionViewModel.lockscreenAlpha, + lockscreenToPrimaryBouncerTransitionViewModel.lockscreenAlpha, + occludedToAodTransitionViewModel.lockscreenAlpha, + occludedToLockscreenTransitionViewModel.lockscreenAlpha, + primaryBouncerToAodTransitionViewModel.lockscreenAlpha, + primaryBouncerToGoneTransitionViewModel.lockscreenAlpha, + primaryBouncerToLockscreenTransitionViewModel.lockscreenAlpha, + ) + .onStart { emit(1f) } ) { isIdleOnCommunal, alpha -> if (isIdleOnCommunal) { // Keyguard should not show while the communal hub is fully visible. This check @@ -131,10 +153,13 @@ constructor( } /** Specific alpha value for elements visible during [KeyguardState.LOCKSCREEN] */ - val lockscreenStateAlpha: Flow<Float> = aodToLockscreenTransitionViewModel.lockscreenAlpha + @Deprecated("only used for legacy status view") + fun lockscreenStateAlpha(viewState: ViewStateAccessor): Flow<Float> { + return aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState) + } /** For elements that appear and move during the animation -> AOD */ - val burnInLayerAlpha: Flow<Float> = aodBurnInViewModel.alpha + val burnInLayerAlpha: Flow<Float> = aodAlphaViewModel.alpha fun translationY(params: BurnInParameters): Flow<Float> { return aodBurnInViewModel.translationY(params) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt index ce47f3c67b21..0cfc75757b7d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt @@ -51,6 +51,8 @@ constructor( onStep = { 1f - it } ) + val lockscreenAlpha: Flow<Float> = shortcutsAlpha + override val deviceEntryParentViewAlpha: Flow<Float> = shadeDependentFlows.transitionFlow( flowWhenShadeIsNotExpanded = diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAodTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAodTransitionViewModel.kt index 07c114163326..c61b1f5cc3be 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAodTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/OccludedToAodTransitionViewModel.kt @@ -23,6 +23,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow @@ -47,6 +48,15 @@ constructor( val deviceEntryBackgroundViewAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f) + /** Lockscreen views alpha */ + val lockscreenAlpha: Flow<Float> = + transitionAnimation.sharedFlow( + startTime = 233.milliseconds, + duration = 250.milliseconds, + onStep = { it }, + onStart = { 0f }, + ) + override val deviceEntryParentViewAlpha: Flow<Float> = deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { udfpsEnrolledAndEnabled -> diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToAodTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToAodTransitionViewModel.kt index 5879d180ec0f..942903bbabd7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToAodTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToAodTransitionViewModel.kt @@ -51,6 +51,12 @@ constructor( val deviceEntryBackgroundViewAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f) + val lockscreenAlpha: Flow<Float> = + transitionAnimation.sharedFlow( + duration = FromPrimaryBouncerTransitionInteractor.TO_AOD_DURATION, + onStep = { it } + ) + override val deviceEntryParentViewAlpha: Flow<Float> = deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { isUdfpsEnrolledAndEnabled -> diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToLockscreenTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToLockscreenTransitionViewModel.kt index 284a134f73c7..34c9ac92a3f3 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToLockscreenTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToLockscreenTransitionViewModel.kt @@ -16,6 +16,7 @@ package com.android.systemui.keyguard.ui.viewmodel +import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE import com.android.systemui.dagger.SysUISingleton import com.android.systemui.deviceentry.domain.interactor.DeviceEntryUdfpsInteractor import com.android.systemui.keyguard.domain.interactor.FromPrimaryBouncerTransitionInteractor @@ -23,6 +24,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow @@ -58,10 +60,13 @@ constructor( val shortcutsAlpha: Flow<Float> = transitionAnimation.sharedFlow( - duration = FromPrimaryBouncerTransitionInteractor.TO_LOCKSCREEN_DURATION, + duration = 250.milliseconds, + interpolator = EMPHASIZED_ACCELERATE, onStep = { it } ) + val lockscreenAlpha: Flow<Float> = shortcutsAlpha + override val deviceEntryParentViewAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(1f) } diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 296849044e33..0e359b7f0eec 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -1158,9 +1158,9 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump // Occluded->Lockscreen collectFlow(mView, mKeyguardTransitionInteractor.getOccludedToLockscreenTransition(), mOccludedToLockscreenTransition, mMainDispatcher); - collectFlow(mView, mOccludedToLockscreenTransitionViewModel.getLockscreenAlpha(), - setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); if (!KeyguardShadeMigrationNssl.isEnabled()) { + collectFlow(mView, mOccludedToLockscreenTransitionViewModel.getLockscreenAlpha(), + setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); collectFlow(mView, mOccludedToLockscreenTransitionViewModel.getLockscreenTranslationY(), setTransitionY(mNotificationStackScrollLayoutController), mMainDispatcher); @@ -1169,9 +1169,11 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump // Lockscreen->Dreaming collectFlow(mView, mKeyguardTransitionInteractor.getLockscreenToDreamingTransition(), mLockscreenToDreamingTransition, mMainDispatcher); - collectFlow(mView, mLockscreenToDreamingTransitionViewModel.getLockscreenAlpha(), - setDreamLockscreenTransitionAlpha(mNotificationStackScrollLayoutController), - mMainDispatcher); + if (!KeyguardShadeMigrationNssl.isEnabled()) { + collectFlow(mView, mLockscreenToDreamingTransitionViewModel.getLockscreenAlpha(), + setDreamLockscreenTransitionAlpha(mNotificationStackScrollLayoutController), + mMainDispatcher); + } collectFlow(mView, mLockscreenToDreamingTransitionViewModel.lockscreenTranslationY( mLockscreenToDreamingTransitionTranslationY), setTransitionY(mNotificationStackScrollLayoutController), mMainDispatcher); @@ -1179,8 +1181,10 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump // Gone->Dreaming collectFlow(mView, mKeyguardTransitionInteractor.getGoneToDreamingTransition(), mGoneToDreamingTransition, mMainDispatcher); - collectFlow(mView, mGoneToDreamingTransitionViewModel.getLockscreenAlpha(), - setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); + if (!KeyguardShadeMigrationNssl.isEnabled()) { + collectFlow(mView, mGoneToDreamingTransitionViewModel.getLockscreenAlpha(), + setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); + } collectFlow(mView, mGoneToDreamingTransitionViewModel.lockscreenTranslationY( mGoneToDreamingTransitionTranslationY), setTransitionY(mNotificationStackScrollLayoutController), mMainDispatcher); @@ -1188,16 +1192,18 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump // Lockscreen->Occluded collectFlow(mView, mKeyguardTransitionInteractor.getLockscreenToOccludedTransition(), mLockscreenToOccludedTransition, mMainDispatcher); - collectFlow(mView, mLockscreenToOccludedTransitionViewModel.getLockscreenAlpha(), - setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); if (!KeyguardShadeMigrationNssl.isEnabled()) { + collectFlow(mView, mLockscreenToOccludedTransitionViewModel.getLockscreenAlpha(), + setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); collectFlow(mView, mLockscreenToOccludedTransitionViewModel.getLockscreenTranslationY(), setTransitionY(mNotificationStackScrollLayoutController), mMainDispatcher); } // Primary bouncer->Gone (ensures lockscreen content is not visible on successful auth) - collectFlow(mView, mPrimaryBouncerToGoneTransitionViewModel.getLockscreenAlpha(), - setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); + if (!KeyguardShadeMigrationNssl.isEnabled()) { + collectFlow(mView, mPrimaryBouncerToGoneTransitionViewModel.getLockscreenAlpha(), + setTransitionAlpha(mNotificationStackScrollLayoutController), mMainDispatcher); + } } @VisibleForTesting @@ -2734,6 +2740,9 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump } private void updateKeyguardBottomAreaAlpha() { + if (KeyguardShadeMigrationNssl.isEnabled()) { + return; + } if (mIsOcclusionTransitionRunning) { return; } 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 ff00cb31783d..476b05492758 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 @@ -25,31 +25,37 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor -import com.android.systemui.keyguard.shared.model.Edge import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER import com.android.systemui.keyguard.shared.model.KeyguardState.AOD import com.android.systemui.keyguard.shared.model.KeyguardState.DOZING -import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB import com.android.systemui.keyguard.shared.model.KeyguardState.GONE import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN -import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER +import com.android.systemui.keyguard.shared.model.StatusBarState.SHADE import com.android.systemui.keyguard.shared.model.StatusBarState.SHADE_LOCKED +import com.android.systemui.keyguard.shared.model.TransitionState.FINISHED import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING import com.android.systemui.keyguard.shared.model.TransitionState.STARTED import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerToGoneTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.AodBurnInViewModel +import com.android.systemui.keyguard.ui.viewmodel.AodToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.BurnInParameters +import com.android.systemui.keyguard.ui.viewmodel.DozingToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.DreamingToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.GoneToDozingTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.GoneToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGoneTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.LockscreenToOccludedTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.LockscreenToPrimaryBouncerTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.OccludedToAodTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.OccludedToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.ViewStateAccessor import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor @@ -85,67 +91,32 @@ constructor( keyguardTransitionInteractor: KeyguardTransitionInteractor, private val shadeInteractor: ShadeInteractor, communalInteractor: CommunalInteractor, + private val alternateBouncerToGoneTransitionViewModel: + AlternateBouncerToGoneTransitionViewModel, + private val aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel, + private val dozingToLockscreenTransitionViewModel: DozingToLockscreenTransitionViewModel, + private val dreamingToLockscreenTransitionViewModel: DreamingToLockscreenTransitionViewModel, + private val glanceableHubToLockscreenTransitionViewModel: + GlanceableHubToLockscreenTransitionViewModel, + private val goneToDozingTransitionViewModel: GoneToDozingTransitionViewModel, + private val goneToDreamingTransitionViewModel: GoneToDreamingTransitionViewModel, + private val lockscreenToDreamingTransitionViewModel: LockscreenToDreamingTransitionViewModel, + private val lockscreenToGlanceableHubTransitionViewModel: + LockscreenToGlanceableHubTransitionViewModel, + private val lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, + private val lockscreenToPrimaryBouncerTransitionViewModel: + LockscreenToPrimaryBouncerTransitionViewModel, + private val lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, + private val occludedToAodTransitionViewModel: OccludedToAodTransitionViewModel, private val occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel, - lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, - alternateBouncerToGoneTransitionViewModel: AlternateBouncerToGoneTransitionViewModel, - primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel, - lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, - dreamingToLockscreenTransitionViewModel: DreamingToLockscreenTransitionViewModel, - lockscreenToDreamingTransitionViewModel: LockscreenToDreamingTransitionViewModel, - glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel, - lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel, + private val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel, + private val primaryBouncerToLockscreenTransitionViewModel: + PrimaryBouncerToLockscreenTransitionViewModel, private val aodBurnInViewModel: AodBurnInViewModel, ) { private val statesForConstrainedNotifications: Set<KeyguardState> = setOf(AOD, LOCKSCREEN, DOZING, ALTERNATE_BOUNCER, PRIMARY_BOUNCER) - private val edgeToAlphaViewModel = - mapOf<Edge?, (ViewStateAccessor) -> Flow<Float>>( - Edge(from = LOCKSCREEN, to = DREAMING) to - { _: ViewStateAccessor -> - lockscreenToDreamingTransitionViewModel.lockscreenAlpha - }, - Edge(from = LOCKSCREEN, to = GONE) to - { viewState: ViewStateAccessor -> - lockscreenToGoneTransitionViewModel.lockscreenAlpha(viewState) - }, - Edge(from = ALTERNATE_BOUNCER, to = GONE) to - { _: ViewStateAccessor -> - alternateBouncerToGoneTransitionViewModel.lockscreenAlpha - }, - Edge(from = PRIMARY_BOUNCER, to = GONE) to - { _: ViewStateAccessor -> - primaryBouncerToGoneTransitionViewModel.lockscreenAlpha - }, - Edge(from = DREAMING, to = LOCKSCREEN) to - { _: ViewStateAccessor -> - dreamingToLockscreenTransitionViewModel.lockscreenAlpha - }, - Edge(from = LOCKSCREEN, to = OCCLUDED) to - { _: ViewStateAccessor -> - lockscreenToOccludedTransitionViewModel.lockscreenAlpha - }, - Edge(from = OCCLUDED, to = LOCKSCREEN) to - { _: ViewStateAccessor -> - occludedToLockscreenTransitionViewModel.lockscreenAlpha - }, - ) - - private val lockscreenTransitionInProgress: Flow<Edge?> = - keyguardTransitionInteractor.transitions - .map { step -> - if ( - (step.transitionState == STARTED || step.transitionState == RUNNING) && - (step.from == LOCKSCREEN || step.to == LOCKSCREEN) - ) { - Edge(step.from, step.to) - } else { - null - } - } - .distinctUntilChanged() - .onStart { emit(null) } - private val lockscreenToGlanceableHubRunning = keyguardTransitionInteractor .transition(LOCKSCREEN, GLANCEABLE_HUB) @@ -300,54 +271,79 @@ constructor( private val alphaForShadeAndQsExpansion: Flow<Float> = interactor.configurationBasedDimensions .flatMapLatest { configurationBasedDimensions -> - combine( + combineTransform( shadeInteractor.shadeExpansion, shadeInteractor.qsExpansion, ) { shadeExpansion, qsExpansion -> if (shadeExpansion > 0f || qsExpansion > 0f) { if (configurationBasedDimensions.useSplitShade) { - 1f + emit(1f) } else { // Fade as QS shade expands - 1f - qsExpansion + emit(1f - qsExpansion) } - } else { - // Not visible unless the shade/qs is visible - 0f } } } - .distinctUntilChanged() + .onStart { emit(0f) } + + private val alphaWhenGoneAndShadeState: Flow<Float> = + combineTransform( + keyguardTransitionInteractor.transitions + .map { step -> step.to == GONE && step.transitionState == FINISHED } + .distinctUntilChanged(), + keyguardInteractor.statusBarState, + ) { isGoneTransitionFinished, statusBarState -> + if (isGoneTransitionFinished && statusBarState == SHADE) { + emit(1f) + } + } fun expansionAlpha(viewState: ViewStateAccessor): Flow<Float> { - // Due to issues with the legacy shade, some shade expansion events are sent incorrectly, - // such as when the shade resets. This can happen while the transition to/from LOCKSCREEN - // is running. Therefore use a series of flatmaps to prevent unwanted interruptions while - // those transitions are in progress. Without this, the alpha value will produce a visible - // flicker. - return lockscreenTransitionInProgress - .flatMapLatest { edge -> - edgeToAlphaViewModel.getOrDefault( - edge, - { _: ViewStateAccessor -> - isOnLockscreenWithoutShade.flatMapLatest { isOnLockscreenWithoutShade -> - combineTransform( - keyguardInteractor.keyguardAlpha, - shadeCollpaseFadeIn, - alphaForShadeAndQsExpansion, - ) { alpha, shadeCollpaseFadeIn, alphaForShadeAndQsExpansion -> - if (isOnLockscreenWithoutShade) { - if (!shadeCollpaseFadeIn) { - emit(alpha) - } - } else { - emit(alphaForShadeAndQsExpansion) - } - } + // All transition view models are mututally exclusive, and safe to merge + val alphaTransitions = + merge( + alternateBouncerToGoneTransitionViewModel.lockscreenAlpha, + aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState), + dozingToLockscreenTransitionViewModel.lockscreenAlpha, + dreamingToLockscreenTransitionViewModel.lockscreenAlpha, + goneToDreamingTransitionViewModel.lockscreenAlpha, + goneToDozingTransitionViewModel.lockscreenAlpha, + lockscreenToDreamingTransitionViewModel.lockscreenAlpha, + lockscreenToGoneTransitionViewModel.lockscreenAlpha(viewState), + lockscreenToOccludedTransitionViewModel.lockscreenAlpha, + lockscreenToPrimaryBouncerTransitionViewModel.lockscreenAlpha, + occludedToAodTransitionViewModel.lockscreenAlpha, + occludedToLockscreenTransitionViewModel.lockscreenAlpha, + primaryBouncerToGoneTransitionViewModel.lockscreenAlpha, + primaryBouncerToLockscreenTransitionViewModel.lockscreenAlpha, + ) + + return merge( + alphaTransitions, + // Sends a final alpha value of 1f when truly gone, to make sure HUNs appear + alphaWhenGoneAndShadeState, + // These remaining cases handle alpha changes within an existing state, such as + // shade expansion or swipe to dismiss + combineTransform( + isOnLockscreenWithoutShade, + shadeCollpaseFadeIn, + alphaForShadeAndQsExpansion, + keyguardInteractor.dismissAlpha, + ) { + isOnLockscreenWithoutShade, + shadeCollpaseFadeIn, + alphaForShadeAndQsExpansion, + dismissAlpha -> + if (isOnLockscreenWithoutShade) { + if (!shadeCollpaseFadeIn && dismissAlpha != null) { + emit(dismissAlpha) } + } else { + emit(alphaForShadeAndQsExpansion) } - )(viewState) - } + }, + ) .distinctUntilChanged() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModelTest.kt index f3807e4a1391..c381749ec6d3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/AodToLockscreenTransitionViewModelTest.kt @@ -59,6 +59,24 @@ class AodToLockscreenTransitionViewModelTest : SysuiTestCase() { } @Test + fun lockscreenAlphaStartsFromViewStateAccessorAlpha() = + testScope.runTest { + val viewState = ViewStateAccessor(alpha = { 0.5f }) + val alpha by collectLastValue(underTest.lockscreenAlpha(viewState)) + + repository.sendTransitionStep(step(0f, TransitionState.STARTED)) + + repository.sendTransitionStep(step(0f)) + assertThat(alpha).isEqualTo(0.5f) + + repository.sendTransitionStep(step(0.5f)) + assertThat(alpha).isEqualTo(0.75f) + + repository.sendTransitionStep(step(1f)) + assertThat(alpha).isEqualTo(1f) + } + + @Test fun deviceEntryBackgroundView_udfps_alphaFadeIn() = testScope.runTest { fingerprintPropertyRepository.supportsUdfps() diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java index 17e4e0fb33cb..61fee16f0431 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java @@ -186,6 +186,8 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { FakeConfigurationRepository configurationRepository = new FakeConfigurationRepository(); FakeSceneContainerFlags sceneContainerFlags = new FakeSceneContainerFlags(); + KeyguardTransitionInteractor keyguardTransitionInteractor = + mKosmos.getKeyguardTransitionInteractor(); KeyguardInteractor keyguardInteractor = new KeyguardInteractor( keyguardRepository, new FakeCommandQueue(), @@ -194,12 +196,10 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { new FakeKeyguardBouncerRepository(), new ConfigurationInteractor(configurationRepository), shadeRepository, + keyguardTransitionInteractor, () -> sceneInteractor); CommunalInteractor communalInteractor = mKosmos.getCommunalInteractor(); - KeyguardTransitionInteractor keyguardTransitionInteractor = - mKosmos.getKeyguardTransitionInteractor(); - mFromLockscreenTransitionInteractor = mKosmos.getFromLockscreenTransitionInteractor(); mFromPrimaryBouncerTransitionInteractor = mKosmos.getFromPrimaryBouncerTransitionInteractor(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerBaseTest.java index 2f765d540b6b..061f88e8a592 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerBaseTest.java @@ -213,6 +213,8 @@ public class QuickSettingsControllerBaseTest extends SysuiTestCase { mKosmos.getDeviceUnlockedInteractor()); FakeSceneContainerFlags sceneContainerFlags = new FakeSceneContainerFlags(); + KeyguardTransitionInteractor keyguardTransitionInteractor = + mKosmos.getKeyguardTransitionInteractor(); KeyguardInteractor keyguardInteractor = new KeyguardInteractor( mKeyguardRepository, new FakeCommandQueue(), @@ -221,11 +223,9 @@ public class QuickSettingsControllerBaseTest extends SysuiTestCase { new FakeKeyguardBouncerRepository(), new ConfigurationInteractor(configurationRepository), mShadeRepository, + keyguardTransitionInteractor, () -> sceneInteractor); - KeyguardTransitionInteractor keyguardTransitionInteractor = - mKosmos.getKeyguardTransitionInteractor(); - mFromLockscreenTransitionInteractor = mKosmos.getFromLockscreenTransitionInteractor(); mFromPrimaryBouncerTransitionInteractor = mKosmos.getFromPrimaryBouncerTransitionInteractor(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt index fb105e2ef759..1396a430df61 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt @@ -122,6 +122,10 @@ class StatusBarStateControllerImplTest : SysuiTestCase() { val shadeRepository = FakeShadeRepository() val sceneContainerFlags = FakeSceneContainerFlags() val configurationRepository = FakeConfigurationRepository() + val keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor + fromLockscreenTransitionInteractor = kosmos.fromLockscreenTransitionInteractor + fromPrimaryBouncerTransitionInteractor = kosmos.fromPrimaryBouncerTransitionInteractor + val keyguardInteractor = KeyguardInteractor( keyguardRepository, @@ -131,11 +135,9 @@ class StatusBarStateControllerImplTest : SysuiTestCase() { FakeKeyguardBouncerRepository(), ConfigurationInteractor(configurationRepository), shadeRepository, + keyguardTransitionInteractor, { kosmos.sceneInteractor }, ) - val keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor - fromLockscreenTransitionInteractor = kosmos.fromLockscreenTransitionInteractor - fromPrimaryBouncerTransitionInteractor = kosmos.fromPrimaryBouncerTransitionInteractor whenever(deviceEntryUdfpsInteractor.isUdfpsSupported).thenReturn(emptyFlow()) shadeInteractor = diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt index 9055ba4e1c4e..2da88e9f0ef9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt @@ -47,6 +47,8 @@ import com.android.systemui.res.R import com.android.systemui.shade.data.repository.shadeRepository import com.android.systemui.shade.mockLargeScreenHeaderHelper import com.android.systemui.statusbar.notification.stack.domain.interactor.sharedNotificationContainerInteractor +import com.android.systemui.statusbar.policy.SplitShadeStateController +import com.android.systemui.statusbar.policy.splitShadeStateController import com.android.systemui.testKosmos import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.whenever @@ -65,6 +67,7 @@ import org.mockito.Mockito.mock @RunWith(AndroidJUnit4::class) class SharedNotificationContainerViewModelTest : SysuiTestCase() { val aodBurnInViewModel = mock(AodBurnInViewModel::class.java) + val splitShadeStateController = mock(SplitShadeStateController::class.java) lateinit var translationYFlow: MutableStateFlow<Float> val kosmos = @@ -77,6 +80,7 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { init { kosmos.aodBurnInViewModel = aodBurnInViewModel + kosmos.splitShadeStateController = splitShadeStateController } val testScope = kosmos.testScope val configurationRepository = kosmos.fakeConfigurationRepository @@ -93,7 +97,7 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { @Before fun setUp() { - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())).thenReturn(false) translationYFlow = MutableStateFlow(0f) whenever(aodBurnInViewModel.translationY(any())).thenReturn(translationYFlow) underTest = kosmos.sharedNotificationContainerViewModel @@ -102,7 +106,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { @Test fun validateMarginStartInSplitShade() = testScope.runTest { - overrideResource(R.bool.config_use_split_notification_shade, true) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(true) overrideResource(R.dimen.notification_panel_margin_horizontal, 20) val dimens by collectLastValue(underTest.configurationBasedDimensions) @@ -115,7 +120,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { @Test fun validateMarginStart() = testScope.runTest { - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) overrideResource(R.dimen.notification_panel_margin_horizontal, 20) val dimens by collectLastValue(underTest.configurationBasedDimensions) @@ -130,7 +136,9 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { testScope.runTest { mSetFlagsRule.disableFlags(FLAG_CENTRALIZED_STATUS_BAR_DIMENS_REFACTOR) whenever(largeScreenHeaderHelper.getLargeScreenHeaderHeight()).thenReturn(5) - overrideResource(R.bool.config_use_split_notification_shade, true) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(true) + overrideResource(R.bool.config_use_large_screen_shade_header, true) overrideResource(R.dimen.large_screen_shade_header_height, 10) overrideResource(R.dimen.keyguard_split_shade_top_margin, 50) @@ -147,12 +155,13 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { testScope.runTest { mSetFlagsRule.enableFlags(FLAG_CENTRALIZED_STATUS_BAR_DIMENS_REFACTOR) whenever(largeScreenHeaderHelper.getLargeScreenHeaderHeight()).thenReturn(5) - overrideResource(R.bool.config_use_split_notification_shade, true) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(true) + overrideResource(R.bool.config_use_large_screen_shade_header, true) overrideResource(R.dimen.large_screen_shade_header_height, 10) overrideResource(R.dimen.keyguard_split_shade_top_margin, 50) val dimens by collectLastValue(underTest.configurationBasedDimensions) - configurationRepository.onAnyConfigurationChange() // Should directly use the header height (flagged on value) @@ -162,7 +171,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { @Test fun validatePaddingTop() = testScope.runTest { - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) overrideResource(R.dimen.large_screen_shade_header_height, 10) overrideResource(R.dimen.keyguard_split_shade_top_margin, 50) @@ -421,7 +431,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { val bounds by collectLastValue(underTest.bounds) // When not in split shade - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) configurationRepository.onAnyConfigurationChange() runCurrent() @@ -443,7 +454,9 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { // When in split shade whenever(largeScreenHeaderHelper.getLargeScreenHeaderHeight()).thenReturn(5) - overrideResource(R.bool.config_use_split_notification_shade, true) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(true) + overrideResource(R.bool.config_use_large_screen_shade_header, true) overrideResource(R.dimen.large_screen_shade_header_height, 10) overrideResource(R.dimen.keyguard_split_shade_top_margin, 50) @@ -470,7 +483,9 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { // When in split shade whenever(largeScreenHeaderHelper.getLargeScreenHeaderHeight()).thenReturn(5) - overrideResource(R.bool.config_use_split_notification_shade, true) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(true) + overrideResource(R.bool.config_use_large_screen_shade_header, true) overrideResource(R.dimen.large_screen_shade_header_height, 10) overrideResource(R.dimen.keyguard_split_shade_top_margin, 50) @@ -528,7 +543,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { showLockscreen() - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) configurationRepository.onAnyConfigurationChange() keyguardInteractor.setNotificationContainerBounds( NotificationContainerBounds(top = 1f, bottom = 2f) @@ -551,7 +567,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { showLockscreen() - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) configurationRepository.onAnyConfigurationChange() keyguardInteractor.setNotificationContainerBounds( NotificationContainerBounds(top = 1f, bottom = 2f) @@ -587,7 +604,8 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() { // Show lockscreen with shade expanded showLockscreenWithShadeExpanded() - overrideResource(R.bool.config_use_split_notification_shade, false) + whenever(splitShadeStateController.shouldUseSplitNotificationShade(any())) + .thenReturn(false) configurationRepository.onAnyConfigurationChange() keyguardInteractor.setNotificationContainerBounds( NotificationContainerBounds(top = 1f, bottom = 2f) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java index 76c9740f77dc..56fc7b9d818f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java @@ -60,6 +60,7 @@ import com.android.systemui.flags.FakeFeatureFlagsClassic; import com.android.systemui.flags.Flags; import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository; import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor; +import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor; import com.android.systemui.kosmos.KosmosJavaAdapter; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.power.domain.interactor.PowerInteractorFactory; @@ -162,7 +163,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); when(mIconManagerFactory.create(any(), any())).thenReturn(mIconManager); - + KeyguardTransitionInteractor keyguardTransitionInteractor = + mKosmos.getKeyguardTransitionInteractor(); mKeyguardInteractor = new KeyguardInteractor( mKeyguardRepository, mCommandQueue, @@ -171,6 +173,7 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { new FakeKeyguardBouncerRepository(), new ConfigurationInteractor(new FakeConfigurationRepository()), new FakeShadeRepository(), + keyguardTransitionInteractor, () -> mKosmos.getSceneInteractor()); mViewModel = new KeyguardStatusBarViewModel( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt index ca0e526bbc30..76913e8e15ee 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/ui/viewmodel/KeyguardStatusBarViewModelTest.kt @@ -24,6 +24,7 @@ import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor +import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.kosmos.testScope import com.android.systemui.power.domain.interactor.PowerInteractorFactory @@ -61,6 +62,7 @@ class KeyguardStatusBarViewModelTest : SysuiTestCase() { FakeKeyguardBouncerRepository(), ConfigurationInteractor(FakeConfigurationRepository()), FakeShadeRepository(), + kosmos.keyguardTransitionInteractor, ) { kosmos.sceneInteractor } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java index 97bd96d605ef..d87df0af6ba9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -420,6 +420,8 @@ public class BubblesTest extends SysuiTestCase { mKosmos.getDeviceUnlockedInteractor()); FakeSceneContainerFlags sceneContainerFlags = new FakeSceneContainerFlags(); + KeyguardTransitionInteractor keyguardTransitionInteractor = + mKosmos.getKeyguardTransitionInteractor(); KeyguardInteractor keyguardInteractor = new KeyguardInteractor( keyguardRepository, new FakeCommandQueue(), @@ -428,11 +430,9 @@ public class BubblesTest extends SysuiTestCase { new FakeKeyguardBouncerRepository(), new ConfigurationInteractor(configurationRepository), shadeRepository, + keyguardTransitionInteractor, () -> sceneInteractor); - KeyguardTransitionInteractor keyguardTransitionInteractor = - mKosmos.getKeyguardTransitionInteractor(); - mFromLockscreenTransitionInteractor = mKosmos.getFromLockscreenTransitionInteractor(); mFromPrimaryBouncerTransitionInteractor = mKosmos.getFromPrimaryBouncerTransitionInteractor(); 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 0bba36b172c0..3893a9b74b2a 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 @@ -23,6 +23,7 @@ import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor 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.power.domain.interactor.PowerInteractor import com.android.systemui.power.domain.interactor.PowerInteractorFactory import com.android.systemui.scene.domain.interactor.SceneInteractor @@ -30,6 +31,8 @@ import com.android.systemui.scene.shared.flag.FakeSceneContainerFlags import com.android.systemui.scene.shared.flag.SceneContainerFlags import com.android.systemui.shade.data.repository.FakeShadeRepository import com.android.systemui.util.mockito.mock +import com.android.systemui.util.mockito.whenever +import kotlinx.coroutines.flow.MutableSharedFlow /** * Simply put, I got tired of adding a constructor argument and then having to tweak dozens of @@ -50,6 +53,11 @@ object KeyguardInteractorFactory { sceneInteractor: SceneInteractor = mock(), powerInteractor: PowerInteractor = PowerInteractorFactory.create().powerInteractor, ): WithDependencies { + // Mock this until the class is replaced by kosmos + val keyguardTransitionInteractor: KeyguardTransitionInteractor = mock() + val currentKeyguardStateFlow = MutableSharedFlow<KeyguardState>() + whenever(keyguardTransitionInteractor.currentKeyguardState) + .thenReturn(currentKeyguardStateFlow) return WithDependencies( repository = repository, commandQueue = commandQueue, @@ -67,6 +75,7 @@ object KeyguardInteractorFactory { configurationInteractor = ConfigurationInteractor(configurationRepository), shadeRepository = shadeRepository, sceneInteractorProvider = { sceneInteractor }, + keyguardTransitionInteractor = keyguardTransitionInteractor, powerInteractor = powerInteractor, ), ) diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorKosmos.kt index 58d99b5bcc12..5140a9f5c2ba 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorKosmos.kt @@ -36,6 +36,7 @@ val Kosmos.keyguardInteractor by bouncerRepository = keyguardBouncerRepository, configurationInteractor = configurationInteractor, shadeRepository = shadeRepository, + keyguardTransitionInteractor = keyguardTransitionInteractor, sceneInteractorProvider = { sceneInteractor }, ) } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorKosmos.kt index 0c38fd9c37a0..6df7493be200 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorKosmos.kt @@ -26,7 +26,6 @@ val Kosmos.keyguardTransitionInteractor: KeyguardTransitionInteractor by KeyguardTransitionInteractor( scope = applicationCoroutineScope, repository = keyguardTransitionRepository, - keyguardInteractor = Lazy { keyguardInteractor }, fromLockscreenTransitionInteractor = Lazy { fromLockscreenTransitionInteractor }, fromPrimaryBouncerTransitionInteractor = Lazy { fromPrimaryBouncerTransitionInteractor }, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelKosmos.kt index 6b89e0f8901a..9fb32841d201 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/AodAlphaViewModelKosmos.kt @@ -18,7 +18,6 @@ package com.android.systemui.keyguard.ui.viewmodel -import com.android.systemui.keyguard.domain.interactor.keyguardInteractor import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture @@ -26,8 +25,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi val Kosmos.aodAlphaViewModel by Fixture { AodAlphaViewModel( - keyguardInteractor = keyguardInteractor, keyguardTransitionInteractor = keyguardTransitionInteractor, - occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel, + goneToAodTransitionViewModel = goneToAodTransitionViewModel, + goneToDozingTransitionViewModel = goneToDozingTransitionViewModel, ) } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModelKosmos.kt new file mode 100644 index 000000000000..4daf46028979 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/GoneToDozingTransitionViewModelKosmos.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 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. + */ + +@file:OptIn(ExperimentalCoroutinesApi::class) + +package com.android.systemui.keyguard.ui.viewmodel + +import com.android.systemui.keyguard.ui.keyguardTransitionAnimationFlow +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.kosmos.Kosmos.Fixture +import kotlinx.coroutines.ExperimentalCoroutinesApi + +val Kosmos.goneToDozingTransitionViewModel by Fixture { + GoneToDozingTransitionViewModel( + animationFlow = keyguardTransitionAnimationFlow, + ) +} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt index 24bb9c5008bf..4939237bbafe 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelKosmos.kt @@ -37,14 +37,24 @@ val Kosmos.keyguardRootViewModel by Fixture { communalInteractor = communalInteractor, keyguardTransitionInteractor = keyguardTransitionInteractor, notificationsKeyguardInteractor = notificationsKeyguardInteractor, + alternateBouncerToGoneTransitionViewModel = alternateBouncerToGoneTransitionViewModel, aodToLockscreenTransitionViewModel = aodToLockscreenTransitionViewModel, + dozingToLockscreenTransitionViewModel = dozingToLockscreenTransitionViewModel, + glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, + lockscreenToDreamingTransitionViewModel = lockscreenToDreamingTransitionViewModel, + lockscreenToGlanceableHubTransitionViewModel = lockscreenToGlanceableHubTransitionViewModel, lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, - alternateBouncerToGoneTransitionViewModel = alternateBouncerToGoneTransitionViewModel, + lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, + lockscreenToPrimaryBouncerTransitionViewModel = + lockscreenToPrimaryBouncerTransitionViewModel, + occludedToAodTransitionViewModel = occludedToAodTransitionViewModel, + occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel, + primaryBouncerToAodTransitionViewModel = primaryBouncerToAodTransitionViewModel, primaryBouncerToGoneTransitionViewModel = primaryBouncerToGoneTransitionViewModel, + primaryBouncerToLockscreenTransitionViewModel = + primaryBouncerToLockscreenTransitionViewModel, screenOffAnimationController = screenOffAnimationController, aodBurnInViewModel = aodBurnInViewModel, aodAlphaViewModel = aodAlphaViewModel, - lockscreenToGlanceableHubTransitionViewModel = lockscreenToGlanceableHubTransitionViewModel, - glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, ) } 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 30d4105e8ca1..8882de06637c 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 @@ -21,14 +21,21 @@ import com.android.systemui.keyguard.domain.interactor.keyguardInteractor import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor import com.android.systemui.keyguard.ui.viewmodel.alternateBouncerToGoneTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.aodBurnInViewModel +import com.android.systemui.keyguard.ui.viewmodel.aodToLockscreenTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.dozingToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.dreamingToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.glanceableHubToLockscreenTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.goneToDozingTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.goneToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToDreamingTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGlanceableHubTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGoneTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.lockscreenToOccludedTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.lockscreenToPrimaryBouncerTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.occludedToAodTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.occludedToLockscreenTransitionViewModel import com.android.systemui.keyguard.ui.viewmodel.primaryBouncerToGoneTransitionViewModel +import com.android.systemui.keyguard.ui.viewmodel.primaryBouncerToLockscreenTransitionViewModel import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture import com.android.systemui.kosmos.applicationCoroutineScope @@ -43,15 +50,24 @@ val Kosmos.sharedNotificationContainerViewModel by Fixture { keyguardTransitionInteractor = keyguardTransitionInteractor, shadeInteractor = shadeInteractor, communalInteractor = communalInteractor, - occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel, - lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, alternateBouncerToGoneTransitionViewModel = alternateBouncerToGoneTransitionViewModel, - primaryBouncerToGoneTransitionViewModel = primaryBouncerToGoneTransitionViewModel, - lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, + aodToLockscreenTransitionViewModel = aodToLockscreenTransitionViewModel, + dozingToLockscreenTransitionViewModel = dozingToLockscreenTransitionViewModel, dreamingToLockscreenTransitionViewModel = dreamingToLockscreenTransitionViewModel, - lockscreenToDreamingTransitionViewModel = lockscreenToDreamingTransitionViewModel, + goneToDozingTransitionViewModel = goneToDozingTransitionViewModel, + goneToDreamingTransitionViewModel = goneToDreamingTransitionViewModel, glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, + lockscreenToDreamingTransitionViewModel = lockscreenToDreamingTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel = lockscreenToGlanceableHubTransitionViewModel, + lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, + lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, + lockscreenToPrimaryBouncerTransitionViewModel = + lockscreenToPrimaryBouncerTransitionViewModel, + occludedToAodTransitionViewModel = occludedToAodTransitionViewModel, + occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel, + primaryBouncerToGoneTransitionViewModel = primaryBouncerToGoneTransitionViewModel, + primaryBouncerToLockscreenTransitionViewModel = + primaryBouncerToLockscreenTransitionViewModel, aodBurnInViewModel = aodBurnInViewModel, ) } |