Merge "Update conversation labels" into rvc-dev

This commit is contained in:
Julia Reynolds
2020-05-21 18:53:24 +00:00
committed by Android (Google) Code Review
7 changed files with 30 additions and 14 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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 =

View File

@@ -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";

View File

@@ -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(

View File

@@ -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(

View File

@@ -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));