summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractorTest.kt20
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt44
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractor.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt30
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/shared/model/WakefulnessModel.kt5
5 files changed, 73 insertions, 36 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractorTest.kt
index 046d92d58978..2ab36501d87d 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromAodTransitionInteractorTest.kt
@@ -443,4 +443,24 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
assertThat(transitionRepository).noTransitionsStarted()
}
+
+ @Test
+ @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
+ fun testDoNotTransitionToGlanceableHub_onWakeUpFromAodDueToMotion() =
+ kosmos.runTest {
+ setCommunalV2Available(true)
+
+ val currentScene by collectLastValue(communalSceneInteractor.currentScene)
+ fakeCommunalSceneRepository.changeScene(CommunalScenes.Blank)
+
+ // Communal is not showing
+ Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
+
+ powerInteractor.setAwakeForTest(reason = PowerManager.WAKE_REASON_LIFT)
+ testScope.advanceTimeBy(100) // account for debouncing
+
+ Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
+ assertThat(transitionRepository)
+ .startedTransition(from = KeyguardState.AOD, to = KeyguardState.LOCKSCREEN)
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
index 096c3dafd01c..c3d18a3d893c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
@@ -20,7 +20,6 @@ import android.os.PowerManager
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
-import android.provider.Settings
import android.service.dream.dreamManager
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
@@ -30,8 +29,6 @@ import com.android.systemui.Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR
import com.android.systemui.Flags.FLAG_SCENE_CONTAINER
import com.android.systemui.Flags.glanceableHubV2
import com.android.systemui.SysuiTestCase
-import com.android.systemui.common.data.repository.batteryRepository
-import com.android.systemui.common.data.repository.fake
import com.android.systemui.communal.data.repository.FakeCommunalSceneRepository
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.data.repository.fakeCommunalSceneRepository
@@ -61,8 +58,6 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
-import com.android.systemui.user.data.repository.fakeUserRepository
-import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.flow.flowOf
@@ -171,15 +166,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
fun testTransitionToLockscreen_onWake_canDream_ktfRefactor() =
kosmos.runTest {
setCommunalAvailable(true)
- if (glanceableHubV2()) {
- val user = fakeUserRepository.asMainUser()
- fakeSettings.putIntForUser(
- Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
- 1,
- user.id,
- )
- batteryRepository.fake.setDevicePluggedIn(true)
- } else {
+ if (!glanceableHubV2()) {
whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
}
@@ -226,15 +213,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
fun testTransitionToGlanceableHub_onWakeup_ifAvailable() =
kosmos.runTest {
setCommunalAvailable(true)
- if (glanceableHubV2()) {
- val user = fakeUserRepository.asMainUser()
- fakeSettings.putIntForUser(
- Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
- 1,
- user.id,
- )
- batteryRepository.fake.setDevicePluggedIn(true)
- } else {
+ if (!glanceableHubV2()) {
whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
}
@@ -250,6 +229,25 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
}
@Test
+ @DisableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR, FLAG_SCENE_CONTAINER)
+ @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
+ fun testTransitionToLockscreen_onWakeupFromLift() =
+ kosmos.runTest {
+ setCommunalAvailable(true)
+ if (!glanceableHubV2()) {
+ whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
+ }
+
+ // Device turns on.
+ powerInteractor.setAwakeForTest(reason = PowerManager.WAKE_REASON_LIFT)
+ testScope.advanceTimeBy(51L)
+
+ // We transition to the lockscreen instead of the hub.
+ assertThat(transitionRepository)
+ .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.LOCKSCREEN)
+ }
+
+ @Test
@EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
fun testTransitionToOccluded_onWakeup_whenOccludingActivityOnTop() =
kosmos.runTest {
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 54af8f5b9806..f53421d539fe 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
@@ -101,14 +101,14 @@ constructor(
)
.collect {
(
- _,
+ detailedWakefulness,
startedStep,
canWakeDirectlyToGone,
) ->
val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
val biometricUnlockMode = keyguardInteractor.biometricUnlockState.value.mode
val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
- val shouldShowCommunal = communalSettingsInteractor.autoOpenEnabled.value
+ val autoOpenCommunal = communalSettingsInteractor.autoOpenEnabled.value
if (!maybeHandleInsecurePowerGesture()) {
val shouldTransitionToLockscreen =
@@ -135,8 +135,12 @@ constructor(
(!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen()) ||
(KeyguardWmStateRefactor.isEnabled && canWakeDirectlyToGone)
+ // Avoid transitioning to communal automatically if the device is waking
+ // up due to motion.
val shouldTransitionToCommunal =
- communalSettingsInteractor.isV2FlagEnabled() && shouldShowCommunal
+ communalSettingsInteractor.isV2FlagEnabled() &&
+ autoOpenCommunal &&
+ !detailedWakefulness.isAwakeFromMotionOrLift()
if (shouldTransitionToGone) {
// TODO(b/360368320): Adapt for scene framework
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 1fc41085f772..4aaa1fab4c65 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
@@ -34,8 +34,9 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
+import com.android.systemui.power.shared.model.WakefulnessModel
import com.android.systemui.scene.shared.flag.SceneContainerFlag
-import com.android.systemui.util.kotlin.Utils.Companion.sample
+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
@@ -121,9 +122,10 @@ constructor(
private fun shouldTransitionToCommunal(
shouldShowCommunal: Boolean,
isCommunalAvailable: Boolean,
+ wakefulness: WakefulnessModel,
) =
if (communalSettingsInteractor.isV2FlagEnabled()) {
- shouldShowCommunal
+ shouldShowCommunal && !wakefulness.isAwakeFromMotionOrLift()
} else {
isCommunalAvailable && dreamManager.canStartDreaming(false)
}
@@ -148,14 +150,14 @@ constructor(
}
scope.launch {
- powerInteractor.isAwake
+ powerInteractor.detailedWakefulness
.debounce(50L)
- .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
- .sample(
+ .filterRelevantKeyguardStateAnd { wakefulness -> wakefulness.isAwake() }
+ .sampleCombine(
communalInteractor.isCommunalAvailable,
communalSettingsInteractor.autoOpenEnabled,
)
- .collect { (_, isCommunalAvailable, shouldShowCommunal) ->
+ .collect { (detailedWakefulness, isCommunalAvailable, shouldShowCommunal) ->
val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
val isKeyguardGoingAway = keyguardInteractor.isKeyguardGoingAway.value
@@ -186,7 +188,11 @@ constructor(
} else if (isKeyguardOccludedLegacy) {
startTransitionTo(KeyguardState.OCCLUDED)
} else if (
- shouldTransitionToCommunal(shouldShowCommunal, isCommunalAvailable)
+ shouldTransitionToCommunal(
+ shouldShowCommunal,
+ isCommunalAvailable,
+ detailedWakefulness,
+ )
) {
if (!SceneContainerFlag.isEnabled) {
transitionToGlanceableHub()
@@ -208,7 +214,7 @@ constructor(
scope.launch {
powerInteractor.detailedWakefulness
.filterRelevantKeyguardStateAnd { it.isAwake() }
- .sample(
+ .sampleCombine(
communalSettingsInteractor.autoOpenEnabled,
communalInteractor.isCommunalAvailable,
keyguardInteractor.biometricUnlockState,
@@ -217,7 +223,7 @@ constructor(
)
.collect {
(
- _,
+ detailedWakefulness,
shouldShowCommunal,
isCommunalAvailable,
biometricUnlockState,
@@ -245,7 +251,11 @@ constructor(
)
}
} else if (
- shouldTransitionToCommunal(shouldShowCommunal, isCommunalAvailable)
+ shouldTransitionToCommunal(
+ shouldShowCommunal,
+ isCommunalAvailable,
+ detailedWakefulness,
+ )
) {
if (!SceneContainerFlag.isEnabled) {
transitionToGlanceableHub()
diff --git a/packages/SystemUI/src/com/android/systemui/power/shared/model/WakefulnessModel.kt b/packages/SystemUI/src/com/android/systemui/power/shared/model/WakefulnessModel.kt
index 297c6af5a4a7..f368c53c5b39 100644
--- a/packages/SystemUI/src/com/android/systemui/power/shared/model/WakefulnessModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/power/shared/model/WakefulnessModel.kt
@@ -61,6 +61,11 @@ data class WakefulnessModel(
(lastWakeReason == WakeSleepReason.TAP || lastWakeReason == WakeSleepReason.GESTURE)
}
+ fun isAwakeFromMotionOrLift(): Boolean {
+ return isAwake() &&
+ (lastWakeReason == WakeSleepReason.MOTION || lastWakeReason == WakeSleepReason.LIFT)
+ }
+
override fun logDiffs(prevVal: WakefulnessModel, row: TableRowLogger) {
row.logChange(columnName = "wakefulness", value = toString())
}