From 6eccf0016b230971cafd8ae0c2fdf0d2a54e3719 Mon Sep 17 00:00:00 2001 From: Geoffrey Pitsch Date: Wed, 5 Apr 2017 12:33:59 -0400 Subject: [PATCH] Don't delete new notification channels not present in backup Test: runtest systemui-notification Change-Id: Ib25a680487b20700b9936926c1769a4d8f81b62a Fixes: 36785228 --- .../android/server/notification/RankingHelper.java | 3 ++- .../server/notification/RankingHelperTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 65aaee0f8ce8a..10c05593556a9 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -152,7 +152,8 @@ public class RankingHelper implements RankingConfig { if (type != XmlPullParser.START_TAG) return; String tag = parser.getName(); if (!TAG_RANKING.equals(tag)) return; - mRecords.clear(); + // Clobber groups and channels with the xml, but don't delete other data that wasn't present + // at the time of serialization. mRestoredWithoutUids.clear(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { tag = parser.getName(); diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java index 40af2f89c93ad..87adcc72d9387 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -489,6 +489,19 @@ public class RankingHelperTest { NotificationChannel.DEFAULT_CHANNEL_ID, false)); } + @Test + public void testLoadingOldChannelsDoesNotDeleteNewlyCreatedChannels() throws Exception { + ByteArrayOutputStream baos = writeXmlAndPurge(PKG, UID, false, + NotificationChannel.DEFAULT_CHANNEL_ID, "bananas"); + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_LOW), true); + + loadStreamXml(baos); + + // Should still have the newly created channel that wasn't in the xml. + assertTrue(mHelper.getNotificationChannel(PKG, UID, "bananas", false) != null); + } + @Test public void testCreateChannel_blocked() throws Exception { mHelper.setImportance(PKG, UID, NotificationManager.IMPORTANCE_NONE);