[SB Refactor] Add table logging for airplane mode.

Bug: 238425913
Test: `adb shell dumpsys activity service
com.android.systemui/.SystemUIService AirplaneTableLog` -> dumps the
list of airplane mode changes
Test: atest TableLogBufferTest

Change-Id: Ia89bcd96089934c4b611adea26de82d5c094780a
This commit is contained in:
Caitlin Shkuratov
2022-11-23 20:02:43 +00:00
parent e3926eeb91
commit 4bca303dff
7 changed files with 88 additions and 6 deletions

View File

@@ -78,3 +78,25 @@ fun <T : Diffable<T>> Flow<T>.logDiffsForTable(
newVal
}
}
/**
* Each time the boolean flow is updated with a new value that's different from the previous value,
* logs the new value to the given [tableLogBuffer].
*/
fun Flow<Boolean>.logDiffsForTable(
tableLogBuffer: TableLogBuffer,
columnPrefix: String,
columnName: String,
initialValue: Boolean,
): Flow<Boolean> {
val initialValueFun = {
tableLogBuffer.logChange(columnPrefix, columnName, initialValue)
initialValue
}
return this.pairwiseBy(initialValueFun) { prevVal, newVal: Boolean ->
if (prevVal != newVal) {
tableLogBuffer.logChange(columnPrefix, columnName, newVal)
}
newVal
}
}

View File

@@ -127,6 +127,11 @@ class TableLogBuffer(
rowInitializer(row)
}
/** Logs a boolean change. */
fun logChange(prefix: String, columnName: String, value: Boolean) {
logChange(systemClock.currentTimeMillis(), prefix, columnName, value)
}
// Keep these individual [logChange] methods private (don't let clients give us their own
// timestamps.)

View File

@@ -23,9 +23,10 @@ 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.qs.SettingObserver
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange
import com.android.systemui.statusbar.pipeline.dagger.AirplaneTableLog
import com.android.systemui.util.settings.GlobalSettings
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -58,7 +59,7 @@ class AirplaneModeRepositoryImpl
constructor(
@Background private val bgHandler: Handler,
private val globalSettings: GlobalSettings,
logger: ConnectivityPipelineLogger,
@AirplaneTableLog logger: TableLogBuffer,
@Application scope: CoroutineScope,
) : AirplaneModeRepository {
// TODO(b/254848912): Replace this with a generic SettingObserver coroutine once we have it.
@@ -82,7 +83,12 @@ constructor(
awaitClose { observer.isListening = false }
}
.distinctUntilChanged()
.logInputChange(logger, "isAirplaneMode")
.logDiffsForTable(
logger,
columnPrefix = "",
columnName = "isAirplaneMode",
initialValue = false
)
.stateIn(
scope,
started = SharingStarted.WhileSubscribed(),

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 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
/** Airplane mode logs in table format. */
@Qualifier
@MustBeDocumented
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class AirplaneTableLog

View File

@@ -71,5 +71,13 @@ abstract class StatusBarPipelineModule {
fun provideWifiTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
return factory.create("WifiTableLog", 100)
}
@JvmStatic
@Provides
@SysUISingleton
@AirplaneTableLog
fun provideAirplaneTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
return factory.create("AirplaneTableLog", 30)
}
}
}

View File

@@ -132,6 +132,22 @@ class TableLogBufferTest : SysuiTestCase() {
underTest.logDiffs("prefix", TestDiffable(), next)
}
@Test
fun logChange_bool_dumpsCorrectly() {
systemClock.setCurrentTimeMillis(4000L)
underTest.logChange("prefix", "columnName", true)
val dumpedString = dumpChanges()
val expected =
TABLE_LOG_DATE_FORMAT.format(4000L) +
SEPARATOR +
"prefix.columnName" +
SEPARATOR +
"true"
assertThat(dumpedString).contains(expected)
}
@Test
fun dumpChanges_strChange_logsFromNext() {
systemClock.setCurrentTimeMillis(100L)

View File

@@ -22,7 +22,7 @@ import android.os.UserHandle
import android.provider.Settings.Global
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.util.settings.FakeSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.CoroutineScope
@@ -45,7 +45,7 @@ class AirplaneModeRepositoryImplTest : SysuiTestCase() {
private lateinit var underTest: AirplaneModeRepositoryImpl
@Mock private lateinit var logger: ConnectivityPipelineLogger
@Mock private lateinit var logger: TableLogBuffer
private lateinit var bgHandler: Handler
private lateinit var scope: CoroutineScope
private lateinit var settings: FakeSettings