Merge "Don't allow blocked apps to post notifications" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f77da6e10
@@ -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.");
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user