Merge "Optimize latency of NotificationChannelSlice"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f4bc45077e
@@ -131,6 +131,7 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
protected final Context mContext;
|
protected final Context mContext;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
NotificationBackend mNotificationBackend;
|
NotificationBackend mNotificationBackend;
|
||||||
|
private NotificationBackend.AppRow mAppRow;
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private int mUid;
|
private int mUid;
|
||||||
|
|
||||||
@@ -200,21 +201,12 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
final String packageName = intent.getStringExtra(PACKAGE_NAME);
|
final String packageName = intent.getStringExtra(PACKAGE_NAME);
|
||||||
final int uid = intent.getIntExtra(PACKAGE_UID, -1);
|
final int uid = intent.getIntExtra(PACKAGE_UID, -1);
|
||||||
final String channelId = intent.getStringExtra(CHANNEL_ID);
|
final String channelId = intent.getStringExtra(CHANNEL_ID);
|
||||||
final PackageInfo packageInfo = getPackageInfo(packageName);
|
final NotificationChannel channel = mNotificationBackend.getChannel(packageName, uid,
|
||||||
final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext,
|
channelId);
|
||||||
mContext.getPackageManager(), packageInfo);
|
final int importance = newState ? IMPORTANCE_LOW : IMPORTANCE_NONE;
|
||||||
|
channel.setImportance(importance);
|
||||||
final List<NotificationChannel> notificationChannels = getEnabledChannels(packageName, uid,
|
channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||||
appRow);
|
mNotificationBackend.updateChannel(packageName, uid, channel);
|
||||||
for (NotificationChannel channel : notificationChannels) {
|
|
||||||
if (TextUtils.equals(channel.getId(), channelId)) {
|
|
||||||
final int importance = newState ? IMPORTANCE_LOW : IMPORTANCE_NONE;
|
|
||||||
channel.setImportance(importance);
|
|
||||||
channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
|
||||||
mNotificationBackend.updateChannel(packageName, uid, channel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -287,16 +279,14 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
private List<ListBuilder.RowBuilder> getNotificationChannelRows(PackageInfo packageInfo,
|
private List<ListBuilder.RowBuilder> getNotificationChannelRows(PackageInfo packageInfo,
|
||||||
IconCompat icon) {
|
IconCompat icon) {
|
||||||
final List<ListBuilder.RowBuilder> notificationChannelRows = new ArrayList<>();
|
final List<ListBuilder.RowBuilder> notificationChannelRows = new ArrayList<>();
|
||||||
final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext,
|
|
||||||
mContext.getPackageManager(), packageInfo);
|
|
||||||
final List<NotificationChannel> enabledChannels = getEnabledChannels(mPackageName, mUid,
|
final List<NotificationChannel> enabledChannels = getEnabledChannels(mPackageName, mUid,
|
||||||
appRow);
|
mAppRow);
|
||||||
|
|
||||||
for (NotificationChannel channel : enabledChannels) {
|
for (NotificationChannel channel : enabledChannels) {
|
||||||
notificationChannelRows.add(new ListBuilder.RowBuilder()
|
notificationChannelRows.add(new ListBuilder.RowBuilder()
|
||||||
.setTitle(channel.getName())
|
.setTitle(channel.getName())
|
||||||
.setSubtitle(NotificationBackend.getSentSummary(
|
.setSubtitle(NotificationBackend.getSentSummary(
|
||||||
mContext, appRow.sentByChannel.get(channel.getId()), false))
|
mContext, mAppRow.sentByChannel.get(channel.getId()), false))
|
||||||
.setPrimaryAction(buildRowSliceAction(channel, icon))
|
.setPrimaryAction(buildRowSliceAction(channel, icon))
|
||||||
.addEndItem(SliceAction.createToggle(getToggleIntent(channel.getId()),
|
.addEndItem(SliceAction.createToggle(getToggleIntent(channel.getId()),
|
||||||
null /* actionTitle */, channel.getImportance() != IMPORTANCE_NONE)));
|
null /* actionTitle */, channel.getImportance() != IMPORTANCE_NONE)));
|
||||||
@@ -407,6 +397,7 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
&& sentCount > maxSentCount) {
|
&& sentCount > maxSentCount) {
|
||||||
maxSentCount = sentCount;
|
maxSentCount = sentCount;
|
||||||
maxSentCountPackage = packageInfo;
|
maxSentCountPackage = packageInfo;
|
||||||
|
mAppRow = appRow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user