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

Commit 0dea5a3d authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Block background dream launch during widget launch and occlusion." into main

parents 8b3b67cb 55f32a1f
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
import com.android.systemui.flags.fakeFeatureFlagsClassic
@@ -73,6 +74,7 @@ class CommunalDreamStartableTest : SysuiTestCase() {
                    keyguardInteractor = kosmos.keyguardInteractor,
                    keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor,
                    dreamManager = dreamManager,
                    communalSceneInteractor = kosmos.communalSceneInteractor,
                    bgScope = kosmos.applicationCoroutineScope,
                )
                .apply { start() }
@@ -158,6 +160,36 @@ class CommunalDreamStartableTest : SysuiTestCase() {
            }
        }

    @Test
    fun shouldNotStartDreamWhenLaunchingWidget() =
        testScope.runTest {
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            kosmos.communalSceneInteractor.setIsLaunchingWidget(true)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
            runCurrent()

            transition(from = KeyguardState.DREAMING, to = KeyguardState.GLANCEABLE_HUB)

            verify(dreamManager, never()).startDream()
        }

    @Test
    fun shouldNotStartDreamWhenOccluded() =
        testScope.runTest {
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            keyguardRepository.setKeyguardOccluded(true)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
            runCurrent()

            transition(from = KeyguardState.DREAMING, to = KeyguardState.GLANCEABLE_HUB)

            verify(dreamManager, never()).startDream()
        }

    private suspend fun TestScope.transition(from: KeyguardState, to: KeyguardState) {
        kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
            from = from,
+4 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.DreamManager
import com.android.systemui.CoreStartable
import com.android.systemui.Flags.glanceableHubAllowKeyguardWhenDreaming
import com.android.systemui.Flags.restartDreamOnUnocclude
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
@@ -55,6 +56,7 @@ constructor(
    private val keyguardInteractor: KeyguardInteractor,
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val dreamManager: DreamManager,
    private val communalSceneInteractor: CommunalSceneInteractor,
    @Background private val bgScope: CoroutineScope,
) : CoreStartable {
    /** Flow that emits when the dream should be started underneath the glanceable hub. */
@@ -66,6 +68,8 @@ constructor(
                not(keyguardInteractor.isDreaming),
                // TODO(b/362830856): Remove this workaround.
                keyguardInteractor.isKeyguardShowing,
                not(communalSceneInteractor.isLaunchingWidget),
                not(keyguardInteractor.isKeyguardOccluded),
            )
            .filter { it }