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

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

[Chipbar] Replace the media-specific logger with a generic

TemporaryViewLogger.

Also add a log for chip addition, since we already had one for chip
removal.

Test: verify MediaTttSender and MediaTttReceiver log buffers still work
Test: systemui.temporarydisplay tests
Test: systemui.media.taptotransfer tests
Change-Id: Idb29d25de75c1a96c533b230d0f7d4286f777ba4
parent 39e6a8a1
Loading
Loading
Loading
Loading
+7 −18
Original line number Diff line number Diff line
@@ -18,22 +18,21 @@ package com.android.systemui.media.taptotransfer.common

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import com.android.systemui.temporarydisplay.TemporaryViewLogger

/**
 * A logger for media tap-to-transfer events.
 *
 * @property deviceTypeTag the type of device triggering the logs -- "Sender" or "Receiver".
 * @param deviceTypeTag the type of device triggering the logs -- "Sender" or "Receiver".
 */
class MediaTttLogger(
    private val deviceTypeTag: String,
    private val buffer: LogBuffer
){
    private val bufferTag = BASE_TAG + deviceTypeTag

    deviceTypeTag: String,
    buffer: LogBuffer
) : TemporaryViewLogger(buffer, BASE_TAG + deviceTypeTag) {
    /** Logs a change in the chip state for the given [mediaRouteId]. */
    fun logStateChange(stateName: String, mediaRouteId: String, packageName: String?) {
        buffer.log(
            bufferTag,
            tag,
            LogLevel.DEBUG,
            {
                str1 = stateName
@@ -44,20 +43,10 @@ class MediaTttLogger(
        )
    }

    /** Logs that we removed the chip for the given [reason]. */
    fun logChipRemoval(reason: String) {
        buffer.log(
            bufferTag,
            LogLevel.DEBUG,
            { str1 = reason },
            { "Chip removed due to $str1" }
        )
    }

    /** Logs that we couldn't find information for [packageName]. */
    fun logPackageNotFound(packageName: String) {
        buffer.log(
            bufferTag,
            tag,
            LogLevel.DEBUG,
            { str1 = packageName },
            { "Package $str1 could not be found" }
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
        powerManager: PowerManager,
        @Main private val mainHandler: Handler,
        private val uiEventLogger: MediaTttReceiverUiEventLogger,
) : TemporaryViewDisplayController<ChipReceiverInfo>(
) : TemporaryViewDisplayController<ChipReceiverInfo, MediaTttLogger>(
        context,
        logger,
        windowManager,
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class MediaTttChipControllerSender @Inject constructor(
        configurationController: ConfigurationController,
        powerManager: PowerManager,
        private val uiEventLogger: MediaTttSenderUiEventLogger
) : TemporaryViewDisplayController<ChipSenderInfo>(
) : TemporaryViewDisplayController<ChipSenderInfo, MediaTttLogger>(
        context,
        logger,
        windowManager,
+3 −6
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
import androidx.annotation.CallSuper
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.concurrency.DelayableExecutor

@@ -45,16 +44,14 @@ import com.android.systemui.util.concurrency.DelayableExecutor
 * The generic type T is expected to contain all the information necessary for the subclasses to
 * display the view in a certain state, since they receive <T> in [updateView].
 *
 * TODO(b/245610654): Remove all the media-specific logic from this class.
 *
 * @property windowTitle the title to use for the window that displays the temporary view. Should be
 *   normally cased, like "Window Title".
 * @property wakeReason a string used for logging if we needed to wake the screen in order to
 *   display the temporary view. Should be screaming snake cased, like WAKE_REASON.
 */
abstract class TemporaryViewDisplayController<T : TemporaryViewInfo>(
abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : TemporaryViewLogger>(
    internal val context: Context,
    internal val logger: MediaTttLogger,
    internal val logger: U,
    internal val windowManager: WindowManager,
    @Main private val mainExecutor: DelayableExecutor,
    private val accessibilityManager: AccessibilityManager,
@@ -120,7 +117,7 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo>(
                        "com.android.systemui:$wakeReason",
                )
            }

            logger.logChipAddition()
            inflateAndUpdateView(newInfo)
        }

+36 −0
Original line number 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.temporarydisplay

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel

/** A logger for temporary view changes -- see [TemporaryViewDisplayController]. */
open class TemporaryViewLogger(
    internal val buffer: LogBuffer,
    internal val tag: String,
) {
    /** Logs that we added the chip to a new window. */
    fun logChipAddition() {
        buffer.log(tag, LogLevel.DEBUG, {}, { "Chip added" })
    }

    /** Logs that we removed the chip for the given [reason]. */
    fun logChipRemoval(reason: String) {
        buffer.log(tag, LogLevel.DEBUG, { str1 = reason }, { "Chip removed due to $str1" })
    }
}
Loading