diff options
| author | 2023-08-22 11:16:19 +0100 | |
|---|---|---|
| committer | 2023-08-22 11:16:19 +0100 | |
| commit | dbbbedb352eca602b27347131e1513d344d9c622 (patch) | |
| tree | cfe9b78dc1e754dfa68d06cc49a41c5528cfec53 | |
| parent | 2d505f3296acd40adfc480ba708dba71d095b28f (diff) | |
Fix bouncer always being on the left side
The keyguard position value was being set to 0 as the initial/default
value, which would be passed on to the view/ui layer on start, which
would then move the bouncer to the left.
At the moment there is code in the view layer that stores the last used
position (left vs right), and by having the 0 value always coming from
the data layer, it would override this setting.
A better refactor in the future, would probably be to have this logic
of storing/retrieving the setting, in the data layer itself, but would
like to leave that fix/improvement for a later stage.
This stage is just to fix the bug.
Test: Unit tests in this CL
Test: Manually - By moving the bouncer and then restarting the device
Fixes: 296845861
Change-Id: Ib5c508ef0c589c173b3e10280b0fe5156274e7e0
4 files changed, 27 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/data/repository/KeyguardBouncerRepository.kt b/packages/SystemUI/src/com/android/systemui/bouncer/data/repository/KeyguardBouncerRepository.kt index 918e1680fc66..f2b4e09c9850 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/data/repository/KeyguardBouncerRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/data/repository/KeyguardBouncerRepository.kt @@ -58,7 +58,7 @@ interface KeyguardBouncerRepository { * ``` */ val panelExpansionAmount: StateFlow<Float> - val keyguardPosition: StateFlow<Float> + val keyguardPosition: StateFlow<Float?> val isBackButtonEnabled: StateFlow<Boolean?> /** Determines if user is already unlocked */ val keyguardAuthenticated: StateFlow<Boolean?> @@ -130,7 +130,7 @@ constructor( */ private val _panelExpansionAmount = MutableStateFlow(EXPANSION_HIDDEN) override val panelExpansionAmount = _panelExpansionAmount.asStateFlow() - private val _keyguardPosition = MutableStateFlow(0f) + private val _keyguardPosition = MutableStateFlow<Float?>(null) override val keyguardPosition = _keyguardPosition.asStateFlow() private val _isBackButtonEnabled = MutableStateFlow<Boolean?>(null) override val isBackButtonEnabled = _isBackButtonEnabled.asStateFlow() @@ -244,6 +244,7 @@ constructor( .logDiffsForTable(buffer, "", "PanelExpansionAmountMillis", -1) .launchIn(applicationScope) keyguardPosition + .filterNotNull() .map { it.toInt() } .logDiffsForTable(buffer, "", "KeyguardPosition", -1) .launchIn(applicationScope) diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt index c48660328bf0..0e0f1f6265d7 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/PrimaryBouncerInteractor.kt @@ -94,7 +94,7 @@ constructor( val startingDisappearAnimation: Flow<Runnable> = repository.primaryBouncerStartingDisappearAnimation.filterNotNull() val resourceUpdateRequests: Flow<Boolean> = repository.resourceUpdateRequests.filter { it } - val keyguardPosition: Flow<Float> = repository.keyguardPosition + val keyguardPosition: Flow<Float> = repository.keyguardPosition.filterNotNull() val panelExpansionAmount: Flow<Float> = repository.panelExpansionAmount /** 0f = bouncer fully hidden. 1f = bouncer fully visible. */ val bouncerExpansion: Flow<Float> = diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/KeyguardBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/KeyguardBouncerViewModelTest.kt index 8236165b62d8..d4bba723a989 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/KeyguardBouncerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/KeyguardBouncerViewModelTest.kt @@ -29,6 +29,8 @@ import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor import com.android.systemui.bouncer.shared.model.BouncerShowMessageModel import com.android.systemui.bouncer.ui.BouncerView import com.android.systemui.classifier.FalsingCollector +import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.coroutines.collectValues import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.DismissCallbackRegistry @@ -156,4 +158,24 @@ class KeyguardBouncerViewModelTest : SysuiTestCase() { assertThat(isShowing).isEqualTo(false) job.cancel() } + + @Test + fun keyguardPosition_noValueSet_emptyByDefault() = runTest { + val positionValues by collectValues(underTest.keyguardPosition) + + runCurrent() + + assertThat(positionValues).isEmpty() + } + + @Test + fun keyguardPosition_valueSet_returnsValue() = runTest { + val position by collectLastValue(underTest.keyguardPosition) + runCurrent() + + repository.setKeyguardPosition(123f) + runCurrent() + + assertThat(position).isEqualTo(123f) + } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/data/repository/FakeKeyguardBouncerRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/data/repository/FakeKeyguardBouncerRepository.kt index 10529e68f00f..0847c8535e4e 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/data/repository/FakeKeyguardBouncerRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/data/repository/FakeKeyguardBouncerRepository.kt @@ -21,7 +21,7 @@ class FakeKeyguardBouncerRepository : KeyguardBouncerRepository { override val primaryBouncerScrimmed = _primaryBouncerScrimmed.asStateFlow() private val _panelExpansionAmount = MutableStateFlow(KeyguardBouncerConstants.EXPANSION_HIDDEN) override val panelExpansionAmount = _panelExpansionAmount.asStateFlow() - private val _keyguardPosition = MutableStateFlow(0f) + private val _keyguardPosition = MutableStateFlow<Float?>(null) override val keyguardPosition = _keyguardPosition.asStateFlow() private val _isBackButtonEnabled = MutableStateFlow<Boolean?>(null) override val isBackButtonEnabled = _isBackButtonEnabled.asStateFlow() |