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

Commit 2e21b11a authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

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

description.

Fixes: 217418566
Test: manual -- verify contentDescription of icon is "System UI"
Test: media.taptotransfer tests
Change-Id: I59ef37d2ba064f1bc51f9d64c716360ba883d8fc
parent bfa7f8af
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -101,8 +101,8 @@ 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) {
        val appIconView = currentChipView.findViewById<CachingIconView>(R.id.app_icon)
        appIconView.contentDescription = chipState.appIconContentDescription
        val appIconView = currentChipView.requireViewById<CachingIconView>(R.id.app_icon)
        appIconView.contentDescription = chipState.getAppName(context)

        val appIcon = chipState.getAppIcon(context)
        val visibility = if (appIcon != null) {
+14 −3
Original line number Diff line number Diff line
@@ -25,12 +25,10 @@ import android.util.Log
 * A superclass chip state that will be subclassed by the sender chip and receiver chip.
 *
 * @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.
 *   app icon and app name.
 */
open class MediaTttChipState(
    internal val appPackageName: String?,
    internal val appIconContentDescription: String
) {
    fun getAppIcon(context: Context): Drawable? {
        appPackageName ?: return null
@@ -41,6 +39,19 @@ open class MediaTttChipState(
            null
        }
    }

    /** Returns the name of the app playing the media or null if we can't find it. */
    fun getAppName(context: Context): String? {
        appPackageName ?: return null
        return try {
            context.packageManager.getApplicationInfo(
                appPackageName, PackageManager.ApplicationInfoFlags.of(0)
            ).loadLabel(context.packageManager).toString()
        } catch (e: PackageManager.NameNotFoundException) {
            Log.w(TAG, "Cannot find name for package $appPackageName", e)
            null
        }
    }
}

private val TAG = MediaTttChipState::class.simpleName!!
+1 −2
Original line number Diff line number Diff line
@@ -24,5 +24,4 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipState
 */
class ChipStateReceiver(
    appPackageName: String?,
    appIconContentDescription: String
) : MediaTttChipState(appPackageName, appIconContentDescription)
) : MediaTttChipState(appPackageName)
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
    ) {
        when(displayState) {
            StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER ->
                displayChip(ChipStateReceiver(routeInfo.packageName, routeInfo.name.toString()))
                displayChip(ChipStateReceiver(routeInfo.packageName))
            StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER -> removeChip()
            else ->
                Log.e(RECEIVER_TAG, "Unhandled MediaTransferReceiverState $displayState")
@@ -74,4 +74,4 @@ class MediaTttChipControllerReceiver @Inject constructor(
    }
}

private const val RECEIVER_TAG = "MediaTapToTransferReceiver"
private const val RECEIVER_TAG = "MediaTapToTransferRcvr"
+10 −22
Original line number Diff line number Diff line
@@ -30,9 +30,8 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipState
 * contain additional information that is necessary for only that state.
 */
sealed class ChipStateSender(
    appPackageName: String?,
    appIconContentDescription: String
) : MediaTttChipState(appPackageName, appIconContentDescription) {
    appPackageName: String?
) : MediaTttChipState(appPackageName) {
    /** Returns a fully-formed string with the text that the chip should display. */
    abstract fun getChipTextString(context: Context): String

@@ -60,9 +59,8 @@ sealed class ChipStateSender(
 */
class AlmostCloseToStartCast(
    appPackageName: String?,
    appIconContentDescription: String,
    private val otherDeviceName: String,
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_move_closer_to_start_cast, otherDeviceName)
    }
@@ -77,9 +75,8 @@ class AlmostCloseToStartCast(
 */
class AlmostCloseToEndCast(
    appPackageName: String?,
    appIconContentDescription: String,
    private val otherDeviceName: String,
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_move_closer_to_end_cast, otherDeviceName)
    }
@@ -93,9 +90,8 @@ class AlmostCloseToEndCast(
 */
class TransferToReceiverTriggered(
    appPackageName: String?,
    appIconContentDescription: String,
    private val otherDeviceName: String
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_transfer_playing_different_device, otherDeviceName)
    }
@@ -109,8 +105,7 @@ class TransferToReceiverTriggered(
 */
class TransferToThisDeviceTriggered(
    appPackageName: String?,
    appIconContentDescription: String
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_transfer_playing_this_device)
    }
@@ -127,10 +122,9 @@ class TransferToThisDeviceTriggered(
 */
class TransferToReceiverSucceeded(
    appPackageName: String?,
    appIconContentDescription: String,
    private val otherDeviceName: String,
    val undoCallback: IUndoMediaTransferCallback? = null
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_transfer_playing_different_device, otherDeviceName)
    }
@@ -148,10 +142,7 @@ class TransferToReceiverSucceeded(
            // but that may take too long to go through the binder and the user may be confused as
            // to why the UI hasn't changed yet. So, we immediately change the UI here.
            controllerSender.displayChip(
                TransferToThisDeviceTriggered(
                    this.appPackageName,
                    this.appIconContentDescription
                )
                TransferToThisDeviceTriggered(this.appPackageName)
            )
        }
    }
@@ -166,10 +157,9 @@ class TransferToReceiverSucceeded(
 */
class TransferToThisDeviceSucceeded(
    appPackageName: String?,
    appIconContentDescription: String,
    private val otherDeviceName: String,
    val undoCallback: IUndoMediaTransferCallback? = null
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_transfer_playing_this_device)
    }
@@ -189,7 +179,6 @@ class TransferToThisDeviceSucceeded(
            controllerSender.displayChip(
                TransferToReceiverTriggered(
                    this.appPackageName,
                    this.appIconContentDescription,
                    this.otherDeviceName
                )
            )
@@ -200,8 +189,7 @@ class TransferToThisDeviceSucceeded(
/** A state representing that a transfer has failed. */
class TransferFailed(
    appPackageName: String?,
    appIconContentDescription: String
) : ChipStateSender(appPackageName, appIconContentDescription) {
) : ChipStateSender(appPackageName) {
    override fun getChipTextString(context: Context): String {
        return context.getString(R.string.media_transfer_failed)
    }
Loading