diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 0a3c581506894..cbbf2a0ee04b1 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -757,7 +757,7 @@ public class PreferencesHelper implements RankingConfig { clearLockedFieldsLocked(channel); channel.setImportanceLockedByOEM(r.oemLockedImportance); if (!channel.isImportanceLockedByOEM()) { - if (r.futureOemLockedChannels.remove(channel.getId())) { + if (r.oemLockedChannels.contains(channel.getId())) { channel.setImportanceLockedByOEM(true); } } @@ -952,11 +952,10 @@ public class PreferencesHelper implements RankingConfig { NotificationChannel channel = r.channels.get(channelId); if (channel != null) { channel.setImportanceLockedByOEM(true); - } else { - // if this channel shows up in the future, make sure it'll - // be locked immediately - r.futureOemLockedChannels.add(channelId); } + // Also store the locked channels on the record, so they aren't + // temporarily lost when data is cleared on the package + r.oemLockedChannels.add(channelId); } } } @@ -1528,9 +1527,9 @@ public class PreferencesHelper implements RankingConfig { pw.print(" oemLocked="); pw.print(r.oemLockedImportance); } - if (!r.futureOemLockedChannels.isEmpty()) { + if (!r.oemLockedChannels.isEmpty()) { pw.print(" futureLockedChannels="); - pw.print(r.futureOemLockedChannels); + pw.print(r.oemLockedChannels); } pw.println(); for (NotificationChannel channel : r.channels.values()) { @@ -1940,7 +1939,7 @@ public class PreferencesHelper implements RankingConfig { // these fields are loaded on boot from a different source of truth and so are not // written to notification policy xml boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE; - List futureOemLockedChannels = new ArrayList<>(); + List oemLockedChannels = new ArrayList<>(); boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE; Delegate delegate = null; 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 776c00e758464..8961796ed6173 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -2416,6 +2416,24 @@ public class PreferencesHelperTest extends UiServiceTestCase { .isImportanceLockedByOEM()); } + @Test + public void testLockChannelsForOEM_channelSpecific_clearData() { + NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); + mHelper.getImportance(PKG_O, UID_O); + mHelper.lockChannelsForOEM(new String[] {PKG_O + ":" + a.getId()}); + mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); + assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) + .isImportanceLockedByOEM()); + + mHelper.clearData(PKG_O, UID_O); + + // it's back! + mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); + // and still locked + assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) + .isImportanceLockedByOEM()); + } + @Test public void testLockChannelsForOEM_channelDoesNotExistYet_appWide() { NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH);