Merge "DO NOT MERGE: Fix incorrect use of UserHandle#getUserHandleForUid(int uid)" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6b771b656a
@@ -1937,7 +1937,8 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
// Context#getPackageName() for getting package name that matches with the PID/UID,
|
// 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.
|
// but it doesn't tell which package has created the MediaController, so useless.
|
||||||
return hasMediaControlPermission(controllerPid, controllerUid)
|
return hasMediaControlPermission(controllerPid, controllerUid)
|
||||||
|| hasEnabledNotificationListener(userId, controllerPackageName);
|
|| hasEnabledNotificationListener(
|
||||||
|
userId, controllerPackageName, controllerUid);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
@@ -2001,29 +2002,29 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
return resolvedUserId;
|
return resolvedUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasEnabledNotificationListener(int resolvedUserId, String packageName)
|
private boolean hasEnabledNotificationListener(int callingUserId,
|
||||||
throws RemoteException {
|
String controllerPackageName, int controllerUid) throws RemoteException {
|
||||||
// You may not access another user's content as an enabled listener.
|
int controllerUserId = UserHandle.getUserHandleForUid(controllerUid).getIdentifier();
|
||||||
final int userId = UserHandle.getUserId(resolvedUserId);
|
if (callingUserId != controllerUserId) {
|
||||||
if (resolvedUserId != userId) {
|
// Enabled notification listener only works within the same user.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jaewan): (Post-P) Propose NotificationManager#hasEnabledNotificationListener(
|
// TODO(jaewan): (Post-P) Propose NotificationManager#hasEnabledNotificationListener(
|
||||||
// String pkgName) to notification team for optimization
|
// String pkgName) to notification team for optimization
|
||||||
final List<ComponentName> enabledNotificationListeners =
|
final List<ComponentName> enabledNotificationListeners =
|
||||||
mNotificationManager.getEnabledNotificationListeners(userId);
|
mNotificationManager.getEnabledNotificationListeners(controllerUserId);
|
||||||
if (enabledNotificationListeners != null) {
|
if (enabledNotificationListeners != null) {
|
||||||
for (int i = 0; i < enabledNotificationListeners.size(); i++) {
|
for (int i = 0; i < enabledNotificationListeners.size(); i++) {
|
||||||
if (TextUtils.equals(packageName,
|
if (TextUtils.equals(controllerPackageName,
|
||||||
enabledNotificationListeners.get(i).getPackageName())) {
|
enabledNotificationListeners.get(i).getPackageName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, packageName + " (uid=" + resolvedUserId + ") doesn't have an enabled "
|
Log.d(TAG, controllerPackageName + " (uid=" + controllerUid
|
||||||
+ "notification listener");
|
+ ") doesn't have an enabled notification listener");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user