diff options
2 files changed, 56 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 06fc9b083086..869bf79137d6 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -7417,6 +7417,10 @@ public class NotificationManagerService extends SystemService { adjustments); if (newChannel == null || newChannel.getId().equals(r.getChannel().getId())) { adjustments.remove(KEY_TYPE); + } else if (android.app.Flags.apiRichOngoing() && hasFlag(r.getNotification().flags, + FLAG_PROMOTED_ONGOING)) { + // Don't bundle any promoted ongoing notifications + adjustments.remove(KEY_TYPE); } else { // Save the app-provided type for logging. int classification = adjustments.getInt(KEY_TYPE); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 902171d614d9..f73fc7cdfa25 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -17680,6 +17680,58 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test + @EnableFlags({android.app.Flags.FLAG_API_RICH_ONGOING, + android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION, + android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI}) + public void testApplyAdjustment_promotedOngoingNotification_doesNotApply() throws Exception { + // promoted ongoing notification which should not have the adjustment applied + Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) + .setSmallIcon(android.R.drawable.sym_def_app_icon) + .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG")) + .setColor(Color.WHITE) + .setColorized(true) + .setOngoing(true) + .setFlag(FLAG_PROMOTED_ONGOING, true) // add manually since we're skipping post + .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post + .build(); + + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0, + n, UserHandle.getUserHandleForUid(mUid), null, 0); + final NotificationRecord r = new NotificationRecord(mContext, sbn, + mTestNotificationChannel); + + // regular notification record for contrast + final NotificationRecord r2 = generateNotificationRecord(mTestNotificationChannel); + + mService.addNotification(r); + mService.addNotification(r2); + NotificationManagerService.WorkerHandler handler = mock( + NotificationManagerService.WorkerHandler.class); + mService.setHandler(handler); + when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true); + when(mAssistants.isAdjustmentAllowedForPackage(anyString(), anyString())).thenReturn(true); + + Bundle signals = new Bundle(); + signals.putInt(KEY_TYPE, TYPE_NEWS); + Bundle signals2 = new Bundle(signals); // copy for the second adjustment + Adjustment adjustment = new Adjustment( + r.getSbn().getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); + Adjustment a2 = new Adjustment(r2.getSbn().getPackageName(), r2.getKey(), signals2, "", + r2.getUser().getIdentifier()); + when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true); + mBinderService.applyAdjustmentsFromAssistant(null, List.of(adjustment, a2)); + + waitForIdle(); + + r.applyAdjustments(); + r2.applyAdjustments(); + + // promoted ongoing notification does not get bundled; regular one does + assertThat(r.getChannel().getId()).isEqualTo(mTestNotificationChannel.getId()); + assertThat(r2.getChannel().getId()).isEqualTo(NEWS_ID); + } + + @Test @EnableFlags({android.app.Flags.FLAG_API_RICH_ONGOING}) public void testSetCanBePromoted_granted_noui() throws Exception { testSetCanBePromoted_granted(); |