diff options
2 files changed, 59 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt index 188be244be4a..4db942cc460c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt @@ -20,7 +20,9 @@ package com.android.systemui.keyguard.ui.viewmodel import androidx.annotation.VisibleForTesting import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel +import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.quickaffordance.ActivationState import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition import com.android.systemui.shade.domain.interactor.ShadeInteractor @@ -57,6 +59,7 @@ constructor( lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel, + transitionInteractor: KeyguardTransitionInteractor, ) { data class PreviewMode( @@ -71,6 +74,24 @@ constructor( */ private val previewMode = MutableStateFlow(PreviewMode()) + private val showingLockscreen: Flow<Boolean> = + transitionInteractor.finishedKeyguardState.map { keyguardState -> + keyguardState == KeyguardState.LOCKSCREEN + } + + /** The only time the expansion is important is while lockscreen is actively displayed */ + private val shadeExpansionAlpha = + combine( + showingLockscreen, + shadeInteractor.anyExpansion, + ) { showingLockscreen, expansion -> + if (showingLockscreen) { + 1 - expansion + } else { + 0f + } + } + /** * ID of the slot that's currently selected in the preview that renders exclusively in the * wallpaper picker application. This is ignored for the actual, real lock screen experience. @@ -101,7 +122,7 @@ constructor( lockscreenToGoneTransitionViewModel.shortcutsAlpha, lockscreenToOccludedTransitionViewModel.shortcutsAlpha, lockscreenToPrimaryBouncerTransitionViewModel.shortcutsAlpha, - shadeInteractor.qsExpansion.map { 1 - it }, + shadeExpansionAlpha, ) /** The source of truth of alpha for all of the quick affordances on lockscreen */ diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt index 18a34ba964cf..1f14afa1d00b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt @@ -44,6 +44,8 @@ import com.android.systemui.keyguard.data.repository.KeyguardQuickAffordanceRepo import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor +import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.quickaffordance.ActivationState import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger @@ -75,6 +77,7 @@ import org.mockito.ArgumentMatchers import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations +import kotlin.test.assertEquals @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @@ -130,6 +133,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { @Mock private lateinit var lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel + @Mock + private lateinit var transitionInteractor: KeyguardTransitionInteractor private lateinit var underTest: KeyguardQuickAffordancesCombinedViewModel @@ -146,6 +151,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { // the viewModel does a `map { 1 - it }` on this value, which is why it's different private val intendedShadeAlphaMutableStateFlow: MutableStateFlow<Float> = MutableStateFlow(0f) + private val intendedFinishedKeyguardStateFlow = MutableStateFlow(KeyguardState.LOCKSCREEN) + @Before fun setUp() { MockitoAnnotations.initMocks(this) @@ -242,6 +249,7 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { intendedAlphaMutableStateFlow.value = 1f intendedShadeAlphaMutableStateFlow.value = 0f + intendedFinishedKeyguardStateFlow.value = KeyguardState.LOCKSCREEN whenever(aodToLockscreenTransitionViewModel.shortcutsAlpha) .thenReturn(intendedAlphaMutableStateFlow) whenever(dozingToLockscreenTransitionViewModel.shortcutsAlpha).thenReturn(emptyFlow()) @@ -263,7 +271,9 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { whenever(lockscreenToOccludedTransitionViewModel.shortcutsAlpha).thenReturn(emptyFlow()) whenever(lockscreenToPrimaryBouncerTransitionViewModel.shortcutsAlpha) .thenReturn(emptyFlow()) - whenever(shadeInteractor.qsExpansion).thenReturn(intendedShadeAlphaMutableStateFlow) + whenever(shadeInteractor.anyExpansion).thenReturn(intendedShadeAlphaMutableStateFlow) + whenever(transitionInteractor.finishedKeyguardState) + .thenReturn(intendedFinishedKeyguardStateFlow) underTest = KeyguardQuickAffordancesCombinedViewModel( @@ -304,7 +314,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel = - lockscreenToPrimaryBouncerTransitionViewModel + lockscreenToPrimaryBouncerTransitionViewModel, + transitionInteractor = transitionInteractor, ) } @@ -682,6 +693,30 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { ) } + @Test + fun shadeExpansionAlpha_changes_whenOnLockscreen() = + testScope.runTest { + intendedFinishedKeyguardStateFlow.value = KeyguardState.LOCKSCREEN + intendedShadeAlphaMutableStateFlow.value = 0.25f + val underTest = collectLastValue(underTest.transitionAlpha) + assertEquals(0.75f, underTest()) + + intendedShadeAlphaMutableStateFlow.value = 0.3f + assertEquals(0.7f, underTest()) + } + + @Test + fun shadeExpansionAlpha_alwaysZero_whenNotOnLockscreen() = + testScope.runTest { + intendedFinishedKeyguardStateFlow.value = KeyguardState.GONE + intendedShadeAlphaMutableStateFlow.value = 0.5f + val underTest = collectLastValue(underTest.transitionAlpha) + assertEquals(0f, underTest()) + + intendedShadeAlphaMutableStateFlow.value = 0.25f + assertEquals(0f, underTest()) + } + private suspend fun setUpQuickAffordanceModel( position: KeyguardQuickAffordancePosition, testConfig: TestConfig, |