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

Commit 7018b6bd authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Handle KeyguardService#setKeyguardEnabled." into main

parents 7d00e139 a77a1844
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.systemui.SystemUIApplication;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.keyguard.domain.interactor.KeyguardEnabledInteractor;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindParamsApplier;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindParamsApplier;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindViewBinder;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindViewBinder;
import com.android.systemui.keyguard.ui.binder.WindowManagerLockscreenVisibilityViewBinder;
import com.android.systemui.keyguard.ui.binder.WindowManagerLockscreenVisibilityViewBinder;
@@ -311,6 +312,7 @@ public class KeyguardService extends Service {
    }
    }


    private final WindowManagerOcclusionManager mWmOcclusionManager;
    private final WindowManagerOcclusionManager mWmOcclusionManager;
    private final KeyguardEnabledInteractor mKeyguardEnabledInteractor;


    private final Lazy<FoldGracePeriodProvider> mFoldGracePeriodProvider = new Lazy<>() {
    private final Lazy<FoldGracePeriodProvider> mFoldGracePeriodProvider = new Lazy<>() {
        @Override
        @Override
@@ -335,7 +337,8 @@ public class KeyguardService extends Service {
            PowerInteractor powerInteractor,
            PowerInteractor powerInteractor,
            WindowManagerOcclusionManager windowManagerOcclusionManager,
            WindowManagerOcclusionManager windowManagerOcclusionManager,
            Lazy<SceneInteractor> sceneInteractorLazy,
            Lazy<SceneInteractor> sceneInteractorLazy,
            @Main Executor mainExecutor) {
            @Main Executor mainExecutor,
            KeyguardEnabledInteractor keyguardEnabledInteractor) {
        super();
        super();
        mKeyguardViewMediator = keyguardViewMediator;
        mKeyguardViewMediator = keyguardViewMediator;
        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
@@ -360,6 +363,7 @@ public class KeyguardService extends Service {
        }
        }


        mWmOcclusionManager = windowManagerOcclusionManager;
        mWmOcclusionManager = windowManagerOcclusionManager;
        mKeyguardEnabledInteractor = keyguardEnabledInteractor;
    }
    }


    @Override
    @Override
@@ -598,6 +602,7 @@ public class KeyguardService extends Service {
        public void setKeyguardEnabled(boolean enabled) {
        public void setKeyguardEnabled(boolean enabled) {
            trace("setKeyguardEnabled enabled" + enabled);
            trace("setKeyguardEnabled enabled" + enabled);
            checkPermission();
            checkPermission();
            mKeyguardEnabledInteractor.notifyKeyguardEnabled(enabled);
            mKeyguardViewMediator.setKeyguardEnabled(enabled);
            mKeyguardViewMediator.setKeyguardEnabled(enabled);
        }
        }


+23 −0
Original line number Original line Diff line number Diff line
@@ -109,6 +109,19 @@ interface KeyguardRepository {
    )
    )
    val isKeyguardGoingAway: Flow<Boolean>
    val isKeyguardGoingAway: Flow<Boolean>


    /**
     * 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.
     */
    val isKeyguardEnabled: StateFlow<Boolean>

    /** Is the always-on display available to be used? */
    /** Is the always-on display available to be used? */
    val isAodAvailable: StateFlow<Boolean>
    val isAodAvailable: StateFlow<Boolean>


@@ -269,6 +282,9 @@ interface KeyguardRepository {
            "'keyguardDoneAnimationsFinished' is when the GONE transition is finished."
            "'keyguardDoneAnimationsFinished' is when the GONE transition is finished."
    )
    )
    fun keyguardDoneAnimationsFinished()
    fun keyguardDoneAnimationsFinished()

    /** Sets whether the keyguard is enabled (see [isKeyguardEnabled]). */
    fun setKeyguardEnabled(enabled: Boolean)
}
}


/** Encapsulates application state for the keyguard. */
/** Encapsulates application state for the keyguard. */
@@ -439,6 +455,9 @@ constructor(
        awaitClose { keyguardStateController.removeCallback(callback) }
        awaitClose { keyguardStateController.removeCallback(callback) }
    }
    }


    private val _isKeyguardEnabled = MutableStateFlow(true)
    override val isKeyguardEnabled: StateFlow<Boolean> = _isKeyguardEnabled.asStateFlow()

    private val _isDozing = MutableStateFlow(statusBarStateController.isDozing)
    private val _isDozing = MutableStateFlow(statusBarStateController.isDozing)
    override val isDozing: StateFlow<Boolean> = _isDozing.asStateFlow()
    override val isDozing: StateFlow<Boolean> = _isDozing.asStateFlow()


