Clean up NotificationChannelSlice

- Remove unused variable.
- Change function interface.

Bug: 123065955
Test: visual, robotests
Change-Id: I39c0a92539d45cdbc11bd9090a3ab97a72482632
This commit is contained in:
Yanting Yang
2019-04-16 23:08:40 +08:00
parent 997128ee91
commit ce3359f4d4

View File

@@ -154,16 +154,12 @@ public class NotificationChannelSlice implements CustomSliceable {
// TODO(b/123065955): Review latency of NotificationChannelSlice // TODO(b/123065955): Review latency of NotificationChannelSlice
final List<PackageInfo> multiChannelPackages = getMultiChannelPackages( final List<PackageInfo> multiChannelPackages = getMultiChannelPackages(
getRecentlyInstalledPackages()); getRecentlyInstalledPackages());
final PackageInfo packageInfo = getMaxSentNotificationsPackage(multiChannelPackages); mPackageName = getMaxSentNotificationsPackage(multiChannelPackages);
if (mPackageName == null) {
// Return a header with IsError flag, if package is not found. // Return a header with IsError flag, if package is not found.
if (packageInfo == null) {
return listBuilder.setHeader(getNoSuggestedAppHeader()) return listBuilder.setHeader(getNoSuggestedAppHeader())
.setIsError(true).build(); .setIsError(true).build();
} }
// Save eligible package name and its uid, they will be used in getIntent().
mPackageName = packageInfo.packageName;
mUid = getApplicationUid(mPackageName); mUid = getApplicationUid(mPackageName);
// Add notification channel header. // Add notification channel header.
@@ -177,7 +173,7 @@ public class NotificationChannelSlice implements CustomSliceable {
.setPrimaryAction(getPrimarySliceAction(icon, title, getIntent()))); .setPrimaryAction(getPrimarySliceAction(icon, title, getIntent())));
// Add notification channel rows. // Add notification channel rows.
final List<ListBuilder.RowBuilder> rows = getNotificationChannelRows(packageInfo, icon); final List<ListBuilder.RowBuilder> rows = getNotificationChannelRows(icon);
for (ListBuilder.RowBuilder rowBuilder : rows) { for (ListBuilder.RowBuilder rowBuilder : rows) {
listBuilder.addRow(rowBuilder); listBuilder.addRow(rowBuilder);
} }
@@ -282,8 +278,7 @@ public class NotificationChannelSlice implements CustomSliceable {
.setPrimaryAction(primarySliceActionForNoSuggestedApp); .setPrimaryAction(primarySliceActionForNoSuggestedApp);
} }
private List<ListBuilder.RowBuilder> getNotificationChannelRows(PackageInfo packageInfo, private List<ListBuilder.RowBuilder> getNotificationChannelRows(IconCompat icon) {
IconCompat icon) {
final List<ListBuilder.RowBuilder> notificationChannelRows = new ArrayList<>(); final List<ListBuilder.RowBuilder> notificationChannelRows = new ArrayList<>();
final List<NotificationChannel> displayableChannels = getDisplayableChannels(mAppRow); final List<NotificationChannel> displayableChannels = getDisplayableChannels(mAppRow);
@@ -388,14 +383,14 @@ public class NotificationChannelSlice implements CustomSliceable {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private PackageInfo getMaxSentNotificationsPackage(List<PackageInfo> packageInfoList) { private String getMaxSentNotificationsPackage(List<PackageInfo> packageInfoList) {
if (packageInfoList.isEmpty()) { if (packageInfoList.isEmpty()) {
return null; return null;
} }
// Get the package which has sent at least ~10 notifications and not turn off channels. // Get the package which has sent at least ~10 notifications and not turn off channels.
int maxSentCount = 0; int maxSentCount = 0;
PackageInfo maxSentCountPackage = null; String maxSentCountPackage = null;
for (PackageInfo packageInfo : packageInfoList) { for (PackageInfo packageInfo : packageInfoList) {
final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext, final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext,
mContext.getPackageManager(), packageInfo); mContext.getPackageManager(), packageInfo);
@@ -408,7 +403,7 @@ public class NotificationChannelSlice implements CustomSliceable {
final int sentCount = appRow.sentByApp.sentCount; final int sentCount = appRow.sentByApp.sentCount;
if (sentCount >= MIN_NOTIFICATION_SENT_COUNT && sentCount > maxSentCount) { if (sentCount >= MIN_NOTIFICATION_SENT_COUNT && sentCount > maxSentCount) {
maxSentCount = sentCount; maxSentCount = sentCount;
maxSentCountPackage = packageInfo; maxSentCountPackage = packageInfo.packageName;
mAppRow = appRow; mAppRow = appRow;
} }
} }