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

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

[SB Refactor] Split the wifi input logging into its own class.

Bug: 238425913
Test: all tests in pipeline.wifi
Test: `adb shell dumpsys activity service
com.android.systemui/.SystemUIService WifiInputLog` -> dumps wifi
network logs

Change-Id: I210fba0bd402dfe582d47a05394ba8e7426a2256
parent 0beef1ec
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.systemui.statusbar.pipeline.dagger
import android.net.wifi.WifiManager
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.plugins.log.LogBuffer
import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepository
import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepositoryImpl
import com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel.AirplaneModeViewModel
@@ -105,6 +107,13 @@ abstract class StatusBarPipelineModule {
            }
        }

        @Provides
        @SysUISingleton
        @WifiInputLog
        fun provideWifiInputLogBuffer(factory: LogBufferFactory): LogBuffer {
            return factory.create("WifiInputLog", 50)
        }

        @Provides
        @SysUISingleton
        @WifiTableLog
+25 −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

/** Wifi logs for inputs into the wifi pipeline. */
@Qualifier
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class WifiInputLog
+6 −41
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.dagger.StatusBarConnectivityLog
import com.android.systemui.plugins.log.LogBuffer
import com.android.systemui.plugins.log.LogLevel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.toString
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
@@ -59,32 +58,6 @@ constructor(
        )
    }

    /** Logs a **data transformation** that we performed within the connectivity pipeline. */
    fun logTransformation(transformationName: String, oldValue: Any?, newValue: Any?) {
        if (oldValue == newValue) {
            buffer.log(
                SB_LOGGING_TAG,
                LogLevel.INFO,
                {
                    str1 = transformationName
                    str2 = oldValue.toString()
                },
                { "Transform: $str1: $str2 (transformation didn't change it)" }
            )
        } else {
            buffer.log(
                SB_LOGGING_TAG,
                LogLevel.INFO,
                {
                    str1 = transformationName
                    str2 = oldValue.toString()
                    str3 = newValue.toString()
                },
                { "Transform: $str1: $str2 -> $str3" }
            )
        }
    }

    /** Logs a change in one of the **outputs** to the connectivity pipeline. */
    fun logOutputChange(outputParamName: String, changeInfo: String) {
        buffer.log(
@@ -103,25 +76,17 @@ constructor(
        networkCapabilities: NetworkCapabilities,
        isDefaultNetworkCallback: Boolean,
    ) {
        buffer.log(
        LoggerHelper.logOnCapabilitiesChanged(
            buffer,
            SB_LOGGING_TAG,
            LogLevel.INFO,
            {
                bool1 = isDefaultNetworkCallback
                int1 = network.getNetId()
                str1 = networkCapabilities.toString()
            },
            { "onCapabilitiesChanged[default=$bool1]: net=$int1 capabilities=$str1" }
            network,
            networkCapabilities,
            isDefaultNetworkCallback,
        )
    }

    fun logOnLost(network: Network) {
        buffer.log(
            SB_LOGGING_TAG,
            LogLevel.INFO,
            { int1 = network.getNetId() },
            { "onLost: net=$int1" }
        )
        LoggerHelper.logOnLost(buffer, SB_LOGGING_TAG, network)
    }

    fun logOnServiceStateChanged(serviceState: ServiceState, subId: Int) {
+48 −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.shared

import android.net.Network
import android.net.NetworkCapabilities
import com.android.systemui.plugins.log.LogBuffer
import com.android.systemui.plugins.log.LogLevel

/** Helper object for logs that are shared between wifi and mobile. */
object LoggerHelper {
    fun logOnCapabilitiesChanged(
        buffer: LogBuffer,
        tag: String,
        network: Network,
        networkCapabilities: NetworkCapabilities,
        isDefaultNetworkCallback: Boolean,
    ) {
        buffer.log(
            tag,
            LogLevel.INFO,
            {
                bool1 = isDefaultNetworkCallback
                int1 = network.getNetId()
                str1 = networkCapabilities.toString()
            },
            { "onCapabilitiesChanged[default=$bool1]: net=$int1 capabilities=$str1" }
        )
    }

    fun logOnLost(buffer: LogBuffer, tag: String, network: Network) {
        buffer.log(tag, LogLevel.INFO, { int1 = network.getNetId() }, { "onLost: net=$int1" })
    }
}
+6 −18
Original line number Diff line number Diff line
@@ -39,12 +39,11 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.logDiffsForTable
import com.android.systemui.statusbar.pipeline.dagger.WifiTableLog
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import com.android.systemui.statusbar.pipeline.shared.data.model.toWifiDataActivityModel
import com.android.systemui.statusbar.pipeline.wifi.data.repository.RealWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.shared.WifiInputLogger
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel
import java.util.concurrent.Executor
import javax.inject.Inject
@@ -58,6 +57,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

/** Real implementation of [WifiRepository]. */
@@ -70,7 +70,7 @@ class WifiRepositoryImpl
constructor(
    broadcastDispatcher: BroadcastDispatcher,
    connectivityManager: ConnectivityManager,
    logger: ConnectivityPipelineLogger,
    logger: WifiInputLogger,
    @WifiTableLog wifiTableLogBuffer: TableLogBuffer,
    @Main mainExecutor: Executor,
    @Application scope: CoroutineScope,
@@ -80,7 +80,7 @@ constructor(
    private val wifiStateChangeEvents: Flow<Unit> =
        broadcastDispatcher
            .broadcastFlow(IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION))
            .logInputChange(logger, "WIFI_STATE_CHANGED_ACTION intent")
            .onEach { logger.logIntent("WIFI_STATE_CHANGED_ACTION") }

    private val wifiNetworkChangeEvents: MutableSharedFlow<Unit> =
        MutableSharedFlow(extraBufferCapacity = 1)
@@ -173,11 +173,6 @@ constructor(
                                        networkCapabilities,
                                        wifiManager,
                                    )
                                logger.logTransformation(
                                    WIFI_NETWORK_CALLBACK_NAME,
                                    oldValue = currentWifi,
                                    newValue = wifiNetworkModel,
                                )
                                currentWifi = wifiNetworkModel
                                trySend(wifiNetworkModel)
                            }
@@ -194,11 +189,6 @@ constructor(
                                    wifi.networkId == network.getNetId()
                            ) {
                                val newNetworkModel = WifiNetworkModel.Inactive
                                logger.logTransformation(
                                    WIFI_NETWORK_CALLBACK_NAME,
                                    oldValue = wifi,
                                    newValue = newNetworkModel,
                                )
                                currentWifi = newNetworkModel
                                trySend(newNetworkModel)
                            }
@@ -228,7 +218,7 @@ constructor(
    override val wifiActivity: StateFlow<DataActivityModel> =
        conflatedCallbackFlow {
                val callback = TrafficStateCallback { state ->
                    logger.logInputChange("onTrafficStateChange", prettyPrintActivity(state))
                    logger.logActivity(prettyPrintActivity(state))
                    trySend(state.toWifiDataActivityModel())
                }
                wifiManager.registerTrafficStateCallback(mainExecutor, callback)
@@ -336,8 +326,6 @@ constructor(
                .addTransportType(TRANSPORT_CELLULAR)
                .build()

        private const val WIFI_NETWORK_CALLBACK_NAME = "wifiNetworkModel"

        private const val CARRIER_MERGED_INVALID_SUB_ID_REASON =
            "Wifi network was carrier merged but had invalid sub ID"
    }
@@ -348,7 +336,7 @@ constructor(
    constructor(
        private val broadcastDispatcher: BroadcastDispatcher,
        private val connectivityManager: ConnectivityManager,
        private val logger: ConnectivityPipelineLogger,
        private val logger: WifiInputLogger,
        @WifiTableLog private val wifiTableLogBuffer: TableLogBuffer,
        @Main private val mainExecutor: Executor,
        @Application private val scope: CoroutineScope,
Loading