Skip to content

Commit d972ca6

Browse files
Julia ReynoldsBayerischeMotorenWerke
authored andcommitted
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 (cherry picked from commit c5b5453) Merged-In:Icc709a6b0d0a8c5f2d9243959992f1b6764354db
1 parent 0a48d1b commit d972ca6

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

services/core/java/com/android/server/notification/PreferencesHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ public void createNotificationChannelGroup(String pkg, int uid, NotificationChan
788788
if (r == null) {
789789
throw new IllegalArgumentException("Invalid package");
790790
}
791+
if (fromTargetApp) {
792+
group.setBlocked(false);
793+
}
791794
final NotificationChannelGroup oldGroup = r.groups.get(group.getId());
792795
if (oldGroup != null) {
793796
group.setChannels(oldGroup.getChannels());

services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,19 @@ public void testIsGroupBlocked_blocked() throws Exception {
21322132
assertTrue(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
21332133
}
21342134

2135+
@Test
2136+
public void testIsGroupBlocked_appCannotCreateAsBlocked() throws Exception {
2137+
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
2138+
group.setBlocked(true);
2139+
mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, group, true);
2140+
assertFalse(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
2141+
2142+
NotificationChannelGroup group3 = group.clone();
2143+
group3.setBlocked(false);
2144+
mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, group3, true);
2145+
assertFalse(mHelper.isGroupBlocked(PKG_N_MR1, UID_N_MR1, group.getId()));
2146+
}
2147+
21352148
@Test
21362149
public void testIsGroup_appCannotResetBlock() throws Exception {
21372150
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
@@ -3402,7 +3415,7 @@ public void testGetConversations_noConversations() {
34023415
public void testGetConversations_noDisabledGroups() {
34033416
NotificationChannelGroup group = new NotificationChannelGroup("a", "a");
34043417
group.setBlocked(true);
3405-
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true);
3418+
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, false);
34063419
NotificationChannel parent = new NotificationChannel("parent", "p", 1);
34073420
mHelper.createNotificationChannel(PKG_O, UID_O, parent, true, false);
34083421

0 commit comments

Comments
 (0)