Add condition to ignore invalid packages in NotificationChannelSlice
If all displayable notification channels of package are turned off, stop showing notification channel slice of package. Bug: 124480122 Test: robotests Change-Id: I3ce9ebc4cca18dac3b4b6f15c28c697b72df81e3
This commit is contained in:
@@ -176,15 +176,10 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
.setSubtitle(getSubTitle(mPackageName, mUid))
|
||||
.setPrimaryAction(getPrimarySliceAction(icon, title, getIntent())));
|
||||
|
||||
// Get rows by notification channel.
|
||||
// Add notification channel rows.
|
||||
final List<ListBuilder.RowBuilder> rows = getNotificationChannelRows(packageInfo, icon);
|
||||
|
||||
// Get displayable notification channel count.
|
||||
final int channelCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
|
||||
|
||||
// According to the displayable channel count to add rows.
|
||||
for (int i = 0; i < channelCount; i++) {
|
||||
listBuilder.addRow(rows.get(i));
|
||||
for (ListBuilder.RowBuilder rowBuilder : rows) {
|
||||
listBuilder.addRow(rowBuilder);
|
||||
}
|
||||
|
||||
return listBuilder.build();
|
||||
@@ -279,10 +274,9 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
private List<ListBuilder.RowBuilder> getNotificationChannelRows(PackageInfo packageInfo,
|
||||
IconCompat icon) {
|
||||
final List<ListBuilder.RowBuilder> notificationChannelRows = new ArrayList<>();
|
||||
final List<NotificationChannel> enabledChannels = getEnabledChannels(mPackageName, mUid,
|
||||
mAppRow);
|
||||
final List<NotificationChannel> displayableChannels = getDisplayableChannels(mAppRow);
|
||||
|
||||
for (NotificationChannel channel : enabledChannels) {
|
||||
for (NotificationChannel channel : displayableChannels) {
|
||||
notificationChannelRows.add(new ListBuilder.RowBuilder()
|
||||
.setTitle(channel.getName())
|
||||
.setSubtitle(NotificationBackend.getSentSummary(
|
||||
@@ -356,10 +350,9 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
title);
|
||||
}
|
||||
|
||||
private List<NotificationChannel> getEnabledChannels(String packageName, int uid,
|
||||
NotificationBackend.AppRow appRow) {
|
||||
private List<NotificationChannel> getDisplayableChannels(NotificationBackend.AppRow appRow) {
|
||||
final List<NotificationChannelGroup> channelGroupList =
|
||||
mNotificationBackend.getGroups(packageName, uid).getList();
|
||||
mNotificationBackend.getGroups(appRow.pkg, appRow.uid).getList();
|
||||
final List<NotificationChannel> channels = channelGroupList.stream()
|
||||
.flatMap(group -> group.getChannels().stream().filter(
|
||||
channel -> isChannelEnabled(group, channel, appRow)))
|
||||
@@ -376,8 +369,11 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
}
|
||||
|
||||
// Sort the notification channels with notification sent count by descending.
|
||||
return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(
|
||||
state -> state.getNotificationChannel()).collect(Collectors.toList());
|
||||
return channelStates.stream()
|
||||
.sorted(CHANNEL_STATE_COMPARATOR)
|
||||
.map(state -> state.getNotificationChannel())
|
||||
.limit(DEFAULT_EXPANDED_ROW_COUNT)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private PackageInfo getMaxSentNotificationsPackage(List<PackageInfo> packageInfoList) {
|
||||
@@ -391,10 +387,14 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
for (PackageInfo packageInfo : packageInfoList) {
|
||||
final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext,
|
||||
mContext.getPackageManager(), packageInfo);
|
||||
// Ignore packages which are banned notifications or block all displayable channels.
|
||||
if (appRow.banned || isAllChannelsBlocked(getDisplayableChannels(appRow))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get sent notification count from app.
|
||||
final int sentCount = appRow.sentByApp.sentCount;
|
||||
if (!appRow.banned && sentCount >= MIN_NOTIFICATION_SENT_COUNT
|
||||
&& sentCount > maxSentCount) {
|
||||
if (sentCount >= MIN_NOTIFICATION_SENT_COUNT && sentCount > maxSentCount) {
|
||||
maxSentCount = sentCount;
|
||||
maxSentCountPackage = packageInfo;
|
||||
mAppRow = appRow;
|
||||
@@ -404,6 +404,15 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
return maxSentCountPackage;
|
||||
}
|
||||
|
||||
private boolean isAllChannelsBlocked(List<NotificationChannel> channels) {
|
||||
for (NotificationChannel channel : channels) {
|
||||
if (channel.getImportance() != IMPORTANCE_NONE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected CharSequence getSubTitle(String packageName, int uid) {
|
||||
final int channelCount = mNotificationBackend.getChannelCount(packageName, uid);
|
||||
|
||||
|
Reference in New Issue
Block a user