diff --git a/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt b/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt index 38af003ffaa57..bb04b6b41a33b 100644 --- a/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt +++ b/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt @@ -78,3 +78,25 @@ fun > Flow.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.logDiffsForTable( + tableLogBuffer: TableLogBuffer, + columnPrefix: String, + columnName: String, + initialValue: Boolean, +): Flow { + val initialValueFun = { + tableLogBuffer.logChange(columnPrefix, columnName, initialValue) + initialValue + } + return this.pairwiseBy(initialValueFun) { prevVal, newVal: Boolean -> + if (prevVal != newVal) { + tableLogBuffer.logChange(columnPrefix, columnName, newVal) + } + newVal + } +} diff --git a/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt b/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt index 0bf530496b28a..9d0b833d26ccb 100644 --- a/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt +++ b/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt @@ -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.) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt index 7aa5ee1389f37..8ff9198da119b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepository.kt @@ -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(), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/AirplaneTableLog.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/AirplaneTableLog.kt new file mode 100644 index 0000000000000..4f70f660187fd --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/AirplaneTableLog.kt @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/StatusBarPipelineModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/StatusBarPipelineModule.kt index 0662fb3d52b95..c961422086f81 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/StatusBarPipelineModule.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/dagger/StatusBarPipelineModule.kt @@ -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) + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/log/table/TableLogBufferTest.kt b/packages/SystemUI/tests/src/com/android/systemui/log/table/TableLogBufferTest.kt index 37fb6af3886a4..2c8d7abd4f4ae 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/log/table/TableLogBufferTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/log/table/TableLogBufferTest.kt @@ -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) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepositoryImplTest.kt index b7a6c0125cfa6..d35ce76d7a9a9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/airplane/data/repository/AirplaneModeRepositoryImplTest.kt @@ -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