Skip to content

Commit 321e9c5

Browse files
committed
Allow any user to clear a notification targeted at USER_ALL.
This also adds the userid to notification_* eventlogs. Bug: 7325802 Change-Id: I48055caf1344acd58b61607bf0be38cc299fc7be
1 parent 308b1a6 commit 321e9c5

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

services/java/com/android/server/EventLogTags.logtags

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ option java_package com.android.server
5252
# NotificationManagerService.java
5353
# ---------------------------
5454
# when a NotificationManager.notify is called
55-
2750 notification_enqueue (pkg|3),(id|1|5),(tag|3),(notification|3)
55+
2750 notification_enqueue (pkg|3),(id|1|5),(tag|3),(userid|1|5),(notification|3)
5656
# when someone tries to cancel a notification, the notification manager sometimes
5757
# calls this with flags too
58-
2751 notification_cancel (pkg|3),(id|1|5),(tag|3),(required_flags|1),(forbidden_flags|1)
58+
2751 notification_cancel (pkg|3),(id|1|5),(tag|3),(userid|1|5),(required_flags|1),(forbidden_flags|1)
5959
# when someone tries to cancel all of the notifications for a particular package
60-
2752 notification_cancel_all (pkg|3),(required_flags|1),(forbidden_flags|1)
60+
2752 notification_cancel_all (pkg|3),(userid|1|5),(required_flags|1),(forbidden_flags|1)
6161

6262

6363
# ---------------------------

services/java/com/android/server/NotificationManagerService.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ public void enqueueNotificationInternal(String pkg, int callingUid, int callingP
916916
// behalf of the download manager without affecting other apps.
917917
if (!pkg.equals("com.android.providers.downloads")
918918
|| Log.isLoggable("DownloadManager", Log.VERBOSE)) {
919-
EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag,
919+
EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
920920
notification.toString());
921921
}
922922

@@ -1207,7 +1207,7 @@ private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete)
12071207
*/
12081208
private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
12091209
int mustNotHaveFlags, boolean sendDelete, int userId) {
1210-
EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag,
1210+
EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
12111211
mustHaveFlags, mustNotHaveFlags);
12121212

12131213
synchronized (mNotificationList) {
@@ -1230,21 +1230,35 @@ private void cancelNotification(String pkg, String tag, int id, int mustHaveFlag
12301230
}
12311231
}
12321232

1233+
/**
1234+
* Determine whether the userId applies to the notification in question, either because
1235+
* they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
1236+
*/
1237+
private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
1238+
return
1239+
// looking for USER_ALL notifications? match everything
1240+
userId == UserHandle.USER_ALL
1241+
// a notification sent to USER_ALL matches any query
1242+
|| r.userId == UserHandle.USER_ALL
1243+
// an exact user match
1244+
|| r.userId == userId;
1245+
}
1246+
12331247
/**
12341248
* Cancels all notifications from a given package that have all of the
12351249
* {@code mustHaveFlags}.
12361250
*/
12371251
boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
12381252
int mustNotHaveFlags, boolean doit, int userId) {
1239-
EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, mustHaveFlags,
1240-
mustNotHaveFlags);
1253+
EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
1254+
mustHaveFlags, mustNotHaveFlags);
12411255

12421256
synchronized (mNotificationList) {
12431257
final int N = mNotificationList.size();
12441258
boolean canceledSomething = false;
12451259
for (int i = N-1; i >= 0; --i) {
12461260
NotificationRecord r = mNotificationList.get(i);
1247-
if (userId != UserHandle.USER_ALL && r.userId != userId) {
1261+
if (!notificationMatchesUserId(r, userId)) {
12481262
continue;
12491263
}
12501264
if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) {
@@ -1322,7 +1336,7 @@ void cancelAll(int userId) {
13221336
for (int i=N-1; i>=0; i--) {
13231337
NotificationRecord r = mNotificationList.get(i);
13241338

1325-
if (r.userId != userId) {
1339+
if (!notificationMatchesUserId(r, userId)) {
13261340
continue;
13271341
}
13281342

@@ -1376,7 +1390,7 @@ private int indexOfNotificationLocked(String pkg, String tag, int id, int userId
13761390
final int len = list.size();
13771391
for (int i=0; i<len; i++) {
13781392
NotificationRecord r = list.get(i);
1379-
if (r.userId != userId || r.id != id) {
1393+
if (!notificationMatchesUserId(r, userId) || r.id != id) {
13801394
continue;
13811395
}
13821396
if (tag == null) {

0 commit comments

Comments
 (0)