DO NOT MERGE Notifs sent from suspended apps should reappear

Notifications sent from suspended apps were being preemptively
blocked by isBlocked in NotificationMangerService. Instead, isBlocked
should only block notifications the user has specified to block. This
should not include suspended packages. (Notifications sent from
suspended apps are marked as hidden/suspended in the RankingMap in
PostNotificationRunnable so they can be resurfaced when the sending
app is unsuspended.)

Change-Id: I377eec04c9636e800bcd2709984c19610f2c524e
Bug: 113100262
Test: atest cts/tests/app/src/android/app/cts/NotificationManagerTest.java
Test: runtest -x cts/tests/tests/notificationlegacy/src/android/app/notification/legacy/cts/LegacyNotificationManagerTest.java
Test: runtest -x frameworks/base/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
This commit is contained in:
Beverly
2018-09-14 09:49:07 -04:00
parent 82b413428e
commit c7858557e1
2 changed files with 11 additions and 13 deletions

View File

@@ -4251,13 +4251,6 @@ public class NotificationManagerService extends SystemService {
final String pkg = r.sbn.getPackageName();
final int callingUid = r.sbn.getUid();
final boolean isPackageSuspended = isPackageSuspendedForUser(pkg, callingUid);
if (isPackageSuspended) {
Slog.e(TAG, "Suppressing notification from package due to package "
+ "suspended by administrator.");
usageStats.registerSuspendedByAdmin(r);
return isPackageSuspended;
}
final boolean isBlocked =
mRankingHelper.isGroupBlocked(pkg, callingUid, r.getChannel().getGroup())
|| mRankingHelper.getImportance(pkg, callingUid)
@@ -4266,8 +4259,9 @@ public class NotificationManagerService extends SystemService {
if (isBlocked) {
Slog.e(TAG, "Suppressing notification from package by user request.");
usageStats.registerBlocked(r);
return true;
}
return isBlocked;
return false;
}
protected class SnoozeNotificationRunnable implements Runnable {
@@ -4445,7 +4439,11 @@ public class NotificationManagerService extends SystemService {
return;
}
r.setHidden(isPackageSuspendedLocked(r));
final boolean isPackageSuspended = isPackageSuspendedLocked(r);
r.setHidden(isPackageSuspended);
if (isPackageSuspended) {
mUsageStats.registerSuspendedByAdmin(r);
}
NotificationRecord old = mNotificationsByKey.get(key);
final StatusBarNotification n = r.sbn;
final Notification notification = n.getNotification();
@@ -6611,7 +6609,6 @@ public class NotificationManagerService extends SystemService {
if (!oldSbnVisible && !sbnVisible) {
continue;
}
// If the notification is hidden, don't notifyPosted listeners targeting < P.
// Instead, those listeners will receive notifyPosted when the notification is
// unhidden.
@@ -7045,7 +7042,7 @@ public class NotificationManagerService extends SystemService {
new String[]{pkg});
final String action = suspend ? Intent.ACTION_PACKAGES_SUSPENDED
: Intent.ACTION_PACKAGES_UNSUSPENDED;
: Intent.ACTION_PACKAGES_UNSUSPENDED;
final Intent intent = new Intent(action);
intent.putExtras(extras);

View File

@@ -500,8 +500,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
NotificationChannel channel = new NotificationChannel("id", "name",
IMPORTANCE_HIGH);
NotificationRecord r = generateNotificationRecord(channel);
assertTrue(mService.isBlocked(r, mUsageStats));
verify(mUsageStats, times(1)).registerSuspendedByAdmin(eq(r));
// isBlocked is only used for user blocking, not app suspension
assertFalse(mService.isBlocked(r, mUsageStats));
}
@Test