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

Commit 2f637041 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow apps to minimize/block* pre-O apps that use FGSes

*blocking will only work on API 23+ apps, when runtime permissions were added

Test: NotificationManagerServiceTest
Fixes: 242544362
Change-Id: I7a0ec0224254ab43a350e2f8c6a30bd4352dd6b6
parent 9fd5ca2a
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -6625,10 +6625,6 @@ public class NotificationManagerService extends SystemService {
                            || r.getImportance() == IMPORTANCE_NONE)) {
                // Increase the importance of foreground service notifications unless the user had
                // an opinion otherwise (and the channel hasn't yet shown a fg service).
                if (TextUtils.isEmpty(channelId)
                        || NotificationChannel.DEFAULT_CHANNEL_ID.equals(channelId)) {
                    r.setSystemImportance(IMPORTANCE_LOW);
                } else {
                channel.setImportance(IMPORTANCE_LOW);
                r.setSystemImportance(IMPORTANCE_LOW);
                if (!fgServiceShown) {
@@ -6638,7 +6634,6 @@ public class NotificationManagerService extends SystemService {
                mPreferencesHelper.updateNotificationChannel(
                        pkg, notificationUid, channel, false);
                r.updateNotificationChannel(channel);
                }
            } else if (!fgServiceShown && !TextUtils.isEmpty(channelId)
                    && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(channelId)) {
                channel.setFgServiceShown(true);
+5 −5
Original line number Diff line number Diff line
@@ -4736,7 +4736,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }

    @Test
    public void testBumpFGImportance_noChannelChangePreOApp() throws Exception {
    public void testBumpFGImportance_channelChangePreOApp() throws Exception {
        String preOPkg = PKG_N_MR1;
        final ApplicationInfo legacy = new ApplicationInfo();
        legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1;
@@ -4754,7 +4754,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setPriority(Notification.PRIORITY_MIN);

        StatusBarNotification sbn = new StatusBarNotification(preOPkg, preOPkg, 9,
                "testBumpFGImportance_noChannelChangePreOApp",
                "testBumpFGImportance_channelChangePreOApp",
                Binder.getCallingUid(), 0, nb.build(),
                UserHandle.getUserHandleForUid(Binder.getCallingUid()), null, 0);

@@ -4774,11 +4774,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setPriority(Notification.PRIORITY_MIN);

        sbn = new StatusBarNotification(preOPkg, preOPkg, 9,
                "testBumpFGImportance_noChannelChangePreOApp", Binder.getCallingUid(),
                "testBumpFGImportance_channelChangePreOApp", Binder.getCallingUid(),
                0, nb.build(), UserHandle.getUserHandleForUid(Binder.getCallingUid()), null, 0);

        mBinderService.enqueueNotificationWithTag(preOPkg, preOPkg,
                "testBumpFGImportance_noChannelChangePreOApp",
                "testBumpFGImportance_channelChangePreOApp",
                sbn.getId(), sbn.getNotification(), sbn.getUserId());
        waitForIdle();
        assertEquals(IMPORTANCE_LOW,
@@ -4786,7 +4786,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        NotificationChannel defaultChannel = mBinderService.getNotificationChannel(
                preOPkg, mContext.getUserId(), preOPkg, NotificationChannel.DEFAULT_CHANNEL_ID);
        assertEquals(IMPORTANCE_UNSPECIFIED, defaultChannel.getImportance());
        assertEquals(IMPORTANCE_LOW, defaultChannel.getImportance());
    }

    @Test