Merge "DO NOT MERGE Fix behavior of getNotificationChannelGroups" into pi-dev

This commit is contained in:
Julia Reynolds
2018-10-03 13:35:49 +00:00
committed by Android (Google) Code Review
4 changed files with 45 additions and 10 deletions

View File

@@ -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
@@ -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

View File

@@ -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);

View File

@@ -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);
@@ -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()));
}

View File

@@ -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())) {
@@ -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())) {
@@ -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 {
@@ -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
@@ -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) {
@@ -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) {