Shortcuts alpha should only react to shadeExpansion when on Lockscreen
Shade expansion was sending a 0f while going from GONE -> AOD
Then during AOD -> LOCKSCREEN, due to the shade expansion value, the
shortcuts were flickering one frame of 1f alpha.
The shortcuts should only be reacting to shade expansion on LOCKSCREEN
Fixes: 325329538
Test: KeyguardQuickAffordancesCombinedViewModelTest.kt
Flag: ACONFIG com.android.systemui.keyguard_bottom_area_refactor TEAMFOOD
Change-Id: I90c218346ff265352de02be955d62cf9a41404ed
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 188be244..4db942cc 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 @@
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 @@
lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel,
lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel,
lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel,
+ transitionInteractor: KeyguardTransitionInteractor,
) {
data class PreviewMode(
@@ -71,6 +74,24 @@
*/
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 @@
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 18a34ba..1f14afa 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.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.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
+import kotlin.test.assertEquals
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -130,6 +133,8 @@
@Mock
private lateinit var lockscreenToPrimaryBouncerTransitionViewModel:
LockscreenToPrimaryBouncerTransitionViewModel
+ @Mock
+ private lateinit var transitionInteractor: KeyguardTransitionInteractor
private lateinit var underTest: KeyguardQuickAffordancesCombinedViewModel
@@ -146,6 +151,8 @@
// 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 @@
intendedAlphaMutableStateFlow.value = 1f
intendedShadeAlphaMutableStateFlow.value = 0f
+ intendedFinishedKeyguardStateFlow.value = KeyguardState.LOCKSCREEN
whenever(aodToLockscreenTransitionViewModel.shortcutsAlpha)
.thenReturn(intendedAlphaMutableStateFlow)
whenever(dozingToLockscreenTransitionViewModel.shortcutsAlpha).thenReturn(emptyFlow())
@@ -263,7 +271,9 @@
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 @@
lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel,
lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel,
lockscreenToPrimaryBouncerTransitionViewModel =
- lockscreenToPrimaryBouncerTransitionViewModel
+ lockscreenToPrimaryBouncerTransitionViewModel,
+ transitionInteractor = transitionInteractor,
)
}
@@ -682,6 +693,30 @@
)
}
+ @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,