Fix channel locking post cleardata

Apps/notification channels that had been marked
non-blockable by oems were being unlocked
post a clear data action until the next time the
device was rebooted. this keeps them locked the
whole time.

Bug: 142065414
Test: atest
Change-Id: If11238efd6f6b3e2d9e97d24adb24626689a87f2
This commit is contained in:
Julia Reynolds
2019-11-12 11:43:39 -05:00
parent 97d3ca1e8f
commit 72b2844319
2 changed files with 25 additions and 8 deletions

View File

@@ -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<String> futureOemLockedChannels = new ArrayList<>();
List<String> oemLockedChannels = new ArrayList<>();
boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
Delegate delegate = null;

View File

@@ -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);