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

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

Merge "Fix swipe cancel lifetime extended notifs" into main

parents 43a9420d c1dfcb56
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(),
@@ -8298,14 +8298,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()
@@ -8322,6 +8314,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;
                    }
@@ -11244,7 +11242,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();