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

Commit b209bdef authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Add a table logger for the parent mobile classes.

This logs almost every flow in the parent repo and interactor. Once
we've sufficiently dogfooded and tested the new pipeline, we can remove
some of these logs.

Bug: 267217719
Bug: 238425913
Test: manual: Dumped MobileSummaryLog
Change-Id: I1f8b2b4ed7316b20eb994170578742f3dbc5dae4
parent ed926619
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline.dagger

import javax.inject.Qualifier

/**
 * Logs for mobile data that's **the same across all connections**.
 *
 * This buffer should only be used for the mobile parent classes like [MobileConnectionsRepository]
 * and [MobileIconsInteractor]. It should *not* be used for classes that represent an individual
 * connection, like [MobileConnectionRepository] or [MobileIconInteractor].
 */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class MobileSummaryLog
+7 −0
Original line number Diff line number Diff line
@@ -118,5 +118,12 @@ abstract class StatusBarPipelineModule {
        fun provideAirplaneTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
            return factory.create("AirplaneTableLog", 30)
        }

        @Provides
        @SysUISingleton
        @MobileSummaryLog
        fun provideMobileSummaryLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
            return factory.create("MobileSummaryLog", 100)
        }
    }
}
+23 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.statusbar.pipeline.mobile.data.model

import android.net.NetworkCapabilities
import com.android.systemui.log.table.Diffable
import com.android.systemui.log.table.TableRowLogger

/** Provides information about a mobile network connection */
data class MobileConnectivityModel(
@@ -24,4 +26,24 @@ data class MobileConnectivityModel(
    val isConnected: Boolean = false,
    /** Whether the mobile transport is validated [NetworkCapabilities.NET_CAPABILITY_VALIDATED] */
    val isValidated: Boolean = false,
)
) : Diffable<MobileConnectivityModel> {
    // TODO(b/267767715): Can we implement [logDiffs] and [logFull] generically for data classes?
    override fun logDiffs(prevVal: MobileConnectivityModel, row: TableRowLogger) {
        if (prevVal.isConnected != isConnected) {
            row.logChange(COL_IS_CONNECTED, isConnected)
        }
        if (prevVal.isValidated != isValidated) {
            row.logChange(COL_IS_VALIDATED, isValidated)
        }
    }

    override fun logFull(row: TableRowLogger) {
        row.logChange(COL_IS_CONNECTED, isConnected)
        row.logChange(COL_IS_VALIDATED, isValidated)
    }

    companion object {
        private const val COL_IS_CONNECTED = "isConnected"
        private const val COL_IS_VALIDATED = "isValidated"
    }
}
+38 −4
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCall
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.dagger.MobileSummaryLog
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
@@ -82,6 +85,7 @@ constructor(
    private val subscriptionManager: SubscriptionManager,
    private val telephonyManager: TelephonyManager,
    private val logger: ConnectivityPipelineLogger,
    @MobileSummaryLog private val tableLogger: TableLogBuffer,
    mobileMappingsProxy: MobileMappingsProxy,
    broadcastDispatcher: BroadcastDispatcher,
    private val context: Context,
@@ -114,6 +118,12 @@ constructor(
                }
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "carrierMergedSubId",
                initialValue = null,
            )
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), null)

    private val mobileSubscriptionsChangeEvent: Flow<Unit> = conflatedCallbackFlow {
@@ -139,8 +149,14 @@ constructor(
    override val subscriptions: StateFlow<List<SubscriptionModel>> =
        merge(mobileSubscriptionsChangeEvent, carrierMergedSubId)
            .mapLatest { fetchSubscriptionsList().map { it.toSubscriptionModel() } }
            .logInputChange(logger, "onSubscriptionsChanged")
            .onEach { infos -> updateRepos(infos) }
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "subscriptions",
                initialValue = listOf(),
            )
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), listOf())

    /** StateFlow that keeps track of the current active mobile data subscription */
@@ -157,7 +173,12 @@ constructor(
                awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
            }
            .distinctUntilChanged()
            .logInputChange(logger, "onActiveDataSubscriptionIdChanged")
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "activeSubId",
                initialValue = INVALID_SUBSCRIPTION_ID,
            )
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), INVALID_SUBSCRIPTION_ID)

    private val defaultDataSubIdChangeEvent: MutableSharedFlow<Unit> =
@@ -171,7 +192,12 @@ constructor(
                intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, INVALID_SUBSCRIPTION_ID)
            }
            .distinctUntilChanged()
            .logInputChange(logger, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED")
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "defaultSubId",
                initialValue = SubscriptionManager.getDefaultDataSubscriptionId(),
            )
            .onEach { defaultDataSubIdChangeEvent.tryEmit(Unit) }
            .stateIn(
                scope,
@@ -247,7 +273,11 @@ constructor(
                awaitClose { connectivityManager.unregisterNetworkCallback(callback) }
            }
            .distinctUntilChanged()
            .logInputChange(logger, "defaultMobileNetworkConnectivity")
            .logDiffsForTable(
                tableLogger,
                columnPrefix = "$LOGGING_PREFIX.defaultConnection",
                initialValue = MobileConnectivityModel(),
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), MobileConnectivityModel())

    /**
@@ -321,4 +351,8 @@ constructor(
            subscriptionId = subscriptionId,
            isOpportunistic = isOpportunistic,
        )

    companion object {
        private const val LOGGING_PREFIX = "Repo"
    }
}
+33 −1
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.TelephonyIcons
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.logDiffsForTable
import com.android.systemui.statusbar.pipeline.dagger.MobileSummaryLog
import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
@@ -104,6 +107,7 @@ constructor(
    private val mobileConnectionsRepo: MobileConnectionsRepository,
    private val carrierConfigTracker: CarrierConfigTracker,
    private val logger: ConnectivityPipelineLogger,
    @MobileSummaryLog private val tableLogger: TableLogBuffer,
    userSetupRepo: UserSetupRepository,
    @Application private val scope: CoroutineScope,
) : MobileIconsInteractor {
@@ -173,7 +177,13 @@ constructor(
            }
        }
            .distinctUntilChanged()
            .onEach { logger.logFilteredSubscriptionsChanged(it) }
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "filteredSubscriptions",
                initialValue = listOf(),
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), listOf())

    override val defaultDataSubId = mobileConnectionsRepo.defaultDataSubId

@@ -195,6 +205,12 @@ constructor(
                delay(2000)
                emit(false)
            }
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "forcingValidation",
                initialValue = false,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> =
@@ -211,6 +227,12 @@ constructor(
                    networkConnectivity
                }
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,
                columnPrefix = "$LOGGING_PREFIX.defaultConnection",
                initialValue = mobileConnectionsRepo.defaultMobileNetworkConnectivity.value,
            )
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
@@ -259,6 +281,12 @@ constructor(
                    !connectivityModel.isValidated
                }
            }
            .logDiffsForTable(
                tableLogger,
                LOGGING_PREFIX,
                columnName = "isDefaultConnectionFailed",
                initialValue = false,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val isUserSetup: StateFlow<Boolean> = userSetupRepo.isUserSetupFlow
@@ -277,4 +305,8 @@ constructor(
            isDefaultConnectionFailed,
            mobileConnectionsRepo.getRepoForSubId(subId),
        )

    companion object {
        private const val LOGGING_PREFIX = "Intr"
    }
}
Loading