diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java | 41 |
1 files changed, 35 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 f66eb5ba008a..a9cd13521225 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -22,6 +22,7 @@ import android.app.PendingIntent; 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,7 @@ 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; @@ -85,6 +87,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"; private static final Intent SETTINGS_INTENT = new Intent(ACTION_MEDIA_CONTROLS_SETTINGS); @@ -578,18 +581,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(); @@ -634,12 +652,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) { @@ -844,6 +862,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 |