Loading services/core/java/com/android/server/notification/PreferencesHelper.java +14 −0 Original line number Original line Diff line number Diff line Loading @@ -101,6 +101,8 @@ public class PreferencesHelper implements RankingConfig { @VisibleForTesting @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 50000; static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 50000; @VisibleForTesting static final int NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT = 50000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; Loading Loading @@ -254,6 +256,7 @@ public class PreferencesHelper implements RankingConfig { } } } } boolean skipWarningLogged = false; boolean skipWarningLogged = false; boolean skipGroupWarningLogged = false; boolean hasSAWPermission = false; boolean hasSAWPermission = false; if (upgradeForBubbles && uid != UNKNOWN_UID) { if (upgradeForBubbles && uid != UNKNOWN_UID) { hasSAWPermission = mAppOps.noteOpNoThrow( hasSAWPermission = mAppOps.noteOpNoThrow( Loading Loading @@ -303,6 +306,14 @@ public class PreferencesHelper implements RankingConfig { String tagName = parser.getName(); String tagName = parser.getName(); // Channel groups // Channel groups if (TAG_GROUP.equals(tagName)) { if (TAG_GROUP.equals(tagName)) { if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) { if (!skipGroupWarningLogged) { Slog.w(TAG, "Skipping further groups for " + r.pkg + "; app has too many"); skipGroupWarningLogged = true; } continue; } String id = parser.getAttributeValue(null, ATT_ID); String id = parser.getAttributeValue(null, ATT_ID); CharSequence groupName = parser.getAttributeValue(null, CharSequence groupName = parser.getAttributeValue(null, ATT_NAME); ATT_NAME); Loading Loading @@ -867,6 +878,9 @@ public class PreferencesHelper implements RankingConfig { } } 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) { Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +47 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.IS import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.UID_FIELD_NUMBER; import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.UID_FIELD_NUMBER; import static com.android.server.notification.PreferencesHelper.DEFAULT_BUBBLE_PREFERENCE; import static com.android.server.notification.PreferencesHelper.DEFAULT_BUBBLE_PREFERENCE; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.UNKNOWN_UID; import static com.android.server.notification.PreferencesHelper.UNKNOWN_UID; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -4249,6 +4250,52 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, extraChannel1, true)); assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, extraChannel1, true)); } } @Test public void testTooManyGroups() { for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) { NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i), String.valueOf(i)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); } try { NotificationChannelGroup group = new NotificationChannelGroup( String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT), String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); fail("Allowed to create too many notification channel groups"); } catch (IllegalStateException e) { // great } } @Test public void testTooManyGroups_xml() throws Exception { String extraGroup = "EXTRA"; String extraGroup1 = "EXTRA1"; // create first... many... directly so we don't need a big xml blob in this test for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) { NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i), String.valueOf(i)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); } final String xml = "<ranking version=\"1\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n" + "<channelGroup id=\"" + extraGroup + "\" name=\"hi\"/>" + "<channelGroup id=\"" + extraGroup1 + "\" name=\"hi2\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertNull(mHelper.getNotificationChannelGroup(extraGroup, PKG_O, UID_O)); assertNull(mHelper.getNotificationChannelGroup(extraGroup1, PKG_O, UID_O)); } @Test @Test public void testRestoreMultiUser() throws Exception { public void testRestoreMultiUser() throws Exception { String pkg = "restore_pkg"; String pkg = "restore_pkg"; Loading Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +14 −0 Original line number Original line Diff line number Diff line Loading @@ -101,6 +101,8 @@ public class PreferencesHelper implements RankingConfig { @VisibleForTesting @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 50000; static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 50000; @VisibleForTesting static final int NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT = 50000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; Loading Loading @@ -254,6 +256,7 @@ public class PreferencesHelper implements RankingConfig { } } } } boolean skipWarningLogged = false; boolean skipWarningLogged = false; boolean skipGroupWarningLogged = false; boolean hasSAWPermission = false; boolean hasSAWPermission = false; if (upgradeForBubbles && uid != UNKNOWN_UID) { if (upgradeForBubbles && uid != UNKNOWN_UID) { hasSAWPermission = mAppOps.noteOpNoThrow( hasSAWPermission = mAppOps.noteOpNoThrow( Loading Loading @@ -303,6 +306,14 @@ public class PreferencesHelper implements RankingConfig { String tagName = parser.getName(); String tagName = parser.getName(); // Channel groups // Channel groups if (TAG_GROUP.equals(tagName)) { if (TAG_GROUP.equals(tagName)) { if (r.groups.size() >= NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT) { if (!skipGroupWarningLogged) { Slog.w(TAG, "Skipping further groups for " + r.pkg + "; app has too many"); skipGroupWarningLogged = true; } continue; } String id = parser.getAttributeValue(null, ATT_ID); String id = parser.getAttributeValue(null, ATT_ID); CharSequence groupName = parser.getAttributeValue(null, CharSequence groupName = parser.getAttributeValue(null, ATT_NAME); ATT_NAME); Loading Loading @@ -867,6 +878,9 @@ public class PreferencesHelper implements RankingConfig { } } 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) { Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +47 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.IS import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.UID_FIELD_NUMBER; import static com.android.os.AtomsProto.PackageNotificationChannelPreferences.UID_FIELD_NUMBER; import static com.android.server.notification.PreferencesHelper.DEFAULT_BUBBLE_PREFERENCE; import static com.android.server.notification.PreferencesHelper.DEFAULT_BUBBLE_PREFERENCE; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; import static com.android.server.notification.PreferencesHelper.UNKNOWN_UID; import static com.android.server.notification.PreferencesHelper.UNKNOWN_UID; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -4249,6 +4250,52 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, extraChannel1, true)); assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, extraChannel1, true)); } } @Test public void testTooManyGroups() { for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) { NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i), String.valueOf(i)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); } try { NotificationChannelGroup group = new NotificationChannelGroup( String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT), String.valueOf(NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); fail("Allowed to create too many notification channel groups"); } catch (IllegalStateException e) { // great } } @Test public void testTooManyGroups_xml() throws Exception { String extraGroup = "EXTRA"; String extraGroup1 = "EXTRA1"; // create first... many... directly so we don't need a big xml blob in this test for (int i = 0; i < NOTIFICATION_CHANNEL_GROUP_COUNT_LIMIT; i++) { NotificationChannelGroup group = new NotificationChannelGroup(String.valueOf(i), String.valueOf(i)); mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true); } final String xml = "<ranking version=\"1\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n" + "<channelGroup id=\"" + extraGroup + "\" name=\"hi\"/>" + "<channelGroup id=\"" + extraGroup1 + "\" name=\"hi2\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertNull(mHelper.getNotificationChannelGroup(extraGroup, PKG_O, UID_O)); assertNull(mHelper.getNotificationChannelGroup(extraGroup1, PKG_O, UID_O)); } @Test @Test public void testRestoreMultiUser() throws Exception { public void testRestoreMultiUser() throws Exception { String pkg = "restore_pkg"; String pkg = "restore_pkg"; Loading