summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-09-02 16:50:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-09-02 16:50:19 +0000
commit6b771b656a7c73caeb60586d148aae658fbdcc9c (patch)
treed2f7fda54b48e01b2689c73fbd1c39c5c4a01dca
parent677078e8727380fcc48890ebe046a5f2cccc8eff (diff)
parent170c118b8105c9bb55d801e2eb4e6c12a89ac80c (diff)
Merge "DO NOT MERGE: Fix incorrect use of UserHandle#getUserHandleForUid(int uid)" into rvc-qpr-dev
-rw-r--r--services/core/java/com/android/server/media/MediaSessionService.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 9b356f0e8eef..803eb862e0f1 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -1937,7 +1937,8 @@ public class MediaSessionService extends SystemService implements Monitor {
// Context#getPackageName() for getting package name that matches with the PID/UID,
// but it doesn't tell which package has created the MediaController, so useless.
return hasMediaControlPermission(controllerPid, controllerUid)
- || hasEnabledNotificationListener(userId, controllerPackageName);
+ || hasEnabledNotificationListener(
+ userId, controllerPackageName, controllerUid);
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -2001,29 +2002,29 @@ public class MediaSessionService extends SystemService implements Monitor {
return resolvedUserId;
}
- private boolean hasEnabledNotificationListener(int resolvedUserId, String packageName)
- throws RemoteException {
- // You may not access another user's content as an enabled listener.
- final int userId = UserHandle.getUserId(resolvedUserId);
- if (resolvedUserId != userId) {
+ private boolean hasEnabledNotificationListener(int callingUserId,
+ String controllerPackageName, int controllerUid) throws RemoteException {
+ int controllerUserId = UserHandle.getUserHandleForUid(controllerUid).getIdentifier();
+ if (callingUserId != controllerUserId) {
+ // Enabled notification listener only works within the same user.
return false;
}
// TODO(jaewan): (Post-P) Propose NotificationManager#hasEnabledNotificationListener(
// String pkgName) to notification team for optimization
final List<ComponentName> enabledNotificationListeners =
- mNotificationManager.getEnabledNotificationListeners(userId);
+ mNotificationManager.getEnabledNotificationListeners(controllerUserId);
if (enabledNotificationListeners != null) {
for (int i = 0; i < enabledNotificationListeners.size(); i++) {
- if (TextUtils.equals(packageName,
+ if (TextUtils.equals(controllerPackageName,
enabledNotificationListeners.get(i).getPackageName())) {
return true;
}
}
}
if (DEBUG) {
- Log.d(TAG, packageName + " (uid=" + resolvedUserId + ") doesn't have an enabled "
- + "notification listener");
+ Log.d(TAG, controllerPackageName + " (uid=" + controllerUid
+ + ") doesn't have an enabled notification listener");
}
return false;
}