Loading services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -2391,7 +2391,7 @@ public class NotificationManagerService extends SystemService { String pkg) { checkCallerIsSystemOrSameApp(pkg); return mPreferencesHelper.getNotificationChannelGroups( pkg, Binder.getCallingUid(), false, false); pkg, Binder.getCallingUid(), false, false, true); } @Override Loading Loading @@ -2467,7 +2467,8 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { checkCallerIsSystem(); return mPreferencesHelper.getNotificationChannelGroups(pkg, uid, includeDeleted, true); return mPreferencesHelper.getNotificationChannelGroups( pkg, uid, includeDeleted, true, false); } @Override Loading services/core/java/com/android/server/notification/PreferencesHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -755,7 +755,7 @@ public class PreferencesHelper 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<>(); PackagePreferences r = getPackagePreferences(pkg, uid); Loading Loading @@ -786,6 +786,13 @@ public class PreferencesHelper 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/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/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +37 −11 Original line number Diff line number Diff line Loading @@ -284,8 +284,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { compareChannels(channel2, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, false, true).getList(); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -354,8 +354,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { compareChannels(channel3, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, false, true).getList(); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -1350,8 +1350,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.onPackagesChanged(true, UserHandle.USER_SYSTEM, new String[]{PKG_N_MR1}, new int[]{ UID_N_MR1}); assertEquals(0, mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList().size()); assertEquals(0, mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList().size()); } @Test Loading Loading @@ -1440,8 +1440,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("id3", "name1", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList(); assertEquals(3, actual.size()); for (NotificationChannelGroup group : actual) { if (group.getId() == null) { Loading Loading @@ -1473,19 +1473,45 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, false); mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true, false).getList(); channel1.setImportance(IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { if (Objects.equals(group.getId(), ncg.getId())) { assertEquals(1, group.getChannels().size()); } } } @Test public void testGetChannelGroups_includeEmptyGroups() { NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1"); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncg, true); NotificationChannelGroup ncgEmpty = new NotificationChannelGroup("group2", "name2"); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncgEmpty, true); NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, 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()); } } } Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -2391,7 +2391,7 @@ public class NotificationManagerService extends SystemService { String pkg) { checkCallerIsSystemOrSameApp(pkg); return mPreferencesHelper.getNotificationChannelGroups( pkg, Binder.getCallingUid(), false, false); pkg, Binder.getCallingUid(), false, false, true); } @Override Loading Loading @@ -2467,7 +2467,8 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { checkCallerIsSystem(); return mPreferencesHelper.getNotificationChannelGroups(pkg, uid, includeDeleted, true); return mPreferencesHelper.getNotificationChannelGroups( pkg, uid, includeDeleted, true, false); } @Override Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -755,7 +755,7 @@ public class PreferencesHelper 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<>(); PackagePreferences r = getPackagePreferences(pkg, uid); Loading Loading @@ -786,6 +786,13 @@ public class PreferencesHelper 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/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/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +37 −11 Original line number Diff line number Diff line Loading @@ -284,8 +284,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { compareChannels(channel2, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, false, true).getList(); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -354,8 +354,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { compareChannels(channel3, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3.getId(), false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, false, true).getList(); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, false, true, false).getList(); boolean foundNcg = false; for (NotificationChannelGroup actual : actualGroups) { if (ncg.getId().equals(actual.getId())) { Loading Loading @@ -1350,8 +1350,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.onPackagesChanged(true, UserHandle.USER_SYSTEM, new String[]{PKG_N_MR1}, new int[]{ UID_N_MR1}); assertEquals(0, mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList().size()); assertEquals(0, mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList().size()); } @Test Loading Loading @@ -1440,8 +1440,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("id3", "name1", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList(); assertEquals(3, actual.size()); for (NotificationChannelGroup group : actual) { if (group.getId() == null) { Loading Loading @@ -1473,19 +1473,45 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, false); mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true, false).getList(); channel1.setImportance(IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(PKG_N_MR1, UID_N_MR1, true, true).getList(); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, true, true, false).getList(); assertEquals(2, actual.size()); for (NotificationChannelGroup group : actual) { if (Objects.equals(group.getId(), ncg.getId())) { assertEquals(1, group.getChannels().size()); } } } @Test public void testGetChannelGroups_includeEmptyGroups() { NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1"); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncg, true); NotificationChannelGroup ncgEmpty = new NotificationChannelGroup("group2", "name2"); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncgEmpty, true); NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); channel1.setGroup(ncg.getId()); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1, true, false); List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups( PKG_N_MR1, UID_N_MR1, 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()); } } } Loading