Support for showing deleted channel count in settings.

Bug: 36119790
Test: runtest systemui-notification
Change-Id: Ie30243314d64ded66267d0dc85cc0ad940d917f8
This commit is contained in:
Julia Reynolds
2017-03-15 11:36:35 -04:00
parent e7f265119d
commit 41103f4212
4 changed files with 43 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ interface INotificationManager
ParceledListSlice getNotificationChannels(String pkg);
ParceledListSlice getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted);
int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted);
int getDeletedChannelCount(String pkg, int uid);
// TODO: Remove this when callers have been migrated to the equivalent
// INotificationListener method.

View File

@@ -1697,6 +1697,12 @@ public class NotificationManagerService extends SystemService {
.getList().size();
}
@Override
public int getDeletedChannelCount(String pkg, int uid) {
enforceSystemOrSystemUI("getDeletedChannelCount");
return mRankingHelper.getDeletedChannelCount(pkg, uid);
}
@Override
public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage(
String pkg, int uid, boolean includeDeleted) {

View File

@@ -766,6 +766,23 @@ public class RankingHelper implements RankingConfig {
return new ParceledListSlice<>(channels);
}
public int getDeletedChannelCount(String pkg, int uid) {
Preconditions.checkNotNull(pkg);
int deletedCount = 0;
Record r = getRecord(pkg, uid);
if (r == null) {
return deletedCount;
}
int N = r.channels.size();
for (int i = 0; i < N; i++) {
final NotificationChannel nc = r.channels.valueAt(i);
if (nc.isDeleted()) {
deletedCount++;
}
}
return deletedCount;
}
/**
* Sets importance.
*/

View File

@@ -722,6 +722,25 @@ public class RankingHelperTest {
}
}
@Test
public void testGetDeletedChannelCount() throws Exception {
NotificationChannel channel =
new NotificationChannel("id2", "name2", IMPORTANCE_LOW);
NotificationChannel channel2 =
new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH);
NotificationChannel channel3 =
new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH);
mHelper.createNotificationChannel(pkg, uid, channel, true);
mHelper.createNotificationChannel(pkg, uid, channel2, true);
mHelper.createNotificationChannel(pkg, uid, channel3, true);
mHelper.deleteNotificationChannel(pkg, uid, channel.getId());
mHelper.deleteNotificationChannel(pkg, uid, channel3.getId());
assertEquals(2, mHelper.getDeletedChannelCount(pkg, uid));
assertEquals(0, mHelper.getDeletedChannelCount(pkg2, uid2));
}
@Test
public void testUpdateDeletedChannels() throws Exception {
NotificationChannel channel =