Loading services/core/java/com/android/server/notification/NotificationManagerService.java +5 −2 Original line number Diff line number Diff line Loading @@ -2299,8 +2299,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups( String pkg) { checkCallerIsSystemOrSameApp(pkg); return mRankingHelper.getNotificationChannelGroups( pkg, Binder.getCallingUid(), false, false); pkg, Binder.getCallingUid(), false, false, true); } @Override Loading Loading @@ -2376,7 +2377,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { checkCallerIsSystem(); return mRankingHelper.getNotificationChannelGroups(pkg, uid, includeDeleted, true); return mRankingHelper.getNotificationChannelGroups( pkg, uid, includeDeleted, true, false); } @Override Loading services/core/java/com/android/server/notification/RankingConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public interface RankingConfig { void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromTargetApp); ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped); int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty); void createNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromTargetApp, boolean hasDndAccess); void updateNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromUser); Loading services/core/java/com/android/server/notification/RankingHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -830,7 +830,7 @@ public class RankingHelper implements RankingConfig { @Override public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped) { int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { Preconditions.checkNotNull(pkg); Map<String, NotificationChannelGroup> groups = new ArrayMap<>(); Record r = getRecord(pkg, uid); Loading Loading @@ -861,6 +861,13 @@ public class RankingHelper implements RankingConfig { if (includeNonGrouped && nonGrouped.getChannels().size() > 0) { groups.put(null, nonGrouped); } if (includeEmpty) { for (NotificationChannelGroup group : r.groups.values()) { if (!groups.containsKey(group.getId())) { groups.put(group.getId(), group); } } } return new ParceledListSlice<>(new ArrayList<>(groups.values())); } Loading services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +31 −6 Original line number Diff line number Diff line Loading @@ -399,7 +399,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG, UID, channel2.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -469,7 +469,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG, UID, channel3.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -784,6 +784,31 @@ public class RankingHelperTest extends UiServiceTestCase { new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false); } @Test public void testGetChannelGroups_includeEmptyGroups() { NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1"); mHelper.createNotificationChannelGroup(PKG, UID, ncg, true); NotificationChannelGroup ncgEmpty = new NotificationChannelGroup("group2", "name2"); mHelper.createNotificationChannelGroup(PKG, UID, ncgEmpty, true); NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG, UID, channel1, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG, UID, false, false, true).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { if (Objects.equals(group.getId(), ncg.getId())) { assertEquals(1, group.getChannels().size()); } if (Objects.equals(group.getId(), ncgEmpty.getId())) { assertEquals(0, group.getChannels().size()); } } } @Test public void testUpdate() throws Exception { Loading Loading @@ -1421,7 +1446,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.onPackagesChanged(true, UserHandle.USER_SYSTEM, new String[]{PKG}, new int[]{UID}); assertEquals(0, mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList().size()); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList().size()); } @Test Loading Loading @@ -1510,7 +1535,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG, UID, channel3, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); assertEquals(3, actual.size()); for (NotificationChannelGroup group : actual) { if (group.getId() == null) { Loading Loading @@ -1542,13 +1567,13 @@ public class RankingHelperTest extends UiServiceTestCase { new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG, UID, channel1, true, false); mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); channel1.setImportance(IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG, UID, channel1, true); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +5 −2 Original line number Diff line number Diff line Loading @@ -2299,8 +2299,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups( String pkg) { checkCallerIsSystemOrSameApp(pkg); return mRankingHelper.getNotificationChannelGroups( pkg, Binder.getCallingUid(), false, false); pkg, Binder.getCallingUid(), false, false, true); } @Override Loading Loading @@ -2376,7 +2377,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { checkCallerIsSystem(); return mRankingHelper.getNotificationChannelGroups(pkg, uid, includeDeleted, true); return mRankingHelper.getNotificationChannelGroups( pkg, uid, includeDeleted, true, false); } @Override Loading
services/core/java/com/android/server/notification/RankingConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public interface RankingConfig { void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromTargetApp); ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped); int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty); void createNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromTargetApp, boolean hasDndAccess); void updateNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromUser); Loading
services/core/java/com/android/server/notification/RankingHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -830,7 +830,7 @@ public class RankingHelper implements RankingConfig { @Override public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped) { int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { Preconditions.checkNotNull(pkg); Map<String, NotificationChannelGroup> groups = new ArrayMap<>(); Record r = getRecord(pkg, uid); Loading Loading @@ -861,6 +861,13 @@ public class RankingHelper implements RankingConfig { if (includeNonGrouped && nonGrouped.getChannels().size() > 0) { groups.put(null, nonGrouped); } if (includeEmpty) { for (NotificationChannelGroup group : r.groups.values()) { if (!groups.containsKey(group.getId())) { groups.put(group.getId(), group); } } } return new ParceledListSlice<>(new ArrayList<>(groups.values())); } Loading
services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +31 −6 Original line number Diff line number Diff line Loading @@ -399,7 +399,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG, UID, channel2.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -469,7 +469,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG, UID, channel3.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -784,6 +784,31 @@ public class RankingHelperTest extends UiServiceTestCase { new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false); } @Test public void testGetChannelGroups_includeEmptyGroups() { NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1"); mHelper.createNotificationChannelGroup(PKG, UID, ncg, true); NotificationChannelGroup ncgEmpty = new NotificationChannelGroup("group2", "name2"); mHelper.createNotificationChannelGroup(PKG, UID, ncgEmpty, true); NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG, UID, channel1, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG, UID, false, false, true).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { if (Objects.equals(group.getId(), ncg.getId())) { assertEquals(1, group.getChannels().size()); } if (Objects.equals(group.getId(), ncgEmpty.getId())) { assertEquals(0, group.getChannels().size()); } } } @Test public void testUpdate() throws Exception { Loading Loading @@ -1421,7 +1446,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.onPackagesChanged(true, UserHandle.USER_SYSTEM, new String[]{PKG}, new int[]{UID}); assertEquals(0, mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList().size()); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList().size()); } @Test Loading Loading @@ -1510,7 +1535,7 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG, UID, channel3, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); assertEquals(3, actual.size()); for (NotificationChannelGroup group : actual) { if (group.getId() == null) { Loading Loading @@ -1542,13 +1567,13 @@ public class RankingHelperTest extends UiServiceTestCase { new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG, UID, channel1, true, false); mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); channel1.setImportance(IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG, UID, channel1, true); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList(); mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { Loading