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

Commit e6249b76 authored by brycelee's avatar brycelee
Browse files

Do not allow low light ambient monitoring when on battery.

This changelist ensures that low light monitoring does not occur when
on battery.

Test: atest LowLightBehaviorCoreStartableTest#testDoNotSubscribeIfDozingForScreenOffBehaviorUnplugged
Fixes: 428556986
Flag: EXEMPT bugfix
Change-Id: I466505654ebed4da10b65f553d4d33aced453304
parent f6ad5c42
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.data.repository.batteryRepository
import com.android.systemui.common.data.repository.fake
import com.android.systemui.common.domain.interactor.batteryInteractor
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.display.domain.interactor.displayStateInteractor
import com.android.systemui.dreams.domain.interactor.dreamSettingsInteractorKosmos
@@ -84,6 +87,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() {
                lowLightBehaviorShellCommand = lowLightBehaviorShellCommand,
                lowLightShellCommand = lowLightShellCommand,
                scope = backgroundScope,
                batteryInteractor = batteryInteractor,
            )
        }

@@ -91,6 +95,10 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() {
        displayRepository.setDefaultDisplayOff(!screenOn)
    }

    private fun Kosmos.setBatteryPluggedIn(pluggedIn: Boolean) {
        batteryRepository.fake.setDevicePluggedIn(pluggedIn)
    }

    private fun Kosmos.setDreamEnabled(enabled: Boolean) {
        fakeSettings.putBoolForUser(
            Settings.Secure.SCREENSAVER_ENABLED,
@@ -142,6 +150,8 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() {
            )
        }
        kosmos.lowLightRepository.addAction(LowLightDisplayBehavior.LOW_LIGHT_DREAM, action)

        kosmos.batteryRepository.fake.setDevicePluggedIn(true)
    }

    @Test
@@ -266,6 +276,7 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() {
                LowLightDisplayBehavior.SCREEN_OFF
            )

            setBatteryPluggedIn(true)
            setDisplayOn(true)

            fakeKeyguardRepository.setDozeTransitionModel(
@@ -276,6 +287,25 @@ class LowLightBehaviorCoreStartableTest : SysuiTestCase() {
            assertThat(ambientLightModeMonitor.fake.started).isTrue()
        }

    @Test
    fun testDoNotSubscribeIfDozingForScreenOffBehaviorUnplugged() =
        kosmos.runTest {
            lowLightRepository.addAction(LowLightDisplayBehavior.SCREEN_OFF, action)
            lowLightSettingsRepository.setLowLightDisplayBehavior(
                LowLightDisplayBehavior.SCREEN_OFF
            )

            setBatteryPluggedIn(false)
            setDisplayOn(true)

            fakeKeyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(from = DozeStateModel.UNINITIALIZED, to = DozeStateModel.DOZE)
            )

            underTest.start()
            assertThat(ambientLightModeMonitor.fake.started).isFalse()
        }

    private fun Kosmos.setLowLightFromSensor(lowlight: Boolean) {
        val lightMode =
            if (lowlight) {
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.os.Flags
import android.os.UserHandle
import com.android.internal.logging.UiEventLogger
import com.android.systemui.CoreStartable
import com.android.systemui.common.domain.interactor.BatteryInteractor
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.display.domain.interactor.DisplayStateInteractor
import com.android.systemui.dreams.domain.interactor.DreamSettingsInteractor
@@ -74,11 +75,15 @@ constructor(
    private val uiEventLogger: UiEventLogger,
    private val lowLightBehaviorShellCommand: LowLightBehaviorShellCommand,
    private val lowLightShellCommand: LowLightShellCommand,
    batteryInteractor: BatteryInteractor,
) : CoreStartable {

    /** Whether the screen is currently on. */
    private val isScreenOn = not(displayStateInteractor.isDefaultDisplayOff).distinctUntilChanged()

    /** Whether device is plugged in */
    private val isPluggedIn = batteryInteractor.isDevicePluggedIn.distinctUntilChanged()

    /** Whether the device is currently in a low-light environment. */
    private val isLowLightFromSensor =
        if (Flags.lowLightDreamBehavior()) {
@@ -152,6 +157,7 @@ constructor(
        return allOf(
                anyOf(isScreenOn, flowOf(behavior.allowedInScreenState(ScreenState.OFF))),
                dreamSettingsInteractor.dreamingEnabled,
                isPluggedIn,
            )
            .flatMapLatestConflated {
                // The second set of conditions are separated from the above allOf flow combination