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

Commit d88e3522 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

FLAG_FOREGROUND_SERVICE requires a running FGS

Bug: 269738057
Test: NotificationManagerServiceTest
Test: NotificationManagerTest
Test: ServiceTest
Change-Id: I11f5d3f19cb38cfb7e37489cbf029f7b2692f67c
parent 74efadf7
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -6992,8 +6992,10 @@ public class Notification implements Parcelable
    /**
     * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS
     * permission. The permission is checked when a notification is enqueued.
     *
     * @hide
     */
    private boolean hasColorizedPermission() {
    public boolean hasColorizedPermission() {
        return (flags & Notification.FLAG_CAN_COLORIZE) != 0;
    }
+17 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.notification;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.NOT_FOREGROUND_SERVICE;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION;
import static android.app.Notification.FLAG_AUTOGROUP_SUMMARY;
@@ -6517,9 +6518,17 @@ public class NotificationManagerService extends SystemService {
        checkRestrictedCategories(notification);
        // Notifications passed to setForegroundService() have FLAG_FOREGROUND_SERVICE,
        // but it's also possible that the app has called notify() with an update to an
        // FGS notification that hasn't yet been displayed.  Make sure we check for any
        // FGS-related situation up front, outside of any locks so it's safe to call into
        // the Activity Manager.
        final ServiceNotificationPolicy policy = mAmi.applyForegroundServiceNotification(
                notification, tag, id, pkg, userId);
        // Fix the notification as best we can.
        try {
            fixNotification(notification, pkg, tag, id, userId, notificationUid);
            fixNotification(notification, pkg, tag, id, userId, notificationUid, policy);
        } catch (Exception e) {
            if (notification.isForegroundService()) {
                throw new SecurityException("Invalid FGS notification", e);
@@ -6528,13 +6537,7 @@ public class NotificationManagerService extends SystemService {
            return;
        }
        // Notifications passed to setForegroundService() have FLAG_FOREGROUND_SERVICE,
        // but it's also possible that the app has called notify() with an update to an
        // FGS notification that hasn't yet been displayed.  Make sure we check for any
        // FGS-related situation up front, outside of any locks so it's safe to call into
        // the Activity Manager.
        final ServiceNotificationPolicy policy = mAmi.applyForegroundServiceNotification(
                notification, tag, id, pkg, userId);
        if (policy == ServiceNotificationPolicy.UPDATE_ONLY) {
            // Proceed if the notification is already showing/known, otherwise ignore
            // because the service lifecycle logic has retained responsibility for its
@@ -6707,14 +6710,17 @@ public class NotificationManagerService extends SystemService {
    @VisibleForTesting
    protected void fixNotification(Notification notification, String pkg, String tag, int id,
            @UserIdInt int userId, int notificationUid) throws NameNotFoundException,
            RemoteException {
            @UserIdInt int userId, int notificationUid, ServiceNotificationPolicy fgsPolicy)
            throws NameNotFoundException, RemoteException {
        final ApplicationInfo ai = mPackageManagerClient.getApplicationInfoAsUser(
                pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                (userId == UserHandle.USER_ALL) ? USER_SYSTEM : userId);
        Notification.addFieldsFromContext(ai, notification);
        if (notification.isForegroundService() && fgsPolicy == NOT_FOREGROUND_SERVICE) {
            notification.flags &= ~FLAG_FOREGROUND_SERVICE;
        }
        // Only notifications that can be non-dismissible can have the flag FLAG_NO_DISMISS
        if (mFlagResolver.isEnabled(ALLOW_DISMISS_ONGOING)) {
            if (((notification.flags & FLAG_ONGOING_EVENT) > 0)
+130 −14
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.notification;

import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.NOT_FOREGROUND_SERVICE;
import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.SHOW_IMMEDIATELY;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP;
import static android.app.Notification.FLAG_AUTO_CANCEL;
@@ -1183,6 +1185,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testEnqueuedBlockedNotifications_appBlockedChannelForegroundService()
            throws Exception {
        when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);

        NotificationChannel channel = new NotificationChannel("blocked", "name",
                NotificationManager.IMPORTANCE_NONE);
@@ -1205,6 +1209,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testEnqueuedBlockedNotifications_userBlockedChannelForegroundService()
            throws Exception {
        when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);

        NotificationChannel channel =
                new NotificationChannel("blockedbyuser", "name", IMPORTANCE_HIGH);
@@ -1284,6 +1290,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testEnqueuedBlockedNotifications_blockedAppForegroundService() throws Exception {
        when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
        when(mPermissionHelper.hasPermission(mUid)).thenReturn(false);
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);

        final StatusBarNotification sbn = generateNotificationRecord(null).getSbn();
        sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
@@ -1613,6 +1621,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testEnqueueNotificationWithTag_FgsAddsFlags_dismissalAllowed() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
        DeviceConfig.setProperty(
@@ -1643,6 +1653,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testEnqueueNotificationWithTag_FGSaddsFlags_dismissalNotAllowed() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
        DeviceConfig.setProperty(
@@ -1931,6 +1943,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testCancelAllNotifications_IgnoreForegroundService() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY);
        final StatusBarNotification sbn = generateNotificationRecord(null).getSbn();
        sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
        mBinderService.enqueueNotificationWithTag(PKG, PKG,
@@ -1944,8 +1958,28 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertEquals(1, mService.getNotificationRecordCount());
    }

    @Test
    public void testCancelAllNotifications_FgsFlag_NoFgs_Allowed() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(NOT_FOREGROUND_SERVICE);
        final StatusBarNotification sbn = generateNotificationRecord(null).getSbn();
        sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
        mBinderService.enqueueNotificationWithTag(PKG, PKG,
                "testCancelAllNotifications_IgnoreForegroundService",
                sbn.getId(), sbn.getNotification(), sbn.getUserId());
        mBinderService.cancelAllNotifications(PKG, sbn.getUserId());
        waitForIdle();
        StatusBarNotification[] notifs =
                mBinderService.getActiveNotifications(sbn.getPackageName());
        assertEquals(0, notifs.length);
    }

    @Test
    public void testCancelAllNotifications_IgnoreOtherPackages() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final StatusBarNotification sbn = generateNotificationRecord(null).getSbn();
        sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
        mBinderService.enqueueNotificationWithTag(PKG, PKG,
@@ -2033,6 +2067,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testRemoveForegroundServiceFlag_ImmediatelyAfterEnqueue() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        Notification n =
                new Notification.Builder(mContext, mTestNotificationChannel.getId())
                        .setSmallIcon(android.R.drawable.sym_def_app_icon)
@@ -2070,6 +2107,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationWithTag_fromApp_cannotCancelFgsChild()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        mService.isSystemUid = false;
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
@@ -2093,6 +2133,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationWithTag_fromApp_cannotCancelFgsParent()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        mService.isSystemUid = false;
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
@@ -2162,6 +2205,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelAllNotificationsFromApp_cannotCancelFgsChild()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        mService.isSystemUid = false;
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
@@ -2187,6 +2233,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelAllNotifications_fromApp_cannotCancelFgsParent()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        mService.isSystemUid = false;
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
@@ -2308,6 +2357,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_clearAll_GroupWithFgsParent()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        parent.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
@@ -2331,6 +2383,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_clearAll_GroupWithFgsChild()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        final NotificationRecord child = generateNotificationRecord(
@@ -2429,6 +2484,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_clearAll_Fgs()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord child2 = generateNotificationRecord(
                mTestNotificationChannel, 3, null, false);
        child2.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
@@ -2493,6 +2551,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_byKey_GroupWithFgsParent()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        parent.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
@@ -2518,6 +2579,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_byKey_GroupWithFgsChild()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        final NotificationRecord child = generateNotificationRecord(
@@ -2623,6 +2687,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    public void testCancelNotificationsFromListener_byKey_Fgs()
            throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord child2 = generateNotificationRecord(
                mTestNotificationChannel, 3, null, false);
        child2.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
@@ -2789,6 +2856,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testUserInitiatedCancelAllWithGroup_ForegroundServiceFlag() throws Exception {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, "group", true);
        final NotificationRecord child = generateNotificationRecord(
@@ -6249,6 +6319,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testRemoveForegroundServiceFlagFromNotification_enqueued() {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        Notification n = new Notification.Builder(mContext, "").build();
        n.flags |= FLAG_FOREGROUND_SERVICE;

@@ -6268,6 +6341,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testRemoveForegroundServiceFlagFromNotification_posted() {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        Notification n = new Notification.Builder(mContext, "").build();
        n.flags |= FLAG_FOREGROUND_SERVICE;

@@ -6291,6 +6367,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testCannotRemoveForegroundFlagWhenOverLimit_enqueued() {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) {
            Notification n = new Notification.Builder(mContext, "").build();
            StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0,
@@ -6319,6 +6398,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testCannotRemoveForegroundFlagWhenOverLimit_posted() {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) {
            Notification n = new Notification.Builder(mContext, "").build();
            StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0,
@@ -8327,7 +8409,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertNotNull(n.publicVersion.bigContentView);
        assertNotNull(n.publicVersion.headsUpContentView);

        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        assertNull(n.contentView);
        assertNull(n.bigContentView);
@@ -9018,6 +9100,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testCanPostFgsWhenOverLimit() throws RemoteException {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) {
            StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel,
                    i, null, false).getSbn();
@@ -9043,6 +9128,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

    @Test
    public void testCannotPostNonFgsWhenOverLimit() throws RemoteException {
        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(SHOW_IMMEDIATELY);
        for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) {
            StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel,
                    i, null, false).getSbn();
@@ -9065,6 +9153,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                "testCanPostFgsWhenOverLimit - non fgs over limit!",
                sbn2.getId(), sbn2.getNotification(), sbn2.getUserId());


        when(mAmi.applyForegroundServiceNotification(
                any(), anyString(), anyInt(), anyString(), anyInt()))
                .thenReturn(NOT_FOREGROUND_SERVICE);
        final StatusBarNotification sbn3 = generateNotificationRecord(mTestNotificationChannel,
                101, null, false).getSbn();
        sbn3.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
        mBinderService.enqueueNotificationWithTag(PKG, PKG,
                "testCanPostFgsWhenOverLimit - fake fgs over limit!",
                sbn3.getId(), sbn3.getNotification(), sbn3.getUserId());

        waitForIdle();

        StatusBarNotification[] notifs =
@@ -10137,7 +10236,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setFullScreenIntent(mock(PendingIntent.class), true)
                .build();

        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        final int stickyFlag = n.flags & Notification.FLAG_FSI_REQUESTED_BUT_DENIED;

@@ -10202,6 +10301,23 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                /* isSticky= */ true);
    }

    @Test
    public void fixNotification_withFgsFlag_butIsNotFgs() throws Exception {
        final ApplicationInfo applicationInfo = new ApplicationInfo();
        when(mPackageManagerClient.getApplicationInfoAsUser(anyString(), anyInt(), anyInt()))
                .thenReturn(applicationInfo);

        Notification n = new Notification.Builder(mContext, "test")
                .setFlag(FLAG_FOREGROUND_SERVICE, true)
                .setFlag(FLAG_CAN_COLORIZE, true)
                .build();

        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        assertFalse(n.isForegroundService());
        assertFalse(n.hasColorizedPermission());
    }

    @Test
    public void fixSystemNotification_withOnGoingFlag_shouldBeNonDismissible()
            throws Exception {
@@ -10219,7 +10335,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .thenReturn(systemAppInfo);

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be set
        assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10238,7 +10354,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be set
        assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10254,7 +10370,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should not be set
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10272,7 +10388,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        n.flags |= Notification.FLAG_NO_DISMISS;

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be cleared
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10294,7 +10410,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .thenReturn(systemAppInfo);

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should not be set
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10318,7 +10434,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .thenReturn(systemAppInfo);

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be cleared
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10336,7 +10452,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should not be set
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10357,7 +10473,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        n.flags |= Notification.FLAG_NO_DISMISS;

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be cleared
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10374,7 +10490,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should not be set
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10393,7 +10509,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be set
        assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10414,7 +10530,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should be set
        assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS);
@@ -10437,7 +10553,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .build();

        // When: fix the notification with NotificationManagerService
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid);
        mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE);

        // Then: the notification's flag FLAG_NO_DISMISS should not be set
        assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS);