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

Commit 81799a75 authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Mobile icon view model logging

Add logging to the mobile icon view models. In order to keep the logs
from duplicating, this CL also adds:

1. The reuse of a single instance of the MobileIconsViewModel
   (top-level), which
2. Caches the individual MobileIconViewModel common implementations on a
   per-subscription basis. There is now a 1-1 correspondence of the
   common mobile icon view model implementations and the number of
   subscriptions.

Also updated the MobileIconViewModelTest and
LocationBasedMobileIconViewModelTest classes to use the TestScope method
of running tests.

Test: adb logcat | grep SbConnectivity
Test: tests in tests/src/com/android/systemui/statusbar/pipeline/mobile/*
Bug: 238425913
Change-Id: I5157cdcfb054d4629db0f9b11da8b583760ce471
parent 4e53da6d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -387,7 +387,7 @@ public interface StatusBarIconController {
            if (statusBarPipelineFlags.runNewMobileIconsBackend()) {
                // This starts the flow for the new pipeline, and will notify us of changes if
                // {@link StatusBarPipelineFlags#useNewMobileIcons} is also true.
                mMobileIconsViewModel = mobileUiAdapter.createMobileIconsViewModel();
                mMobileIconsViewModel = mobileUiAdapter.getMobileIconsViewModel();
                MobileIconsBinder.bind(mGroup, mMobileIconsViewModel);
            } else {
                mMobileIconsViewModel = null;
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
import kotlinx.coroutines.flow.Flow
@@ -39,6 +40,13 @@ import kotlinx.coroutines.flow.StateFlow
interface MobileConnectionRepository {
    /** The subscriptionId that this connection represents */
    val subId: Int

    /**
     * The table log buffer created for this connection. Will have the name "MobileConnectionLog
     * [subId]"
     */
    val tableLogBuffer: TableLogBuffer

    /**
     * A flow that aggregates all necessary callbacks from [TelephonyCallback] into a single
     * listener + model.
+17 −2
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.settingslib.SignalIcon
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
@@ -60,6 +62,7 @@ constructor(
    private val dataSource: DemoModeMobileConnectionDataSource,
    @Application private val scope: CoroutineScope,
    context: Context,
    private val logFactory: TableLogBufferFactory,
) : MobileConnectionsRepository {

    private var demoCommandJob: Job? = null
@@ -149,7 +152,16 @@ constructor(

    override fun getRepoForSubId(subId: Int): DemoMobileConnectionRepository {
        return connectionRepoCache[subId]
            ?: DemoMobileConnectionRepository(subId).also { connectionRepoCache[subId] = it }
            ?: createDemoMobileConnectionRepo(subId).also { connectionRepoCache[subId] = it }
    }

    private fun createDemoMobileConnectionRepo(subId: Int): DemoMobileConnectionRepository {
        val tableLogBuffer = logFactory.create("DemoMobileConnectionLog [$subId]", 100)

        return DemoMobileConnectionRepository(
            subId,
            tableLogBuffer,
        )
    }

    override val globalMobileDataSettingChangedEvent = MutableStateFlow(Unit)
@@ -260,7 +272,10 @@ constructor(
    }
}

class DemoMobileConnectionRepository(override val subId: Int) : MobileConnectionRepository {
class DemoMobileConnectionRepository(
    override val subId: Int,
    override val tableLogBuffer: TableLogBuffer,
) : MobileConnectionRepository {
    override val connectionInfo = MutableStateFlow(MobileConnectionModel())

    override val dataEnabled = MutableStateFlow(true)
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ class MobileConnectionRepositoryImpl(

    private val telephonyCallbackEvent = MutableSharedFlow<Unit>(extraBufferCapacity = 1)

    override val tableLogBuffer: TableLogBuffer = mobileLogger

    override val connectionInfo: StateFlow<MobileConnectionModel> = run {
        var state = MobileConnectionModel()
        conflatedCallbackFlow {
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.pipeline.mobile.domain.interactor
import android.telephony.CarrierConfigManager
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Connected
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
@@ -35,6 +36,9 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.stateIn

interface MobileIconInteractor {
    /** The table log created for this connection */
    val tableLogBuffer: TableLogBuffer

    /** The current mobile data activity */
    val activity: Flow<DataActivityModel>

@@ -97,6 +101,8 @@ class MobileIconInteractorImpl(
) : MobileIconInteractor {
    private val connectionInfo = connectionRepository.connectionInfo

    override val tableLogBuffer: TableLogBuffer = connectionRepository.tableLogBuffer

    override val activity = connectionInfo.mapLatest { it.dataActivityDirection }

    override val isDataEnabled: StateFlow<Boolean> = connectionRepository.dataEnabled
Loading