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

Commit c21d2de9 authored by Alexander Roederer's avatar Alexander Roederer Committed by Android (Google) Code Review
Browse files

Merge "Dismiss lifetime extended notifications on click" into main

parents 9f9ba1b2 8b4013e5
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -1315,10 +1315,24 @@ public class NotificationManagerService extends SystemService {
                        nv.rank, nv.count);
                StatusBarNotification sbn = r.getSbn();
                // Notifications should be cancelled on click if they have been lifetime extended,
                // regardless of presence or absence of FLAG_AUTO_CANCEL.
                if (lifetimeExtensionRefactor()
                        && (sbn.getNotification().flags
                        & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY) != 0) {
                    cancelNotification(callingUid, callingPid, sbn.getPackageName(), sbn.getTag(),
                            sbn.getId(), FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY,
                            FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB
                                    | FLAG_BUBBLE,
                            false, r.getUserId(), REASON_CLICK, nv.rank, nv.count, null);
                } else {
                    // Otherwise, only FLAG_AUTO_CANCEL notifications should be canceled on click.
                    cancelNotification(callingUid, callingPid, sbn.getPackageName(), sbn.getTag(),
                            sbn.getId(), FLAG_AUTO_CANCEL,
                            FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB | FLAG_BUBBLE,
                            false, r.getUserId(), REASON_CLICK, nv.rank, nv.count, null);
                }
                nv.recycle();
                reportUserInteraction(r);
                mAssistants.notifyAssistantNotificationClicked(r);
+23 −0
Original line number Diff line number Diff line
@@ -3104,6 +3104,29 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY);
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR)
    public void testLifetimeExtendedCancelledOnClick() throws Exception {
        // Adds a lifetime extended notification.
        final NotificationRecord notif = generateNotificationRecord(mTestNotificationChannel, 1,
                null, false);
        notif.getSbn().getNotification().flags =
                Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY;
        mService.addNotification(notif);
        // Verify that the notification is posted and active.
        assertThat(mBinderService.getActiveNotifications(mPkg).length).isEqualTo(1);
        // Click the notification.
        final NotificationVisibility nv = NotificationVisibility.obtain(notif.getKey(), 1, 2, true);
        mService.mNotificationDelegate.onNotificationClick(mUid, Binder.getCallingPid(),
                notif.getKey(), nv);
        waitForIdle();
        // The notification has been cancelled.
        StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg);
        assertThat(notifs.length).isEqualTo(0);
    }
    @Test
    public void testCancelNotificationWithTag_fromApp_cannotCancelFgsChild()
            throws Exception {