Merge "Detect when group children are mis-ordered to ensure stability invalidation." into tm-qpr-dev
This commit is contained in:
@@ -986,7 +986,7 @@ public class ShadeListBuilder implements Dumpable {
|
|||||||
// Check for suppressed order changes
|
// Check for suppressed order changes
|
||||||
if (!getStabilityManager().isEveryChangeAllowed()) {
|
if (!getStabilityManager().isEveryChangeAllowed()) {
|
||||||
mForceReorderable = true;
|
mForceReorderable = true;
|
||||||
boolean isSorted = isSorted(mNotifList, mTopLevelComparator);
|
boolean isSorted = isShadeSorted();
|
||||||
mForceReorderable = false;
|
mForceReorderable = false;
|
||||||
if (!isSorted) {
|
if (!isSorted) {
|
||||||
getStabilityManager().onEntryReorderSuppressed();
|
getStabilityManager().onEntryReorderSuppressed();
|
||||||
@@ -995,9 +995,23 @@ public class ShadeListBuilder implements Dumpable {
|
|||||||
Trace.endSection();
|
Trace.endSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isShadeSorted() {
|
||||||
|
if (!isSorted(mNotifList, mTopLevelComparator)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (ListEntry entry : mNotifList) {
|
||||||
|
if (entry instanceof GroupEntry) {
|
||||||
|
if (!isSorted(((GroupEntry) entry).getChildren(), mGroupChildrenComparator)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Determine whether the items in the list are sorted according to the comparator */
|
/** Determine whether the items in the list are sorted according to the comparator */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static <T> boolean isSorted(List<T> items, Comparator<T> comparator) {
|
public static <T> boolean isSorted(List<T> items, Comparator<? super T> comparator) {
|
||||||
if (items.size() <= 1) {
|
if (items.size() <= 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1205,7 +1219,7 @@ public class ShadeListBuilder implements Dumpable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private final Comparator<ListEntry> mGroupChildrenComparator = (o1, o2) -> {
|
private final Comparator<NotificationEntry> mGroupChildrenComparator = (o1, o2) -> {
|
||||||
int index1 = canReorder(o1) ? -1 : o1.getPreviousAttachState().getStableIndex();
|
int index1 = canReorder(o1) ? -1 : o1.getPreviousAttachState().getStableIndex();
|
||||||
int index2 = canReorder(o2) ? -1 : o2.getPreviousAttachState().getStableIndex();
|
int index2 = canReorder(o2) ? -1 : o2.getPreviousAttachState().getStableIndex();
|
||||||
int cmp = Integer.compare(index1, index2);
|
int cmp = Integer.compare(index1, index2);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import androidx.test.filters.SmallTest;
|
|||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.systemui.dump.DumpManager;
|
import com.android.systemui.dump.DumpManager;
|
||||||
import com.android.systemui.statusbar.NotificationInteractionTracker;
|
import com.android.systemui.statusbar.NotificationInteractionTracker;
|
||||||
|
import com.android.systemui.statusbar.RankingBuilder;
|
||||||
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
|
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
|
||||||
import com.android.systemui.statusbar.notification.collection.ShadeListBuilder.OnRenderListListener;
|
import com.android.systemui.statusbar.notification.collection.ShadeListBuilder.OnRenderListListener;
|
||||||
import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection;
|
import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection;
|
||||||
@@ -1797,6 +1798,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStableMultipleSectionOrdering() {
|
public void testStableMultipleSectionOrdering() {
|
||||||
|
// WHEN the list is originally built with reordering disabled
|
||||||
mListBuilder.setSectioners(asList(
|
mListBuilder.setSectioners(asList(
|
||||||
new PackageSectioner(PACKAGE_1), new PackageSectioner(PACKAGE_2)));
|
new PackageSectioner(PACKAGE_1), new PackageSectioner(PACKAGE_2)));
|
||||||
mStabilityManager.setAllowEntryReordering(false);
|
mStabilityManager.setAllowEntryReordering(false);
|
||||||
@@ -1807,12 +1809,94 @@ public class ShadeListBuilderTest extends SysuiTestCase {
|
|||||||
addNotif(3, PACKAGE_1).setRank(3);
|
addNotif(3, PACKAGE_1).setRank(3);
|
||||||
dispatchBuild();
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY the order and that entry reordering has not been suppressed
|
||||||
verifyBuiltList(
|
verifyBuiltList(
|
||||||
notif(0),
|
notif(0),
|
||||||
notif(1),
|
notif(1),
|
||||||
notif(3),
|
notif(3),
|
||||||
notif(2)
|
notif(2)
|
||||||
);
|
);
|
||||||
|
verify(mStabilityManager, never()).onEntryReorderSuppressed();
|
||||||
|
|
||||||
|
// WHEN the ranks change
|
||||||
|
setNewRank(notif(0).entry, 4);
|
||||||
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY the order does not change that entry reordering has been suppressed
|
||||||
|
verifyBuiltList(
|
||||||
|
notif(0),
|
||||||
|
notif(1),
|
||||||
|
notif(3),
|
||||||
|
notif(2)
|
||||||
|
);
|
||||||
|
verify(mStabilityManager).onEntryReorderSuppressed();
|
||||||
|
|
||||||
|
// WHEN reordering is now allowed again
|
||||||
|
mStabilityManager.setAllowEntryReordering(true);
|
||||||
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY that list order changes
|
||||||
|
verifyBuiltList(
|
||||||
|
notif(1),
|
||||||
|
notif(3),
|
||||||
|
notif(0),
|
||||||
|
notif(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStableChildOrdering() {
|
||||||
|
// WHEN the list is originally built with reordering disabled
|
||||||
|
mStabilityManager.setAllowEntryReordering(false);
|
||||||
|
addGroupSummary(0, PACKAGE_1, GROUP_1).setRank(0);
|
||||||
|
addGroupChild(1, PACKAGE_1, GROUP_1).setRank(1);
|
||||||
|
addGroupChild(2, PACKAGE_1, GROUP_1).setRank(2);
|
||||||
|
addGroupChild(3, PACKAGE_1, GROUP_1).setRank(3);
|
||||||
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY the order and that entry reordering has not been suppressed
|
||||||
|
verifyBuiltList(
|
||||||
|
group(
|
||||||
|
summary(0),
|
||||||
|
child(1),
|
||||||
|
child(2),
|
||||||
|
child(3)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
verify(mStabilityManager, never()).onEntryReorderSuppressed();
|
||||||
|
|
||||||
|
// WHEN the ranks change
|
||||||
|
setNewRank(notif(2).entry, 5);
|
||||||
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY the order does not change that entry reordering has been suppressed
|
||||||
|
verifyBuiltList(
|
||||||
|
group(
|
||||||
|
summary(0),
|
||||||
|
child(1),
|
||||||
|
child(2),
|
||||||
|
child(3)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
verify(mStabilityManager).onEntryReorderSuppressed();
|
||||||
|
|
||||||
|
// WHEN reordering is now allowed again
|
||||||
|
mStabilityManager.setAllowEntryReordering(true);
|
||||||
|
dispatchBuild();
|
||||||
|
|
||||||
|
// VERIFY that list order changes
|
||||||
|
verifyBuiltList(
|
||||||
|
group(
|
||||||
|
summary(0),
|
||||||
|
child(1),
|
||||||
|
child(3),
|
||||||
|
child(2)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setNewRank(NotificationEntry entry, int rank) {
|
||||||
|
entry.setRanking(new RankingBuilder(entry.getRanking()).setRank(rank).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user