summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yuri Lin <yurilin@google.com> 2025-03-19 12:34:52 -0400
committer Yuri Lin <yurilin@google.com> 2025-03-20 08:06:32 -0700
commitcfd420e6cfff005df77e06a8d13c1defb1353753 (patch)
tree76f7b54b97f991f414d15da270100a568a53cb87
parent8c37fec12f237d5fa743e7e649332084c6d4e17e (diff)
Don't allow RONS to be bundled
Removes any classification adjustments if FLAG_PROMOTED_ONGOING is on the notification. Flag: android.service.notification.notification_classification Flag: android.app.api_rich_ongoing Fixes: 401265826 Test: NotificationManagerServiceTest Change-Id: Ib7c664f15e7df897c3835e5a6a099c16b9e5f448
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java4
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java52
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();