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

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

[Media TTT] Put package error logs in the log buffer with all the other

logs.

Bug: 246574567
Test: verified logs in logcat if invalid package name
Test: media.taptotransfer tests
Change-Id: I5b86508ecbfe0dd2e13f094bab236255afe850cc
parent 28d58530
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -28,10 +28,12 @@ class MediaTttLogger(
    private val deviceTypeTag: String,
    private val buffer: LogBuffer
){
    private val bufferTag = BASE_TAG + deviceTypeTag

    /** Logs a change in the chip state for the given [mediaRouteId]. */
    fun logStateChange(stateName: String, mediaRouteId: String, packageName: String?) {
        buffer.log(
            BASE_TAG + deviceTypeTag,
            bufferTag,
            LogLevel.DEBUG,
            {
                str1 = stateName
@@ -45,12 +47,22 @@ class MediaTttLogger(
    /** Logs that we removed the chip for the given [reason]. */
    fun logChipRemoval(reason: String) {
        buffer.log(
            BASE_TAG + deviceTypeTag,
            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,
            LogLevel.DEBUG,
            { str1 = packageName },
            { "Package $str1 could not be found" }
        )
    }
}

private const val BASE_TAG = "MediaTtt"
+7 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.media.taptotransfer.common
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.util.Log
import com.android.internal.widget.CachingIconView
import com.android.settingslib.Utils
import com.android.systemui.R
@@ -34,8 +33,13 @@ class MediaTttUtils {
         * default name and icon if we can't find the app name/icon.
         *
         * @param appPackageName the package name of the app playing the media.
         * @param logger the logger to use for any errors.
         */
        fun getIconInfoFromPackageName(context: Context, appPackageName: String?): IconInfo {
        fun getIconInfoFromPackageName(
            context: Context,
            appPackageName: String?,
            logger: MediaTttLogger
        ): IconInfo {
            if (appPackageName != null) {
                try {
                    val contentDescription =
@@ -52,7 +56,7 @@ class MediaTttUtils {
                        isAppIcon = true
                    )
                } catch (e: PackageManager.NameNotFoundException) {
                    Log.w(TAG, "Cannot find package $appPackageName", e)
                    logger.logPackageNotFound(appPackageName)
                }
            }
            return IconInfo(
@@ -101,5 +105,3 @@ data class IconInfo(
     */
    val isAppIcon: Boolean
)

private const val TAG = "MediaTtt"
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
        super.updateView(newInfo, currentView)

        val iconInfo = MediaTttUtils.getIconInfoFromPackageName(
            context, newInfo.routeInfo.clientPackageName
            context, newInfo.routeInfo.clientPackageName, logger
        )
        val iconDrawable = newInfo.appIconDrawableOverride ?: iconInfo.drawable
        val iconContentDescription = newInfo.appNameOverride ?: iconInfo.contentDescription
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ class MediaTttChipControllerSender @Inject constructor(

        // App icon
        val iconInfo = MediaTttUtils.getIconInfoFromPackageName(
            context, newInfo.routeInfo.clientPackageName
            context, newInfo.routeInfo.clientPackageName, logger
        )
        MediaTttUtils.setIcon(
            currentView.requireViewById(R.id.app_icon),
+13 −0
Original line number Diff line number Diff line
@@ -72,6 +72,19 @@ class MediaTttLoggerTest : SysuiTestCase() {
        assertThat(actualString).contains(DEVICE_TYPE_TAG)
        assertThat(actualString).contains(reason)
    }

    @Test
    fun logPackageNotFound_bufferHasPackageName() {
        val packageName = "this.is.a.package"

        logger.logPackageNotFound(packageName)

        val stringWriter = StringWriter()
        buffer.dump(PrintWriter(stringWriter), tailLength = 0)
        val actualString = stringWriter.toString()

        assertThat(actualString).contains(packageName)
    }
}

private const val DEVICE_TYPE_TAG = "TEST TYPE"
Loading