diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java index 6af39f8c55d28..fd77b4e5881d0 100644 --- a/media/java/android/media/session/MediaSessionManager.java +++ b/media/java/android/media/session/MediaSessionManager.java @@ -180,7 +180,7 @@ public final class MediaSessionManager { * be provided in priority order with the most important controller at index * 0. *
- * This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL + * This requires the {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} * permission be held by the calling app. You may also retrieve this list if * your app is an enabled notification listener using the * {@link NotificationListenerService} APIs, in which case you must pass the @@ -196,14 +196,18 @@ public final class MediaSessionManager { } /** - * Get active sessions for a specific user. To retrieve actions for a user - * other than your own you must hold the - * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission - * in addition to any other requirements. If you are an enabled notification - * listener you may only get sessions for the users you are enabled for. + * Get active sessions for the given user. + *
+ * This requires the {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be + * held by the calling app. You may also retrieve this list if your app is an enabled + * notification listener using the {@link NotificationListenerService} APIs, in which case you + * must pass the {@link ComponentName} of your enabled listener. + *
+ * The calling application needs to hold the + * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission in order to + * retrieve sessions for user ids that do not belong to current process. * - * @param notificationListener The enabled notification listener component. - * May be null. + * @param notificationListener The enabled notification listener component. May be null. * @param userId The user id to fetch sessions for. * @return A list of controllers for ongoing sessions. * @hide @@ -248,8 +252,9 @@ public final class MediaSessionManager { * Gets a list of {@link Session2Token} with type {@link Session2Token#TYPE_SESSION} for the * given user. *
- * If you want to get tokens for another user, you must hold the - * android.Manifest.permission#INTERACT_ACROSS_USERS_FULL permission. + * The calling application needs to hold the + * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission in order to + * retrieve session tokens for user ids that do not belong to current process. * * @param userId The user id to fetch sessions for. * @return A list of {@link Session2Token} @@ -267,11 +272,12 @@ public final class MediaSessionManager { } /** - * Add a listener to be notified when the list of active sessions changes. This requires the - * {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be held by the calling - * app. You may also retrieve this list if your app is an enabled notification listener using - * the {@link NotificationListenerService} APIs, in which case you must pass the - * {@link ComponentName} of your enabled listener. + * Add a listener to be notified when the list of active sessions changes. + *
+ * This requires the {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be + * held by the calling app. You may also retrieve this list if your app is an enabled + * notificationlistener using the {@link NotificationListenerService} APIs, in which case you + * must pass the {@link ComponentName} of your enabled listener. * * @param sessionListener The listener to add. * @param notificationListener The enabled notification listener component. May be null. @@ -283,12 +289,13 @@ public final class MediaSessionManager { } /** - * Add a listener to be notified when the list of active sessions changes. This requires the - * {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be held by the calling - * app. You may also retrieve this list if your app is an enabled notification listener using - * the {@link NotificationListenerService} APIs, in which case you must pass the - * {@link ComponentName} of your enabled listener. Updates will be posted to the handler - * specified or to the caller's thread if the handler is null. + * Add a listener to be notified when the list of active sessions changes. + *
+ * This requires the {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be + * held by the calling app. You may also retrieve this list if your app is an enabled + * notification listener using the {@link NotificationListenerService} APIs, in which case you + * must pass the {@link ComponentName} of your enabled listener. Updates will be posted to the + * handler specified or to the caller's thread if the handler is null. * * @param sessionListener The listener to add. * @param notificationListener The enabled notification listener component. May be null. @@ -302,15 +309,17 @@ public final class MediaSessionManager { } /** - * Add a listener to be notified when the list of active sessions changes for the given user. - * The calling app must have the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} - * permission if it wants to call this method for a user that is not running the app. + * Add a listener to be notified when the list of active sessions changes. *
* This requires the {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission be * held by the calling app. You may also retrieve this list if your app is an enabled * notification listener using the {@link NotificationListenerService} APIs, in which case you * must pass the {@link ComponentName} of your enabled listener. Updates will be posted to the * handler specified or to the caller's thread if the handler is null. + *
+ * The calling application needs to hold the + * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission in order to + * add listeners for user ids that do not belong to current process. * * @param sessionListener The listener to add. * @param notificationListener The enabled notification listener component. May be null. @@ -407,6 +416,10 @@ public final class MediaSessionManager { * Library for consistent behavior across all devices. *
* Adds a listener to be notified when the {@link #getSession2Tokens()} changes. + *
+ * The calling application needs to hold the + * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission in order to + * add listeners for user ids that do not belong to current process. * * @param userId The userId to listen for changes on * @param listener The listener to add @@ -705,8 +718,9 @@ public final class MediaSessionManager { /** * Checks whether the remote user is a trusted app. *
- * An app is trusted if the app holds the android.Manifest.permission.MEDIA_CONTENT_CONTROL
- * permission or has an enabled notification listener.
+ * An app is trusted if the app holds the
+ * {@link android.Manifest.permission#MEDIA_CONTENT_CONTROL} permission or has an enabled
+ * notification listener.
*
* @param userInfo The remote user info from either
* {@link MediaSession#getCurrentControllerInfo()} or
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 4be7689780ac4..17ceb15601469 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -16,6 +16,7 @@
package com.android.server.media;
+import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.os.UserHandle.ALL;
import static android.os.UserHandle.CURRENT;
@@ -1115,8 +1116,7 @@ public class MediaSessionService extends SystemService implements Monitor {
final long token = Binder.clearCallingIdentity();
try {
enforcePackageName(packageName, uid);
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- false /* allowAll */, true /* requireFull */, "createSession", packageName);
+ int resolvedUserId = handleIncomingUser(pid, uid, userId, packageName);
if (cb == null) {
throw new IllegalArgumentException("Controller callback cannot be null");
}
@@ -1191,11 +1191,8 @@ public class MediaSessionService extends SystemService implements Monitor {
final long token = Binder.clearCallingIdentity();
try {
- // Check that they can make calls on behalf of the user and
- // get the final user id
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- true /* allowAll */, true /* requireFull */, "getSession2Tokens",
- null /* optional packageName */);
+ // Check that they can make calls on behalf of the user and get the final user id
+ int resolvedUserId = handleIncomingUser(pid, uid, userId, null);
List