Loading services/core/java/com/android/server/notification/NotificationManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -7410,6 +7410,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); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -17681,6 +17681,58 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(r.getChannel().getId()).isEqualTo(NEWS_ID); } @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 { Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -7410,6 +7410,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); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -17681,6 +17681,58 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(r.getChannel().getId()).isEqualTo(NEWS_ID); } @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 {