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

Commit e2ec68b0 authored by Valentin Iftime's avatar Valentin Iftime Committed by Iavor-Valentin Iftime
Browse files

Fix autogroup summary HUN update with duplicate summary

 When a duplicate summary is detected, use the autogroup summary instead.

Flag: EXEMPT bugfix

Test: ShadeListBuilderTest
Bug: 386810962
Bug: 396573298

Change-Id: Ic62e8220da8e450e75e38168c864caf639fbb3dd
parent c018324a
Loading
Loading
Loading
Loading
+29 −6
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import static java.util.Objects.requireNonNull;


import android.annotation.MainThread;
import android.annotation.MainThread;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.Notification;
import android.os.Trace;
import android.os.Trace;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.ArrayMap;
@@ -682,6 +683,15 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
                    } else {
                    } else {
                        mLogger.logDuplicateSummary(mIterationCount, group, existingSummary, entry);
                        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
                            // Use whichever one was posted most recently
                            if (entry.getSbn().getPostTime()
                            if (entry.getSbn().getPostTime()
                                    > existingSummary.getSbn().getPostTime()) {
                                    > existingSummary.getSbn().getPostTime()) {
@@ -691,6 +701,7 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
                                annulAddition(entry, out);
                                annulAddition(entry, out);
                            }
                            }
                        }
                        }
                    }
                } else {
                } else {
                    group.addChild(entry);
                    group.addChild(entry);
                }
                }
@@ -709,6 +720,18 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        Trace.endSection();
        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
    @Nullable
    private BundleEntry getBundleEntry(String id) {
    private BundleEntry getBundleEntry(String id) {
        BundleEntry be = mIdToBundleEntry.get(id);
        BundleEntry be = mIdToBundleEntry.get(id);
+46 −0
Original line number Original line 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.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonList;


import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannel;
import android.os.SystemClock;
import android.os.SystemClock;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.DisableFlags;
@@ -330,6 +331,38 @@ public class ShadeListBuilderTest extends SysuiTestCase {
        assertNull(mEntrySet.get(6).getParent());
        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
    @Test
    public void testGroupsWithNoSummaryAreUngrouped() {
    public void testGroupsWithNoSummaryAreUngrouped() {
        // GIVEN a group with no summary
        // GIVEN a group with no summary
@@ -2720,6 +2753,19 @@ public class ShadeListBuilderTest extends SysuiTestCase {
        return addGroupSummary(index, packageId, groupId, "test_channel");
        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,
    private NotificationEntryBuilder addGroupChildWithTag(int index, String packageId,
            String groupId, String tag, String channelId) {
            String groupId, String tag, String channelId) {