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

Commit cfd420e6 authored by Yuri Lin's avatar Yuri Lin
Browse files

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
parent 8c37fec1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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);
+52 −0
Original line number Diff line number Diff line
@@ -17679,6 +17679,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 {