diff options
| author | 2020-08-24 16:03:35 +0000 | |
|---|---|---|
| committer | 2020-08-24 16:03:35 +0000 | |
| commit | 3f151d9d76fbbbc3c4a6e3abcf8f153121cdf090 (patch) | |
| tree | f60ac24ec54fd3429d7287b493d1710fe342facf | |
| parent | 788b3c7f76f962ce159a02d409ee998ad0e92563 (diff) | |
| parent | cd1aec744c5e09313dc412e3fdc4a92fe9e55bbe (diff) | |
Grant URI permissions to NotificationListenerServices when added. am: cd1aec744c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12434562
Change-Id: I5a77003ea0e9362a0581148bc4e57874ec88f82e
| -rwxr-xr-x | services/core/java/com/android/server/notification/NotificationManagerService.java | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index acd863ca8246..ee1a4b28141a 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -9195,6 +9195,7 @@ public class NotificationManagerService extends SystemService { final NotificationRankingUpdate update; synchronized (mNotificationLock) { update = makeRankingUpdateLocked(info); + grantUriPermissionsForActiveNotificationsLocked(info); } try { listener.onListenerConnected(update); @@ -9297,13 +9298,8 @@ public class NotificationManagerService extends SystemService { // This notification became invisible -> remove the old one. if (oldSbnVisible && !sbnVisible) { final StatusBarNotification oldSbnLightClone = oldSbn.cloneLight(); - mHandler.post(new Runnable() { - @Override - public void run() { - notifyRemoved( - info, oldSbnLightClone, update, null, REASON_USER_STOPPED); - } - }); + mHandler.post(() -> notifyRemoved( + info, oldSbnLightClone, update, null, REASON_USER_STOPPED)); continue; } @@ -9313,12 +9309,7 @@ public class NotificationManagerService extends SystemService { updateUriPermissions(r, old, info.component.getPackageName(), targetUserId); final StatusBarNotification sbnToPost = trimCache.ForListener(info); - mHandler.post(new Runnable() { - @Override - public void run() { - notifyPosted(info, sbnToPost, update); - } - }); + mHandler.post(() -> notifyPosted(info, sbnToPost, update)); } } catch (Exception e) { Slog.e(TAG, "Could not notify listeners for " + r.getKey(), e); @@ -9326,6 +9317,32 @@ public class NotificationManagerService extends SystemService { } /** + * Synchronously grant permissions to Uris for all active and visible notifications to the + * NotificationListenerService provided. + */ + @GuardedBy("mNotificationLock") + private void grantUriPermissionsForActiveNotificationsLocked(ManagedServiceInfo info) { + try { + for (final NotificationRecord r : mNotificationList) { + // This notification isn't visible -> ignore. + if (!isVisibleToListener(r.getSbn(), info)) { + continue; + } + // If the notification is hidden, permissions are not required by the listener. + if (r.isHidden() && info.targetSdkVersion < Build.VERSION_CODES.P) { + continue; + } + // Grant access before listener is initialized + final int targetUserId = (info.userid == UserHandle.USER_ALL) + ? UserHandle.USER_SYSTEM : info.userid; + updateUriPermissions(r, null, info.component.getPackageName(), targetUserId); + } + } catch (Exception e) { + Slog.e(TAG, "Could not grant Uri permissions to " + info.component, e); + } + } + + /** * asynchronously notify all listeners about a removed notification */ @GuardedBy("mNotificationLock") |