diff options
7 files changed, 30 insertions, 14 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index a033b82f48cd..90206b693772 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -7209,7 +7209,8 @@ public class Notification implements Parcelable * * <p>Starting in {@link Build.VERSION_CODES#R, this conversation title will be ignored if a * valid shortcutId is added via {@link Notification.Builder#setShortcutId(String)}. In this - * case, {@link ShortcutInfo#getShortLabel()} will be shown as the conversation title + * case, {@link ShortcutInfo#getLongLabel()} (or, if missing, + * {@link ShortcutInfo#getShortLabel()}) will be shown as the conversation title * instead. * * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java index 85bf11ceb723..dcc6cb25c95b 100644 --- a/core/java/android/content/pm/ShortcutInfo.java +++ b/core/java/android/content/pm/ShortcutInfo.java @@ -1450,6 +1450,21 @@ public final class ShortcutInfo implements Parcelable { return mText; } + /** + * Returns the {@link #getLongLabel()} if it's populated, and if not, the + * {@link #getShortLabel()}. + * @hide + */ + @Nullable + public CharSequence getLabel() { + CharSequence label = getLongLabel(); + if (TextUtils.isEmpty(label)) { + label = getShortLabel(); + } + + return label; + } + /** @hide */ public int getLongLabelResourceId() { return mTextResId; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ConversationNotifications.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ConversationNotifications.kt index 53ec57090321..fc6c2be1ce9a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ConversationNotifications.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ConversationNotifications.kt @@ -45,8 +45,8 @@ class ConversationNotificationProcessor @Inject constructor( Notification.MessagingStyle.CONVERSATION_TYPE_NORMAL entry.ranking.shortcutInfo?.let { shortcutInfo -> messagingStyle.shortcutIcon = launcherApps.getShortcutIcon(shortcutInfo) - shortcutInfo.shortLabel?.let { shortLabel -> - messagingStyle.conversationTitle = shortLabel + shortcutInfo.label?.let { label -> + messagingStyle.conversationTitle = label } } messagingStyle.unreadMessageCount = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationChannelHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationChannelHelper.java index 1c2a00ed601a..5794f73a98f4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationChannelHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationChannelHelper.java @@ -67,14 +67,14 @@ public class NotificationChannelHelper { return channel; } - private static String getName(NotificationEntry entry) { - if (entry.getRanking().getShortcutInfo().getShortLabel() != null) { - return entry.getRanking().getShortcutInfo().getShortLabel().toString(); + private static CharSequence getName(NotificationEntry entry) { + if (entry.getRanking().getShortcutInfo().getLabel() != null) { + return entry.getRanking().getShortcutInfo().getLabel().toString(); } Bundle extras = entry.getSbn().getNotification().extras; - String nameString = extras.getString(Notification.EXTRA_CONVERSATION_TITLE); + CharSequence nameString = extras.getCharSequence(Notification.EXTRA_CONVERSATION_TITLE); if (TextUtils.isEmpty(nameString)) { - nameString = extras.getString(Notification.EXTRA_TITLE); + nameString = extras.getCharSequence(Notification.EXTRA_TITLE); } if (TextUtils.isEmpty(nameString)) { nameString = "fallback"; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleHubNotificationListener.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleHubNotificationListener.kt index 2fbd3ee0094a..d32d09dff630 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleHubNotificationListener.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleHubNotificationListener.kt @@ -220,9 +220,9 @@ class PeopleHubDataSourceImpl @Inject constructor( } val clickRunnable = Runnable { notificationListener.unsnoozeNotification(key) } val extras = sbn.notification.extras - val name = ranking.shortcutInfo?.shortLabel - ?: extras.getString(Notification.EXTRA_CONVERSATION_TITLE) - ?: extras.getString(Notification.EXTRA_TITLE) + val name = ranking.shortcutInfo?.label + ?: extras.getCharSequence(Notification.EXTRA_CONVERSATION_TITLE) + ?: extras.getCharSequence(Notification.EXTRA_TITLE) ?: return null val drawable = ranking.getIcon(iconFactory, sbn) ?: iconFactory.getConversationDrawable( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java index dbf40e467c95..4b21ef294db8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java @@ -193,7 +193,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase { when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) .thenReturn(packageInfo); - when(mShortcutInfo.getShortLabel()).thenReturn("Convo name"); + when(mShortcutInfo.getLabel()).thenReturn("Convo name"); List<ShortcutInfo> shortcuts = Arrays.asList(mShortcutInfo); when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts); when(mIconFactory.getConversationDrawable( diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index d45ecc9a3329..ced780475fb7 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -6557,7 +6557,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(si.getPackage()).thenReturn(PKG_P); when(si.getId()).thenReturn("convo"); when(si.getUserId()).thenReturn(USER_SYSTEM); - when(si.getShortLabel()).thenReturn("Hello"); + when(si.getLabel()).thenReturn("Hello"); when(si.isLongLived()).thenReturn(true); when(si.isEnabled()).thenReturn(true); when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si)); @@ -6591,7 +6591,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(si.getPackage()).thenReturn(PKG_P); when(si.getId()).thenReturn("convo"); when(si.getUserId()).thenReturn(USER_SYSTEM); - when(si.getShortLabel()).thenReturn("Hello"); + when(si.getLabel()).thenReturn("Hello"); when(si.isLongLived()).thenReturn(false); when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si)); |