Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt +22 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -57,6 +59,7 @@ constructor( lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel, transitionInteractor: KeyguardTransitionInteractor, ) { data class PreviewMode( Loading @@ -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. Loading Loading @@ -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 */ Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt +37 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -130,6 +133,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { @Mock private lateinit var lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel @Mock private lateinit var transitionInteractor: KeyguardTransitionInteractor private lateinit var underTest: KeyguardQuickAffordancesCombinedViewModel Loading @@ -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) Loading Loading @@ -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()) Loading @@ -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( Loading Loading @@ -304,7 +314,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel = lockscreenToPrimaryBouncerTransitionViewModel lockscreenToPrimaryBouncerTransitionViewModel, transitionInteractor = transitionInteractor, ) } Loading Loading @@ -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, Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt +22 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -57,6 +59,7 @@ constructor( lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel, transitionInteractor: KeyguardTransitionInteractor, ) { data class PreviewMode( Loading @@ -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. Loading Loading @@ -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 */ Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelTest.kt +37 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -130,6 +133,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { @Mock private lateinit var lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel @Mock private lateinit var transitionInteractor: KeyguardTransitionInteractor private lateinit var underTest: KeyguardQuickAffordancesCombinedViewModel Loading @@ -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) Loading Loading @@ -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()) Loading @@ -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( Loading Loading @@ -304,7 +314,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() { lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel, lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel, lockscreenToPrimaryBouncerTransitionViewModel = lockscreenToPrimaryBouncerTransitionViewModel lockscreenToPrimaryBouncerTransitionViewModel, transitionInteractor = transitionInteractor, ) } Loading Loading @@ -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, Loading