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

Commit d89cec2f authored by Bryce Lee's avatar Bryce Lee Committed by brycelee
Browse files

Execute low light conditions on background thread.

This changelist ensures that low light logic occurs within the
background scope so no blocking calls are made on the main thread.
The only exception is DeviceInactiveCondition, which requires
keyguard update callbacks to be registered on the main thread.

Fixes: 394520234
Test: atest DirectBootConditionTest
Test: atest DeviceInactiveConditionTest
Test: atest ForceLowLightConditionTest
Test: atest LowLightConditionTest
Test: atest ScreenSaverEnabledConditionTest
Flag: EXEMPT bugfix
Change-Id: Iab9dd2ae99ef698ee185b148634807f2503b0143
parent 3b3ec4a9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ class DeviceInactiveConditionTest : SysuiTestCase() {
    private val Kosmos.underTest by
        Kosmos.Fixture {
            DeviceInactiveCondition(
                applicationCoroutineScope,
                applicationCoroutineScope,
                keyguardStateController,
                wakefulnessLifecycle,
+8 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.communal
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.shared.model.DozeStateModel.Companion.isDozeOff
@@ -28,6 +29,7 @@ import com.android.systemui.util.kotlin.JavaAdapter
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch

/**
 * Condition which estimates device inactivity in order to avoid launching a full-screen activity
@@ -36,13 +38,14 @@ import kotlinx.coroutines.Job
class DeviceInactiveCondition
@Inject
constructor(
    @Application scope: CoroutineScope,
    @Application private val applicationScope: CoroutineScope,
    @Background backgroundScope: CoroutineScope,
    private val keyguardStateController: KeyguardStateController,
    private val wakefulnessLifecycle: WakefulnessLifecycle,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val keyguardInteractor: KeyguardInteractor,
    private val javaAdapter: JavaAdapter,
) : Condition(scope) {
) : Condition(backgroundScope) {
    private var anyDozeListenerJob: Job? = null
    private var anyDoze = false
    private val keyguardStateCallback: KeyguardStateController.Callback =
@@ -67,7 +70,9 @@ constructor(
    override suspend fun start() {
        updateState()
        keyguardStateController.addCallback(keyguardStateCallback)
        keyguardUpdateMonitor.registerCallback(keyguardUpdateCallback)

        // Keyguard update monitor callbacks must be registered on the main thread
        applicationScope.launch { keyguardUpdateMonitor.registerCallback(keyguardUpdateCallback) }
        wakefulnessLifecycle.addObserver(wakefulnessObserver)
        anyDozeListenerJob =
            javaAdapter.alwaysCollectFlow(keyguardInteractor.dozeTransitionModel) {
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.UserManager
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.shared.condition.Condition
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -35,7 +35,7 @@ class DirectBootCondition
constructor(
    broadcastDispatcher: BroadcastDispatcher,
    private val userManager: UserManager,
    @Application private val coroutineScope: CoroutineScope,
    @Background private val coroutineScope: CoroutineScope,
) : Condition(coroutineScope) {
    private var job: Job? = null
    private val directBootFlow =
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ package com.android.systemui.lowlightclock

import android.text.TextUtils
import android.util.Log
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.shared.condition.Condition
import com.android.systemui.statusbar.commandline.Command
import com.android.systemui.statusbar.commandline.CommandRegistry
@@ -31,7 +31,7 @@ import kotlinx.coroutines.CoroutineScope
 */
class ForceLowLightCondition
@Inject
constructor(@Application scope: CoroutineScope, commandRegistry: CommandRegistry) :
constructor(@Background scope: CoroutineScope, commandRegistry: CommandRegistry) :
    Condition(scope, null, true) {
    /**
     * Default Constructor.
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
package com.android.systemui.lowlightclock

import com.android.internal.logging.UiEventLogger
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.shared.condition.Condition
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -25,7 +25,7 @@ import kotlinx.coroutines.CoroutineScope
class LowLightCondition
@Inject
constructor(
    @Application scope: CoroutineScope,
    @Background scope: CoroutineScope,
    private val ambientLightModeMonitor: AmbientLightModeMonitor,
    private val uiEventLogger: UiEventLogger,
) : Condition(scope) {
Loading