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

Commit c9df14ba authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Don't allow blocked apps to post notifications" into oc-dev

am: 2f77da6e

Change-Id: I17808b200cba543f163bea8e3326bcce4792ef1f
parents 1282acdc 2f77da6e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -231,7 +231,6 @@ public class NotificationManagerService extends SystemService {

    static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;

    static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
    static final boolean ENABLE_BLOCKED_TOASTS = true;

    // When #matchesCallFilter is called from the ringer, wait at most
@@ -1580,7 +1579,7 @@ public class NotificationManagerService extends SystemService {

            mRankingHelper.setEnabled(pkg, uid, enabled);
            // Now, cancel any outstanding notifications that are part of a just-disabled app
            if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
            if (!enabled) {
                cancelAllNotificationsInt(MY_UID, MY_PID, pkg, null, 0, 0, true,
                        UserHandle.getUserId(uid), REASON_PACKAGE_BANNED, null);
            }
@@ -3338,7 +3337,8 @@ public class NotificationManagerService extends SystemService {
            return isPackageSuspended;
        }

        final boolean isBlocked = r.getImportance() == NotificationManager.IMPORTANCE_NONE
        final boolean isBlocked =
                mRankingHelper.getImportance(pkg, callingUid) == NotificationManager.IMPORTANCE_NONE
                || r.getChannel().getImportance() == NotificationManager.IMPORTANCE_NONE;
        if (isBlocked) {
            Slog.e(TAG, "Suppressing notification from package by user request.");
+10 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.notification;

import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
@@ -67,7 +68,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import com.android.server.lights.Light;
@@ -285,15 +285,16 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
    }

    @Test
    public void testBlockedNotifications_blockedApp() throws Exception {
    public void testEnqueuedBlockedNotifications_blockedApp() throws Exception {
        when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);

        NotificationChannel channel = new NotificationChannel("id", "name",
                NotificationManager.IMPORTANCE_HIGH);
        NotificationRecord r = generateNotificationRecord(channel);
        r.setUserImportance(NotificationManager.IMPORTANCE_NONE);
        assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
        verify(mUsageStats, times(1)).registerBlocked(eq(r));
        mBinderService.setNotificationsEnabledForPackage(PKG, uid, false);

        final StatusBarNotification sbn = generateNotificationRecord(null).sbn;
        mBinderService.enqueueNotificationWithTag(PKG, "opPkg", "tag",
                sbn.getId(), sbn.getNotification(), sbn.getUserId());
        waitForIdle();
        assertEquals(0, mBinderService.getActiveNotifications(sbn.getPackageName()).length);
    }

    @Test
@@ -644,6 +645,7 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
        associations.add("a");
        when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
        mListener = mock(ManagedServices.ManagedServiceInfo.class);
        mListener.component = new ComponentName(PKG, PKG);
        when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
        when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);