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

Commit 7e1c1cad authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge changes I136613b5,I3d663fdc into main

* changes:
  Cleanup autogroup summary when enqueued after group cancel
  Exempt autogroup summaries from NMS#checkDisqualifyingFeatures
parents 2133fcff 2e188a4e
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;
+11 −8
Original line number Diff line number Diff line
@@ -7695,16 +7695,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) {
@@ -9337,8 +9339,9 @@ public class NotificationManagerService extends SystemService {
                }
            }
            // limit the number of non-fgs/uij outstanding notificationrecords an app can have
            if (!n.isFgsOrUij()) {
            // Limit the number of non-fgs/uij outstanding notificationrecords an app can have
            // Do not count autogroup summaries
            if (!n.isFgsOrUij() && !GroupHelper.isAggregatedGroup(r)) {
                int count = getNotificationCount(pkg, userId, id, tag);
                if (count >= MAX_PACKAGE_NOTIFICATIONS) {
                    mUsageStats.registerOverCountQuota(pkg);
+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() {
+53 −0
Original line number Diff line number Diff line
@@ -2830,6 +2830,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})
@@ -15068,6 +15090,37 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                r.getSbn().getId(), r.getSbn().getTag(), r, false, false)).isTrue();
    }
    @Test
    public void checkAutogroupSummaryExemptFromLimit() throws Exception {
        // Add maximum number of notifications per package
        for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) {
            Notification n = new Notification.Builder(mContext, "").build();
            StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, i, null, mUid, 0,
                    n, UserHandle.getUserHandleForUid(mUid), null, 0);
            NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
            mService.addNotification(r);
        }
        // Check that next regular summary notification is diqualified from enqueueing
        StatusBarNotification sbn = generateSbn(mPkg, mUid, 0, UserHandle.getUserId(mUid));
        sbn.getNotification().flags |= FLAG_GROUP_SUMMARY;
        NotificationRecord summary = new NotificationRecord(mContext, sbn,
                mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(summary.getUserId(), summary.getUid(),
                summary.getSbn().getId(), summary.getSbn().getTag(), summary, true,
                false)).isFalse();
        // Check that next autogroup summary notification is exempt from checkDisqualifyingFeatures
        sbn = generateSbn(mPkg, mUid, 0, UserHandle.getUserId(mUid));
        sbn.getNotification().flags |= Notification.FLAG_AUTOGROUP_SUMMARY;
        summary = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(summary.getUserId(), summary.getUid(),
                summary.getSbn().getId(), summary.getSbn().getTag(), summary, true,
                false)).isTrue();
    }
    private Notification createBigPictureNotification(boolean isBigPictureStyle, boolean hasImage,
            boolean isImageBitmap) {
        Notification.Builder builder = new Notification.Builder(mContext)