@@ -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