Loading services/core/java/com/android/server/notification/NotificationManagerService.java +18 −4 Original line number Diff line number Diff line Loading @@ -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); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +18 −4 Original line number Diff line number Diff line Loading @@ -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); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading