Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45830862 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Allow transition to Gone when keyguard is disabled.

If the keyguard is disabled, it's valid to go to the Gone scene, even if
the device is still locked.

Bug: 348644111
Test: added unit tests
Flag: com.android.systemui.scene_container
Change-Id: I129264678d800c88a5654762839e09f0183594b0
parent c9729d7e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.Idle
@@ -450,4 +451,16 @@ class SceneInteractorTest : SysuiTestCase() {
            progress.value = 0.9f
            assertThat(transitionValue).isEqualTo(0f)
        }

    @Test
    fun changeScene_toGone_whenKeyguardDisabled_doesNotThrow() =
        testScope.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
            kosmos.keyguardEnabledInteractor.notifyKeyguardEnabled(false)

            underTest.changeScene(Scenes.Gone, "")

            assertThat(currentScene).isEqualTo(Scenes.Gone)
        }
}
+32 −18
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
@@ -48,25 +49,18 @@ constructor(
    transitionInteractor: KeyguardTransitionInteractor,
) {

    init {
    /**
         * Whenever keyguard is disabled, transition to GONE unless we're in lockdown or already
         * GONE.
     * Whether the keyguard is enabled, per [KeyguardService]. If the keyguard is not enabled, the
     * lockscreen cannot be shown and the device will go from AOD/DOZING directly to GONE.
     *
     * Keyguard can be disabled by selecting Security: "None" in settings, or by apps that hold
     * permission to do so (such as Phone).
     *
     * If the keyguard is disabled while we're locked, we will transition to GONE unless we're in
     * lockdown mode. If the keyguard is re-enabled, we'll transition back to LOCKSCREEN if we were
     * locked when it was disabled.
     */
        scope.launch {
            repository.isKeyguardEnabled
                .filter { enabled -> !enabled }
                .sampleCombine(
                    biometricSettingsRepository.isCurrentUserInLockdown,
                    transitionInteractor.currentTransitionInfoInternal,
                )
                .collect { (_, inLockdown, currentTransitionInfo) ->
                    if (currentTransitionInfo.to != KeyguardState.GONE && !inLockdown) {
                        transitionInteractor.startDismissKeyguardTransition("keyguard disabled")
                    }
                }
        }
    }
    val isKeyguardEnabled: StateFlow<Boolean> = repository.isKeyguardEnabled

    /**
     * Whether we need to show the keyguard when the keyguard is re-enabled, since we hid it when it
@@ -86,6 +80,26 @@ constructor(
                transitionInfo.to != KeyguardState.GONE && !inLockdown
            }

    init {
        /**
         * Whenever keyguard is disabled, transition to GONE unless we're in lockdown or already
         * GONE.
         */
        scope.launch {
            repository.isKeyguardEnabled
                .filter { enabled -> !enabled }
                .sampleCombine(
                    biometricSettingsRepository.isCurrentUserInLockdown,
                    transitionInteractor.currentTransitionInfoInternal,
                )
                .collect { (_, inLockdown, currentTransitionInfo) ->
                    if (currentTransitionInfo.to != KeyguardState.GONE && !inLockdown) {
                        transitionInteractor.startDismissKeyguardTransition("keyguard disabled")
                    }
                }
        }
    }

    fun notifyKeyguardEnabled(enabled: Boolean) {
        repository.setKeyguardEnabled(enabled)
    }
+4 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardEnabledInteractor
import com.android.systemui.scene.data.repository.SceneContainerRepository
import com.android.systemui.scene.domain.resolver.SceneResolver
import com.android.systemui.scene.shared.logger.SceneLogger
@@ -60,6 +61,7 @@ constructor(
    private val logger: SceneLogger,
    private val sceneFamilyResolvers: Lazy<Map<SceneKey, @JvmSuppressWildcards SceneResolver>>,
    private val deviceUnlockedInteractor: DeviceUnlockedInteractor,
    private val keyguardEnabledInteractor: KeyguardEnabledInteractor,
) {

    interface OnSceneAboutToChangeListener {
@@ -381,7 +383,8 @@ constructor(
        val isChangeAllowed =
            to != Scenes.Gone ||
                inMidTransitionFromGone ||
                deviceUnlockedInteractor.deviceUnlockStatus.value.isUnlocked
                deviceUnlockedInteractor.deviceUnlockStatus.value.isUnlocked ||
                !keyguardEnabledInteractor.isKeyguardEnabled.value
        check(isChangeAllowed) {
            "Cannot change to the Gone scene while the device is locked and not currently" +
                " transitioning from Gone. Current transition state is ${transitionState.value}." +
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.scene.domain.interactor

import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.scene.data.repository.sceneContainerRepository
@@ -31,5 +32,6 @@ val Kosmos.sceneInteractor by
            logger = sceneLogger,
            sceneFamilyResolvers = { sceneFamilyResolvers },
            deviceUnlockedInteractor = deviceUnlockedInteractor,
            keyguardEnabledInteractor = keyguardEnabledInteractor,
        )
    }