Merge "Use State.value instead of sample()" into main
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 81b0064..49303e0 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 @@
* 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 2a8bb47..13d54ba 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 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 @@
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 @@
.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 @@
// 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 @@
!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 61446c1..0c12f8c 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 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 @@
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 @@
.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 @@
} 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 17c1e82..7bf9c2f1 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.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 @@
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 0df989e..4cab2bb 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 @@
/** 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 @@
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 @@
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 4571c19..54a6c0c 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 @@
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