From 62608f6fe7d400d11b445e774d639656ee62d0c2 Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Tue, 26 Mar 2019 18:18:48 +0800 Subject: [PATCH] Optimize latency of NotificationChannelSlice - Use NotificationBackend.getChannel() in onNotifyChange(). - Record AppRow and use it in getEnabledChannels(). Bug: 123065955 Test: robotests Change-Id: I92466d31544128f09d599d86fb265997207eb55c --- .../slices/NotificationChannelSlice.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java index c319dca8c5a..d174156dc67 100644 --- a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java +++ b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java @@ -131,6 +131,7 @@ public class NotificationChannelSlice implements CustomSliceable { protected final Context mContext; @VisibleForTesting NotificationBackend mNotificationBackend; + private NotificationBackend.AppRow mAppRow; private String mPackageName; private int mUid; @@ -200,21 +201,12 @@ public class NotificationChannelSlice implements CustomSliceable { final String packageName = intent.getStringExtra(PACKAGE_NAME); final int uid = intent.getIntExtra(PACKAGE_UID, -1); final String channelId = intent.getStringExtra(CHANNEL_ID); - final PackageInfo packageInfo = getPackageInfo(packageName); - final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext, - mContext.getPackageManager(), packageInfo); - - final List notificationChannels = getEnabledChannels(packageName, uid, - appRow); - 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; - } - } + final NotificationChannel channel = mNotificationBackend.getChannel(packageName, uid, + channelId); + final int importance = newState ? IMPORTANCE_LOW : IMPORTANCE_NONE; + channel.setImportance(importance); + channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); + mNotificationBackend.updateChannel(packageName, uid, channel); } @Override @@ -287,16 +279,14 @@ public class NotificationChannelSlice implements CustomSliceable { private List getNotificationChannelRows(PackageInfo packageInfo, IconCompat icon) { final List notificationChannelRows = new ArrayList<>(); - final NotificationBackend.AppRow appRow = mNotificationBackend.loadAppRow(mContext, - mContext.getPackageManager(), packageInfo); final List enabledChannels = getEnabledChannels(mPackageName, mUid, - appRow); + mAppRow); for (NotificationChannel channel : enabledChannels) { notificationChannelRows.add(new ListBuilder.RowBuilder() .setTitle(channel.getName()) .setSubtitle(NotificationBackend.getSentSummary( - mContext, appRow.sentByChannel.get(channel.getId()), false)) + mContext, mAppRow.sentByChannel.get(channel.getId()), false)) .setPrimaryAction(buildRowSliceAction(channel, icon)) .addEndItem(SliceAction.createToggle(getToggleIntent(channel.getId()), null /* actionTitle */, channel.getImportance() != IMPORTANCE_NONE))); @@ -407,6 +397,7 @@ public class NotificationChannelSlice implements CustomSliceable { && sentCount > maxSentCount) { maxSentCount = sentCount; maxSentCountPackage = packageInfo; + mAppRow = appRow; } }