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

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

Merge changes Idda37d4e,I5b5ad599 into main

* changes:
  If a PRIMARY_BOUNCER->LOCKSCREEN is running...
  Hide keyguard immediately on DOZING->GONE
parents caa3f365 5ffdbdd5
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class DozingToGoneTransitionViewModelTest : SysuiTestCase() {
    @Test
    fun lockscreenAlpha() =
        testScope.runTest {
            val viewState = ViewStateAccessor(alpha = { 0.6f })
            val viewState = ViewStateAccessor()
            val alpha by collectValues(underTest.lockscreenAlpha(viewState))

            keyguardTransitionRepository.sendTransitionSteps(
@@ -62,11 +62,9 @@ class DozingToGoneTransitionViewModelTest : SysuiTestCase() {
                testScope
            )

            assertThat(alpha[0]).isEqualTo(0.6f)
            // Fades out just prior to halfway
            // Remain at zero throughout
            assertThat(alpha[0]).isEqualTo(0f)
            assertThat(alpha[1]).isEqualTo(0f)
            // Must finish at 0
            assertThat(alpha[2]).isEqualTo(0f)
        }

    @Test
+47 −0
Original line number Diff line number Diff line
@@ -398,6 +398,53 @@ class KeyguardRootViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    fun alphaFromShadeExpansion_doesNotEmitWhenTransitionRunning() =
        testScope.runTest {
            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
                to = KeyguardState.LOCKSCREEN,
                testScope,
            )

            val alpha by collectLastValue(underTest.alpha(viewState))
            shadeTestUtil.setQsExpansion(0f)
            runCurrent()
            assertThat(alpha).isEqualTo(1f)

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.PRIMARY_BOUNCER,
                testScope,
            )
            assertThat(alpha).isEqualTo(0f)

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
                    TransitionStep(
                        from = KeyguardState.PRIMARY_BOUNCER,
                        to = KeyguardState.LOCKSCREEN,
                        transitionState = TransitionState.STARTED,
                        value = 0f,
                    ),
                    TransitionStep(
                        from = KeyguardState.PRIMARY_BOUNCER,
                        to = KeyguardState.LOCKSCREEN,
                        transitionState = TransitionState.RUNNING,
                        value = 0.8f,
                    ),
                ),
                testScope,
            )
            // Alpha should be 1f from the above transition
            assertThat(alpha).isEqualTo(1f)

            shadeTestUtil.setQsExpansion(0.5f)
            // Alpha should remain unchanged instead of fading out
            assertThat(alpha).isEqualTo(1f)
        }

    @Test
    fun alpha_shadeClosedOverLockscreen_isOne() =
        testScope.runTest {
+31 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.util.kotlin.Utils.Companion.sample
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
@@ -65,6 +66,7 @@ constructor(

    override fun start() {
        listenForDozingToAny()
        listenForDozingToGoneViaBiometrics()
        listenForWakeFromDozing()
        listenForTransitionToCamera(scope, keyguardInteractor)
    }
@@ -77,6 +79,35 @@ constructor(
            isKeyguardDismissible && !isKeyguardShowing
        }

    private fun listenForDozingToGoneViaBiometrics() {
        if (KeyguardWmStateRefactor.isEnabled) {
            return
        }

        // This is separate from `listenForDozingToAny` because any delay on wake and unlock will
        // cause a noticeable issue with animations
        scope.launch {
            powerInteractor.isAwake
                .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
                .sample(
                    keyguardInteractor.biometricUnlockState,
                    ::Pair,
                )
                .collect {
                    (
                        _,
                        biometricUnlockState,
                    ) ->
                    if (isWakeAndUnlock(biometricUnlockState.mode)) {
                        startTransitionTo(
                            KeyguardState.GONE,
                            ownerReason = "biometric wake and unlock",
                        )
                    }
                }
        }
    }

    private fun listenForDozingToAny() {
        if (KeyguardWmStateRefactor.isEnabled) {
            return
@@ -87,7 +118,6 @@ constructor(
                .debounce(50L)
                .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
                .sample(
                    keyguardInteractor.biometricUnlockState,
                    keyguardInteractor.isKeyguardOccluded,
                    communalInteractor.isIdleOnCommunal,
                    canTransitionToGoneOnWake,
@@ -96,7 +126,6 @@ constructor(
                .collect {
                    (
                        _,
                        biometricUnlockState,
                        occluded,
                        isIdleOnCommunal,
                        canTransitionToGoneOnWake,
@@ -104,8 +133,6 @@ constructor(
                    startTransitionTo(
                        if (!deviceEntryRepository.isLockscreenEnabled()) {
                            KeyguardState.GONE
                        } else if (isWakeAndUnlock(biometricUnlockState.mode)) {
                            KeyguardState.GONE
                        } else if (canTransitionToGoneOnWake) {
                            KeyguardState.GONE
                        } else if (primaryBouncerShowing) {
+11 −4
Original line number Diff line number Diff line
@@ -222,17 +222,24 @@ constructor(
    override fun getDefaultAnimatorForTransitionsToState(toState: KeyguardState): ValueAnimator {
        return ValueAnimator().apply {
            interpolator = Interpolators.LINEAR
            duration = DEFAULT_DURATION.inWholeMilliseconds
            duration =
                when (toState) {
                    KeyguardState.AOD -> TO_AOD_DURATION
                    KeyguardState.DOZING -> TO_DOZING_DURATION
                    KeyguardState.GONE -> TO_GONE_DURATION
                    KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION
                    else -> DEFAULT_DURATION
                }.inWholeMilliseconds
        }
    }

    companion object {
        private val DEFAULT_DURATION = 300.milliseconds
        val TO_GONE_DURATION = 500.milliseconds
        val TO_GONE_SHORT_DURATION = 200.milliseconds
        val TO_AOD_DURATION = DEFAULT_DURATION
        val TO_LOCKSCREEN_DURATION = DEFAULT_DURATION
        val TO_DOZING_DURATION = DEFAULT_DURATION
        val TO_GONE_DURATION = 500.milliseconds
        val TO_GONE_SHORT_DURATION = 200.milliseconds
        val TO_LOCKSCREEN_DURATION = 450.milliseconds
        val TO_GONE_SURFACE_BEHIND_VISIBLE_THRESHOLD = 0.5f
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -103,6 +103,12 @@ constructor(
            }
        }

        scope.launch {
            keyguardInteractor.isKeyguardGoingAway.collect {
                logger.log(TAG, VERBOSE, "isKeyguardGoingAway", it)
            }
        }

        scope.launch {
            keyguardInteractor.isKeyguardOccluded.collect {
                logger.log(TAG, VERBOSE, "isOccluded", it)
Loading