diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index ffae6015c7327..66f766bb14578 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1005,6 +1005,9 @@ 100dp 95dp + + 70dp 35dp diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttCommandLineHelper.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttCommandLineHelper.kt index 3961f079748b4..e4b8874ff601e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttCommandLineHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttCommandLineHelper.kt @@ -128,19 +128,21 @@ class MediaTttCommandLineHelper @Inject constructor( as StatusBarManager val routeInfo = MediaRoute2Info.Builder("id", "Test Name") .addFeature("feature") - .setPackageName(TEST_PACKAGE_NAME) - .build() + if (args.size >= 2 && args[1] == "useAppIcon=true") { + routeInfo.setPackageName(TEST_PACKAGE_NAME) + } statusBarManager.updateMediaTapToTransferReceiverDisplay( displayState, - routeInfo, + routeInfo.build(), null, null ) } override fun help(pw: PrintWriter) { - pw.println("Usage: adb shell cmd statusbar $RECEIVER_COMMAND ") + pw.println("Usage: adb shell cmd statusbar $RECEIVER_COMMAND " + + " useAppIcon=[true|false]") } } } diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt index 3d5b3a3f70dfe..54b0c13456010 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt @@ -31,6 +31,7 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.view.WindowManager +import android.widget.LinearLayout import com.android.internal.widget.CachingIconView import com.android.settingslib.Utils import com.android.systemui.R @@ -136,6 +137,11 @@ abstract class MediaTttChipControllerCommon( */ abstract fun updateChipView(chipInfo: T, currentChipView: ViewGroup) + /** + * Returns the size that the icon should be, or null if no size override is needed. + */ + open fun getIconSize(isAppIcon: Boolean): Int? = null + /** * An internal method to set the icon on the view. * @@ -151,35 +157,47 @@ abstract class MediaTttChipControllerCommon( appNameOverride: CharSequence? = null, ) { val appIconView = currentChipView.requireViewById(R.id.app_icon) - val appInfo = getAppInfo(appPackageName) - appIconView.contentDescription = appNameOverride ?: appInfo.appName - appIconView.setImageDrawable(appIconDrawableOverride ?: appInfo.appIcon) + val iconInfo = getIconInfo(appPackageName) + + getIconSize(iconInfo.isAppIcon)?.let { size -> + val lp = appIconView.layoutParams + lp.width = size + lp.height = size + appIconView.layoutParams = lp + } + + appIconView.contentDescription = appNameOverride ?: iconInfo.iconName + appIconView.setImageDrawable(appIconDrawableOverride ?: iconInfo.icon) } /** - * Returns the app name and icon of the app playing media, or a default name and icon if we - * can't find the app name/icon. + * Returns the information needed to display the icon. + * + * The information will either contain app name and icon of the app playing media, or a default + * name and icon if we can't find the app name/icon. */ - private fun getAppInfo(appPackageName: String?): AppInfo { + private fun getIconInfo(appPackageName: String?): IconInfo { if (appPackageName != null) { try { - return AppInfo( - appName = context.packageManager.getApplicationInfo( + return IconInfo( + iconName = context.packageManager.getApplicationInfo( appPackageName, PackageManager.ApplicationInfoFlags.of(0) ).loadLabel(context.packageManager).toString(), - appIcon = context.packageManager.getApplicationIcon(appPackageName) + icon = context.packageManager.getApplicationIcon(appPackageName), + isAppIcon = true ) } catch (e: PackageManager.NameNotFoundException) { Log.w(TAG, "Cannot find package $appPackageName", e) } } - return AppInfo( - appName = context.getString(R.string.media_output_dialog_unknown_launch_app_name), - appIcon = context.resources.getDrawable(R.drawable.ic_cast).apply { + return IconInfo( + iconName = context.getString(R.string.media_output_dialog_unknown_launch_app_name), + icon = context.resources.getDrawable(R.drawable.ic_cast).apply { this.setTint( Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary) ) - } + }, + isAppIcon = false ) } @@ -203,7 +221,9 @@ object MediaTttRemovalReason { const val REASON_SCREEN_TAP = "SCREEN_TAP" } -private data class AppInfo( - val appName: String, - val appIcon: Drawable +private data class IconInfo( + val iconName: String, + val icon: Drawable, + /** True if [icon] is the app's icon, and false if [icon] is some generic default icon. */ + val isAppIcon: Boolean ) diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt index 44965d7058026..072263fcf38cf 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt @@ -127,6 +127,15 @@ class MediaTttChipControllerReceiver @Inject constructor( chipInfo.appNameOverride ) } + + override fun getIconSize(isAppIcon: Boolean): Int? = + context.resources.getDimensionPixelSize( + if (isAppIcon) { + R.dimen.media_ttt_icon_size_receiver + } else { + R.dimen.media_ttt_generic_icon_size_receiver + } + ) } data class ChipReceiverInfo( diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt index 962d78c129f95..b9a69bb8641a1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt @@ -192,9 +192,9 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { verify(windowManager, never()).removeView(any()) } - + @Test - fun displayChip_nullAppIconDrawableAndNullPackageName_stillHasIcon() { + fun setIcon_nullAppIconDrawableAndNullPackageName_stillHasIcon() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -204,7 +204,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_nullAppIconDrawableAndInvalidPackageName_stillHasIcon() { + fun setIcon_nullAppIconDrawableAndInvalidPackageName_stillHasIcon() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -226,7 +226,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_hasAppIconDrawable_iconIsDrawable() { + fun setIcon_hasAppIconDrawable_iconIsDrawable() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -237,7 +237,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_nullAppNameAndNullPackageName_stillHasContentDescription() { + fun setIcon_nullAppNameAndNullPackageName_stillHasContentDescription() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -247,7 +247,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_nullAppNameAndInvalidPackageName_stillHasContentDescription() { + fun setIcon_nullAppNameAndInvalidPackageName_stillHasContentDescription() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -259,7 +259,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_nullAppName_iconContentDescriptionIsFromPackageName() { + fun setIcon_nullAppName_iconContentDescriptionIsFromPackageName() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -269,7 +269,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_hasAppName_iconContentDescriptionIsAppNameOverride() { + fun setIcon_hasAppName_iconContentDescriptionIsAppNameOverride() { controllerCommon.displayChip(getState()) val chipView = getChipView() @@ -279,6 +279,21 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { assertThat(chipView.getAppIconView().contentDescription).isEqualTo(appName) } + @Test + fun setIcon_iconSizeMatchesGetIconSize() { + controllerCommon.displayChip(getState()) + val chipView = getChipView() + + controllerCommon.setIcon(chipView, PACKAGE_NAME) + chipView.measure( + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + ) + + assertThat(chipView.getAppIconView().measuredWidth).isEqualTo(ICON_SIZE) + assertThat(chipView.getAppIconView().measuredHeight).isEqualTo(ICON_SIZE) + } + @Test fun tapGestureDetected_outsideViewBounds_viewHidden() { controllerCommon.displayChip(getState()) @@ -344,6 +359,8 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { override fun updateChipView(chipInfo: ChipInfo, currentChipView: ViewGroup) { } + + override fun getIconSize(isAppIcon: Boolean): Int? = ICON_SIZE } inner class ChipInfo : ChipInfoCommon { @@ -354,3 +371,4 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { private const val PACKAGE_NAME = "com.android.systemui" private const val APP_NAME = "Fake App Name" private const val TIMEOUT_MS = 10000L +private const val ICON_SIZE = 47 \ No newline at end of file diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt index 355d3fe4b8d1f..067607f9b8aed 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt @@ -174,12 +174,47 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() { verify(logger).logStateChange(any(), any()) } + @Test + fun setIcon_isAppIcon_usesAppIconSize() { + controllerReceiver.displayChip(getChipReceiverInfo()) + val chipView = getChipView() + + controllerReceiver.setIcon(chipView, PACKAGE_NAME) + chipView.measure( + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + ) + + val expectedSize = controllerReceiver.getIconSize(isAppIcon = true) + assertThat(chipView.getAppIconView().measuredWidth).isEqualTo(expectedSize) + assertThat(chipView.getAppIconView().measuredHeight).isEqualTo(expectedSize) + } + + @Test + fun setIcon_notAppIcon_usesGenericIconSize() { + controllerReceiver.displayChip(getChipReceiverInfo()) + val chipView = getChipView() + + controllerReceiver.setIcon(chipView, appPackageName = null) + chipView.measure( + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + ) + + val expectedSize = controllerReceiver.getIconSize(isAppIcon = false) + assertThat(chipView.getAppIconView().measuredWidth).isEqualTo(expectedSize) + assertThat(chipView.getAppIconView().measuredHeight).isEqualTo(expectedSize) + } + private fun getChipView(): ViewGroup { val viewCaptor = ArgumentCaptor.forClass(View::class.java) verify(windowManager).addView(viewCaptor.capture(), any()) return viewCaptor.value as ViewGroup } + private fun getChipReceiverInfo(): ChipReceiverInfo = + ChipReceiverInfo(routeInfo, null, null) + private fun ViewGroup.getAppIconView() = this.requireViewById(R.id.app_icon) }