@@ -664,6 +683,10 @@ constructor(
        _clockShouldBeCentered.value = shouldBeCentered
        _clockShouldBeCentered.value = shouldBeCentered
    }
    }


    override fun setKeyguardEnabled(enabled: Boolean) {
        _isKeyguardEnabled.value = enabled
    }

    private fun statusBarStateIntToObject(value: Int): StatusBarState {
    private fun statusBarStateIntToObject(value: Int): StatusBarState {
        return when (value) {
        return when (value) {
            0 -> StatusBarState.SHADE
            0 -> StatusBarState.SHADE
+8 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.app.tracing.coroutines.launch
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
@@ -50,6 +51,7 @@ constructor(
    private val keyguardInteractor: KeyguardInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    powerInteractor: PowerInteractor,
    powerInteractor: PowerInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    val deviceEntryRepository: DeviceEntryRepository,
) :
) :
    TransitionInteractor(
    TransitionInteractor(
        fromState = KeyguardState.AOD,
        fromState = KeyguardState.AOD,
@@ -125,7 +127,12 @@ constructor(
                        val shouldTransitionToOccluded =
                        val shouldTransitionToOccluded =
                            !KeyguardWmStateRefactor.isEnabled && isKeyguardOccludedLegacy
                            !KeyguardWmStateRefactor.isEnabled && isKeyguardOccludedLegacy


                        if (canDismissLockscreen) {
                        val shouldTransitionToGone =
                            (!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen) ||
                                (KeyguardWmStateRefactor.isEnabled &&
                                    !deviceEntryRepository.isLockscreenEnabled())

                        if (shouldTransitionToGone) {
                            startTransitionTo(
                            startTransitionTo(
                                toState = KeyguardState.GONE,
                                toState = KeyguardState.GONE,
                            )
                            )
+13 −3
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
@@ -50,6 +51,7 @@ constructor(
    powerInteractor: PowerInteractor,
    powerInteractor: PowerInteractor,
    private val communalInteractor: CommunalInteractor,
    private val communalInteractor: CommunalInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    val deviceEntryRepository: DeviceEntryRepository,
) :
) :
    TransitionInteractor(
    TransitionInteractor(
        fromState = KeyguardState.DOZING,
        fromState = KeyguardState.DOZING,
@@ -99,7 +101,9 @@ constructor(
                        canTransitionToGoneOnWake,
                        canTransitionToGoneOnWake,
                        primaryBouncerShowing) ->
                        primaryBouncerShowing) ->
                    startTransitionTo(
                    startTransitionTo(
                        if (isWakeAndUnlock(biometricUnlockState.mode)) {
                        if (!deviceEntryRepository.isLockscreenEnabled()) {
                            KeyguardState.GONE
                        } else if (isWakeAndUnlock(biometricUnlockState.mode)) {
                            KeyguardState.GONE
                            KeyguardState.GONE
                        } else if (canTransitionToGoneOnWake) {
                        } else if (canTransitionToGoneOnWake) {
                            KeyguardState.GONE
                            KeyguardState.GONE
@@ -145,7 +149,12 @@ constructor(
                            !isWakeAndUnlock(biometricUnlockState.mode)
                            !isWakeAndUnlock(biometricUnlockState.mode)
                    ) {
                    ) {
                        startTransitionTo(
                        startTransitionTo(
                            if (canDismissLockscreen) {
                            if (!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen) {
                                KeyguardState.GONE
                            } else if (
                                KeyguardWmStateRefactor.isEnabled &&
                                    !deviceEntryRepository.isLockscreenEnabled()
                            ) {
                                KeyguardState.GONE
                                KeyguardState.GONE
                            } else if (primaryBouncerShowing) {
                            } else if (primaryBouncerShowing) {
                                KeyguardState.PRIMARY_BOUNCER
                                KeyguardState.PRIMARY_BOUNCER
@@ -153,7 +162,8 @@ constructor(
                                KeyguardState.GLANCEABLE_HUB
                                KeyguardState.GLANCEABLE_HUB
                            } else {
                            } else {
                                KeyguardState.LOCKSCREEN
                                KeyguardState.LOCKSCREEN
                            }
                            },
                            ownerReason = "waking from dozing"
                        )
                        )
                    }
                    }
                }
                }
+19 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
import com.android.systemui.keyguard.data.repository.KeyguardRepository
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
@@ -36,6 +37,7 @@ import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import kotlinx.coroutines.launch


@SysUISingleton
@SysUISingleton
@@ -52,6 +54,8 @@ constructor(
    private val communalInteractor: CommunalInteractor,
    private val communalInteractor: CommunalInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    keyguardOcclusionInteractor: KeyguardOcclusionInteractor,
    private val biometricSettingsRepository: BiometricSettingsRepository,
    private val biometricSettingsRepository: BiometricSettingsRepository,
    private val keyguardRepository: KeyguardRepository,
    private val keyguardEnabledInteractor: KeyguardEnabledInteractor,
) :
) :
    TransitionInteractor(
    TransitionInteractor(
        fromState = KeyguardState.GONE,
        fromState = KeyguardState.GONE,
@@ -93,6 +97,21 @@ constructor(
                        startTransitionTo(to, ownerReason = "User initiated lockdown")
                        startTransitionTo(to, ownerReason = "User initiated lockdown")
                    }
                    }
            }
            }

            scope.launch {
                keyguardRepository.isKeyguardEnabled
                    .filterRelevantKeyguardStateAnd { enabled -> enabled }
                    .sample(keyguardEnabledInteractor.showKeyguardWhenReenabled)
                    .filter { reshow -> reshow }
                    .collect {
                        startTransitionTo(
                            KeyguardState.LOCKSCREEN,
                            ownerReason =
                                "Keyguard was re-enabled, and we weren't GONE when it " +
                                    "was originally disabled"
                        )
                    }
            }
        } else {
        } else {
            scope.launch("$TAG#listenForGoneToLockscreenOrHub") {
            scope.launch("$TAG#listenForGoneToLockscreenOrHub") {
                keyguardInteractor.isKeyguardShowing
                keyguardInteractor.isKeyguardShowing
Loading