Merge "Check channel group limit when creating from a NotificationListener" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7e08f7c9f2
@@ -862,11 +862,11 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
if (r == null) {
|
if (r == null) {
|
||||||
throw new IllegalArgumentException("Invalid package");
|
throw new IllegalArgumentException("Invalid package");
|
||||||
}
|
}
|
||||||
|
if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) {
|
||||||
|
throw new IllegalStateException("Limit exceed; cannot create more groups");
|
||||||
|
}
|
||||||
if (fromTargetApp) {
|
if (fromTargetApp) {
|
||||||
group.setBlocked(false);
|
group.setBlocked(false);
|
||||||
if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) {
|
|
||||||
throw new IllegalStateException("Limit exceed; cannot create more groups");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final NotificationChannelGroup oldGroup = r.groups.get(group.getId());
|
final NotificationChannelGroup oldGroup = r.groups.get(group.getId());
|
||||||
if (oldGroup != null) {
|
if (oldGroup != null) {
|
||||||
|
|||||||
@@ -4131,17 +4131,26 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTooManyGroups() {
|
public void testTooManyGroups_fromTargetApp() {
|
||||||
|
testTooManyGroups(/* fromTargetApp= */ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTooManyGroups_fromListener() {
|
||||||
|
testTooManyGroups(/* fromTargetApp= */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testTooManyGroups(boolean fromTargetApp) {
|
||||||
for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) {
|
for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) {
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i),
|
NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i),
|
||||||
String.valueOf(i));
|
String.valueOf(i));
|
||||||
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true);
|
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, fromTargetApp);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup(
|
NotificationChannelGroup group = new NotificationChannelGroup(
|
||||||
String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT),
|
String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT),
|
||||||
String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT));
|
String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT));
|
||||||
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true);
|
mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, fromTargetApp);
|
||||||
fail("Allowed to create too many notification channel groups");
|
fail("Allowed to create too many notification channel groups");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// great
|
// great
|
||||||
|
|||||||
Reference in New Issue
Block a user