[flexiglass] Skip lockscreen when devices wakes.
...if the auth method is None. Fix: 292502433 Test: manually verified that, with an auth method of None, turning on the device skips the lockscreen (but the lockscreen _is_ shown when the device display is asleep - to show AOD). Test: manually verified that, with a secure auth method (tried pattern), turning on the device does NOT skip the lockscreen. Test: added unit tests cases to cover new functionality. Change-Id: I5d80ff6dc52b4f0dc0e7adf16159df32858f8815
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.systemui.scene.domain.startable
|
||||
|
||||
import com.android.systemui.CoreStartable
|
||||
import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor
|
||||
import com.android.systemui.authentication.domain.model.AuthenticationMethodModel
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.dagger.qualifiers.Application
|
||||
import com.android.systemui.dagger.qualifiers.DisplayId
|
||||
@@ -135,22 +136,27 @@ constructor(
|
||||
|
||||
applicationScope.launch {
|
||||
keyguardInteractor.wakefulnessModel
|
||||
.map { it.state == WakefulnessState.ASLEEP }
|
||||
.map { wakefulnessModel -> wakefulnessModel.state }
|
||||
.distinctUntilChanged()
|
||||
.collect { isAsleep ->
|
||||
if (isAsleep) {
|
||||
// When the device goes to sleep, reset the current scene.
|
||||
val isUnlocked = authenticationInteractor.isUnlocked.value
|
||||
val (targetSceneKey, loggingReason) =
|
||||
if (isUnlocked) {
|
||||
SceneKey.Gone to "device is asleep while unlocked"
|
||||
} else {
|
||||
SceneKey.Lockscreen to "device is asleep while locked"
|
||||
.collect { wakefulnessState ->
|
||||
when (wakefulnessState) {
|
||||
WakefulnessState.STARTING_TO_SLEEP -> {
|
||||
switchToScene(
|
||||
targetSceneKey = SceneKey.Lockscreen,
|
||||
loggingReason = "device is asleep",
|
||||
)
|
||||
}
|
||||
WakefulnessState.STARTING_TO_WAKE -> {
|
||||
val authMethod = authenticationInteractor.getAuthenticationMethod()
|
||||
if (authMethod == AuthenticationMethodModel.None) {
|
||||
switchToScene(
|
||||
targetSceneKey = SceneKey.Gone,
|
||||
loggingReason =
|
||||
"device is starting to wake up while auth method is None",
|
||||
)
|
||||
}
|
||||
switchToScene(
|
||||
targetSceneKey = targetSceneKey,
|
||||
loggingReason = loggingReason,
|
||||
)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.android.systemui.scene.domain.startable
|
||||
import android.view.Display
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.authentication.data.model.AuthenticationMethodModel
|
||||
import com.android.systemui.coroutines.collectLastValue
|
||||
import com.android.systemui.flags.Flags
|
||||
import com.android.systemui.keyguard.shared.model.WakeSleepReason
|
||||
@@ -244,40 +245,6 @@ class SceneContainerStartableTest : SysuiTestCase() {
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToGoneWhenDeviceSleepsUnlocked_featureEnabled() =
|
||||
testScope.runTest {
|
||||
val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key })
|
||||
prepareState(
|
||||
isFeatureEnabled = true,
|
||||
isDeviceUnlocked = true,
|
||||
initialSceneKey = SceneKey.Shade,
|
||||
)
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(ASLEEP)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Gone)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToGoneWhenDeviceSleepsUnlocked_featureDisabled() =
|
||||
testScope.runTest {
|
||||
val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key })
|
||||
prepareState(
|
||||
isFeatureEnabled = false,
|
||||
isDeviceUnlocked = true,
|
||||
initialSceneKey = SceneKey.Shade,
|
||||
)
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(ASLEEP)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToLockscreenWhenDeviceSleepsLocked_featureEnabled() =
|
||||
testScope.runTest {
|
||||
@@ -290,7 +257,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(ASLEEP)
|
||||
keyguardRepository.setWakefulnessModel(STARTING_TO_SLEEP)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
}
|
||||
@@ -307,7 +274,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(ASLEEP)
|
||||
keyguardRepository.setWakefulnessModel(STARTING_TO_SLEEP)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Shade)
|
||||
}
|
||||
@@ -334,22 +301,86 @@ class SceneContainerStartableTest : SysuiTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNone_featureEnabled() =
|
||||
testScope.runTest {
|
||||
val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key })
|
||||
prepareState(
|
||||
isFeatureEnabled = true,
|
||||
initialSceneKey = SceneKey.Lockscreen,
|
||||
authenticationMethod = AuthenticationMethodModel.None,
|
||||
)
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Gone)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNotNone_featureEnabled() =
|
||||
testScope.runTest {
|
||||
val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key })
|
||||
prepareState(
|
||||
isFeatureEnabled = true,
|
||||
initialSceneKey = SceneKey.Lockscreen,
|
||||
authenticationMethod = AuthenticationMethodModel.Pin,
|
||||
)
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNone_featureDisabled() =
|
||||
testScope.runTest {
|
||||
val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key })
|
||||
prepareState(
|
||||
isFeatureEnabled = false,
|
||||
initialSceneKey = SceneKey.Lockscreen,
|
||||
authenticationMethod = AuthenticationMethodModel.None,
|
||||
)
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
underTest.start()
|
||||
|
||||
keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE)
|
||||
|
||||
assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen)
|
||||
}
|
||||
|
||||
private fun prepareState(
|
||||
isFeatureEnabled: Boolean = true,
|
||||
isDeviceUnlocked: Boolean = false,
|
||||
isBypassEnabled: Boolean = false,
|
||||
initialSceneKey: SceneKey? = null,
|
||||
authenticationMethod: AuthenticationMethodModel? = null,
|
||||
) {
|
||||
featureFlags.set(Flags.SCENE_CONTAINER, isFeatureEnabled)
|
||||
authenticationRepository.setUnlocked(isDeviceUnlocked)
|
||||
keyguardRepository.setBypassEnabled(isBypassEnabled)
|
||||
initialSceneKey?.let { sceneInteractor.setCurrentScene(SceneModel(it), "reason") }
|
||||
authenticationMethod?.let {
|
||||
authenticationRepository.setAuthenticationMethod(authenticationMethod)
|
||||
authenticationRepository.setLockscreenEnabled(
|
||||
authenticationMethod != AuthenticationMethodModel.None
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ASLEEP =
|
||||
private val STARTING_TO_SLEEP =
|
||||
WakefulnessModel(
|
||||
state = WakefulnessState.ASLEEP,
|
||||
state = WakefulnessState.STARTING_TO_SLEEP,
|
||||
lastWakeReason = WakeSleepReason.POWER_BUTTON,
|
||||
lastSleepReason = WakeSleepReason.POWER_BUTTON
|
||||
)
|
||||
private val STARTING_TO_WAKE =
|
||||
WakefulnessModel(
|
||||
state = WakefulnessState.STARTING_TO_WAKE,
|
||||
lastWakeReason = WakeSleepReason.POWER_BUTTON,
|
||||
lastSleepReason = WakeSleepReason.POWER_BUTTON
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user