Grant URI permissions to NotificationListenerServices when added.
Bug: 162233630
Test: android.app.cts.NotificationManagerTest
Change-Id: I54b8aa8cf99e0713ee903bee00f5b6361b276608
(cherry picked from commit 41fe38a9e5)
This commit is contained in:
@@ -9191,6 +9191,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
final NotificationRankingUpdate update;
|
final NotificationRankingUpdate update;
|
||||||
synchronized (mNotificationLock) {
|
synchronized (mNotificationLock) {
|
||||||
update = makeRankingUpdateLocked(info);
|
update = makeRankingUpdateLocked(info);
|
||||||
|
grantUriPermissionsForActiveNotificationsLocked(info);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
listener.onListenerConnected(update);
|
listener.onListenerConnected(update);
|
||||||
@@ -9293,13 +9294,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
// This notification became invisible -> remove the old one.
|
// This notification became invisible -> remove the old one.
|
||||||
if (oldSbnVisible && !sbnVisible) {
|
if (oldSbnVisible && !sbnVisible) {
|
||||||
final StatusBarNotification oldSbnLightClone = oldSbn.cloneLight();
|
final StatusBarNotification oldSbnLightClone = oldSbn.cloneLight();
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(() -> notifyRemoved(
|
||||||
@Override
|
info, oldSbnLightClone, update, null, REASON_USER_STOPPED));
|
||||||
public void run() {
|
|
||||||
notifyRemoved(
|
|
||||||
info, oldSbnLightClone, update, null, REASON_USER_STOPPED);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9309,18 +9305,39 @@ public class NotificationManagerService extends SystemService {
|
|||||||
updateUriPermissions(r, old, info.component.getPackageName(), targetUserId);
|
updateUriPermissions(r, old, info.component.getPackageName(), targetUserId);
|
||||||
|
|
||||||
final StatusBarNotification sbnToPost = trimCache.ForListener(info);
|
final StatusBarNotification sbnToPost = trimCache.ForListener(info);
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(() -> notifyPosted(info, sbnToPost, update));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
notifyPosted(info, sbnToPost, update);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.e(TAG, "Could not notify listeners for " + r.getKey(), e);
|
Slog.e(TAG, "Could not notify listeners for " + r.getKey(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* asynchronously notify all listeners about a removed notification
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user