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

Commit bdb510af authored by Bryce Lee's avatar Bryce Lee
Browse files

Listen to DisplayStateInteractor for LowLightMonitor display changes.

This change switches to DisplayStateInteractor for default display
on/off state, which handles the case where the screen is turned off due
to proximity.

Fixes: 402352708
Flag: EXEMPT bugfix
Test: atest LowLightMonitorTest
Change-Id: Ie6b4dd453a6a62f573c08eabf708a5db4a506b5a
parent 7d72a8d0
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.dream.lowlight.LowLightDreamManager
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.domain.interactor.displayStateInteractor
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.power.data.repository.fakePowerRepository
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.shared.condition.Condition
import com.android.systemui.shared.condition.Monitor
import com.android.systemui.testKosmos
@@ -86,13 +86,7 @@ class LowLightMonitorTest : SysuiTestCase() {
    }

    private fun setDisplayOn(screenOn: Boolean) {
        kosmos.fakePowerRepository.setScreenPowerState(
            if (screenOn) {
                ScreenPowerState.SCREEN_ON
            } else {
                ScreenPowerState.SCREEN_OFF
            }
        )
        kosmos.displayRepository.setDefaultDisplayOff(!screenOn)
    }

    @Before
@@ -105,7 +99,7 @@ class LowLightMonitorTest : SysuiTestCase() {
                lowLightDreamManagerLazy,
                monitor,
                lazyConditions,
                kosmos.powerInteractor,
                kosmos.displayStateInteractor,
                logger,
                dreamComponent,
                packageManager,
@@ -205,6 +199,7 @@ class LowLightMonitorTest : SysuiTestCase() {
            setDisplayOn(true)
            clearInvocations(monitor)
            setDisplayOn(false)
            runCurrent()
            // Verify doesn't remove subscription since there is none.
            Mockito.verify(monitor).removeSubscription(ArgumentMatchers.any())
        }
@@ -221,7 +216,7 @@ class LowLightMonitorTest : SysuiTestCase() {
                    lowLightDreamManagerLazy,
                    monitor,
                    lazyConditions,
                    powerInteractor,
                    displayStateInteractor,
                    logger,
                    dreamComponent,
                    packageManager,
@@ -251,7 +246,7 @@ class LowLightMonitorTest : SysuiTestCase() {
                    lowLightDreamManagerLazy,
                    monitor,
                    lazyConditions,
                    powerInteractor,
                    displayStateInteractor,
                    logger,
                    null,
                    packageManager,
+4 −8
Original line number Diff line number Diff line
@@ -18,15 +18,15 @@ package com.android.systemui.lowlightclock
import android.content.ComponentName
import android.content.pm.PackageManager
import com.android.dream.lowlight.LowLightDreamManager
import com.android.systemui.biometrics.domain.interactor.DisplayStateInteractor
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.SystemUser
import com.android.systemui.dreams.dagger.DreamModule
import com.android.systemui.lowlightclock.dagger.LowLightModule
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.shared.condition.Condition
import com.android.systemui.shared.condition.Monitor
import com.android.systemui.util.condition.ConditionalCoreStartable
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import dagger.Lazy
import javax.inject.Inject
@@ -38,7 +38,6 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

/**
@@ -52,17 +51,14 @@ constructor(
    @param:SystemUser private val conditionsMonitor: Monitor,
    @param:Named(LowLightModule.LOW_LIGHT_PRECONDITIONS)
    private val lowLightConditions: Lazy<Set<Condition>>,
    powerInteractor: PowerInteractor,
    displayStateInteractor: DisplayStateInteractor,
    private val logger: LowLightLogger,
    @param:Named(DreamModule.LOW_LIGHT_DREAM_SERVICE)
    private val lowLightDreamService: ComponentName?,
    private val packageManager: PackageManager,
    @Background private val scope: CoroutineScope,
) : ConditionalCoreStartable(conditionsMonitor) {
    private val isScreenOn =
        powerInteractor.screenPowerState
            .map { it == ScreenPowerState.SCREEN_ON }
            .distinctUntilChanged()
    private val isScreenOn = not(displayStateInteractor.isDefaultDisplayOff).distinctUntilChanged()

    private val isLowLight = conflatedCallbackFlow {
        val token =