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

Commit 8b4013e5 authored by Alexander Roederer's avatar Alexander Roederer
Browse files

Dismiss lifetime extended notifications on click

Lifetime extended notifications should still be dismissed on click,
if they're not already considered FLAG_AUTO_CANCEL.

Bug: 352643817
Test: atest NotificationManagerServiceTest, integration test in chain cl
Flag: android.app.lifetime_extension_refactor
Change-Id: Ifee95202c04a519d629d6ab90dcb0ae8ec06ecda
parent 9124b479
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 {