diff options
| author | 2017-02-21 19:46:50 +0000 | |
|---|---|---|
| committer | 2017-02-21 19:46:55 +0000 | |
| commit | 1ddddee33f51551c9ddf0a94be8e7734b4643ff6 (patch) | |
| tree | afe14b80fe75ed7dc491246a0f3d3e20d4ca07bc | |
| parent | d4177b861004ac7d1d941e3a72e3f46bf4af33ff (diff) | |
| parent | 1139944efd9e970ed0bdf5b477cd80517c088451 (diff) | |
Merge "[DO NOT MERGE] The system can post notifications for any package" into nyc-mr2-dev
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationManagerService.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 4973e17f33bf..b1fd26583685 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2529,7 +2529,6 @@ public class NotificationManagerService extends SystemService { final int userId = ActivityManager.handleIncomingUser(callingPid, callingUid, incomingUserId, true, false, "enqueueNotification", pkg); final UserHandle user = new UserHandle(userId); - // Fix the notification as best we can. try { final ApplicationInfo ai = getContext().getPackageManager().getApplicationInfoAsUser( @@ -2543,13 +2542,16 @@ public class NotificationManagerService extends SystemService { mUsageStats.registerEnqueuedByApp(pkg); - if (pkg == null || notification == null) { throw new IllegalArgumentException("null not allowed: pkg=" + pkg + " id=" + id + " notification=" + notification); } + + // The system can post notifications for any package, let us resolve that. + final int notificationUid = resolveNotificationUid(opPkg, callingUid, userId); + final StatusBarNotification n = new StatusBarNotification( - pkg, opPkg, id, tag, callingUid, callingPid, 0, notification, + pkg, opPkg, id, tag, notificationUid, callingPid, 0, notification, user); // Limit the number of notifications that any given package except the android @@ -2619,6 +2621,19 @@ public class NotificationManagerService extends SystemService { idOut[0] = id; } + private int resolveNotificationUid(String opPackageName, int callingUid, int userId) { + // The system can post notifications on behalf of any package it wants + if (isCallerSystem() && opPackageName != null && !"android".equals(opPackageName)) { + try { + return getContext().getPackageManager() + .getPackageUidAsUser(opPackageName, userId); + } catch (NameNotFoundException e) { + /* ignore */ + } + } + return callingUid; + } + private class EnqueueNotificationRunnable implements Runnable { private final NotificationRecord r; private final int userId; |