Loading services/core/java/com/android/server/notification/NotificationManagerService.java +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); } Loading Loading @@ -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."); Loading services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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); } Loading Loading @@ -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."); Loading
services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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); Loading