[SB Refactor] Remove non-mobile usages of MobileInputLogger.

Also removes the `logInputChange` and `logOutputChange` methods, since
now all logs to this logger are, by definition, input changes.

Also lints the ConnectivityRepository(Test) files, since they apparently
were incorrectly linted before.

Bug: 238425913
Test: atest MobileInputLoggerTest
Test: `adb shell dumpsys activity service
com.android.systemui/.SystemUIService MobileInputLog` -> verify logs
appear

Change-Id: I469cd3aaa7205694229c6f8cb08480f37af6fe80
This commit is contained in:
Caitlin Shkuratov
2023-02-13 19:40:46 +00:00
parent 77a386eb5c
commit 3a4245bb68
14 changed files with 240 additions and 397 deletions

View File

@@ -265,16 +265,6 @@ public class LogModule {
return factory.create("MediaCarouselCtlrLog", 20);
}
/**
* Provides a {@link LogBuffer} for use in the status bar connectivity pipeline
*/
@Provides
@SysUISingleton
@StatusBarConnectivityLog
public static LogBuffer provideStatusBarConnectivityBuffer(LogBufferFactory factory) {
return factory.create("SbConnectivity", 64);
}
/** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */
@Provides
@SysUISingleton

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 The Android Open Source Project
* 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.
@@ -14,22 +14,12 @@
* limitations under the License.
*/
package com.android.systemui.log.dagger;
package com.android.systemui.statusbar.pipeline.dagger
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import javax.inject.Qualifier
import com.android.systemui.plugins.log.LogBuffer;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Qualifier;
/**
* A {@link LogBuffer} for status bar connectivity events.
*/
/** Logs for inputs into the mobile pipeline. */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface StatusBarConnectivityLog {
}
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class MobileInputLog

View File

@@ -141,5 +141,12 @@ abstract class StatusBarPipelineModule {
fun provideMobileSummaryLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
return factory.create("MobileSummaryLog", 100)
}
@Provides
@SysUISingleton
@MobileInputLog
fun provideMobileInputLogBuffer(factory: LogBufferFactory): LogBuffer {
return factory.create("MobileInputLog", 100)
}
}
}

View File

