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

Commit c1dfcb56 authored by Alexander Roederer's avatar Alexander Roederer
Browse files

Fix swipe cancel lifetime extended notifs

Allows LE notifications to be cancelled again. This was broken in
ag/26818707 when we moved the sysui specific update into the
CancelationRunnable, and excepted action clicks, but not swipe
cancellations or any other cancellation reason
from having that update sent (which resulted in sysui showing an update
whenever the notification was swiped away).

Bug: 333704739
Test: atest NotificationManagerServiceTest
Flag: ACONFIG android.app.lifetime_extension_refactor STAGING
Change-Id: I9826e1cb7579acf3fc14e1a14f1871d02067a35c
parent 722a4c72
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -3785,9 +3785,9 @@ public class NotificationManagerService extends SystemService {
                // If cancellation will be prevented due to lifetime extension, we send updates
                // to system UI.
                synchronized (mNotificationLock) {
                    notifySystemUiListenerLifetimeExtendedListLocked(mNotificationList,
                    maybeNotifySystemUiListenerLifetimeExtendedListLocked(mNotificationList,
                            packageImportance);
                    notifySystemUiListenerLifetimeExtendedListLocked(mEnqueuedNotifications,
                    maybeNotifySystemUiListenerLifetimeExtendedListLocked(mEnqueuedNotifications,
                            packageImportance);
                }
            } else {
@@ -4974,10 +4974,10 @@ public class NotificationManagerService extends SystemService {
                                            | FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY);
                            // If cancellation will be prevented due to lifetime extension, we send
                            // an update to system UI.
                            notifySystemUiListenerLifetimeExtendedListLocked(mNotificationList,
                                    packageImportance);
                            notifySystemUiListenerLifetimeExtendedListLocked(mEnqueuedNotifications,
                                    packageImportance);
                            maybeNotifySystemUiListenerLifetimeExtendedListLocked(
                                    mNotificationList, packageImportance);
                            maybeNotifySystemUiListenerLifetimeExtendedListLocked(
                                    mEnqueuedNotifications, packageImportance);
                        } else {
                            cancelAllLocked(callingUid, callingPid, info.userid,
                                    REASON_LISTENER_CANCEL_ALL, info, info.supportsProfiles(),
@@ -8294,14 +8294,6 @@ public class NotificationManagerService extends SystemService {
                        mUsageStats.registerClickedByUser(r);
                    }
                    // If cancellation will be prevented due to lifetime extension, we need to
                    // send an update to system UI. This must be checked before flags are checked.
                    // We do not want to send this update.
                    if (lifetimeExtensionRefactor() && mReason != REASON_CLICK) {
                        maybeNotifySystemUiListenerLifetimeExtendedLocked(r, mPkg,
                                packageImportance);
                    }
                    if ((mReason == REASON_LISTENER_CANCEL
                            && r.getNotification().isBubbleNotification())
                            || (mReason == REASON_CLICK && r.canBubble()
@@ -8318,6 +8310,12 @@ public class NotificationManagerService extends SystemService {
                        return;
                    }
                    if ((r.getNotification().flags & mMustNotHaveFlags) != 0) {
                        if (lifetimeExtensionRefactor()) {
                            // If cancellation will be prevented due to lifetime extension,
                            // we need to send an update to system UI first.
                            maybeNotifySystemUiListenerLifetimeExtendedLocked(r, mPkg,
                                    packageImportance);
                        }
                        return;
                    }
@@ -11240,7 +11238,7 @@ public class NotificationManagerService extends SystemService {
    @FlaggedApi(FLAG_LIFETIME_EXTENSION_REFACTOR)
    @GuardedBy("mNotificationLock")
    private void notifySystemUiListenerLifetimeExtendedListLocked(
    private void maybeNotifySystemUiListenerLifetimeExtendedListLocked(
            List<NotificationRecord> notificationList, int packageImportance) {
        for (int i = notificationList.size() - 1; i >= 0; --i) {
            NotificationRecord record = notificationList.get(i);
+26 −5
Original line number Diff line number Diff line
@@ -2616,7 +2616,30 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    @EnableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR)
    public void testCancelAllDoesNotCancelLifetimeExtended() throws Exception {
    public void testCancelAllClearsLifetimeExtended() throws Exception {
        final NotificationRecord notif = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        notif.getNotification().flags |= Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY;
        mService.addNotification(notif);
        StatusBarNotification[] notifs =
                mBinderService.getActiveNotifications(notif.getSbn().getPackageName());
        assertThat(notifs.length).isEqualTo(1);
        // Simulate a "cancel all" received.
        mService.mNotificationDelegate.onClearAll(mUid, Binder.getCallingPid(),
                notif.getUserId());
        waitForIdle();
        notifs = mBinderService.getActiveNotifications(notif.getSbn().getPackageName());
        assertThat(notifs.length).isEqualTo(0);
        // Test that no update post is sent to System UI.
        verify(mWorkerHandler, never())
                .post(any(NotificationManagerService.EnqueueNotificationRunnable.class));
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR)
    public void testAppCancelAllDoesNotCancelLifetimeExtended() throws Exception {
        // Adds a lifetime extended notification.
        final NotificationRecord notif = generateNotificationRecord(mTestNotificationChannel, 1,
                null, false);
@@ -8836,9 +8859,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR)
    public void testActionClickLifetimeExtendedCancel_PreventByNoDismiss() throws Exception {
        mSetFlagsRule.enableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);
        final Notification.Action action =
                new Notification.Action.Builder(null, "text", PendingIntent.getActivity(
                        mContext, 0, new Intent(), PendingIntent.FLAG_IMMUTABLE)).build();
@@ -8879,9 +8901,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR)
    public void testUpdateOnActionClickDropsLifetimeExtendedCancel() throws Exception {
        mSetFlagsRule.enableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);
        final Notification.Action action =
                new Notification.Action.Builder(null, "text", PendingIntent.getActivity(
                        mContext, 0, new Intent(), PendingIntent.FLAG_IMMUTABLE)).build();