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

Commit 7065aedb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add method to get blocked channel counts" into pi-dev

parents f01e2024 f2e499d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ interface INotificationManager
    ParceledListSlice getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted);
    int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted);
    int getDeletedChannelCount(String pkg, int uid);
    int getBlockedChannelCount(String pkg, int uid);
    void deleteNotificationChannelGroup(String pkg, String channelGroupId);
    NotificationChannelGroup getNotificationChannelGroup(String pkg, String channelGroupId);
    ParceledListSlice getNotificationChannelGroups(String pkg);
+6 −0
Original line number Diff line number Diff line
@@ -2285,6 +2285,12 @@ public class NotificationManagerService extends SystemService {
            return mRankingHelper.getDeletedChannelCount(pkg, uid);
        }

        @Override
        public int getBlockedChannelCount(String pkg, int uid) {
            enforceSystemOrSystemUI("getBlockedChannelCount");
            return mRankingHelper.getBlockedChannelCount(pkg, uid);
        }

        @Override
        public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage(
                String pkg, int uid, boolean includeDeleted) {
+23 −4
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.notification;

import static android.app.NotificationManager.IMPORTANCE_NONE;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
@@ -619,7 +621,7 @@ public class RankingHelper implements RankingConfig {
            updateConfig();
            return;
        }
        if (channel.getImportance() < NotificationManager.IMPORTANCE_NONE
        if (channel.getImportance() < IMPORTANCE_NONE
                || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) {
            throw new IllegalArgumentException("Invalid importance level");
        }
@@ -959,6 +961,23 @@ public class RankingHelper implements RankingConfig {
        return deletedCount;
    }

    public int getBlockedChannelCount(String pkg, int uid) {
        Preconditions.checkNotNull(pkg);
        int blockedCount = 0;
        Record r = getRecord(pkg, uid);
        if (r == null) {
            return blockedCount;
        }
        int N = r.channels.size();
        for (int i = 0; i < N; i++) {
            final NotificationChannel nc = r.channels.valueAt(i);
            if (!nc.isDeleted() && IMPORTANCE_NONE == nc.getImportance()) {
                blockedCount++;
            }
        }
        return blockedCount;
    }

    /**
     * Sets importance.
     */
@@ -969,12 +988,12 @@ public class RankingHelper implements RankingConfig {
    }

    public void setEnabled(String packageName, int uid, boolean enabled) {
        boolean wasEnabled = getImportance(packageName, uid) != NotificationManager.IMPORTANCE_NONE;
        boolean wasEnabled = getImportance(packageName, uid) != IMPORTANCE_NONE;
        if (wasEnabled == enabled) {
            return;
        }
        setImportance(packageName, uid,
                enabled ? DEFAULT_IMPORTANCE : NotificationManager.IMPORTANCE_NONE);
                enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE);
    }

    @VisibleForTesting
@@ -1199,7 +1218,7 @@ public class RankingHelper implements RankingConfig {
            ArrayMap<Integer, String> packageBans = new ArrayMap<>(N);
            for (int i = 0; i < N; i++) {
                final Record r = mRecords.valueAt(i);
                if (r.importance == NotificationManager.IMPORTANCE_NONE) {
                if (r.importance == IMPORTANCE_NONE) {
                    packageBans.put(r.uid, r.pkg);
                }
            }
+19 −1
Original line number Diff line number Diff line
@@ -1093,7 +1093,7 @@ public class RankingHelperTest extends UiServiceTestCase {
        NotificationChannel channel2 =
                new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH);
        NotificationChannel channel3 =
                new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH);
                new NotificationChannel("id5", "a", NotificationManager.IMPORTANCE_HIGH);
        mHelper.createNotificationChannel(PKG, UID, channel, true, false);
        mHelper.createNotificationChannel(PKG, UID, channel2, true, false);
        mHelper.createNotificationChannel(PKG, UID, channel3, true, false);
@@ -1105,6 +1105,24 @@ public class RankingHelperTest extends UiServiceTestCase {
        assertEquals(0, mHelper.getDeletedChannelCount("pkg2", UID2));
    }

    @Test
    public void testGetBlockedChannelCount() throws Exception {
        NotificationChannel channel =
                new NotificationChannel("id2", "name2", IMPORTANCE_LOW);
        NotificationChannel channel2 =
                new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_NONE);
        NotificationChannel channel3 =
                new NotificationChannel("id5", "a", NotificationManager.IMPORTANCE_NONE);
        mHelper.createNotificationChannel(PKG, UID, channel, true, false);
        mHelper.createNotificationChannel(PKG, UID, channel2, true, false);
        mHelper.createNotificationChannel(PKG, UID, channel3, true, false);

        mHelper.deleteNotificationChannel(PKG, UID, channel3.getId());

        assertEquals(1, mHelper.getBlockedChannelCount(PKG, UID));
        assertEquals(0, mHelper.getBlockedChannelCount("pkg2", UID2));
    }

    @Test
    public void testCreateDeletedChannel() throws Exception {
        long[] vibration = new long[]{100, 67, 145, 156};