From b1b9d64b5a97a99794291fe9740c0d1c68fe3ba4 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 22 Apr 2020 16:18:44 -0400 Subject: [PATCH] Only return non demoted conversations Demoted conversations should enver display in a conversation space Test: atest Bug: 150791002 Change-Id: Icf7d6e7e2a22f14c47f30e625767ed71c4f993b8 --- .../notification/PreferencesHelper.java | 1 + .../notification/PreferencesHelperTest.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 3e6d6f5fe1922..f4f0e7850291e 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -1255,6 +1255,7 @@ public class PreferencesHelper implements RankingConfig { for (int i = 0; i < N; i++) { final NotificationChannel nc = p.channels.valueAt(i); if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted() + && !nc.isDemoted() && (nc.isImportantConversation() || !onlyImportant)) { ConversationChannelWrapper conversation = new ConversationChannelWrapper(); conversation.setPkg(p.pkg); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index ac51750f23f82..f5d58a1b15a53 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -3141,6 +3141,44 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue(conversationWrapperContainsChannel(convos, channel2)); } + @Test + public void testGetConversations_notDemoted() { + String convoId = "convo"; + NotificationChannel messages = + new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_O, UID_O, messages, true, false); + NotificationChannel calls = + new NotificationChannel("calls", "Calls", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_O, UID_O, calls, true, false); + NotificationChannel p = + new NotificationChannel("p calls", "Calls", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, UID_P, p, true, false); + + NotificationChannel channel = + new NotificationChannel("A person msgs", "messages from A", IMPORTANCE_DEFAULT); + channel.setConversationId(messages.getId(), convoId); + mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false); + + NotificationChannel diffConvo = + new NotificationChannel("B person msgs", "messages from B", IMPORTANCE_DEFAULT); + diffConvo.setConversationId(p.getId(), "different convo"); + diffConvo.setDemoted(true); + mHelper.createNotificationChannel(PKG_P, UID_P, diffConvo, true, false); + + NotificationChannel channel2 = + new NotificationChannel("A person calls", "calls from A", IMPORTANCE_DEFAULT); + channel2.setConversationId(calls.getId(), convoId); + channel2.setImportantConversation(true); + mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); + + List convos = mHelper.getConversations(false); + + assertEquals(2, convos.size()); + assertTrue(conversationWrapperContainsChannel(convos, channel)); + assertFalse(conversationWrapperContainsChannel(convos, diffConvo)); + assertTrue(conversationWrapperContainsChannel(convos, channel2)); + } + @Test public void testGetConversations_onlyImportant() { String convoId = "convo";