Loading services/core/java/com/android/server/media/MediaSession2Record.java +13 −3 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final Object mLock = new Object(); private final int mUniqueId; @GuardedBy("mLock") private final Session2Token mSessionToken; @GuardedBy("mLock") Loading @@ -63,11 +64,13 @@ public class MediaSession2Record implements MediaSessionRecordImpl { MediaSessionService service, Looper handlerLooper, int pid, int policies) { int policies, int uniqueId) { // The lock is required to prevent `Controller2Callback` from using partially initialized // `MediaSession2Record.this`. synchronized (mLock) { mSessionToken = sessionToken; mUniqueId = uniqueId; mService = service; mHandlerExecutor = new HandlerExecutor(new Handler(handlerLooper)); mController = new MediaController2.Builder(service.getContext(), sessionToken) Loading Loading @@ -97,6 +100,13 @@ public class MediaSession2Record implements MediaSessionRecordImpl { } } @Override public int getUniqueId() { synchronized (mLock) { return mUniqueId; } } @Override public String getPackageName() { return mSessionToken.getPackageName(); Loading Loading @@ -200,6 +210,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { @Override public void dump(PrintWriter pw, String prefix) { pw.println(prefix + "uniqueId=" + mUniqueId); pw.println(prefix + "token=" + mSessionToken); pw.println(prefix + "controller=" + mController); Loading @@ -209,8 +220,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { @Override public String toString() { // TODO(jaewan): Also add getId(). return getPackageName() + " (userId=" + getUserId() + ")"; return getPackageName() + "/" + mUniqueId + " (userId=" + getUserId() + ")"; } private class Controller2Callback extends MediaController2.ControllerCallback { Loading services/core/java/com/android/server/media/MediaSessionRecord.java +25 −4 Original line number Diff line number Diff line Loading @@ -173,6 +173,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR private final int mUserId; private final String mPackageName; private final String mTag; private final int mUniqueId; private final Bundle mSessionInfo; private final ControllerStub mController; private final MediaSession.Token mSessionToken; Loading Loading @@ -223,15 +224,25 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR private int mPolicies; public MediaSessionRecord(int ownerPid, int ownerUid, int userId, String ownerPackageName, ISessionCallback cb, String tag, Bundle sessionInfo, MediaSessionService service, Looper handlerLooper, int policies) public MediaSessionRecord( int ownerPid, int ownerUid, int userId, String ownerPackageName, ISessionCallback cb, String tag, int uniqueId, Bundle sessionInfo, MediaSessionService service, Looper handlerLooper, int policies) throws RemoteException { mOwnerPid = ownerPid; mOwnerUid = ownerUid; mUserId = userId; mPackageName = ownerPackageName; mTag = tag; mUniqueId = uniqueId; mSessionInfo = sessionInfo; mController = new ControllerStub(); mSessionToken = new MediaSession.Token(ownerUid, mController); Loading Loading @@ -291,6 +302,16 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR return mSessionToken; } /** * Get the unique id of this session record. * * @return a unique id of this session record. */ @Override public int getUniqueId() { return mUniqueId; } /** * Get the info for this session. * Loading Loading @@ -703,7 +724,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR @Override public String toString() { return mPackageName + "/" + mTag + " (userId=" + mUserId + ")"; return mPackageName + "/" + mTag + "/" + mUniqueId + " (userId=" + mUserId + ")"; } @Override Loading services/core/java/com/android/server/media/MediaSessionRecordImpl.java +7 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,13 @@ import java.io.PrintWriter; */ public interface MediaSessionRecordImpl extends AutoCloseable { /** * Get the unique id of this session record. * * @return a unique id of this session record. */ int getUniqueId(); /** * Get the info for this session. * Loading services/core/java/com/android/server/media/MediaSessionService.java +18 −4 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; /** * System implementation of MediaSessionManager Loading Loading @@ -155,6 +156,8 @@ public class MediaSessionService extends SystemService implements Monitor { /* Maps uid with all user engaging session tokens associated to it */ private final SparseArray<Set<MediaSession.Token>> mUserEngagingSessions = new SparseArray<>(); private final AtomicInteger mNextMediaSessionRecordId = new AtomicInteger(1); // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile) // It's always not null after the MediaSessionService is started. private FullUserRecord mCurrentFullUserRecord; Loading Loading @@ -193,7 +196,8 @@ public class MediaSessionService extends SystemService implements Monitor { MediaSessionService.this, mRecordThread.getLooper(), pid, /* policies= */ 0); /* policies= */ 0, /* uniqueId= */ mNextMediaSessionRecordId.getAndIncrement()); synchronized (mLock) { FullUserRecord user = getFullUserRecordLocked(record.getUserId()); if (user != null) { Loading Loading @@ -794,9 +798,19 @@ public class MediaSessionService extends SystemService implements Monitor { final MediaSessionRecord session; try { session = new MediaSessionRecord(callerPid, callerUid, userId, callerPackageName, cb, tag, sessionInfo, this, mRecordThread.getLooper(), policies); session = new MediaSessionRecord( callerPid, callerUid, userId, callerPackageName, cb, tag, /* uniqueId= */ mNextMediaSessionRecordId.getAndIncrement(), sessionInfo, this, mRecordThread.getLooper(), policies); } catch (RemoteException e) { throw new RuntimeException("Media Session owner died prematurely.", e); } Loading Loading
services/core/java/com/android/server/media/MediaSession2Record.java +13 −3 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final Object mLock = new Object(); private final int mUniqueId; @GuardedBy("mLock") private final Session2Token mSessionToken; @GuardedBy("mLock") Loading @@ -63,11 +64,13 @@ public class MediaSession2Record implements MediaSessionRecordImpl { MediaSessionService service, Looper handlerLooper, int pid, int policies) { int policies, int uniqueId) { // The lock is required to prevent `Controller2Callback` from using partially initialized // `MediaSession2Record.this`. synchronized (mLock) { mSessionToken = sessionToken; mUniqueId = uniqueId; mService = service; mHandlerExecutor = new HandlerExecutor(new Handler(handlerLooper)); mController = new MediaController2.Builder(service.getContext(), sessionToken) Loading Loading @@ -97,6 +100,13 @@ public class MediaSession2Record implements MediaSessionRecordImpl { } } @Override public int getUniqueId() { synchronized (mLock) { return mUniqueId; } } @Override public String getPackageName() { return mSessionToken.getPackageName(); Loading Loading @@ -200,6 +210,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { @Override public void dump(PrintWriter pw, String prefix) { pw.println(prefix + "uniqueId=" + mUniqueId); pw.println(prefix + "token=" + mSessionToken); pw.println(prefix + "controller=" + mController); Loading @@ -209,8 +220,7 @@ public class MediaSession2Record implements MediaSessionRecordImpl { @Override public String toString() { // TODO(jaewan): Also add getId(). return getPackageName() + " (userId=" + getUserId() + ")"; return getPackageName() + "/" + mUniqueId + " (userId=" + getUserId() + ")"; } private class Controller2Callback extends MediaController2.ControllerCallback { Loading
services/core/java/com/android/server/media/MediaSessionRecord.java +25 −4 Original line number Diff line number Diff line Loading @@ -173,6 +173,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR private final int mUserId; private final String mPackageName; private final String mTag; private final int mUniqueId; private final Bundle mSessionInfo; private final ControllerStub mController; private final MediaSession.Token mSessionToken; Loading Loading @@ -223,15 +224,25 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR private int mPolicies; public MediaSessionRecord(int ownerPid, int ownerUid, int userId, String ownerPackageName, ISessionCallback cb, String tag, Bundle sessionInfo, MediaSessionService service, Looper handlerLooper, int policies) public MediaSessionRecord( int ownerPid, int ownerUid, int userId, String ownerPackageName, ISessionCallback cb, String tag, int uniqueId, Bundle sessionInfo, MediaSessionService service, Looper handlerLooper, int policies) throws RemoteException { mOwnerPid = ownerPid; mOwnerUid = ownerUid; mUserId = userId; mPackageName = ownerPackageName; mTag = tag; mUniqueId = uniqueId; mSessionInfo = sessionInfo; mController = new ControllerStub(); mSessionToken = new MediaSession.Token(ownerUid, mController); Loading Loading @@ -291,6 +302,16 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR return mSessionToken; } /** * Get the unique id of this session record. * * @return a unique id of this session record. */ @Override public int getUniqueId() { return mUniqueId; } /** * Get the info for this session. * Loading Loading @@ -703,7 +724,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR @Override public String toString() { return mPackageName + "/" + mTag + " (userId=" + mUserId + ")"; return mPackageName + "/" + mTag + "/" + mUniqueId + " (userId=" + mUserId + ")"; } @Override Loading
services/core/java/com/android/server/media/MediaSessionRecordImpl.java +7 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,13 @@ import java.io.PrintWriter; */ public interface MediaSessionRecordImpl extends AutoCloseable { /** * Get the unique id of this session record. * * @return a unique id of this session record. */ int getUniqueId(); /** * Get the info for this session. * Loading
services/core/java/com/android/server/media/MediaSessionService.java +18 −4 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; /** * System implementation of MediaSessionManager Loading Loading @@ -155,6 +156,8 @@ public class MediaSessionService extends SystemService implements Monitor { /* Maps uid with all user engaging session tokens associated to it */ private final SparseArray<Set<MediaSession.Token>> mUserEngagingSessions = new SparseArray<>(); private final AtomicInteger mNextMediaSessionRecordId = new AtomicInteger(1); // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile) // It's always not null after the MediaSessionService is started. private FullUserRecord mCurrentFullUserRecord; Loading Loading @@ -193,7 +196,8 @@ public class MediaSessionService extends SystemService implements Monitor { MediaSessionService.this, mRecordThread.getLooper(), pid, /* policies= */ 0); /* policies= */ 0, /* uniqueId= */ mNextMediaSessionRecordId.getAndIncrement()); synchronized (mLock) { FullUserRecord user = getFullUserRecordLocked(record.getUserId()); if (user != null) { Loading Loading @@ -794,9 +798,19 @@ public class MediaSessionService extends SystemService implements Monitor { final MediaSessionRecord session; try { session = new MediaSessionRecord(callerPid, callerUid, userId, callerPackageName, cb, tag, sessionInfo, this, mRecordThread.getLooper(), policies); session = new MediaSessionRecord( callerPid, callerUid, userId, callerPackageName, cb, tag, /* uniqueId= */ mNextMediaSessionRecordId.getAndIncrement(), sessionInfo, this, mRecordThread.getLooper(), policies); } catch (RemoteException e) { throw new RuntimeException("Media Session owner died prematurely.", e); } Loading