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

Commit 32295ed2 authored by Matt Pietal's avatar Matt Pietal
Browse files

Safety check for OCCLUDED on wakeup

There is a rare case where on device wakeup, occlusion also starts
as during a phone call. If these signals come in at just the wrong
time, the existing FromAodTransitionInteractor will decide to go
to LOCKSCREEN. This adds a failsafe check to ensure any transition
to LOCKSCREEN gets redirected to OCCLUDED if need be.

Fixes: 441275202
Test: atest FromLockscreenTransitionInteractor
Flag: EXEMPT bugfix
Change-Id: Ie88f7c6399911b5859e1c70c601deb884499f7f6
parent 5b13bd1e
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

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

import android.app.ActivityManager
import android.app.WindowConfiguration
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -29,7 +27,6 @@ import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
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.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.StatusBarState.KEYGUARD
@@ -69,6 +66,38 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
        transitionRepository = kosmos.fakeKeyguardTransitionRepository
    }

    @Test
    @DisableSceneContainer
    fun testOccludedFailsafe() =
        testScope.runTest {
            underTest.start()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.OFF,
                to = KeyguardState.AOD,
                testScope,
            )

            // Simulate the device being put into OCCLUDED state, but was somehow missed by the
            // FromAodTransitionInteractor
            keyguardRepository.setKeyguardOccluded(true)
            runCurrent()
            reset(transitionRepository)

            transitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                )
            )
            runCurrent()

            // After the above step was STARTED, the transition should be corrected to go to
            // OCCLUDED
            assertThatRepository(transitionRepository)
                .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.OCCLUDED)
        }

    @Test
    @DisableSceneContainer
    fun testSurfaceBehindVisibility() =
+20 −0
Original line number Diff line number Diff line
@@ -332,6 +332,26 @@ constructor(
                    .filterRelevantKeyguardStateAnd { isOccluded -> isOccluded }
                    .collect { startTransitionTo(KeyguardState.OCCLUDED) }
            }
            // Safety check added for incoming phone calls while on AOD/DOZING. If a transition has
            // begun to LOCKSCREEN but keyguard is occluded then make sure we change the transition
            // to go to OCCLUDED. This intentionally uses the [startedKeyguardTransitionStep] to
            // ensure that the transition has really begun
            scope.launch("$TAG#listenForLockscreenToOccludedOrDreamingFailSafe") {
                transitionInteractor.startedKeyguardTransitionStep
                    .filter {
                        it.from != KeyguardState.OCCLUDED &&
                            it.from != KeyguardState.DREAMING &&
                            it.to == KeyguardState.LOCKSCREEN
                    }
                    .collect {
                        if (keyguardInteractor.isKeyguardOccluded.value) {
                            startTransitionTo(
                                KeyguardState.OCCLUDED,
                                ownerReason = "occluded failsafe",
                            )
                        }
                    }
            }
        }
    }