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

Commit bfa7f8af authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media TTT] Use the app's package name to fetch its icon.

Fixes: 216141279
Fixes: 216141276
Bug: 217418566
Test: Verify systemui's icon is shown on the chip
Change-Id: Ia933b9c0187ea70a8fb262ad5be80d3ac0368e0d
parent 810cb921
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ class MediaTttCommandLineHelper @Inject constructor(
        override fun execute(pw: PrintWriter, args: List<String>) {
            val routeInfo = MediaRoute2Info.Builder("id", args[0])
                    .addFeature("feature")
                    .setPackageName(TEST_PACKAGE_NAME)
                    .build()

            val commandName = args[1]
@@ -137,6 +138,11 @@ class MediaTttCommandLineHelper @Inject constructor(
        override fun execute(pw: PrintWriter, args: List<String>) {
            val statusBarManager = context.getSystemService(Context.STATUS_BAR_SERVICE)
                    as StatusBarManager
            val routeInfo = MediaRoute2Info.Builder("id", "Test Name")
                .addFeature("feature")
                .setPackageName(TEST_PACKAGE_NAME)
                .build()

            when(val commandName = args[0]) {
                CLOSE_TO_SENDER_STATE ->
                    statusBarManager.updateMediaTapToTransferReceiverDisplay(
@@ -170,7 +176,4 @@ const val CLOSE_TO_SENDER_STATE = "CloseToSender"
@VisibleForTesting
const val FAR_FROM_SENDER_STATE = "FarFromSender"
private const val CLI_TAG = "MediaTransferCli"

private val routeInfo = MediaRoute2Info.Builder("id", "Test Name")
    .addFeature("feature")
    .build()
 No newline at end of file
private const val TEST_PACKAGE_NAME = "com.android.systemui"
+11 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context
import android.graphics.PixelFormat
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.android.internal.widget.CachingIconView
@@ -100,10 +101,17 @@ abstract class MediaTttChipControllerCommon<T : MediaTttChipState>(
     * This is in the common superclass since both the sender and the receiver show an icon.
     */
    internal fun setIcon(chipState: T, currentChipView: ViewGroup) {
        currentChipView.findViewById<CachingIconView>(R.id.app_icon).apply {
            this.setImageDrawable(chipState.appIconDrawable)
            this.contentDescription = chipState.appIconContentDescription
        val appIconView = currentChipView.findViewById<CachingIconView>(R.id.app_icon)
        appIconView.contentDescription = chipState.appIconContentDescription

        val appIcon = chipState.getAppIcon(context)
        val visibility = if (appIcon != null) {
            View.VISIBLE
        } else {
            View.GONE
        }
        appIconView.setImageDrawable(appIcon)
        appIconView.visibility = visibility
    }
}

+19 −3
Original line number Diff line number Diff line
@@ -16,15 +16,31 @@

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

/**
 * A superclass chip state that will be subclassed by the sender chip and receiver chip.
 *
 * @property appIconDrawable a drawable representing the icon of the app playing the media.
 * @property appPackageName the package name of the app playing the media. Will be used to fetch the
 *   app icon.
 * @property appIconContentDescription a string to use as the content description for the icon.
 */
open class MediaTttChipState(
    internal val appIconDrawable: Drawable,
    internal val appPackageName: String?,
    internal val appIconContentDescription: String
)
) {
    fun getAppIcon(context: Context): Drawable? {
        appPackageName ?: return null
        return try {
            context.packageManager.getApplicationIcon(appPackageName)
        } catch (e: PackageManager.NameNotFoundException) {
            Log.w(TAG, "Cannot find icon for package $appPackageName", e)
            null
        }
    }
}

private val TAG = MediaTttChipState::class.simpleName!!
+2 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.media.taptotransfer.receiver

import android.graphics.drawable.Drawable
import com.android.systemui.media.taptotransfer.common.MediaTttChipState

/**
@@ -24,6 +23,6 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipState
 * the receiver device.
 */
class ChipStateReceiver(
    appIconDrawable: Drawable,
    appPackageName: String?,
    appIconContentDescription: String
) : MediaTttChipState(appIconDrawable, appIconContentDescription)
) : MediaTttChipState(appPackageName, appIconContentDescription)
+1 −9
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.systemui.media.taptotransfer.receiver

import android.app.StatusBarManager
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Icon
import android.media.MediaRoute2Info
import android.util.Log
import android.view.ViewGroup
@@ -43,12 +41,6 @@ class MediaTttChipControllerReceiver @Inject constructor(
) : MediaTttChipControllerCommon<ChipStateReceiver>(
    context, windowManager, R.layout.media_ttt_chip_receiver
) {
    // TODO(b/216141279): Use app icon from media route info instead of this fake one.
    private val fakeAppIconDrawable =
        Icon.createWithResource(context, R.drawable.ic_avatar_user).loadDrawable(context).also {
            it.setTint(Color.YELLOW)
        }

    private val commandQueueCallbacks = object : CommandQueue.Callbacks {
        override fun updateMediaTapToTransferReceiverDisplay(
            @StatusBarManager.MediaTransferReceiverState displayState: Int,
@@ -70,7 +62,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
    ) {
        when(displayState) {
            StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER ->
                displayChip(ChipStateReceiver(fakeAppIconDrawable, routeInfo.name.toString()))
                displayChip(ChipStateReceiver(routeInfo.packageName, routeInfo.name.toString()))
            StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER -> removeChip()
            else ->
                Log.e(RECEIVER_TAG, "Unhandled MediaTransferReceiverState $displayState")
Loading