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

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

Removes Lifetime extension on Action Click

Removes the FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY when an action click
occurs. This allows a notification to be cancelled by an app after a
user clicks on one of the actions, even if it has previously been
lifetime extended.

Bug: 230652175
Test: atest NotificationManagerServiceTest
Change-Id: I198424998b64d09097b92aaf56556bd06e2a9c5d
parent 6c5bc978
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1340,6 +1340,10 @@ public class NotificationManagerService extends SystemService {
                nv.recycle();
                reportUserInteraction(r);
                mAssistants.notifyAssistantActionClicked(r, action, generatedByAssistant);
                // Notifications that have been interacted with don't need to be lifetime extended.
                if (lifetimeExtensionRefactor()) {
                    r.getSbn().getNotification().flags &= ~FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY;
                }
            }
        }
+21 −0
Original line number Diff line number Diff line
@@ -8409,6 +8409,27 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                mNotificationRecordLogger.event(0));
    }
    @Test
    public void testOnNotificationActionClickLifetimeExtendedEnds() {
        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();
        // Creates a notification marked as being lifetime extended.
        NotificationRecord r = generateNotificationRecord(mTestNotificationChannel);
        r.getSbn().getNotification().flags |= FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY;
        mService.addNotification(r);
        // Call on action click.
        NotificationVisibility notificationVisibility =
                NotificationVisibility.obtain(r.getKey(), 1, 2, true);
        mService.mNotificationDelegate.onNotificationActionClick(
                10, 10, r.getKey(), /*actionIndex=*/2, action, notificationVisibility,
                /*generatedByAssistant=*/false);
        // The flag is removed, so the notification is no longer lifetime extended.
        assertThat(r.getSbn().getNotification().flags
                & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY).isEqualTo(0);
    }
    @Test
    public void testOnAssistantNotificationActionClick() {
        final int actionIndex = 1;