summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java29
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java42
2 files changed, 68 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index 6bc4f7e333e2..9968b95aeabf 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -29,6 +29,7 @@ import android.app.ActivityManager;
import android.app.IActivityManager;
import android.app.Notification;
import android.app.NotificationChannel;
+import android.app.Person;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
@@ -556,7 +557,7 @@ public final class NotificationRecord {
pw.println(prefix + "bigContentView=" + formatRemoteViews(notification.bigContentView));
pw.println(prefix + "headsUpContentView="
+ formatRemoteViews(notification.headsUpContentView));
- pw.print(prefix + String.format("color=0x%08x", notification.color));
+ pw.println(prefix + String.format("color=0x%08x", notification.color));
pw.println(prefix + "timeout="
+ TimeUtils.formatForLogging(notification.getTimeoutAfter()));
if (notification.actions != null && notification.actions.length > 0) {
@@ -1438,8 +1439,8 @@ public final class NotificationRecord {
}
if (mTargetSdkVersion >= Build.VERSION_CODES.R
- && Notification.MessagingStyle.class.equals(notification.getNotificationStyle())
- && mShortcutInfo == null) {
+ && Notification.MessagingStyle.class.equals(notification.getNotificationStyle())
+ && (mShortcutInfo == null || isOnlyBots(mShortcutInfo.getPersons()))) {
return false;
}
if (mHasSentValidMsg && mShortcutInfo == null) {
@@ -1448,6 +1449,28 @@ public final class NotificationRecord {
return true;
}
+ /**
+ * Determines if the {@link ShortcutInfo#getPersons()} array includes only bots, for the purpose
+ * of excluding that shortcut from the "conversations" section of the notification shade. If
+ * the shortcut has no people, this returns false to allow the conversation into the shade, and
+ * if there is any non-bot person we allow it as well. Otherwise, this is only bots and will
+ * not count as a conversation.
+ */
+ private boolean isOnlyBots(Person[] persons) {
+ // Return false if there are no persons at all
+ if (persons == null || persons.length == 0) {
+ return false;
+ }
+ // Return false if there are any non-bot persons
+ for (Person person : persons) {
+ if (!person.isBot()) {
+ return false;
+ }
+ }
+ // Return true otherwise
+ return true;
+ }
+
StatusBarNotification getSbn() {
return sbn;
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
index da613e6f4d1d..38c470da5029 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
@@ -1134,6 +1134,48 @@ public class NotificationRecordTest extends UiServiceTestCase {
}
@Test
+ public void testIsConversation_shortcutHasOneBot_targetsR() {
+ StatusBarNotification sbn = getMessagingStyleNotification(PKG_R);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+ ShortcutInfo shortcutMock = mock(ShortcutInfo.class);
+ when(shortcutMock.getPersons()).thenReturn(new Person[]{
+ new Person.Builder().setName("Bot").setBot(true).build()
+ });
+ record.setShortcutInfo(shortcutMock);
+
+ assertFalse(record.isConversation());
+ }
+
+ @Test
+ public void testIsConversation_shortcutHasOnePerson_targetsR() {
+ StatusBarNotification sbn = getMessagingStyleNotification(PKG_R);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+ ShortcutInfo shortcutMock = mock(ShortcutInfo.class);
+ when(shortcutMock.getPersons()).thenReturn(new Person[]{
+ new Person.Builder().setName("Person").setBot(false).build()
+ });
+ record.setShortcutInfo(shortcutMock);
+
+ assertTrue(record.isConversation());
+ assertEquals(FLAG_FILTER_TYPE_CONVERSATIONS, record.getNotificationType());
+ }
+
+ @Test
+ public void testIsConversation_shortcutHasOneBotOnePerson_targetsR() {
+ StatusBarNotification sbn = getMessagingStyleNotification(PKG_R);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+ ShortcutInfo shortcutMock = mock(ShortcutInfo.class);
+ when(shortcutMock.getPersons()).thenReturn(new Person[]{
+ new Person.Builder().setName("Bot").setBot(true).build(),
+ new Person.Builder().setName("Person").setBot(false).build()
+ });
+ record.setShortcutInfo(shortcutMock);
+
+ assertTrue(record.isConversation());
+ assertEquals(FLAG_FILTER_TYPE_CONVERSATIONS, record.getNotificationType());
+ }
+
+ @Test
public void testIsConversation_noShortcut() {
StatusBarNotification sbn = getMessagingStyleNotification();
NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);