SysUI: Ignore group children when summary is present

This is an optimization to avoid inflating Views for notifications
we're not going to show and free up memory ASAP. No behavioral changes
expected.

Bug: 16302692
Change-Id: I5fa03dcc9ad9cae4afc7cd6102d7ea8bfbdcbfd5
This commit is contained in:
Christoph Studer
2014-09-02 11:49:19 +02:00
parent 8591fb27c0
commit d722f27323
2 changed files with 27 additions and 7 deletions

View File

@@ -365,6 +365,24 @@ public abstract class BaseStatusBar extends SystemUI implements
Notification n = sbn.getNotification();
boolean isUpdate = mNotificationData.get(sbn.getKey()) != null
|| isHeadsUp(sbn.getKey());
// Ignore children of notifications that have a summary, since we're not
// going to show them anyway. This is true also when the summary is canceled,
// because children are automatically canceled by NoMan in that case.
if (n.isGroupChild() &&
mNotificationData.isGroupWithSummary(sbn.getGroupKey())) {
if (DEBUG) {
Log.d(TAG, "Ignoring group child due to existing summary: " + sbn);
}
// Remove existing notification to avoid stale data.
if (isUpdate) {
removeNotification(sbn.getKey(), rankingMap);
} else {
mNotificationData.updateRanking(rankingMap);
}
return;
}
if (isUpdate) {
updateNotification(sbn, rankingMap);
} else {

View File

@@ -89,6 +89,7 @@ public class NotificationData {
private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
private final ArrayList<Entry> mSortedAndFiltered = new ArrayList<>();
private ArraySet<String> mGroupsWithSummaries = new ArraySet<>();
private RankingMap mRankingMap;
private final Ranking mTmpRanking = new Ranking();
@@ -183,8 +184,8 @@ public class NotificationData {
// anything changed, and this class should call back the UI so it updates itself.
public void filterAndSort() {
mSortedAndFiltered.clear();
mGroupsWithSummaries.clear();
ArraySet<String> groupsWithSummaries = null;
final int N = mEntries.size();
for (int i = 0; i < N; i++) {
Entry entry = mEntries.valueAt(i);
@@ -195,22 +196,19 @@ public class NotificationData {
}
if (sbn.getNotification().isGroupSummary()) {
if (groupsWithSummaries == null) {
groupsWithSummaries = new ArraySet<>();
}
groupsWithSummaries.add(sbn.getGroupKey());
mGroupsWithSummaries.add(sbn.getGroupKey());
}
mSortedAndFiltered.add(entry);
}
// Second pass: Filter out group children with summary.
if (groupsWithSummaries != null) {
if (!mGroupsWithSummaries.isEmpty()) {
final int M = mSortedAndFiltered.size();
for (int i = M - 1; i >= 0; i--) {
Entry ent = mSortedAndFiltered.get(i);
StatusBarNotification sbn = ent.notification;
if (sbn.getNotification().isGroupChild() &&
groupsWithSummaries.contains(sbn.getGroupKey())) {
mGroupsWithSummaries.contains(sbn.getGroupKey())) {
mSortedAndFiltered.remove(i);
}
}
@@ -219,6 +217,10 @@ public class NotificationData {
Collections.sort(mSortedAndFiltered, mRankingComparator);
}
public boolean isGroupWithSummary(String groupKey) {
return mGroupsWithSummaries.contains(groupKey);
}
private boolean shouldFilterOut(StatusBarNotification sbn) {
if (!(mEnvironment.isDeviceProvisioned() ||
showNotificationEvenIfUnprovisioned(sbn))) {