summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Remi NGUYEN VAN <reminv@google.com> 2022-03-24 10:58:35 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-03-24 10:58:35 +0000
commit9825a592b99a74952de6a5e66a9195e87c841af5 (patch)
treef46b99b20e83bada75465af12dde9294d20ea039
parentfd45ea359bc01c7e33a7a68bb4cf30593096e3a0 (diff)
parent6d0ec387857e5aedf329df1cbeb4d3c78c772291 (diff)
Merge "[conflict] Merge changes from topic "presubmit-am-f474a3dff5ca458a90dc89a6dc7b03f7" into sc-v2-dev-plus-aosp am: 0932ef9285" into tm-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java42
1 files changed, 36 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
index e1602dbb27a0..d2f953f65b8f 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
@@ -23,6 +23,7 @@ import android.app.WallpaperColors;
import android.app.smartspace.SmartspaceAction;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
@@ -35,6 +36,8 @@ import android.media.session.MediaController;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.os.Process;
+import android.text.Layout;
+import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -87,6 +90,7 @@ public class MediaControlPanel {
private static final int MEDIA_RECOMMENDATION_MAX_NUM = 6;
private static final String KEY_SMARTSPACE_ARTIST_NAME = "artist_name";
private static final String KEY_SMARTSPACE_OPEN_IN_FOREGROUND = "KEY_OPEN_IN_FOREGROUND";
+ private static final String KEY_SMARTSPACE_APP_NAME = "KEY_SMARTSPACE_APP_NAME";
// Event types logged by smartspace
private static final int SMARTSPACE_CARD_CLICK_EVENT = 760;
@@ -735,18 +739,33 @@ public class MediaControlPanel {
icon.setColorFilter(getGrayscaleFilter());
ImageView headerLogoImageView = mRecommendationViewHolder.getCardIcon();
headerLogoImageView.setImageDrawable(icon);
+
// Set up media source app's label text.
- CharSequence appLabel = packageManager.getApplicationLabel(applicationInfo);
- if (appLabel.length() != 0) {
+ CharSequence appName = getAppName(data.getCardAction());
+ if (TextUtils.isEmpty(appName)) {
+ Intent launchIntent =
+ packageManager.getLaunchIntentForPackage(data.getPackageName());
+ if (launchIntent != null) {
+ ActivityInfo launchActivity = launchIntent.resolveActivityInfo(packageManager, 0);
+ appName = launchActivity.loadLabel(packageManager);
+ } else {
+ Log.w(TAG, "Package " + data.getPackageName()
+ + " does not have a main launcher activity. Fallback to full app name");
+ appName = packageManager.getApplicationLabel(applicationInfo);
+ }
+ }
+ // Set the app name as card's title.
+ if (!TextUtils.isEmpty(appName)) {
TextView headerTitleText = mRecommendationViewHolder.getCardText();
- headerTitleText.setText(appLabel);
+ headerTitleText.setText(appName);
}
+
// Set up media rec card's tap action if applicable.
setSmartspaceRecItemOnClickListener(recommendationCard, data.getCardAction(),
/* interactedSubcardRank */ -1);
// Set up media rec card's accessibility label.
recommendationCard.setContentDescription(
- mContext.getString(R.string.controls_media_smartspace_rec_description, appLabel));
+ mContext.getString(R.string.controls_media_smartspace_rec_description, appName));
List<ImageView> mediaCoverItems = mRecommendationViewHolder.getMediaCoverItems();
List<ViewGroup> mediaCoverContainers = mRecommendationViewHolder.getMediaCoverContainers();
@@ -791,12 +810,12 @@ public class MediaControlPanel {
mediaCoverImageView.setContentDescription(
mContext.getString(
R.string.controls_media_smartspace_rec_item_no_artist_description,
- recommendation.getTitle(), appLabel));
+ recommendation.getTitle(), appName));
} else {
mediaCoverImageView.setContentDescription(
mContext.getString(
R.string.controls_media_smartspace_rec_item_description,
- recommendation.getTitle(), artistName, appLabel));
+ recommendation.getTitle(), artistName, appName));
}
if (uiComponentIndex < MEDIA_RECOMMENDATION_ITEMS_PER_ROW) {
@@ -978,6 +997,17 @@ public class MediaControlPanel {
});
}
+ /** Returns the upstream app name if available. */
+ @Nullable
+ private String getAppName(SmartspaceAction action) {
+ if (action == null || action.getIntent() == null
+ || action.getIntent().getExtras() == null) {
+ return null;
+ }
+
+ return action.getIntent().getExtras().getString(KEY_SMARTSPACE_APP_NAME);
+ }
+
/** Returns if the Smartspace action will open the activity in foreground. */
private boolean shouldSmartspaceRecItemOpenInForeground(SmartspaceAction action) {
if (action == null || action.getIntent() == null