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

Commit 173a482b authored by Julia Reynolds's avatar Julia Reynolds
Browse files

DO NOT MERGE Fix behavior of getNotificationChannelGroups

Which needs to return groups without channels when
called via NotificationManager.

Test: runtest systemui-notification
Change-Id: I2042e21f5cf0339e4cd828e6de8244df12ef3d88
Fixes: 115709729
parent aba1abc6
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -2299,8 +2299,9 @@ public class NotificationManagerService extends SystemService {
        public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(
                String pkg) {
            checkCallerIsSystemOrSameApp(pkg);

            return mRankingHelper.getNotificationChannelGroups(
                    pkg, Binder.getCallingUid(), false, false);
                    pkg, Binder.getCallingUid(), false, false, true);
        }

        @Override
@@ -2376,7 +2377,9 @@ public class NotificationManagerService extends SystemService {
        public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage(
                String pkg, int uid, boolean includeDeleted) {
            checkCallerIsSystem();
            return mRankingHelper.getNotificationChannelGroups(pkg, uid, includeDeleted, true);

            return mRankingHelper.getNotificationChannelGroups(
                    pkg, uid, includeDeleted, true, false);
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public interface RankingConfig {
    void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
            boolean fromTargetApp);
    ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
            int uid, boolean includeDeleted, boolean includeNonGrouped);
            int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty);
    void createNotificationChannel(String pkg, int uid, NotificationChannel channel,
            boolean fromTargetApp, boolean hasDndAccess);
    void updateNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromUser);
+8 −1
Original line number Diff line number Diff line
@@ -830,7 +830,7 @@ public class RankingHelper implements RankingConfig {

    @Override
    public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
            int uid, boolean includeDeleted, boolean includeNonGrouped) {
            int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) {
        Preconditions.checkNotNull(pkg);
        Map<String, NotificationChannelGroup> groups = new ArrayMap<>();
        Record r = getRecord(pkg, uid);
@@ -861,6 +861,13 @@ public class RankingHelper implements RankingConfig {
        if (includeNonGrouped && nonGrouped.getChannels().size() > 0) {
            groups.put(null, nonGrouped);
        }
        if (includeEmpty) {
            for (NotificationChannelGroup group : r.groups.values()) {
                if (!groups.containsKey(group.getId())) {
                    groups.put(group.getId(), group);
                }
            }
        }
        return new ParceledListSlice<>(new ArrayList<>(groups.values()));
    }

+31 −6
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ public class RankingHelperTest extends UiServiceTestCase {
                mHelper.getNotificationChannel(PKG, UID, channel2.getId(), false));

        List<NotificationChannelGroup> actualGroups =
                mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList();
                mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList();
        boolean foundNcg = false;
        for (NotificationChannelGroup actual : actualGroups) {
            if (ncg.getId().equals(actual.getId())) {
@@ -469,7 +469,7 @@ public class RankingHelperTest extends UiServiceTestCase {
                mHelper.getNotificationChannel(PKG, UID, channel3.getId(), false));

        List<NotificationChannelGroup> actualGroups =
                mHelper.getNotificationChannelGroups(PKG, UID, false, true).getList();
                mHelper.getNotificationChannelGroups(PKG, UID, false, true, false).getList();
        boolean foundNcg = false;
        for (NotificationChannelGroup actual : actualGroups) {
            if (ncg.getId().equals(actual.getId())) {
@@ -784,6 +784,31 @@ public class RankingHelperTest extends UiServiceTestCase {
                new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false);
    }

    @Test
    public void testGetChannelGroups_includeEmptyGroups() {
        NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1");
        mHelper.createNotificationChannelGroup(PKG, UID, ncg, true);
        NotificationChannelGroup ncgEmpty = new NotificationChannelGroup("group2", "name2");
        mHelper.createNotificationChannelGroup(PKG, UID, ncgEmpty, true);

        NotificationChannel channel1 =
                new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH);
        channel1.setGroup(ncg.getId());
        mHelper.createNotificationChannel(PKG, UID, channel1, true, false);

        List<NotificationChannelGroup> actual = mHelper.getNotificationChannelGroups(
                PKG, UID, false, false, true).getList();

        assertEquals(2, actual.size());
        for (NotificationChannelGroup group : actual) {
            if (Objects.equals(group.getId(), ncg.getId())) {
                assertEquals(1, group.getChannels().size());
            }
            if (Objects.equals(group.getId(), ncgEmpty.getId())) {
                assertEquals(0, group.getChannels().size());
            }
        }
    }

    @Test
    public void testUpdate() throws Exception {
@@ -1421,7 +1446,7 @@ public class RankingHelperTest extends UiServiceTestCase {
        mHelper.onPackagesChanged(true, UserHandle.USER_SYSTEM, new String[]{PKG}, new int[]{UID});

        assertEquals(0,
                mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList().size());
                mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList().size());
    }

    @Test
@@ -1510,7 +1535,7 @@ public class RankingHelperTest extends UiServiceTestCase {
        mHelper.createNotificationChannel(PKG, UID, channel3, true, false);

        List<NotificationChannelGroup> actual =
                mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList();
                mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList();
        assertEquals(3, actual.size());
        for (NotificationChannelGroup group : actual) {
            if (group.getId() == null) {
@@ -1542,13 +1567,13 @@ public class RankingHelperTest extends UiServiceTestCase {
                new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH);
        channel1.setGroup(ncg.getId());
        mHelper.createNotificationChannel(PKG, UID, channel1, true, false);
        mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList();
        mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList();

        channel1.setImportance(IMPORTANCE_LOW);
        mHelper.updateNotificationChannel(PKG, UID, channel1, true);

        List<NotificationChannelGroup> actual =
                mHelper.getNotificationChannelGroups(PKG, UID, true, true).getList();
                mHelper.getNotificationChannelGroups(PKG, UID, true, true, false).getList();

        assertEquals(2, actual.size());
        for (NotificationChannelGroup group : actual) {