Add Session2Token#getExtras()
Bug: 125691206 Test: Passed MediaSession2Test and MediaController2Test Change-Id: I8f6a74ec0a9a733b08fbb7c2000609e9084af279
This commit is contained in:
@@ -26011,6 +26011,7 @@ package android.media {
|
||||
public static final class MediaSession2.Builder {
|
||||
ctor public MediaSession2.Builder(@NonNull android.content.Context);
|
||||
method @NonNull public android.media.MediaSession2 build();
|
||||
method @NonNull public android.media.MediaSession2.Builder setExtras(@Nullable android.os.Bundle);
|
||||
method @NonNull public android.media.MediaSession2.Builder setId(@NonNull String);
|
||||
method @NonNull public android.media.MediaSession2.Builder setSessionActivity(@Nullable android.app.PendingIntent);
|
||||
method @NonNull public android.media.MediaSession2.Builder setSessionCallback(@NonNull java.util.concurrent.Executor, @NonNull android.media.MediaSession2.SessionCallback);
|
||||
@@ -26373,6 +26374,7 @@ package android.media {
|
||||
public final class Session2Token implements android.os.Parcelable {
|
||||
ctor public Session2Token(@NonNull android.content.Context, @NonNull android.content.ComponentName);
|
||||
method public int describeContents();
|
||||
method @Nullable public android.os.Bundle getExtras();
|
||||
method @NonNull public String getPackageName();
|
||||
method @Nullable public String getServiceName();
|
||||
method public int getType();
|
||||
|
||||
@@ -27,6 +27,7 @@ class MediaConstants {
|
||||
static final String KEY_SESSION2LINK = "android.media.key.SESSION2LINK";
|
||||
static final String KEY_ALLOWED_COMMANDS = "android.media.key.ALLOWED_COMMANDS";
|
||||
static final String KEY_PLAYBACK_ACTIVE = "android.media.key.PLAYBACK_ACTIVE";
|
||||
static final String KEY_TOKEN_EXTRAS = "android.media.key.TOKEN_EXTRAS";
|
||||
|
||||
private MediaConstants() {
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static android.media.MediaConstants.KEY_PACKAGE_NAME;
|
||||
import static android.media.MediaConstants.KEY_PID;
|
||||
import static android.media.MediaConstants.KEY_PLAYBACK_ACTIVE;
|
||||
import static android.media.MediaConstants.KEY_SESSION2LINK;
|
||||
import static android.media.MediaConstants.KEY_TOKEN_EXTRAS;
|
||||
import static android.media.Session2Command.RESULT_ERROR_UNKNOWN_ERROR;
|
||||
import static android.media.Session2Command.RESULT_INFO_SKIPPED;
|
||||
import static android.media.Session2Token.TYPE_SESSION;
|
||||
@@ -264,6 +265,7 @@ public class MediaController2 implements AutoCloseable {
|
||||
Session2CommandGroup allowedCommands =
|
||||
connectionResult.getParcelable(KEY_ALLOWED_COMMANDS);
|
||||
boolean playbackActive = connectionResult.getBoolean(KEY_PLAYBACK_ACTIVE);
|
||||
Bundle tokenExtras = connectionResult.getBundle(KEY_TOKEN_EXTRAS);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "notifyConnected sessionBinder=" + sessionBinder
|
||||
+ ", allowedCommands=" + allowedCommands);
|
||||
@@ -282,7 +284,7 @@ public class MediaController2 implements AutoCloseable {
|
||||
// so can be used without worrying about deadlock.
|
||||
sessionBinder.linkToDeath(mDeathRecipient, 0);
|
||||
mConnectedToken = new Session2Token(mSessionToken.getUid(), TYPE_SESSION,
|
||||
mSessionToken.getPackageName(), sessionBinder);
|
||||
mSessionToken.getPackageName(), sessionBinder, tokenExtras);
|
||||
}
|
||||
mCallbackExecutor.execute(() -> {
|
||||
mCallback.onConnected(MediaController2.this, allowedCommands);
|
||||
|
||||
@@ -21,6 +21,7 @@ import static android.media.MediaConstants.KEY_PACKAGE_NAME;
|
||||
import static android.media.MediaConstants.KEY_PID;
|
||||
import static android.media.MediaConstants.KEY_PLAYBACK_ACTIVE;
|
||||
import static android.media.MediaConstants.KEY_SESSION2LINK;
|
||||
import static android.media.MediaConstants.KEY_TOKEN_EXTRAS;
|
||||
import static android.media.Session2Command.RESULT_ERROR_UNKNOWN_ERROR;
|
||||
import static android.media.Session2Command.RESULT_INFO_SKIPPED;
|
||||
import static android.media.Session2Token.TYPE_SESSION;
|
||||
@@ -94,7 +95,8 @@ public class MediaSession2 implements AutoCloseable {
|
||||
private ForegroundServiceEventCallback mForegroundServiceEventCallback;
|
||||
|
||||
MediaSession2(@NonNull Context context, @NonNull String id, PendingIntent sessionActivity,
|
||||
@NonNull Executor callbackExecutor, @NonNull SessionCallback callback) {
|
||||
@NonNull Executor callbackExecutor, @NonNull SessionCallback callback,
|
||||
Bundle tokenExtras) {
|
||||
synchronized (MediaSession2.class) {
|
||||
if (SESSION_ID_LIST.contains(id)) {
|
||||
throw new IllegalStateException("Session ID must be unique. ID=" + id);
|
||||
@@ -109,7 +111,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
mCallback = callback;
|
||||
mSessionStub = new Session2Link(this);
|
||||
mSessionToken = new Session2Token(Process.myUid(), TYPE_SESSION, context.getPackageName(),
|
||||
mSessionStub);
|
||||
mSessionStub, tokenExtras);
|
||||
mSessionManager = (MediaSessionManager) mContext.getSystemService(
|
||||
Context.MEDIA_SESSION_SERVICE);
|
||||
// NOTE: mResultHandler uses main looper, so this MUST NOT be blocked.
|
||||
@@ -339,6 +341,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
connectionResult.putParcelable(KEY_ALLOWED_COMMANDS,
|
||||
controllerInfo.mAllowedCommands);
|
||||
connectionResult.putBoolean(KEY_PLAYBACK_ACTIVE, isPlaybackActive());
|
||||
connectionResult.putBundle(KEY_TOKEN_EXTRAS, mSessionToken.getExtras());
|
||||
|
||||
// Double check if session is still there, because close() can be called in
|
||||
// another thread.
|
||||
@@ -444,6 +447,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
private PendingIntent mSessionActivity;
|
||||
private Executor mCallbackExecutor;
|
||||
private SessionCallback mCallback;
|
||||
private Bundle mExtras;
|
||||
|
||||
/**
|
||||
* Creates a builder for {@link MediaSession2}.
|
||||
@@ -506,6 +510,18 @@ public class MediaSession2 implements AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extras for the session token.
|
||||
*
|
||||
* @return The Builder to allow chaining
|
||||
* @see Session2Token#getExtras()
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setExtras(@Nullable Bundle extras) {
|
||||
mExtras = extras;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build {@link MediaSession2}.
|
||||
*
|
||||
@@ -525,7 +541,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
mId = "";
|
||||
}
|
||||
MediaSession2 session2 = new MediaSession2(mContext, mId, mSessionActivity,
|
||||
mCallbackExecutor, mCallback);
|
||||
mCallbackExecutor, mCallback, mExtras);
|
||||
|
||||
// Notify framework about the newly create session after the constructor is finished.
|
||||
// Otherwise, framework may access the session before the initialization is finished.
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
@@ -88,6 +89,7 @@ public final class Session2Token implements Parcelable {
|
||||
private final String mServiceName;
|
||||
private final Session2Link mSessionLink;
|
||||
private final ComponentName mComponentName;
|
||||
private final Bundle mExtras;
|
||||
|
||||
/**
|
||||
* Constructor for the token with type {@link #TYPE_SESSION_SERVICE}.
|
||||
@@ -116,15 +118,18 @@ public final class Session2Token implements Parcelable {
|
||||
mUid = uid;
|
||||
mType = TYPE_SESSION_SERVICE;
|
||||
mSessionLink = null;
|
||||
mExtras = null;
|
||||
}
|
||||
|
||||
Session2Token(int uid, int type, String packageName, Session2Link sessionLink) {
|
||||
Session2Token(int uid, int type, String packageName, Session2Link sessionLink,
|
||||
Bundle tokenExtras) {
|
||||
mUid = uid;
|
||||
mType = type;
|
||||
mPackageName = packageName;
|
||||
mServiceName = null;
|
||||
mComponentName = null;
|
||||
mSessionLink = sessionLink;
|
||||
mExtras = tokenExtras;
|
||||
}
|
||||
|
||||
Session2Token(Parcel in) {
|
||||
@@ -134,6 +139,7 @@ public final class Session2Token implements Parcelable {
|
||||
mServiceName = in.readString();
|
||||
mSessionLink = in.readParcelable(null);
|
||||
mComponentName = ComponentName.unflattenFromString(in.readString());
|
||||
mExtras = in.readBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,6 +150,7 @@ public final class Session2Token implements Parcelable {
|
||||
dest.writeString(mServiceName);
|
||||
dest.writeParcelable(mSessionLink, flags);
|
||||
dest.writeString(mComponentName == null ? "" : mComponentName.flattenToString());
|
||||
dest.writeBundle(mExtras);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,6 +214,14 @@ public final class Session2Token implements Parcelable {
|
||||
return mType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return extras of the token
|
||||
*/
|
||||
@Nullable
|
||||
public Bundle getExtras() {
|
||||
return mExtras;
|
||||
}
|
||||
|
||||
Session2Link getSessionLink() {
|
||||
return mSessionLink;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user