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

Commit 074765a7 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Fix autogroup summary HUN update with duplicate summary" into main

parents c5a28975 e2ec68b0
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static java.util.Objects.requireNonNull;

import android.annotation.MainThread;
import android.annotation.Nullable;
import android.app.Notification;
import android.os.Trace;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
@@ -682,6 +683,15 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
                    } else {
                        mLogger.logDuplicateSummary(mIterationCount, group, existingSummary, entry);

                        NotificationEntry autogroupSummary = getAutogroupSummary(entry,
                                existingSummary);
                        if (autogroupSummary != null) {
                            // Prioritize the autogroup summary if duplicate summaries found
                            group.setSummary(autogroupSummary);
                            NotificationEntry otherEntry =
                                    autogroupSummary.equals(entry) ? existingSummary : entry;
                            annulAddition(otherEntry, out);
                        } else {
                            // Use whichever one was posted most recently
                            if (entry.getSbn().getPostTime()
                                    > existingSummary.getSbn().getPostTime()) {
@@ -691,6 +701,7 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
                                annulAddition(entry, out);
                            }
                        }
                    }
                } else {
                    group.addChild(entry);
                }
@@ -709,6 +720,18 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        Trace.endSection();
    }

    private @Nullable NotificationEntry getAutogroupSummary(NotificationEntry newSummary,
            NotificationEntry existingSummary) {
        if ((newSummary.getSbn().getNotification().flags
                & Notification.FLAG_AUTOGROUP_SUMMARY) != 0) {
            return newSummary;
        } else if ((existingSummary.getSbn().getNotification().flags
                & Notification.FLAG_AUTOGROUP_SUMMARY) != 0) {
            return existingSummary;
        }
        return null;
    }

    @Nullable
    private BundleEntry getBundleEntry(String id) {
        BundleEntry be = mIdToBundleEntry.get(id);
+46 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;

import android.app.Notification;
import android.app.NotificationChannel;
import android.os.SystemClock;
import android.platform.test.annotations.DisableFlags;
@@ -330,6 +331,38 @@ public class ShadeListBuilderTest extends SysuiTestCase {
        assertNull(mEntrySet.get(6).getParent());
    }

    @Test
    public void testDuplicateGroupSummaries_prioritizeAutogroupSummary() {
        // GIVEN a simple pipeline

        // WHEN a group with multiple summaries is added & one of them is FLAG_AUTOGROUP_SUMMARY
        addNotif(0, PACKAGE_3);
        addGroupChild(1, PACKAGE_1, GROUP_1);
        addGroupChild(2, PACKAGE_1, GROUP_1);
        addGroupSummary(3, PACKAGE_1, GROUP_1).setPostTime(22);
        addAutoGroupSummary(4, PACKAGE_1, GROUP_1).setPostTime(13);
        addNotif(5, PACKAGE_2);
        addGroupSummary(6, PACKAGE_1, GROUP_1).setPostTime(11);
        addGroupChild(7, PACKAGE_1, GROUP_1);
        dispatchBuild();

        // THEN only the autogroup summary is used
        verifyBuiltList(
                notif(0),
                group(
                        summary(4),
                        child(1),
                        child(2),
                        child(7)
                ),
                notif(5)
        );

        // THEN the extra summaries have their parents set to null
        assertNull(mEntrySet.get(3).getParent());
        assertNull(mEntrySet.get(6).getParent());
    }

    @Test
    public void testGroupsWithNoSummaryAreUngrouped() {
        // GIVEN a group with no summary
@@ -2720,6 +2753,19 @@ public class ShadeListBuilderTest extends SysuiTestCase {
        return addGroupSummary(index, packageId, groupId, "test_channel");
    }

    private NotificationEntryBuilder addAutoGroupSummary(int index, String packageId,
            String groupId) {
        final NotificationEntryBuilder builder = addGroupSummary(index, packageId, groupId);
        mPendingSet.remove(builder);

        builder.modifyNotification(mContext)
                .setFlag(Notification.FLAG_AUTOGROUP_SUMMARY, true);

        assertEquals(mEntrySet.size() + mPendingSet.size(), index);
        mPendingSet.add(builder);
        return builder;
    }

    private NotificationEntryBuilder addGroupChildWithTag(int index, String packageId,
            String groupId, String tag, String channelId) {