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

Commit b8510490 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Move DisplayStateRepository flows in the background

This was causing delays in the ui thread after every unfold.

Bug: 312894757
Flag: None
Test: DisplayStateRepositoryTest
Change-Id: I2ddc4f8945f57a7c2776239ad4b7ab18566f1ba1
parent 73330b61
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -30,13 +30,16 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import java.util.concurrent.Executor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.stateIn

/** Repository for the current state of the display */
@@ -66,7 +69,8 @@ constructor(
    deviceStateManager: DeviceStateManager,
    displayManager: DisplayManager,
    @Main handler: Handler,
    @Main mainExecutor: Executor
    @Background backgroundExecutor: Executor,
    @Background backgroundDispatcher: CoroutineDispatcher,
) : DisplayStateRepository {
    override val isReverseDefaultRotation =
        context.resources.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)
@@ -94,9 +98,10 @@ constructor(
                    }

                sendRearDisplayStateUpdate(false)
                deviceStateManager.registerCallback(mainExecutor, callback)
                deviceStateManager.registerCallback(backgroundExecutor, callback)
                awaitClose { deviceStateManager.unregisterCallback(callback) }
            }
            .flowOn(backgroundDispatcher)
            .stateIn(
                applicationScope,
                started = SharingStarted.Eagerly,
@@ -137,6 +142,7 @@ constructor(
                )
                awaitClose { displayManager.unregisterDisplayListener(callback) }
            }
            .flowOn(backgroundDispatcher)
            .stateIn(
                applicationScope,
                started = SharingStarted.Eagerly,
+3 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
@@ -97,7 +98,8 @@ class DisplayStateRepositoryTest : SysuiTestCase() {
                deviceStateManager,
                displayManager,
                handler,
                fakeExecutor
                fakeExecutor,
                UnconfinedTestDispatcher(),
            )
    }