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

Commit 6221183a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[SB Refactor] Add table logging for airplane mode." into tm-qpr-dev

parents 574d0b6e 4bca303d
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
@@ -78,3 +78,25 @@ fun <T : Diffable<T>> Flow<T>.logDiffsForTable(
        newVal
        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
    }
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -127,6 +127,11 @@ class TableLogBuffer(
        rowInitializer(row)
        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
    // Keep these individual [logChange] methods private (don't let clients give us their own
    // timestamps.)
    // timestamps.)


+10 −4
Original line number Original line Diff line number Diff line
@@ -23,9 +23,10 @@ import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCall
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
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.qs.SettingObserver
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.statusbar.pipeline.dagger.AirplaneTableLog
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.GlobalSettings
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
@@ -58,7 +59,7 @@ class AirplaneModeRepositoryImpl
constructor(
constructor(
    @Background private val bgHandler: Handler,
    @Background private val bgHandler: Handler,
    private val globalSettings: GlobalSettings,
    private val globalSettings: GlobalSettings,
    logger: ConnectivityPipelineLogger,
    @AirplaneTableLog logger: TableLogBuffer,
    @Application scope: CoroutineScope,
    @Application scope: CoroutineScope,
) : AirplaneModeRepository {
) : AirplaneModeRepository {
    // TODO(b/254848912): Replace this with a generic SettingObserver coroutine once we have it.
    // TODO(b/254848912): Replace this with a generic SettingObserver coroutine once we have it.
@@ -82,7 +83,12 @@ constructor(
                awaitClose { observer.isListening = false }
                awaitClose { observer.isListening = false }
            }
            }
            .distinctUntilChanged()
            .distinctUntilChanged()
            .logInputChange(logger, "isAirplaneMode")
            .logDiffsForTable(
                logger,
                columnPrefix = "",
                columnName = "isAirplaneMode",
                initialValue = false
            )
            .stateIn(
            .stateIn(
                scope,
                scope,
                started = SharingStarted.WhileSubscribed(),
                started = SharingStarted.WhileSubscribed(),
+25 −0
Original line number Original line Diff line number Diff line
/*
 * 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
+8 −0
Original line number Original line Diff line number Diff line
@@ -71,5 +71,13 @@ abstract class StatusBarPipelineModule {
        fun provideWifiTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
        fun provideWifiTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
            return factory.create("WifiTableLog", 100)
            return factory.create("WifiTableLog", 100)
        }
        }

        @JvmStatic
        @Provides
        @SysUISingleton
        @AirplaneTableLog
        fun provideAirplaneTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
            return factory.create("AirplaneTableLog", 30)
        }
    }
    }
}
}
Loading