MediaSessionManager: Apply API council review
Here's the comments from the review
- RemoteUserInfo needs to override .hashCode() as well
- Verify package name and the UID in the RemoteUserInfo
- Docs: Document how to get RemoteUserInfo
- Docs: Document that RemoteUserInfo is only valid on thread that the
command is being called from
* It's already documented in the
MediaSession#getCurrentControllerInfo() and
MediaBrowserService#getCurrentBrowserInfo().
Bug: 77507337
Test: Run following CtsMediaTestCases
- MediaBrowserTest
- MediaBrowserServiceTest
- MediaControllerTest
Change-Id: If37560a7bc59d1ef5517ec1f3e0a8b74c2bb2980
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 6413ba9..a3c6c80 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -1515,6 +1515,24 @@
final int uid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
try {
+ int controllerUserId = UserHandle.getUserId(controllerUid);
+ int controllerUidFromPackageName;
+ try {
+ controllerUidFromPackageName = getContext().getPackageManager()
+ .getPackageUidAsUser(controllerPackageName, controllerUserId);
+ } catch (NameNotFoundException e) {
+ if (DEBUG) {
+ Log.d(TAG, "Package " + controllerPackageName + " doesn't exist");
+ }
+ return false;
+ }
+ if (controllerUidFromPackageName != controllerUid) {
+ if (DEBUG) {
+ Log.d(TAG, "Package name " + controllerPackageName
+ + " doesn't match with the uid " + controllerUid);
+ }
+ return false;
+ }
return hasMediaControlPermission(UserHandle.getUserId(uid), controllerPackageName,
controllerPid, controllerUid);
} finally {