@@ -50,7 +50,6 @@ import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameMode
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.logInputChange
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel
@@ -222,13 +221,13 @@ constructor(
private val carrierConfigChangedEvent =
broadcastDispatcher
.broadcastFlow(IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED))
.logInputChange(logger, "ACTION_CARRIER_CONFIG_CHANGED")
.onEach { logger.logActionCarrierConfigChanged() }
override val defaultDataSubRatConfig: StateFlow<Config> =
merge(defaultDataSubIdChangeEvent, carrierConfigChangedEvent)
.mapLatest { Config.readConfig(context) }
.distinctUntilChanged()
.logInputChange(logger, "defaultDataSubRatConfig")
.onEach { logger.logDefaultDataSubRatConfig(it) }
.stateIn(
scope,
SharingStarted.WhileSubscribed(),
@@ -239,13 +238,13 @@ constructor(
defaultDataSubRatConfig
.map { mobileMappingsProxy.mapIconSets(it) }
.distinctUntilChanged()
.logInputChange(logger, "defaultMobileIconMapping")
.onEach { logger.logDefaultMobileIconMapping(it) }
override val defaultMobileIconGroup: Flow<MobileIconGroup> =
defaultDataSubRatConfig
.map { mobileMappingsProxy.getDefaultIcons(it) }
.distinctUntilChanged()
.logInputChange(logger, "defaultMobileIconGroup")
.onEach { logger.logDefaultMobileIconGroup(it) }
override fun getRepoForSubId(subId: Int): FullMobileConnectionRepository {
if (!isValidSubId(subId)) {

View File

@@ -30,7 +30,6 @@ import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionMod
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.UserSetupRepository
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger
import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
import com.android.systemui.util.CarrierConfigTracker
@@ -111,7 +110,6 @@ class MobileIconsInteractorImpl
constructor(
private val mobileConnectionsRepo: MobileConnectionsRepository,
private val carrierConfigTracker: CarrierConfigTracker,
private val logger: MobileInputLogger,
@MobileSummaryLog private val tableLogger: TableLogBuffer,
connectivityRepository: ConnectivityRepository,
userSetupRepo: UserSetupRepository,

View File

@@ -21,57 +21,22 @@ import android.net.NetworkCapabilities
import android.telephony.ServiceState
import android.telephony.SignalStrength
import android.telephony.TelephonyDisplayInfo
import com.android.settingslib.SignalIcon
import com.android.settingslib.mobile.MobileMappings
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.shared.MobileInputLogger.Companion.toString
import com.android.systemui.statusbar.pipeline.dagger.MobileInputLog
import com.android.systemui.statusbar.pipeline.shared.LoggerHelper
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onEach
/** Logs for inputs into the mobile pipeline. */
@SysUISingleton
class MobileInputLogger
@Inject
constructor(
@StatusBarConnectivityLog private val buffer: LogBuffer,
@MobileInputLog private val buffer: LogBuffer,
) {
/**
* Logs a change in one of the **raw inputs** to the connectivity pipeline.
*
* Use this method for inputs that don't have any extra information besides their callback name.
*/
fun logInputChange(callbackName: String) {
buffer.log(SB_LOGGING_TAG, LogLevel.INFO, { str1 = callbackName }, { "Input: $str1" })
}
/** Logs a change in one of the **raw inputs** to the connectivity pipeline. */
fun logInputChange(callbackName: String, changeInfo: String?) {
buffer.log(
SB_LOGGING_TAG,
LogLevel.INFO,
{
str1 = callbackName
str2 = changeInfo
},
{ "Input: $str1: $str2" }
)
}
/** Logs a change in one of the **outputs** to the connectivity pipeline. */
fun logOutputChange(outputParamName: String, changeInfo: String) {
buffer.log(
SB_LOGGING_TAG,
LogLevel.INFO,
{
str1 = outputParamName
str2 = changeInfo
},
{ "Output: $str1: $str2" }
)
}
fun logOnCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities,
@@ -79,7 +44,7 @@ constructor(
) {
LoggerHelper.logOnCapabilitiesChanged(
buffer,
SB_LOGGING_TAG,
TAG,
network,
networkCapabilities,
isDefaultNetworkCallback,
@@ -87,12 +52,12 @@ constructor(
}
fun logOnLost(network: Network) {
LoggerHelper.logOnLost(buffer, SB_LOGGING_TAG, network)
LoggerHelper.logOnLost(buffer, TAG, network)
}
fun logOnServiceStateChanged(serviceState: ServiceState, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -109,7 +74,7 @@ constructor(
fun logOnSignalStrengthsChanged(signalStrength: SignalStrength, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -121,7 +86,7 @@ constructor(
fun logOnDataConnectionStateChanged(dataState: Int, networkType: Int, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -134,7 +99,7 @@ constructor(
fun logOnDataActivity(direction: Int, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -146,7 +111,7 @@ constructor(
fun logOnCarrierNetworkChange(active: Boolean, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -158,7 +123,7 @@ constructor(
fun logOnDisplayInfoChanged(displayInfo: TelephonyDisplayInfo, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -168,11 +133,9 @@ constructor(
)
}
// TODO(b/238425913): We should split this class into mobile-specific and wifi-specific loggers.
fun logUiAdapterSubIdsUpdated(subs: List<Int>) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{ str1 = subs.toString() },
{ "Sub IDs in MobileUiAdapter updated internally: $str1" },
@@ -181,7 +144,7 @@ constructor(
fun logUiAdapterSubIdsSentToIconController(subs: List<Int>) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{ str1 = subs.toString() },
{ "Sub IDs in MobileUiAdapter being sent to icon controller: $str1" },
@@ -190,7 +153,7 @@ constructor(
fun logCarrierConfigChanged(subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{ int1 = subId },
{ "onCarrierConfigChanged: subId=$int1" },
@@ -199,7 +162,7 @@ constructor(
fun logOnDataEnabledChanged(enabled: Boolean, subId: Int) {
buffer.log(
SB_LOGGING_TAG,
TAG,
LogLevel.INFO,
{
int1 = subId
@@ -209,43 +172,31 @@ constructor(
)
}
companion object {
const val SB_LOGGING_TAG = "SbConnectivity"
fun logActionCarrierConfigChanged() {
buffer.log(TAG, LogLevel.INFO, {}, { "Intent received: ACTION_CARRIER_CONFIG_CHANGED" })
}
/** Log a change in one of the **inputs** to the connectivity pipeline. */
fun Flow<Unit>.logInputChange(
logger: MobileInputLogger,
inputParamName: String,
): Flow<Unit> {
return this.onEach { logger.logInputChange(inputParamName) }
}
fun logDefaultDataSubRatConfig(config: MobileMappings.Config) {
buffer.log(
TAG,
LogLevel.INFO,
{ str1 = config.toString() },
{ "defaultDataSubRatConfig: $str1" }
)
}
/**
* Log a change in one of the **inputs** to the connectivity pipeline.
*
* @param prettyPrint an optional function to transform the value into a readable string.
* [toString] is used if no custom function is provided.
*/
fun <T> Flow<T>.logInputChange(
logger: MobileInputLogger,
inputParamName: String,
prettyPrint: (T) -> String = { it.toString() }
): Flow<T> {
return this.onEach { logger.logInputChange(inputParamName, prettyPrint(it)) }
}
fun logDefaultMobileIconMapping(mapping: Map<String, SignalIcon.MobileIconGroup>) {
buffer.log(
TAG,
LogLevel.INFO,
{ str1 = mapping.toString() },
{ "defaultMobileIconMapping: $str1" }
)
}
/**
* Log a change in one of the **outputs** to the connectivity pipeline.
*
* @param prettyPrint an optional function to transform the value into a readable string.
* [toString] is used if no custom function is provided.
*/
fun <T> Flow<T>.logOutputChange(
logger: MobileInputLogger,
outputParamName: String,
prettyPrint: (T) -> String = { it.toString() }
): Flow<T> {
return this.onEach { logger.logOutputChange(outputParamName, prettyPrint(it)) }
}
fun logDefaultMobileIconGroup(group: SignalIcon.MobileIconGroup) {
buffer.log(TAG, LogLevel.INFO, { str1 = group.name }, { "defaultMobileIconGroup: $str1" })
}
}
private const val TAG = "MobileInputLog"

View File

@@ -25,7 +25,6 @@ import com.android.systemui.statusbar.pipeline.airplane.domain.interactor.Airpla
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.ui.view.ModernStatusBarMobileView
import com.android.systemui.statusbar.pipeline.shared.ConnectivityConstants
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
@@ -42,7 +41,6 @@ constructor(
val subscriptionIdsFlow: StateFlow<List<Int>>,
private val interactor: MobileIconsInteractor,
private val airplaneModeInteractor: AirplaneModeInteractor,
private val logger: MobileInputLogger,
private val constants: ConnectivityConstants,
@Application private val scope: CoroutineScope,
private val statusBarPipelineFlags: StatusBarPipelineFlags,
@@ -83,7 +81,6 @@ constructor(
constructor(
private val interactor: MobileIconsInteractor,
private val airplaneModeInteractor: AirplaneModeInteractor,
private val logger: MobileInputLogger,
private val constants: ConnectivityConstants,
@Application private val scope: CoroutineScope,
private val statusBarPipelineFlags: StatusBarPipelineFlags,
@@ -93,7 +90,6 @@ constructor(
subscriptionIdsFlow,
interactor,
airplaneModeInteractor,
logger,
constants,
scope,
statusBarPipelineFlags,

View File

@@ -22,7 +22,6 @@ import com.android.systemui.Dumpable
import com.android.systemui.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.SB_LOGGING_TAG
import java.io.PrintWriter
import javax.inject.Inject
@@ -40,7 +39,7 @@ constructor(
telephonyManager: TelephonyManager,
) : Dumpable {
init {
dumpManager.registerNormalDumpable("${SB_LOGGING_TAG}Constants", this)
dumpManager.registerNormalDumpable("ConnectivityConstants", this)
}
/** True if this device has the capability for data connections and false otherwise. */

View File

@@ -27,7 +27,6 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.phone.StatusBarIconController
import com.android.systemui.statusbar.pipeline.shared.ConnectivityInputLogger
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.SB_LOGGING_TAG
import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot
import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlots
import com.android.systemui.tuner.TunerService
@@ -45,15 +44,15 @@ import kotlinx.coroutines.flow.stateIn
* types of connectivity (wifi, mobile, ethernet, etc.)
*/
interface ConnectivityRepository {
/**
* Observable for the current set of connectivity icons that should be force-hidden.
*/
/** Observable for the current set of connectivity icons that should be force-hidden. */
val forceHiddenSlots: StateFlow<Set<ConnectivitySlot>>
}
@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
class ConnectivityRepositoryImpl @Inject constructor(
class ConnectivityRepositoryImpl
@Inject
constructor(
private val connectivitySlots: ConnectivitySlots,
context: Context,
dumpManager: DumpManager,
@@ -62,42 +61,44 @@ class ConnectivityRepositoryImpl @Inject constructor(
tunerService: TunerService,
) : ConnectivityRepository, Dumpable {
init {
dumpManager.registerDumpable("${SB_LOGGING_TAG}Repository", this)
dumpManager.registerDumpable("ConnectivityRepository", this)
}
// The default set of hidden icons to use if we don't get any from [TunerService].
private val defaultHiddenIcons: Set<ConnectivitySlot> =
context.resources.getStringArray(DEFAULT_HIDDEN_ICONS_RESOURCE)
.asList()
.toSlotSet(connectivitySlots)
context.resources
.getStringArray(DEFAULT_HIDDEN_ICONS_RESOURCE)
.asList()
.toSlotSet(connectivitySlots)
override val forceHiddenSlots: StateFlow<Set<ConnectivitySlot>> = conflatedCallbackFlow {
val callback = object : TunerService.Tunable {
override fun onTuningChanged(key: String, newHideList: String?) {
if (key != HIDDEN_ICONS_TUNABLE_KEY) {
return
}
logger.logTuningChanged(newHideList)
override val forceHiddenSlots: StateFlow<Set<ConnectivitySlot>> =
conflatedCallbackFlow {
val callback =
object : TunerService.Tunable {
override fun onTuningChanged(key: String, newHideList: String?) {
if (key != HIDDEN_ICONS_TUNABLE_KEY) {
return
}
logger.logTuningChanged(newHideList)
val outputList = newHideList?.split(",")?.toSlotSet(connectivitySlots)
?: defaultHiddenIcons
trySend(outputList)
val outputList =
newHideList?.split(",")?.toSlotSet(connectivitySlots)
?: defaultHiddenIcons
trySend(outputList)
}
}
tunerService.addTunable(callback, HIDDEN_ICONS_TUNABLE_KEY)
awaitClose { tunerService.removeTunable(callback) }
}
}
tunerService.addTunable(callback, HIDDEN_ICONS_TUNABLE_KEY)
awaitClose { tunerService.removeTunable(callback) }
}
.stateIn(
scope,
started = SharingStarted.WhileSubscribed(),
initialValue = defaultHiddenIcons
)
.stateIn(
scope,
started = SharingStarted.WhileSubscribed(),
initialValue = defaultHiddenIcons
)
override fun dump(pw: PrintWriter, args: Array<out String>) {
pw.apply {
println("defaultHiddenIcons=$defaultHiddenIcons")
}
pw.apply { println("defaultHiddenIcons=$defaultHiddenIcons") }
}
companion object {
@@ -111,8 +112,7 @@ class ConnectivityRepositoryImpl @Inject constructor(
private fun List<String>.toSlotSet(
connectivitySlots: ConnectivitySlots
): Set<ConnectivitySlot> {
return this
.filter { it.isNotBlank() }
return this.filter { it.isNotBlank() }
.mapNotNull { connectivitySlots.getSlotFromName(it) }
.toSet()
}

View File

@@ -21,7 +21,6 @@ import com.android.systemui.Dumpable
import com.android.systemui.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.SB_LOGGING_TAG
import java.io.PrintWriter
import javax.inject.Inject
@@ -37,7 +36,7 @@ constructor(
dumpManager: DumpManager,
) : Dumpable {
init {
dumpManager.registerDumpable("${SB_LOGGING_TAG}WifiConstants", this)
dumpManager.registerNormalDumpable("WifiConstants", this)
}
/** True if we should always show the wifi icon when wifi is enabled and false otherwise. */

View File

@@ -83,7 +83,6 @@ class MobileIconsInteractorTest : SysuiTestCase() {
MobileIconsInteractorImpl(
connectionsRepository,
carrierConfigTracker,
logger = mock(),
tableLogger = mock(),
connectivityRepository,
userSetupRepository,

View File

@@ -23,24 +23,17 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.log.LogBufferFactory
import com.android.systemui.plugins.log.LogcatEchoTracker
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.logInputChange
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger.Companion.logOutputChange
import com.google.common.truth.Truth.assertThat
import java.io.PrintWriter
import java.io.StringWriter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.mockito.Mockito
import org.mockito.Mockito.mock
@SmallTest
class MobileInputLoggerTest : SysuiTestCase() {
private val buffer = LogBufferFactory(DumpManager(), mock(LogcatEchoTracker::class.java))
.create("buffer", 10)
private val buffer =
LogBufferFactory(DumpManager(), mock(LogcatEchoTracker::class.java)).create("buffer", 10)
private val logger = MobileInputLogger(buffer)
@Test
@@ -72,70 +65,16 @@ class MobileInputLoggerTest : SysuiTestCase() {
assertThat(actualString).contains(expectedNetId)
}
@Test
fun logOutputChange_printsValuesAndNulls() = runBlocking(IMMEDIATE) {
val flow: Flow<Int?> = flowOf(1, null, 3)
val job = flow
.logOutputChange(logger, "testInts")
.launchIn(this)
val stringWriter = StringWriter()
buffer.dump(PrintWriter(stringWriter), tailLength = 0)
val actualString = stringWriter.toString()
assertThat(actualString).contains("1")
assertThat(actualString).contains("null")
assertThat(actualString).contains("3")
job.cancel()
}
@Test
fun logInputChange_unit_printsInputName() = runBlocking(IMMEDIATE) {
val flow: Flow<Unit> = flowOf(Unit, Unit)
val job = flow
.logInputChange(logger, "testInputs")
.launchIn(this)
val stringWriter = StringWriter()
buffer.dump(PrintWriter(stringWriter), tailLength = 0)
val actualString = stringWriter.toString()
assertThat(actualString).contains("testInputs")
job.cancel()
}
@Test
fun logInputChange_any_printsValuesAndNulls() = runBlocking(IMMEDIATE) {
val flow: Flow<Any?> = flowOf(null, 2, "threeString")
val job = flow
.logInputChange(logger, "testInputs")
.launchIn(this)
val stringWriter = StringWriter()
buffer.dump(PrintWriter(stringWriter), tailLength = 0)
val actualString = stringWriter.toString()
assertThat(actualString).contains("null")
assertThat(actualString).contains("2")
assertThat(actualString).contains("threeString")
job.cancel()
}
companion object {
private const val NET_1_ID = 100
private val NET_1 = com.android.systemui.util.mockito.mock<Network>().also {
Mockito.`when`(it.getNetId()).thenReturn(NET_1_ID)
}
private val NET_1_CAPS = NetworkCapabilities.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
.build()
private val IMMEDIATE = Dispatchers.Main.immediate
private val NET_1 =
com.android.systemui.util.mockito.mock<Network>().also {
Mockito.`when`(it.getNetId()).thenReturn(NET_1_ID)
}
private val NET_1_CAPS =
NetworkCapabilities.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
.build()
}
}

View File

@@ -24,7 +24,6 @@ import com.android.systemui.statusbar.pipeline.airplane.data.repository.FakeAirp
import com.android.systemui.statusbar.pipeline.airplane.domain.interactor.AirplaneModeInteractor
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.FakeMobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.shared.MobileInputLogger
import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
import com.android.systemui.statusbar.pipeline.shared.ConnectivityConstants
import com.android.systemui.statusbar.pipeline.shared.data.repository.FakeConnectivityRepository
@@ -51,7 +50,6 @@ class MobileIconsViewModelTest : SysuiTestCase() {
private lateinit var airplaneModeInteractor: AirplaneModeInteractor
@Mock private lateinit var statusBarPipelineFlags: StatusBarPipelineFlags
@Mock private lateinit var logger: MobileInputLogger
@Mock private lateinit var constants: ConnectivityConstants
private val testDispatcher = UnconfinedTestDispatcher()
@@ -77,7 +75,6 @@ class MobileIconsViewModelTest : SysuiTestCase() {
subscriptionIdsFlow,
interactor,
airplaneModeInteractor,
logger,
constants,
testScope.backgroundScope,
statusBarPipelineFlags,

View File

@@ -61,14 +61,15 @@ class ConnectivityRepositoryImplTest : SysuiTestCase() {
MockitoAnnotations.initMocks(this)
scope = CoroutineScope(IMMEDIATE)
underTest = ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
underTest =
ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
}
@After
@@ -77,199 +78,179 @@ class ConnectivityRepositoryImplTest : SysuiTestCase() {
}
@Test
fun forceHiddenSlots_initiallyGetsDefault() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
context.getOrCreateTestableResources().addOverride(
DEFAULT_HIDDEN_ICONS_RESOURCE,
arrayOf(SLOT_WIFI, SLOT_ETHERNET)
)
// Re-create our [ConnectivityRepositoryImpl], since it fetches
// config_statusBarIconsToExclude when it's first constructed
underTest = ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
fun forceHiddenSlots_initiallyGetsDefault() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
context
.getOrCreateTestableResources()
.addOverride(DEFAULT_HIDDEN_ICONS_RESOURCE, arrayOf(SLOT_WIFI, SLOT_ETHERNET))
// Re-create our [ConnectivityRepositoryImpl], since it fetches
// config_statusBarIconsToExclude when it's first constructed
underTest =
ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
assertThat(latest).containsExactly(ConnectivitySlot.ETHERNET, ConnectivitySlot.WIFI)
assertThat(latest).containsExactly(ConnectivitySlot.ETHERNET, ConnectivitySlot.WIFI)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_slotNamesAdded_flowHasSlots() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
fun forceHiddenSlots_slotNamesAdded_flowHasSlots() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_wrongKey_doesNotUpdate() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
fun forceHiddenSlots_wrongKey_doesNotUpdate() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
// WHEN onTuningChanged with the wrong key
getTunable().onTuningChanged("wrongKey", SLOT_WIFI)
yield()
// WHEN onTuningChanged with the wrong key
getTunable().onTuningChanged("wrongKey", SLOT_WIFI)
yield()
// THEN we didn't update our value and still have the old one
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
// THEN we didn't update our value and still have the old one
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_slotNamesAddedThenNull_flowHasDefault() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
context.getOrCreateTestableResources().addOverride(
DEFAULT_HIDDEN_ICONS_RESOURCE,
arrayOf(SLOT_WIFI, SLOT_ETHERNET)
)
// Re-create our [ConnectivityRepositoryImpl], since it fetches
// config_statusBarIconsToExclude when it's first constructed
underTest = ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
fun forceHiddenSlots_slotNamesAddedThenNull_flowHasDefault() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
context
.getOrCreateTestableResources()
.addOverride(DEFAULT_HIDDEN_ICONS_RESOURCE, arrayOf(SLOT_WIFI, SLOT_ETHERNET))
// Re-create our [ConnectivityRepositoryImpl], since it fetches
// config_statusBarIconsToExclude when it's first constructed
underTest =
ConnectivityRepositoryImpl(
connectivitySlots,
context,
dumpManager,
logger,
scope,
tunerService,
)
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
// First, update the slots
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
// First, update the slots
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, SLOT_MOBILE)
assertThat(latest).containsExactly(ConnectivitySlot.MOBILE)
// WHEN we update to a null value
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, null)
yield()
// WHEN we update to a null value
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, null)
yield()
// THEN we go back to our default value
assertThat(latest).containsExactly(ConnectivitySlot.ETHERNET, ConnectivitySlot.WIFI)
// THEN we go back to our default value
assertThat(latest).containsExactly(ConnectivitySlot.ETHERNET, ConnectivitySlot.WIFI)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_someInvalidSlotNames_flowHasValidSlotsOnly() = runBlocking(IMMEDIATE) {
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
fun forceHiddenSlots_someInvalidSlotNames_flowHasValidSlotsOnly() =
runBlocking(IMMEDIATE) {
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI))
.thenReturn(ConnectivitySlot.WIFI)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI)).thenReturn(ConnectivitySlot.WIFI)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE)).thenReturn(null)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_WIFI,$SLOT_MOBILE")
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_WIFI,$SLOT_MOBILE")
assertThat(latest).containsExactly(ConnectivitySlot.WIFI)
assertThat(latest).containsExactly(ConnectivitySlot.WIFI)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_someEmptySlotNames_flowHasValidSlotsOnly() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
fun forceHiddenSlots_someEmptySlotNames_flowHasValidSlotsOnly() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
// WHEN there's empty and blank slot names
getTunable().onTuningChanged(
HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_MOBILE, ,,$SLOT_WIFI"
)
// WHEN there's empty and blank slot names
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_MOBILE, ,,$SLOT_WIFI")
// THEN we skip that slot but still process the other ones
assertThat(latest).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.MOBILE)
// THEN we skip that slot but still process the other ones
assertThat(latest).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.MOBILE)
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_allInvalidOrEmptySlotNames_flowHasEmpty() = runBlocking(IMMEDIATE) {
var latest: Set<ConnectivitySlot>? = null
val job = underTest
.forceHiddenSlots
.onEach { latest = it }
.launchIn(this)
fun forceHiddenSlots_allInvalidOrEmptySlotNames_flowHasEmpty() =
runBlocking(IMMEDIATE) {
var latest: Set<ConnectivitySlot>? = null
val job = underTest.forceHiddenSlots.onEach { latest = it }.launchIn(this)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_ETHERNET)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_ETHERNET)).thenReturn(null)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE)).thenReturn(null)
getTunable().onTuningChanged(
HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_MOBILE,,$SLOT_WIFI,$SLOT_ETHERNET,,,"
)
getTunable()
.onTuningChanged(
HIDDEN_ICONS_TUNABLE_KEY,
"$SLOT_MOBILE,,$SLOT_WIFI,$SLOT_ETHERNET,,,"
)
assertThat(latest).isEmpty()
assertThat(latest).isEmpty()
job.cancel()
}
job.cancel()
}
@Test
fun forceHiddenSlots_newSubscriberGetsCurrentValue() = runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
fun forceHiddenSlots_newSubscriberGetsCurrentValue() =
runBlocking(IMMEDIATE) {
setUpEthernetWifiMobileSlotNames()
var latest1: Set<ConnectivitySlot>? = null
val job1 = underTest
.forceHiddenSlots
.onEach { latest1 = it }
.launchIn(this)
var latest1: Set<ConnectivitySlot>? = null
val job1 = underTest.forceHiddenSlots.onEach { latest1 = it }.launchIn(this)
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_WIFI,$SLOT_ETHERNET")
getTunable().onTuningChanged(HIDDEN_ICONS_TUNABLE_KEY, "$SLOT_WIFI,$SLOT_ETHERNET")
assertThat(latest1).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.ETHERNET)
assertThat(latest1).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.ETHERNET)
// WHEN we add a second subscriber after having already emitted a value
var latest2: Set<ConnectivitySlot>? = null
val job2 = underTest
.forceHiddenSlots
.onEach { latest2 = it }
.launchIn(this)
// WHEN we add a second subscriber after having already emitted a value
var latest2: Set<ConnectivitySlot>? = null
val job2 = underTest.forceHiddenSlots.onEach { latest2 = it }.launchIn(this)
// THEN the second subscribe receives the already-emitted value
assertThat(latest2).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.ETHERNET)
// THEN the second subscribe receives the already-emitted value
assertThat(latest2).containsExactly(ConnectivitySlot.WIFI, ConnectivitySlot.ETHERNET)
job1.cancel()
job2.cancel()
}
job1.cancel()
job2.cancel()
}
private fun getTunable(): TunerService.Tunable {
val callbackCaptor = argumentCaptor<TunerService.Tunable>()
@@ -280,10 +261,8 @@ class ConnectivityRepositoryImplTest : SysuiTestCase() {
private fun setUpEthernetWifiMobileSlotNames() {
whenever(connectivitySlots.getSlotFromName(SLOT_ETHERNET))
.thenReturn(ConnectivitySlot.ETHERNET)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI))
.thenReturn(ConnectivitySlot.WIFI)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE))
.thenReturn(ConnectivitySlot.MOBILE)
whenever(connectivitySlots.getSlotFromName(SLOT_WIFI)).thenReturn(ConnectivitySlot.WIFI)
whenever(connectivitySlots.getSlotFromName(SLOT_MOBILE)).thenReturn(ConnectivitySlot.MOBILE)
}
companion object {