[automerge] Prune summaries if only group children filtered 2p: be918ae7ee 2p: 75b1db6e47
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17453689 Change-Id: I6e5e83dbde1f7841d7cfd21ccb60fe48b3c490f0
This commit is contained in:
committed by
Presubmit Automerger Backend
commit
85262afd87
@@ -35,6 +35,7 @@ import static java.util.Objects.requireNonNull;
|
||||
import android.annotation.MainThread;
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Trace;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
|
||||
@@ -703,13 +704,17 @@ public class ShadeListBuilder implements Dumpable {
|
||||
// having its summary promoted, regardless of how many children it has
|
||||
Set<String> groupsWithChildrenLostToStability =
|
||||
getGroupsWithChildrenLostToStability(shadeList);
|
||||
// Like groups which lost a child to stability, any group which lost a child to promotion
|
||||
// is exempt from having its summary promoted when it has no attached children.
|
||||
Set<String> groupsWithChildrenLostToPromotionOrStability =
|
||||
getGroupsWithChildrenLostToPromotion(shadeList);
|
||||
groupsWithChildrenLostToPromotionOrStability.addAll(groupsWithChildrenLostToStability);
|
||||
// Groups with children lost to stability are exempt from summary promotion.
|
||||
ArraySet<String> groupsExemptFromSummaryPromotion =
|
||||
new ArraySet<>(groupsWithChildrenLostToStability);
|
||||
// Any group which lost a child to filtering or promotion is exempt from having its summary
|
||||
// promoted when it has no attached children.
|
||||
getGroupsWithChildrenLostToFiltering(groupsExemptFromSummaryPromotion);
|
||||
getGroupsWithChildrenLostToPromotion(shadeList, groupsExemptFromSummaryPromotion);
|
||||
|
||||
for (int i = 0; i < shadeList.size(); i++) {
|
||||
// Iterate backwards, so that we can remove elements without affecting indices of
|
||||
// yet-to-be-accessed entries.
|
||||
for (int i = shadeList.size() - 1; i >= 0; i--) {
|
||||
final ListEntry tle = shadeList.get(i);
|
||||
|
||||
if (tle instanceof GroupEntry) {
|
||||
@@ -718,7 +723,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
final boolean hasSummary = group.getSummary() != null;
|
||||
|
||||
if (hasSummary && children.size() == 0) {
|
||||
if (groupsWithChildrenLostToPromotionOrStability.contains(group.getKey())) {
|
||||
if (groupsExemptFromSummaryPromotion.contains(group.getKey())) {
|
||||
// This group lost a child on this run to promotion or stability, so it is
|
||||
// exempt from having its summary promoted to the top level, so prune it.
|
||||
// It has no children, so it will just vanish.
|
||||
@@ -727,14 +732,10 @@ public class ShadeListBuilder implements Dumpable {
|
||||
// For any other summary with no children, promote the summary.
|
||||
pruneGroupAtIndexAndPromoteSummary(shadeList, group, i);
|
||||
}
|
||||
|
||||
i--; // The node we visited is gone, so be sure to visit this index again.
|
||||
} else if (!hasSummary) {
|
||||
// If the group doesn't provide a summary, ignore it and add
|
||||
// any children it may have directly to top-level.
|
||||
pruneGroupAtIndexAndPromoteAnyChildren(shadeList, group, i);
|
||||
|
||||
i--; // The node we visited is gone, so be sure to visit this index again.
|
||||
} else if (children.size() < MIN_CHILDREN_FOR_GROUP) {
|
||||
// This group has a summary and insufficient, but nonzero children.
|
||||
checkState(hasSummary, "group must have summary at this point");
|
||||
@@ -759,8 +760,6 @@ public class ShadeListBuilder implements Dumpable {
|
||||
// The group is too small, ignore it and add
|
||||
// its children (if any) directly to top-level.
|
||||
pruneGroupAtIndexAndPromoteAnyChildren(shadeList, group, i);
|
||||
|
||||
i--; // The node we visited is gone, so be sure to visit this index again.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -866,18 +865,32 @@ public class ShadeListBuilder implements Dumpable {
|
||||
*
|
||||
* These groups will be exempt from appearing without any children.
|
||||
*/
|
||||
@NonNull
|
||||
private Set<String> getGroupsWithChildrenLostToPromotion(List<ListEntry> shadeList) {
|
||||
ArraySet<String> groupsWithChildrenLostToPromotion = new ArraySet<>();
|
||||
private void getGroupsWithChildrenLostToPromotion(List<ListEntry> shadeList, Set<String> out) {
|
||||
for (int i = 0; i < shadeList.size(); i++) {
|
||||
final ListEntry tle = shadeList.get(i);
|
||||
if (tle.getAttachState().getPromoter() != null) {
|
||||
// This top-level-entry was part of a group, but was promoted out of it.
|
||||
final String groupKey = tle.getRepresentativeEntry().getSbn().getGroupKey();
|
||||
groupsWithChildrenLostToPromotion.add(groupKey);
|
||||
out.add(groupKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the keys of any groups which have already lost a child to a {@link NotifFilter}
|
||||
* this run.
|
||||
*
|
||||
* These groups will be exempt from appearing without any children.
|
||||
*/
|
||||
private void getGroupsWithChildrenLostToFiltering(Set<String> out) {
|
||||
for (ListEntry tle : mAllEntries) {
|
||||
StatusBarNotification sbn = tle.getRepresentativeEntry().getSbn();
|
||||
if (sbn.isGroup()
|
||||
&& !sbn.getNotification().isGroupSummary()
|
||||
&& tle.getAttachState().getExcludingFilter() != null) {
|
||||
out.add(sbn.getGroup());
|
||||
}
|
||||
}
|
||||
return groupsWithChildrenLostToPromotion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1450,6 +1450,25 @@ public class ShadeListBuilderTest extends SysuiTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupWithChildRemovedByFilterIsPrunedWhenOtherwiseEmpty() {
|
||||
// GIVEN a group with only one child
|
||||
addGroupSummary(0, PACKAGE_1, GROUP_1);
|
||||
addGroupChild(1, PACKAGE_1, GROUP_1);
|
||||
dispatchBuild();
|
||||
// NOTICE that the group is pruned and the child is moved to the top level
|
||||
verifyBuiltList(
|
||||
notif(1) // group with only one child is promoted
|
||||
);
|
||||
|
||||
// WHEN the only child is filtered
|
||||
mFinalizeFilter.mIndicesToFilter.add(1);
|
||||
dispatchBuild();
|
||||
|
||||
// THEN the new list should be empty (the group summary should not be promoted)
|
||||
verifyBuiltList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFinalizeFilteredSummaryPromotesChildren() {
|
||||
// GIVEN a group with only one child was already drawn
|
||||
|
||||
Reference in New Issue
Block a user