Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7926d236 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Sort children of bundles by rank.

Fixes: 419608865
Test: ShadeListBuilderTest
Flag: com.android.systemui.notification_bundle_ui
Change-Id: Ibed5498ff08704f2f44f64809cf3348c99d8647c
parent 65b1c341
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1324,6 +1324,7 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
            if (entry instanceof GroupEntry parent) {
                allSorted &= sortGroupChildren(parent.getRawChildren());
            } else if (entry instanceof BundleEntry bundleEntry) {
                allSorted &= sortBundleChildren(bundleEntry.getRawChildren());
                // Sort children of groups within bundles
                for (ListEntry le : bundleEntry.getChildren()) {
                    if (le instanceof GroupEntry ge) {
@@ -1360,6 +1361,15 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        }
    }

    private boolean sortBundleChildren(List<ListEntry> entries) {
        if (getStabilityManager().isEveryChangeAllowed()) {
            entries.sort(mBundleChildrenComparator);
            return true;
        } else {
            return mSemiStableSort.sort(entries, mStableOrder, mBundleChildrenComparator);
        }
    }

    /** Determine whether the items in the list are sorted according to the comparator */
    @VisibleForTesting
    public static <T> boolean isSorted(List<T> items, Comparator<? super T> comparator) {
@@ -1611,6 +1621,18 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        return cmp;
    };

    private final Comparator<ListEntry> mBundleChildrenComparator = (o1, o2) -> {
        int cmp = Integer.compare(
                o1.getRepresentativeEntry().getRanking().getRank(),
                o2.getRepresentativeEntry().getRanking().getRank());
        if (cmp != 0) return cmp;

        cmp = -1 * Long.compare(
                o1.getRepresentativeEntry().getSbn().getNotification().getWhen(),
                o2.getRepresentativeEntry().getSbn().getNotification().getWhen());
        return cmp;
    };

    @Nullable
    private Integer getStableOrderRank(PipelineEntry entry) {
        if (getStabilityManager().isEntryReorderingAllowed(entry)) {
+24 −1
Original line number Diff line number Diff line
@@ -1082,13 +1082,36 @@ public class ShadeListBuilderTest extends SysuiTestCase {
        verify(idPromoter, never()).shouldPromoteToTopLevel(eq(promotableChild));
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void testBundle_bundleChildrenAreSorted() {
        mListBuilder.setBundler(TestBundler.INSTANCE);
        // GIVEN a simple pipeline
        // WHEN we three notifs in a bundle
        addNotif(0, PACKAGE_1, BUNDLE_1).setRank(3);
        addNotif(1, PACKAGE_1, BUNDLE_1).setRank(2);
        addNotif(2, PACKAGE_1, BUNDLE_1).setRank(1);

        dispatchBuild();

        // THEN bundle children are sorted by rank
        verifyBuiltList(
                bundle(
                        BUNDLE_1,
                        notif(2),
                        notif(1),
                        notif(0)
                )
        );
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void testBundle_groupChildrenAreSorted() {
        mListBuilder.setBundler(TestBundler.INSTANCE);

        // GIVEN a simple pipeline
        // WHEN we add two groups
        // WHEN we a group with three children
        addGroupChild(0, PACKAGE_1, GROUP_1, BUNDLE_1).setRank(3);
        addGroupChild(1, PACKAGE_1, GROUP_1, BUNDLE_1).setRank(2);
        addGroupChild(2, PACKAGE_1, GROUP_1, BUNDLE_1).setRank(1);