diff options
| author | 2017-06-05 17:38:32 +0000 | |
|---|---|---|
| committer | 2017-06-05 17:38:38 +0000 | |
| commit | f7bf933dc62595ad20f3d6ca541753e929d0e74e (patch) | |
| tree | 9a4553959f9637d27d268084f298122a96aad633 | |
| parent | 74ad8f03be089c8cde532fb58fae231f02fb457b (diff) | |
| parent | de9c540fe53a7d71fb3309005416a028a4120b41 (diff) | |
Merge "Merge "Don't allow blocked apps to post notifications" into oc-dev am: 2f77da6e10 am: c9df14bad9"
2 files changed, 14 insertions, 12 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 41682eb55204..197baa538cf6 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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); } @@ -3195,7 +3194,7 @@ public class NotificationManagerService extends SystemService { user, null, System.currentTimeMillis()); final NotificationRecord r = new NotificationRecord(getContext(), n, channel); - if (!checkDisqualifyingFeatures(userId, notificationUid, id,tag, r)) { + if (!checkDisqualifyingFeatures(userId, notificationUid, id, tag, r)) { return; } @@ -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."); diff --git a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java index dfc69eadc52c..0a4cb1080b04 100644 --- a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -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; @@ -68,7 +69,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; @@ -287,15 +287,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 @@ -646,6 +647,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); |