summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matt Pietal <mpietal@google.com> 2024-08-14 12:32:13 +0000
committer Matt Pietal <mpietal@google.com> 2024-08-14 17:37:24 +0000
commitd6624fb4517efc3da8dcf07b9876f2fc079ee54e (patch)
tree5ac9d74c74b9e231e866f569df890b0023abba80
parentd842bdb91844e6b95002f7528e5ef274905c2e87 (diff)
Use State.value instead of sample()
Replace some early uses of sample(), which were used to access state. There is no need for coroutines to flow these values, and it may cause some race conditions if coroutine execution is delayed. Just check the current value of the StateFlow. Fixes: 356696593 Test: atest SystemUiRoboTests:com.android.systemui.keyguard.domain.interactor Flag: EXEMPT bugfix Change-Id: I62e8db5a066f888b0402beb91c5044d081b1acab
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt36
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt32
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt17
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt8
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt4
6 files changed, 38 insertions, 63 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt
index 81b0064f0f03..49303e089036 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt
@@ -91,11 +91,11 @@ interface KeyguardRepository {
* the z-order (which is not really above the system UI window, but rather - the lock-screen
* becomes invisible to reveal the "occluding activity").
*/
- val isKeyguardShowing: Flow<Boolean>
+ val isKeyguardShowing: StateFlow<Boolean>
/** Is an activity showing over the keyguard? */
@Deprecated("Use KeyguardTransitionInteractor + KeyguardState.OCCLUDED")
- val isKeyguardOccluded: Flow<Boolean>
+ val isKeyguardOccluded: StateFlow<Boolean>
/**
* Whether the device is locked or unlocked right now. This is true when keyguard has been
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt
index 2a8bb471c217..13d54bac8339 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt
@@ -36,8 +36,6 @@ import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
@SysUISingleton
@@ -73,15 +71,11 @@ constructor(
listenForTransitionToCamera(scope, keyguardInteractor)
}
- private val canDismissLockscreen: Flow<Boolean> =
- combine(
- keyguardInteractor.isKeyguardShowing,
- keyguardInteractor.isKeyguardDismissible,
- keyguardInteractor.biometricUnlockState,
- ) { isKeyguardShowing, isKeyguardDismissible, biometricUnlockState ->
- (isWakeAndUnlock(biometricUnlockState.mode) ||
- (!isKeyguardShowing && isKeyguardDismissible))
- }
+ private fun canDismissLockscreen(): Boolean {
+ return isWakeAndUnlock(keyguardInteractor.biometricUnlockState.value.mode) ||
+ (!keyguardInteractor.isKeyguardShowing.value &&
+ keyguardInteractor.isKeyguardDismissible.value)
+ }
/**
* Listen for the signal that we're waking up and figure what state we need to transition to.
@@ -96,22 +90,18 @@ constructor(
.debounce(50L)
.sample(
startedKeyguardTransitionStep,
- keyguardInteractor.biometricUnlockState,
- keyguardInteractor.primaryBouncerShowing,
- keyguardInteractor.isKeyguardOccluded,
- canDismissLockscreen,
wakeToGoneInteractor.canWakeDirectlyToGone,
)
.collect {
(
_,
startedStep,
- biometricUnlockState,
- primaryBouncerShowing,
- isKeyguardOccludedLegacy,
- canDismissLockscreen,
canWakeDirectlyToGone,
) ->
+ val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
+ val biometricUnlockMode = keyguardInteractor.biometricUnlockState.value.mode
+ val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
+
if (!maybeHandleInsecurePowerGesture()) {
val shouldTransitionToLockscreen =
if (KeyguardWmStateRefactor.isEnabled) {
@@ -121,12 +111,10 @@ constructor(
// completes.
!maybeStartTransitionToOccludedOrInsecureCamera { state, reason ->
startTransitionTo(state, ownerReason = reason)
- } &&
- !isWakeAndUnlock(biometricUnlockState.mode) &&
- !primaryBouncerShowing
+ } && !isWakeAndUnlock(biometricUnlockMode) && !primaryBouncerShowing
} else {
!isKeyguardOccludedLegacy &&
- !isWakeAndUnlock(biometricUnlockState.mode) &&
+ !isWakeAndUnlock(biometricUnlockMode) &&
!primaryBouncerShowing
}
@@ -136,7 +124,7 @@ constructor(
!KeyguardWmStateRefactor.isEnabled && isKeyguardOccludedLegacy
val shouldTransitionToGone =
- (!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen) ||
+ (!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen()) ||
(KeyguardWmStateRefactor.isEnabled && canWakeDirectlyToGone)
if (shouldTransitionToGone) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt
index 61446c19605c..0c12f8cee943 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt
@@ -42,8 +42,6 @@ import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch
@@ -83,13 +81,10 @@ constructor(
listenForTransitionToCamera(scope, keyguardInteractor)
}
- private val canTransitionToGoneOnWake: Flow<Boolean> =
- combine(
- keyguardInteractor.isKeyguardShowing,
- keyguardInteractor.isKeyguardDismissible,
- ) { isKeyguardShowing, isKeyguardDismissible ->
- isKeyguardDismissible && !isKeyguardShowing
- }
+ private fun canDismissLockscreen(): Boolean {
+ return !keyguardInteractor.isKeyguardShowing.value &&
+ keyguardInteractor.isKeyguardDismissible.value
+ }
private fun listenForDozingToGoneViaBiometrics() {
if (KeyguardWmStateRefactor.isEnabled) {
@@ -135,27 +130,20 @@ constructor(
.debounce(50L)
.filterRelevantKeyguardStateAnd { isAwake -> isAwake }
.sample(
- keyguardInteractor.isKeyguardOccluded,
communalInteractor.isCommunalAvailable,
communalSceneInteractor.isIdleOnCommunal,
- canTransitionToGoneOnWake,
- keyguardInteractor.primaryBouncerShowing,
)
- .collect {
- (
- _,
- occluded,
- isCommunalAvailable,
- isIdleOnCommunal,
- canTransitionToGoneOnWake,
- primaryBouncerShowing) ->
+ .collect { (_, isCommunalAvailable, isIdleOnCommunal) ->
+ val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
+ val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
+
if (!deviceEntryInteractor.isLockscreenEnabled()) {
if (SceneContainerFlag.isEnabled) {
// TODO(b/336576536): Check if adaptation for scene framework is needed
} else {
startTransitionTo(KeyguardState.GONE)
}
- } else if (canTransitionToGoneOnWake) {
+ } else if (canDismissLockscreen()) {
if (SceneContainerFlag.isEnabled) {
// TODO(b/336576536): Check if adaptation for scene framework is needed
} else {
@@ -167,7 +155,7 @@ constructor(
} else {
startTransitionTo(KeyguardState.PRIMARY_BOUNCER)
}
- } else if (occluded) {
+ } else if (isKeyguardOccludedLegacy) {
startTransitionTo(KeyguardState.OCCLUDED)
} else if (isIdleOnCommunal && !communalSceneKtfRefactor()) {
if (SceneContainerFlag.isEnabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt
index 17c1e823a1ca..7bf9c2f1dc7a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDreamingTransitionInteractor.kt
@@ -32,7 +32,6 @@ import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
-import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
@@ -208,15 +207,15 @@ constructor(
scope.launch {
keyguardInteractor.isAbleToDream
- .sampleCombine(
- keyguardInteractor.isKeyguardShowing,
- keyguardInteractor.isKeyguardDismissible,
- )
- .filterRelevantKeyguardStateAnd {
- (isDreaming, isKeyguardShowing, isKeyguardDismissible) ->
- !isDreaming && isKeyguardDismissible && !isKeyguardShowing
+ .filterRelevantKeyguardStateAnd { isDreaming -> !isDreaming }
+ .collect {
+ if (
+ keyguardInteractor.isKeyguardDismissible.value &&
+ !keyguardInteractor.isKeyguardShowing.value
+ ) {
+ startTransitionTo(KeyguardState.GONE)
+ }
}
- .collect { startTransitionTo(KeyguardState.GONE) }
}
}
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 0df989e9353f..4cab2bb5dba8 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
@@ -216,14 +216,14 @@ constructor(
/** Whether the keyguard is showing or not. */
@Deprecated("Use KeyguardTransitionInteractor + KeyguardState")
- val isKeyguardShowing: Flow<Boolean> = repository.isKeyguardShowing
+ val isKeyguardShowing: StateFlow<Boolean> = repository.isKeyguardShowing
/** Whether the keyguard is dismissible or not. */
val isKeyguardDismissible: StateFlow<Boolean> = repository.isKeyguardDismissible
/** Whether the keyguard is occluded (covered by an activity). */
@Deprecated("Use KeyguardTransitionInteractor + KeyguardState.OCCLUDED")
- val isKeyguardOccluded: Flow<Boolean> = repository.isKeyguardOccluded
+ val isKeyguardOccluded: StateFlow<Boolean> = repository.isKeyguardOccluded
/** Whether the keyguard is going away. */
@Deprecated("Use KeyguardTransitionInteractor + KeyguardState.GONE")
@@ -253,7 +253,7 @@ constructor(
val ambientIndicationVisible: Flow<Boolean> = repository.ambientIndicationVisible.asStateFlow()
/** Whether the primary bouncer is showing or not. */
- @JvmField val primaryBouncerShowing: Flow<Boolean> = bouncerRepository.primaryBouncerShow
+ @JvmField val primaryBouncerShowing: StateFlow<Boolean> = bouncerRepository.primaryBouncerShow
/** Whether the alternate bouncer is showing or not. */
val alternateBouncerShowing: Flow<Boolean> =
@@ -274,7 +274,7 @@ constructor(
val statusBarState: Flow<StatusBarState> = repository.statusBarState
/** Observable for [BiometricUnlockModel] when biometrics are used to unlock the device. */
- val biometricUnlockState: Flow<BiometricUnlockModel> = repository.biometricUnlockState
+ val biometricUnlockState: StateFlow<BiometricUnlockModel> = repository.biometricUnlockState
/** Keyguard is present and is not occluded. */
val isKeyguardVisible: Flow<Boolean> =
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt
index 4571c19d101a..54a6c0c1d182 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt
@@ -60,13 +60,13 @@ class FakeKeyguardRepository @Inject constructor() : KeyguardRepository {
override val bottomAreaAlpha: StateFlow<Float> = _bottomAreaAlpha
private val _isKeyguardShowing = MutableStateFlow(false)
- override val isKeyguardShowing: Flow<Boolean> = _isKeyguardShowing
+ override val isKeyguardShowing: StateFlow<Boolean> = _isKeyguardShowing
private val _isKeyguardUnlocked = MutableStateFlow(false)
override val isKeyguardDismissible: StateFlow<Boolean> = _isKeyguardUnlocked.asStateFlow()
private val _isKeyguardOccluded = MutableStateFlow(false)
- override val isKeyguardOccluded: Flow<Boolean> = _isKeyguardOccluded
+ override val isKeyguardOccluded: StateFlow<Boolean> = _isKeyguardOccluded
private val _isDozing = MutableStateFlow(false)
override val isDozing: StateFlow<Boolean> = _isDozing