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

Commit 831d5dc7 authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Set FLAG_SILENT only for autogrouping updates

 - addAutogroupKeyLocked: only for forced grouped (app grouped) notifications
 - updateAutobundledSummaryLocked: when updating an autogroup summary

Flag: android.service.notification.notification_force_grouping
Test: atest NotificationManagerServiceTest

Bug: 408823758
Bug: 396573298
Change-Id: I709622182222ce5e59197a7af77080c20991a0a0
parent cd602c84
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -1084,6 +1084,7 @@ public class NotificationManagerService extends SystemService {
        }
        int oldFlags = summary.getSbn().getNotification().flags;
        int newFlags = summaryAttr.flags != GroupHelper.FLAG_INVALID ? summaryAttr.flags : oldFlags;
        boolean attributesUpdated =
                !summaryAttr.icon.sameAs(summary.getSbn().getNotification().getSmallIcon())
@@ -1093,7 +1094,7 @@ public class NotificationManagerService extends SystemService {
                        summary.getSbn().getNotification().getGroupAlertBehavior();
        if (notificationForceGrouping()) {
            summary.getNotification().flags |= Notification.FLAG_SILENT;
            newFlags |= Notification.FLAG_SILENT;
            if (!summary.getChannel().getId().equals(summaryAttr.channelId)) {
                NotificationChannel newChannel = mPreferencesHelper.getNotificationChannel(pkg,
                        summary.getUid(), summaryAttr.channelId, false);
@@ -1104,9 +1105,8 @@ public class NotificationManagerService extends SystemService {
            }
        }
        if (oldFlags != summaryAttr.flags || attributesUpdated) {
            summary.getSbn().getNotification().flags =
                    summaryAttr.flags != GroupHelper.FLAG_INVALID ? summaryAttr.flags : oldFlags;
        if (oldFlags != newFlags || attributesUpdated) {
            summary.getSbn().getNotification().flags = newFlags;
            summary.getSbn().getNotification().setSmallIcon(summaryAttr.icon);
            summary.getSbn().getNotification().color = summaryAttr.iconColor;
            summary.getSbn().getNotification().visibility = summaryAttr.visibility;
@@ -7516,9 +7516,9 @@ public class NotificationManagerService extends SystemService {
                if (r.getSbn().isAppGroup()) {
                    // Override group key early for forced grouped notifications
                    r.setOverrideGroupKey(groupName);
                }
                    r.getNotification().flags |= Notification.FLAG_SILENT;
                }
            }
            addAutoGroupAdjustment(r, groupName);
            EventLogTags.writeNotificationAutogrouped(key);
+31 −1
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ import static android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATIO
import static android.service.notification.Flags.FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT;
import static android.service.notification.Flags.FLAG_NOTIFICATION_FORCE_GROUPING;
import static android.service.notification.Flags.FLAG_NOTIFICATION_REGROUP_ON_CLASSIFICATION;
import static android.service.notification.Flags.FLAG_NOTIFICATION_SILENT_FLAG;
import static android.service.notification.Flags.FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS;
@@ -2622,7 +2623,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }
    @Test
    @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING)
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_SILENT_FLAG})
    public void testAggregatedSummary_updateSummaryAttributes() {
        final String aggregateGroupName = "Aggregate_Test";
        final String newChannelId = "newChannelId";
@@ -2638,6 +2639,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.mAutobundledSummaries.get(0).put(groupKey, summary.getKey());
        when(mPreferencesHelper.getNotificationChannel(eq("pkg"), anyInt(),
                eq(newChannelId), anyBoolean())).thenReturn(newChannel);
        assertThat(summary.getNotification().isSilent()).isFalse();
        mService.updateAutobundledSummaryLocked(0, "pkg", groupKey,
                new NotificationAttributes(GroupHelper.BASE_FLAGS | FLAG_ONGOING_EVENT,
@@ -2645,6 +2647,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                    false);
        waitForIdle();
        assertThat(summary.getNotification().isSilent()).isTrue();
        assertTrue(summary.getSbn().isOngoing());
        assertThat(summary.getNotification().getGroupAlertBehavior()).isEqualTo(
                GROUP_ALERT_CHILDREN);
@@ -2666,6 +2669,33 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mListeners, times(1)).notifyPostedLocked(eq(r), eq(r));
    }
    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_SILENT_FLAG})
    public void testAddUngroupedAggregateNotification_silentFlagNotSet() throws Exception {
        final NotificationRecord r =
                generateNotificationRecord(mTestNotificationChannel, 0, null, false);
        assertThat(r.getNotification().isSilent()).isFalse();
        mService.addNotification(r);
        mService.addAutogroupKeyLocked(r.getKey(), "AggregateGrp", true);
        assertThat(r.hasAdjustment(Adjustment.KEY_GROUP_KEY)).isTrue();
        assertThat(r.getNotification().isSilent()).isFalse();
    }
    @Test
    @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, FLAG_NOTIFICATION_SILENT_FLAG})
    public void testAddGroupedAggregateNotification_silentFlagSet() throws Exception {
        final String originalGroupName = "originalGroup";
        final NotificationRecord r =
                generateNotificationRecord(mTestNotificationChannel, 0, originalGroupName, false);
        assertThat(r.getNotification().isSilent()).isFalse();
        mService.addNotification(r);
        mService.addAutogroupKeyLocked(r.getKey(), "AggregateGrp", true);
        assertThat(r.getSbn().getOverrideGroupKey()).isEqualTo("AggregateGrp");
        assertThat(r.getNotification().isSilent()).isTrue();
    }
    @Test
    @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING)
    public void testAddAggregateSummaryNotification_convertSummary() throws Exception {