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

Commit 7c9f31af authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I82e011c6,I0a231e65 into main

* changes:
  Cancel the notification group summary when the last non-regrouped child notification is canceled
  Use actual GroupHelper in NotificationManagerServiceTest
parents e882b110 da650505
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -872,7 +872,7 @@ public class GroupHelper {
    }

    @GuardedBy("mAggregatedNotifications")
    private void addToUngroupedAndMaybeAggregate(NotificationRecord record,
    private boolean addToUngroupedAndMaybeAggregate(NotificationRecord record,
            FullyQualifiedGroupKey fullAggregateGroupKey, NotificationSectioner sectioner) {
        ArrayMap<String, NotificationAttributes> ungrouped =
                mUngroupedAbuseNotifications.getOrDefault(fullAggregateGroupKey,
@@ -901,7 +901,9 @@ public class GroupHelper {
            }
            aggregateUngroupedNotifications(fullAggregateGroupKey, record.getKey(),
                    ungrouped, hasSummary, sectioner.mSummaryId);
            return true;
        }
        return false;
    }

    private static boolean isGroupChildBundled(final NotificationRecord record,
@@ -1099,7 +1101,18 @@ public class GroupHelper {
                if (DEBUG) {
                    Slog.i(TAG, "isGroupSummaryWithoutChild " + summaryRecord);
                }
                addToUngroupedAndMaybeAggregate(summaryRecord, fullAggregateGroupKey, sectioner);
                boolean aggregated = addToUngroupedAndMaybeAggregate(summaryRecord,
                        fullAggregateGroupKey, sectioner);
                if (!aggregated) {
                    // Cancel the summary and cache it if does not get aggregated
                    // in order to avoid empty summaries
                    if (DEBUG) {
                        Slog.i(TAG,
                                "Empty group summary to be canceled and cached: " + summaryRecord);
                    }
                    mCallback.removeAppProvidedSummary(summaryRecord.getKey());
                    cacheCanceledSummary(summaryRecord);
                }
                return;
            }

+4 −2
Original line number Diff line number Diff line
@@ -669,7 +669,8 @@ public class NotificationManagerService extends SystemService {
    static final long NOTIFICATION_MAX_AGE_AT_POST = Duration.ofDays(14).toMillis();
    // Minium number of sparse groups for a package before autogrouping them
    private static final int AUTOGROUP_SPARSE_GROUPS_AT_COUNT = 6;
    @VisibleForTesting
    static final int AUTOGROUP_SPARSE_GROUPS_AT_COUNT = 6;
    // Minimum number notifications in a bundle section before autogrouping them
    private static final int AUTOGROUP_BUNDLE_SECTIONS_AT_COUNT = 1;
@@ -3282,7 +3283,8 @@ public class NotificationManagerService extends SystemService {
        return StatsManager.PULL_SUCCESS;
    }
    private GroupHelper getGroupHelper() {
    @VisibleForTesting
    protected GroupHelper getGroupHelper() {
        mAutoGroupAtCount =
                getContext().getResources().getInteger(R.integer.config_autoGroupAtCount);
        return new GroupHelper(getContext(), getContext().getPackageManager(),
+106 −1
Original line number Diff line number Diff line
@@ -1863,7 +1863,8 @@ public class GroupHelperTest extends UiServiceTestCase {
        // Remove all child notifications from the valid group => summary without children
        Mockito.reset(mCallback);
        for (NotificationRecord r: notificationList) {
            if (r.getGroupKey().contains(groupToRemove)) {
            if (r.getGroupKey().contains(groupToRemove)
                    && r.getSbn().getNotification().isGroupChild()) {
                r.isCanceled = true;
                mGroupHelper.onNotificationRemoved(r, notificationList, false);
            }
@@ -1875,6 +1876,110 @@ public class GroupHelperTest extends UiServiceTestCase {
        verifyNoMoreInteractions(mCallback);
    }

    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_FORCE_GROUP_SINGLETONS})
    public void testRemoveAllGroupChildNotifications_emptySummaryCanceled() {
        // Check that removing all notifications from a group will not trigger any force grouping
        // re-evaluation
        final List<NotificationRecord> notificationList = new ArrayList<>();
        final ArrayMap<String, NotificationRecord> summaryByGroup = new ArrayMap<>();
        final String pkg = "package";
        // Post a valid (full) group
        final int summaryId = 4242;
        final int numChildren = 3;
        final String groupToRemove = "testRemoveGrp";
        NotificationRecord summary = getNotificationRecord(pkg, summaryId,
                String.valueOf(summaryId), UserHandle.SYSTEM, groupToRemove, true);
        notificationList.add(summary);
        summaryByGroup.put(summary.getGroupKey(), summary);
        final ArrayList<NotificationRecord> childrenToRemove = new ArrayList<>();
        for (int i = 0; i < numChildren; i++) {
            NotificationRecord child = getNotificationRecord(pkg, i + 42,
                    String.valueOf(i + 42), UserHandle.SYSTEM, groupToRemove, false);
            notificationList.add(child);
            childrenToRemove.add(child);
        }
        mGroupHelper.onNotificationPostedWithDelay(summary, notificationList, summaryByGroup);
        verifyNoMoreInteractions(mCallback);

        // Remove all child notifications from the valid group => summary without children
        Mockito.reset(mCallback);
        for (NotificationRecord r: childrenToRemove) {
            notificationList.remove(r);
            mGroupHelper.onNotificationRemoved(r, notificationList, false);
        }

        // Only call onGroupedNotificationRemovedWithDelay with the summary notification
        mGroupHelper.onGroupedNotificationRemovedWithDelay(summary, notificationList,
                summaryByGroup);

        // Check that the summary was canceled
        verify(mCallback, times(1)).removeAppProvidedSummary(summary.getKey());
        // Check that nothing else was calledback
        verifyNoMoreInteractions(mCallback);
    }

    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_FORCE_GROUP_SINGLETONS})
    public void testRemoveAllGroupChildNotifications_emptySummaryCanceledAndCached() {
        // Check that removing all notifications from a group will not trigger any force grouping
        // re-evaluation
        final List<NotificationRecord> notificationList = new ArrayList<>();
        final ArrayMap<String, NotificationRecord> summaryByGroup = new ArrayMap<>();
        final String pkg = "package";
        // Post a valid (full) group
        final int summaryId = 4242;
        final int numChildren = AUTOGROUP_AT_COUNT - 1;
        final String groupToRemove = "testRemoveGrp";
        PendingIntent summaryDeleteIntent = PendingIntent.getActivity(mContext, 1,
                new Intent(), PendingIntent.FLAG_IMMUTABLE);
        NotificationRecord summary = getNotificationRecord(pkg, summaryId,
                String.valueOf(summaryId), UserHandle.SYSTEM, groupToRemove, true);
        summary.getNotification().deleteIntent = summaryDeleteIntent;
        notificationList.add(summary);
        summaryByGroup.put(summary.getGroupKey(), summary);
        final ArrayList<NotificationRecord> childrenToRemove = new ArrayList<>();
        for (int i = 0; i < numChildren; i++) {
            NotificationRecord child = getNotificationRecord(pkg, i + 42,
                    String.valueOf(i + 42), UserHandle.SYSTEM, groupToRemove, false);
            notificationList.add(child);
            childrenToRemove.add(child);
        }

        NotificationRecord childBundled = getNotificationRecord(pkg, numChildren + 42,
                String.valueOf(numChildren + 42), UserHandle.SYSTEM, groupToRemove, false);
        final String expectedGroupKey = GroupHelper.getFullAggregateGroupKey(pkg,
                AGGREGATE_GROUP_KEY + "AlertingSection", UserHandle.SYSTEM.getIdentifier());
        childBundled.setOverrideGroupKey(expectedGroupKey);
        notificationList.add(childBundled);

        mGroupHelper.onNotificationPostedWithDelay(summary, notificationList, summaryByGroup);
        verifyNoMoreInteractions(mCallback);

        // Remove all child notifications from the valid group => summary without children
        Mockito.reset(mCallback);
        for (NotificationRecord r: childrenToRemove) {
            notificationList.remove(r);
            mGroupHelper.onNotificationRemoved(r, notificationList, false);
        }

        // Only call onGroupedNotificationRemovedWithDelay with the summary notification
        notificationList.remove(summary);
        mGroupHelper.onGroupedNotificationRemovedWithDelay(summary, notificationList,
                summaryByGroup);

        // Check that the summary was canceled
        verify(mCallback, times(1)).removeAppProvidedSummary(summary.getKey());

        // Cancel the last child
        childBundled.isCanceled = true;
        notificationList.remove(childBundled);
        mGroupHelper.onNotificationRemoved(childBundled, notificationList, true);

        // Check that the summary delete intent was triggered
        verify(mCallback).sendAppProvidedSummaryDeleteIntent(eq(pkg), eq(summaryDeleteIntent));
    }

    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_FORCE_GROUP_SINGLETONS})
    public void testUpdateToUngroupableSection_cleanupUngrouped() {
+233 −176

File changed.

Preview size limit exceeded, changes collapsed.