DO NOT MERGE Prevent apps from creating blocked channel groups

setBlocked is a hidden API, so apps should not be calling
the method, but fix up the data in case they do

Test: PreferencesHelperTest; manual with ApiDemos FGS
Bug: 209966086
Change-Id: Icc709a6b0d0a8c5f2d9243959992f1b6764354db
Merged-In: I8a27853c7ed05d9dfd38a3142fbbe185946c3992
This commit is contained in:
Julia Reynolds
2022-01-12 15:08:29 -05:00
parent a9828ff519
commit b993531c0d
2 changed files with 16 additions and 0 deletions

View File

@@ -589,6 +589,9 @@ public class PreferencesHelper implements RankingConfig {
if (r == null) {
throw new IllegalArgumentException("Invalid package");
}
if (fromTargetApp) {
group.setBlocked(false);
}
final NotificationChannelGroup oldGroup = r.groups.get(group.getId());
if (!group.equals(oldGroup)) {
// will log for new entries as well as name/description changes

View File

@@ -2030,6 +2030,19 @@ public class PreferencesHelperTest extends UiServiceTestCase {
assertTrue(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
}
@Test
public void testIsGroupBlocked_appCannotCreateAsBlocked() throws Exception {
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
group.setBlocked(true);
mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, group, true);
assertFalse(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
NotificationChannelGroup group3 = group.clone();
group3.setBlocked(false);
mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, group3, true);
assertFalse(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
}
@Test
public void testIsGroup_appCannotResetBlock() throws Exception {
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");