Use the image of the person or large image for bubble experiment

Bug: 143173197
Test: manual
Change-Id: I8958ebe9cb7368bab60ab4dfb0966206ea1d1659
This commit is contained in:
Mady Mellor
2019-11-13 17:32:01 -08:00
parent b547e5ed52
commit 89eb3481e8

View File

@@ -16,6 +16,7 @@
package com.android.systemui.bubbles;
import static android.app.Notification.EXTRA_MESSAGES;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
@@ -24,16 +25,21 @@ import static com.android.systemui.bubbles.BubbleController.canLaunchIntentInAct
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Person;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.UserHandle;
import android.provider.Settings;
import com.android.internal.util.ArrayUtils;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -148,11 +154,21 @@ public class BubbleExperimentConfig {
static Notification.BubbleMetadata createFromNotif(Context context, NotificationEntry entry) {
Notification notification = entry.getSbn().getNotification();
final PendingIntent intent = notification.contentIntent;
final Icon smallIcon = entry.getSbn().getNotification().getSmallIcon();
Icon icon = null;
// Use the icon of the person if available
List<Person> personList = getPeopleFromNotification(entry);
if (personList.size() > 0) {
icon = personList.get(0).getIcon();
}
if (icon == null) {
icon = notification.getLargeIcon() != null
? notification.getLargeIcon()
: notification.getSmallIcon();
}
if (canLaunchIntentInActivityView(context, entry, intent)) {
return new Notification.BubbleMetadata.Builder()
.setDesiredHeight(BUBBLE_HEIGHT)
.setIcon(smallIcon)
.setIcon(icon)
.setIntent(intent)
.build();
}
@@ -199,4 +215,31 @@ public class BubbleExperimentConfig {
static boolean isShortcutIntent(PendingIntent intent) {
return intent.equals(sDummyShortcutIntent);
}
static List<Person> getPeopleFromNotification(NotificationEntry entry) {
Bundle extras = entry.getSbn().getNotification().extras;
ArrayList<Person> personList = new ArrayList<>();
if (extras == null) {
return personList;
}
List<Person> p = extras.getParcelableArrayList(Notification.EXTRA_PEOPLE_LIST);
if (p != null) {
personList.addAll(p);
}
if (Notification.MessagingStyle.class.equals(
entry.getSbn().getNotification().getNotificationStyle())) {
final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES);
if (!ArrayUtils.isEmpty(messages)) {
for (Notification.MessagingStyle.Message message :
Notification.MessagingStyle.Message
.getMessagesFromBundleArray(messages)) {
personList.add(message.getSenderPerson());
}
}
}
return personList;
}
}