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

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

Cleanup autogroup summary when enqueued after group cancel

 Ensure that there is no empty autogroup summary.

Flag: EXEMPT bugfix

Test: atest NotificationManagerServiceTest
Test: atest GroupHelperTest

Bug: 421160533
Change-Id: I136613b541967f02e5cdbee84940202a016a8375
parent 7c2f9153
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -764,6 +764,15 @@ public class GroupHelper {
                    }
                    updateAggregateAppGroup(fullAggregateGroupKey, sbn.getKey(), true, 0);
                }
            } else if (record.getGroupKey().equals(fullAggregateGroupKey.toString())
                        && isAggregatedGroup(record)
                        && aggregatedNotificationsAttrs.isEmpty()) {
                // Remove autogroup summary if posted after all children were canceled
                if (DEBUG) {
                    Slog.i(TAG, "Aggregate group is empty: " + fullAggregateGroupKey);
                }
                mCallback.removeAutoGroupSummary(userId, pkgName, fullAggregateGroupKey.toString());
                mAggregatedNotifications.remove(fullAggregateGroupKey);
            }
        }
        return wasUnAggregated;
+8 −6
Original line number Diff line number Diff line
@@ -7691,16 +7691,18 @@ public class NotificationManagerService extends SystemService {
            autbundledGroupKey = pkg;
        }
        ArrayMap<String, String> summaries = mAutobundledSummaries.get(userId);
        final NotificationRecord autogroupSummary;
        if (summaries != null && summaries.containsKey(autbundledGroupKey)) {
            final NotificationRecord removed = findNotificationByKeyLocked(
                    summaries.remove(autbundledGroupKey));
            if (removed != null) {
                final StatusBarNotification sbn = removed.getSbn();
            autogroupSummary = findNotificationByKeyLocked(summaries.remove(autbundledGroupKey));
        } else {
            autogroupSummary = mSummaryByGroupKey.get(autbundledGroupKey);
        }
        if (autogroupSummary != null) {
            final StatusBarNotification sbn = autogroupSummary.getSbn();
            cancelNotification(MY_UID, MY_PID, pkg, sbn.getTag(), sbn.getId(), 0, 0, false,
                    userId, REASON_UNAUTOBUNDLED, null);
        }
    }
    }
    @GuardedBy("mNotificationLock")
    void removeAppSummaryLocked(String key) {
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server.notification;

import static android.app.Notification.COLOR_DEFAULT;
import static android.app.Notification.FLAG_AUTOGROUP_SUMMARY;
import static android.app.Notification.FLAG_AUTO_CANCEL;
import static android.app.Notification.FLAG_BUBBLE;
import static android.app.Notification.FLAG_CAN_COLORIZE;
@@ -929,6 +930,26 @@ public class GroupHelperTest extends UiServiceTestCase {
                anyString(), anyInt(), any());
    }

    @Test
    @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING)
    public void testPostedAutogroupSummaryCanceled_ifAutogroupEmpty() {
        final String pkg = "package";
        final String groupName = AGGREGATE_GROUP_KEY + "AlertingSection";
        final String expectedGroupKey = GroupHelper.getFullAggregateGroupKey(pkg, groupName,
                UserHandle.SYSTEM.getIdentifier());
        StatusBarNotification sbn = getSbn(pkg, 0, "0", UserHandle.SYSTEM, groupName);
        sbn.getNotification().flags |= FLAG_AUTOGROUP_SUMMARY;
        NotificationRecord autogroupSummary = getNotificationRecord(sbn);
        mGroupHelper.onNotificationPosted(autogroupSummary, false);

        verify(mCallback, times(1)).removeAutoGroupSummary(anyInt(), eq(pkg),
                eq(expectedGroupKey));
        verify(mCallback, never()).addAutoGroupSummary(anyInt(), anyString(), anyString(),
                anyString(), anyInt(), any());
        verify(mCallback, never()).addAutoGroup(anyString(), anyString(), anyBoolean());
        verify(mCallback, never()).removeAutoGroup(anyString());
    }

    @Test
    @EnableFlags({Flags.FLAG_AUTOGROUP_SUMMARY_ICON_UPDATE})
    public void testAddSummary_sameIcon_sameColor() {
+22 −0
Original line number Diff line number Diff line
@@ -2829,6 +2829,28 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertThat(mService.getNotificationRecordCount()).isEqualTo(0);
    }
    @Test
    @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING)
    public void testUngroupingAggregateSummary_missingFromAutobundledSummaries() throws Exception {
        final String aggregateGroupName = "Aggregate_Test";
        NotificationRecord summary =
                generateNotificationRecord(mTestNotificationChannel, 0, aggregateGroupName, false);
        mService.addNotification(summary);
        final String fullAggregateGroupKey = summary.getGroupKey();
        // Check that only mSummaryByGroupKey contains the summary
        assertThat(mService.mSummaryByGroupKey.containsKey(fullAggregateGroupKey)).isTrue();
        assertThat(mService.mAutobundledSummaries.get(summary.getUser().getIdentifier())).isNull();
        // Check that the autogroup summary is removed
        mService.clearAutogroupSummaryLocked(summary.getUserId(), summary.getSbn().getPackageName(),
                fullAggregateGroupKey);
        waitForIdle();
        // Make sure the summary was removed and not re-posted
        assertThat(mService.getNotificationRecordCount()).isEqualTo(0);
    }
    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING,
            Flags.FLAG_NOTIFICATION_FORCE_GROUP_SINGLETONS})