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

Commit f0b5393e authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge "Clear package from disallowed NLS filter only on remove" into main

parents c64add5f bdc4b7c8
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -11449,21 +11449,20 @@ public class NotificationManagerService extends SystemService {
                            }
                        }
                    }
                }
                // clean up anything in the disallowed pkgs list
                    // Clean up removed package from the disallowed packages list
                    for (int i = 0; i < pkgList.length; i++) {
                        String pkg = pkgList[i];
                        for (int j = mRequestedNotificationListeners.size() - 1; j >= 0; j--) {
                            NotificationListenerFilter nlf =
                                    mRequestedNotificationListeners.valueAt(j);
                            VersionedPackage ai = new VersionedPackage(pkg, uidList[i]);
                            nlf.removePackage(ai);
                        }
                    }
                }
            }
        }
        @Override
        protected String getRequiredPermission() {
+20 −1
Original line number Diff line number Diff line
@@ -426,7 +426,7 @@ public class NotificationListenersTest extends UiServiceTestCase {
    }

    @Test
    public void testOnPackageChanged_removingDisallowedPackage() {
    public void testOnPackageChanged_removingPackage_removeFromDisallowed() {
        NotificationListenerFilter nlf = new NotificationListenerFilter(7, new ArraySet<>());
        VersionedPackage a1 = new VersionedPackage("pkg1", 243);
        NotificationListenerFilter nlf2 =
@@ -440,6 +440,25 @@ public class NotificationListenersTest extends UiServiceTestCase {

        assertThat(mListeners.getNotificationListenerFilter(Pair.create(mCn1, 0))
                .getDisallowedPackages()).isEmpty();
        assertThat(mListeners.getNotificationListenerFilter(Pair.create(mCn2, 0))
                .getDisallowedPackages()).isEmpty();
    }

    @Test
    public void testOnPackageChanged_notRemovingPackage_staysInDisallowed() {
        NotificationListenerFilter nlf = new NotificationListenerFilter(7, new ArraySet<>());
        VersionedPackage a1 = new VersionedPackage("pkg1", 243);
        NotificationListenerFilter nlf2 =
                new NotificationListenerFilter(4, new ArraySet<>(new VersionedPackage[] {a1}));
        mListeners.setNotificationListenerFilter(Pair.create(mCn1, 0), nlf);
        mListeners.setNotificationListenerFilter(Pair.create(mCn2, 0), nlf2);

        String[] pkgs = new String[] {"pkg1"};
        int[] uids = new int[] {243};
        mListeners.onPackagesChanged(false, pkgs, uids);

        assertThat(mListeners.getNotificationListenerFilter(Pair.create(mCn2, 0))
                .getDisallowedPackages()).contains(a1);
    }

    @Test