From 52742ec890f80677336b4c58c240772769c3747f Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Tue, 2 Feb 2021 11:56:54 -0500 Subject: [PATCH] Fix NPE The parent channel of a conversation can be deleted; we should still show the customized channel if the app didn't choose to delete that as well. Test: PreferencesHelperTest Fixes: 179127295 Change-Id: If4a3c16c37126096a34aefa2f97da0c4ce081545 --- .../notification/PreferencesHelper.java | 6 +++-- .../notification/PreferencesHelperTest.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 61c8b178b4c0d..461d51912983f 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -1419,8 +1419,10 @@ public class PreferencesHelper implements RankingConfig { conversation.setPkg(p.pkg); conversation.setUid(p.uid); conversation.setNotificationChannel(nc); - conversation.setParentChannelLabel( - p.channels.get(nc.getParentChannelId()).getName()); + NotificationChannel parent = p.channels.get(nc.getParentChannelId()); + conversation.setParentChannelLabel(parent == null + ? null + : parent.getName()); boolean blockedByGroup = false; if (nc.getGroup() != null) { NotificationChannelGroup group = p.groups.get(nc.getGroup()); 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 8c744c94249b3..fc1cb70cf7462 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -3536,6 +3536,28 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(conversationWrapperContainsChannel(convos, channel2)); } + @Test + public void testGetConversations_parentDeleted() { + String convoId = "convo"; + NotificationChannel messages = + new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_O, UID_O, messages, true, false); + + NotificationChannel channel = + new NotificationChannel("A person msgs", "messages from A", IMPORTANCE_DEFAULT); + channel.setConversationId(messages.getId(), convoId); + channel.setImportantConversation(true); + mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false); + + mHelper.permanentlyDeleteNotificationChannel(PKG_O, UID_O, "messages"); + + List convos = + mHelper.getConversations(IntArray.wrap(new int[] {0}), true); + + assertEquals(1, convos.size()); + assertTrue(conversationWrapperContainsChannel(convos, channel)); + } + private boolean conversationWrapperContainsChannel(List list, NotificationChannel expected) { for (ConversationChannelWrapper ccw : list) {