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

Commit 4e2d4b72 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi
Browse files

Offload status bar network flows to bg

This moves ~100 blocking calls off of main thread during shade open CUJ,
which should significatly improve the performance.

Flag: com.android.systemui.qs_new_tiles
Bug: 384059560
Test: manual. open quick settings, enable or disable Wifi. Verify status
bar correctly reflects the state update.

Change-Id: I60d78be17e95157f02d5ca65fdc57b0607e1bc6a
parent 16125969
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.os.Handler
import android.provider.Settings.Global
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.log.table.TableLogBuffer
import com.android.systemui.log.table.logDiffsForTable
@@ -65,7 +64,7 @@ constructor(
    @Background private val backgroundContext: CoroutineContext,
    private val globalSettings: GlobalSettings,
    @AirplaneTableLog logger: TableLogBuffer,
    @Application scope: CoroutineScope,
    @Background scope: CoroutineScope,
) : AirplaneModeRepository {
    // TODO(b/254848912): Replace this with a generic SettingObserver coroutine once we have it.
    override val isAirplaneMode: StateFlow<Boolean> =
@@ -86,7 +85,7 @@ constructor(
                logger,
                columnPrefix = "",
                columnName = "isAirplaneMode",
                initialValue = false
                initialValue = false,
            )
            .stateIn(
                scope,
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.logDiffsForTable
import com.android.systemui.statusbar.pipeline.airplane.domain.interactor.AirplaneModeInteractor
@@ -48,7 +48,7 @@ class AirplaneModeViewModelImpl
constructor(
    interactor: AirplaneModeInteractor,
    @AirplaneTableLog logger: TableLogBuffer,
    @Application private val scope: CoroutineScope,
    @Background scope: CoroutineScope,
) : AirplaneModeViewModel {
    override val isAirplaneModeIconVisible: StateFlow<Boolean> =
        combine(interactor.isAirplaneMode, interactor.isForceHidden) {
+3 −3
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@

package com.android.systemui.statusbar.pipeline.mobile.data.repository

import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import com.android.app.tracing.coroutines.launchTraced as launch

/**
 * Core startable which configures the [CarrierConfigRepository] to listen for updates for the
@@ -30,7 +30,7 @@ class CarrierConfigCoreStartable
@Inject
constructor(
    private val carrierConfigRepository: CarrierConfigRepository,
    @Application private val scope: CoroutineScope,
    @Background private val scope: CoroutineScope,
) : CoreStartable {

    override fun start() {
+0 −3
Original line number Diff line number Diff line
@@ -28,13 +28,11 @@ import androidx.core.util.keyIterator
import com.android.systemui.Dumpable
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.pipeline.mobile.data.MobileInputLogger
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfig
import java.io.PrintWriter
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.mapNotNull
@@ -48,7 +46,6 @@ constructor(
    private val carrierConfigManager: CarrierConfigManager?,
    dumpManager: DumpManager,
    logger: MobileInputLogger,
    @Application scope: CoroutineScope,
) : CarrierConfigRepository, Dumpable {
    private var isListening = false
    private val defaultConfig: PersistableBundle by lazy { CarrierConfigManager.getDefaultConfig() }
+8 −8
Original line number Diff line number Diff line
@@ -20,14 +20,14 @@ import android.os.Bundle
import androidx.annotation.VisibleForTesting
import com.android.settingslib.SignalIcon
import com.android.settingslib.mobile.MobileMappings
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.demomode.DemoMode
import com.android.systemui.demomode.DemoModeController
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -67,7 +67,7 @@ import kotlinx.coroutines.flow.stateIn
class MobileRepositorySwitcher
@Inject
constructor(
    @Application scope: CoroutineScope,
    @Background scope: CoroutineScope,
    val realRepository: MobileConnectionsRepositoryImpl,
    val demoMobileConnectionsRepository: DemoMobileConnectionsRepository,
    demoModeController: DemoModeController,
@@ -121,7 +121,7 @@ constructor(
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.activeMobileDataSubscriptionId.value
                realRepository.activeMobileDataSubscriptionId.value,
            )

    override val activeMobileDataRepository: StateFlow<MobileConnectionRepository?> =
@@ -130,7 +130,7 @@ constructor(
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.activeMobileDataRepository.value
                realRepository.activeMobileDataRepository.value,
            )

    override val activeSubChangedInGroupEvent: Flow<Unit> =
@@ -142,7 +142,7 @@ constructor(
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.defaultDataSubRatConfig.value
                realRepository.defaultDataSubRatConfig.value,
            )

    override val defaultMobileIconMapping: Flow<Map<String, SignalIcon.MobileIconGroup>> =
@@ -157,7 +157,7 @@ constructor(
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.isDeviceEmergencyCallCapable.value
                realRepository.isDeviceEmergencyCallCapable.value,
            )

    override val isAnySimSecure: Flow<Boolean> = activeRepo.flatMapLatest { it.isAnySimSecure }
@@ -189,7 +189,7 @@ constructor(
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.defaultConnectionIsValidated.value
                realRepository.defaultConnectionIsValidated.value,
            )

    override fun getRepoForSubId(subId: Int): MobileConnectionRepository {
Loading