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

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

Merge "Support GONE->OCCLUDED" into main

parents 391f8136 71f2e261
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.keyguard.domain.interactor

import com.android.systemui.keyguard.shared.model.DozeStateModel.Companion.isDozeOff
import com.android.systemui.coroutines.collectLastValue
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -28,18 +26,16 @@ import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepos
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.statusbar.domain.interactor.keyguardOcclusionInteractor
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -49,7 +45,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.reset
import org.mockito.Mockito.spy
import com.google.common.truth.Truth.assertThat

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
+24 −0
Original line number Diff line number Diff line
@@ -756,6 +756,30 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
            coroutineContext.cancelChildren()
        }

    @Test
    @BrokenWithSceneContainer(339465026)
    fun goneToOccluded() =
        testScope.runTest {
            // GIVEN a prior transition has run to GONE
            runTransitionAndSetWakefulness(KeyguardState.LOCKSCREEN, KeyguardState.GONE)

            // WHEN an occluding app is running and showDismissibleKeyguard is called
            keyguardRepository.setKeyguardOccluded(true)
            keyguardRepository.showDismissibleKeyguard()
            runCurrent()

            assertThat(transitionRepository)
                .startedTransition(
                    from = KeyguardState.GONE,
                    to = KeyguardState.OCCLUDED,
                    ownerName =
                        "FromGoneTransitionInteractor" + "(Dismissible keyguard with occlusion)",
                    animatorAssertion = { it.isNotNull() }
                )

            coroutineContext.cancelChildren()
        }

    @Test
    @DisableSceneContainer
    fun goneToDreaming() =
+3 −0
Original line number Diff line number Diff line
@@ -645,6 +645,9 @@ public class KeyguardService extends Service {
        public void showDismissibleKeyguard() {
            trace("showDismissibleKeyguard");
            checkPermission();
            if (mFoldGracePeriodProvider.get().isEnabled()) {
                mKeyguardInteractor.showDismissibleKeyguard();
            }
            mKeyguardViewMediator.showDismissibleKeyguard();

            if (SceneContainerFlag.isEnabled() && mFoldGracePeriodProvider.get().isEnabled()) {
+11 −0
Original line number Diff line number Diff line
@@ -232,6 +232,9 @@ interface KeyguardRepository {
    /** Receive an event for doze time tick */
    val dozeTimeTick: Flow<Long>

    /** Receive an event lockscreen being shown in a dismissible state */
    val showDismissibleKeyguard: MutableStateFlow<Long>

    /** Observable for DismissAction */
    val dismissAction: StateFlow<DismissAction>

@@ -305,6 +308,8 @@ interface KeyguardRepository {

    fun dozeTimeTick()

    fun showDismissibleKeyguard()

    fun setDismissAction(dismissAction: DismissAction)

    suspend fun setKeyguardDone(keyguardDoneType: KeyguardDone)
@@ -439,6 +444,12 @@ constructor(
        _dozeTimeTick.value = systemClock.uptimeMillis()
    }

    override val showDismissibleKeyguard = MutableStateFlow<Long>(0L)

    override fun showDismissibleKeyguard() {
        showDismissibleKeyguard.value = systemClock.uptimeMillis()
    }

    private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
    override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow()

+26 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ constructor(
        listenForGoneToAodOrDozing()
        listenForGoneToDreaming()
        listenForGoneToLockscreenOrHub()
        listenForGoneToOccluded()
        listenForGoneToDreamingLockscreenHosted()
    }

@@ -81,6 +82,27 @@ constructor(
        scope.launch("$TAG#showKeyguard") { startTransitionTo(KeyguardState.LOCKSCREEN) }
    }

    /**
     * A special case supported on foldables, where folding the device may put the device on an
     * unlocked lockscreen, but if an occluding app is already showing (like a active phone call),
     * then go directly to OCCLUDED.
     */
    private fun listenForGoneToOccluded() {
        scope.launch("$TAG#listenForGoneToOccluded") {
            keyguardInteractor.showDismissibleKeyguard
                .filterRelevantKeyguardState()
                .sample(keyguardInteractor.isKeyguardOccluded, ::Pair)
                .collect { (_, isKeyguardOccluded) ->
                    if (isKeyguardOccluded) {
                        startTransitionTo(
                            KeyguardState.OCCLUDED,
                            ownerReason = "Dismissible keyguard with occlusion"
                        )
                    }
                }
        }
    }

    // Primarily for when the user chooses to lock down the device
    private fun listenForGoneToLockscreenOrHub() {
        if (KeyguardWmStateRefactor.isEnabled) {
@@ -166,11 +188,12 @@ constructor(
            interpolator = Interpolators.LINEAR
            duration =
                when (toState) {
                    KeyguardState.DREAMING -> TO_DREAMING_DURATION
                    KeyguardState.AOD -> TO_AOD_DURATION
                    KeyguardState.DOZING -> TO_DOZING_DURATION
                    KeyguardState.DREAMING -> TO_DREAMING_DURATION
                    KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION
                    KeyguardState.GLANCEABLE_HUB -> TO_GLANCEABLE_HUB_DURATION
                    KeyguardState.OCCLUDED -> TO_OCCLUDED_DURATION
                    else -> DEFAULT_DURATION
                }.inWholeMilliseconds
        }
@@ -179,10 +202,11 @@ constructor(
    companion object {
        private const val TAG = "FromGoneTransitionInteractor"
        private val DEFAULT_DURATION = 500.milliseconds
        val TO_DREAMING_DURATION = 933.milliseconds
        val TO_AOD_DURATION = 1300.milliseconds
        val TO_DOZING_DURATION = 933.milliseconds
        val TO_DREAMING_DURATION = 933.milliseconds
        val TO_LOCKSCREEN_DURATION = DEFAULT_DURATION
        val TO_GLANCEABLE_HUB_DURATION = DEFAULT_DURATION
        val TO_OCCLUDED_DURATION = 100.milliseconds
    }
}
Loading