Revert changes to androidx.media3.session.legacy
This commit is contained in:
parent
b90f00c774
commit
ed15ab012f
@ -308,9 +308,10 @@ public class AudioAttributesCompat {
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
return new AudioAttributesCompat(new AudioAttributesImplApi26((AudioAttributes) aa));
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
return new AudioAttributesCompat(new AudioAttributesImplApi21((AudioAttributes) aa));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// The rest of this file implements an approximation to AudioAttributes using old stream types
|
||||
@ -376,8 +377,10 @@ public class AudioAttributesCompat {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder();
|
||||
} else if (Build.VERSION.SDK_INT >= 26) {
|
||||
mBuilderImpl = new AudioAttributesImplApi26.Builder();
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder();
|
||||
} else {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder();
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,8 +394,10 @@ public class AudioAttributesCompat {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder(aa);
|
||||
} else if (Build.VERSION.SDK_INT >= 26) {
|
||||
mBuilderImpl = new AudioAttributesImplApi26.Builder(checkNotNull(aa.unwrap()));
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder(checkNotNull(aa.unwrap()));
|
||||
} else {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder(aa);
|
||||
}
|
||||
}
|
||||
|
||||
@ -938,6 +943,7 @@ public class AudioAttributesCompat {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
public static class AudioAttributesImplApi21 implements AudioAttributesImpl {
|
||||
|
||||
@Nullable public AudioAttributes mAudioAttributes;
|
||||
@ -1014,6 +1020,7 @@ public class AudioAttributesCompat {
|
||||
return "AudioAttributesCompat: audioattributes=" + mAudioAttributes;
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
static class Builder implements AudioAttributesImpl.Builder {
|
||||
final AudioAttributes.Builder mFwkBuilder;
|
||||
|
||||
|
@ -88,7 +88,7 @@ public final class LegacyParcelableUtil {
|
||||
// TODO: b/335804969 - Remove this workaround once the bug fix is in the androidx.media dependency
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T maybeApplyMediaDescriptionParcelableBugWorkaround(T value) {
|
||||
if (Util.SDK_INT >= 23) {
|
||||
if (Util.SDK_INT < 21 || Util.SDK_INT >= 23) {
|
||||
return value;
|
||||
}
|
||||
if (value instanceof android.support.v4.media.MediaBrowserCompat.MediaItem) {
|
||||
|
@ -56,6 +56,7 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.media.MediaDescription;
|
||||
import android.media.browse.MediaBrowser;
|
||||
import android.os.BadParcelableException;
|
||||
import android.os.Binder;
|
||||
@ -72,8 +73,8 @@ import android.os.RemoteException;
|
||||
import android.support.v4.os.ResultReceiver;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.DoNotInline;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
@ -204,8 +205,10 @@ public final class MediaBrowserCompat {
|
||||
mImpl = new MediaBrowserImplApi26(context, serviceComponent, callback, rootHints);
|
||||
} else if (Build.VERSION.SDK_INT >= 23) {
|
||||
mImpl = new MediaBrowserImplApi23(context, serviceComponent, callback, rootHints);
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaBrowserImplApi21(context, serviceComponent, callback, rootHints);
|
||||
} else {
|
||||
mImpl = new MediaBrowserImplBase(context, serviceComponent, callback, rootHints);
|
||||
}
|
||||
}
|
||||
|
||||
@ -455,18 +458,20 @@ public final class MediaBrowserCompat {
|
||||
* Creates an instance from a framework {@link android.media.browse.MediaBrowser.MediaItem}
|
||||
* object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+. On API 20 and below, it returns null.
|
||||
*
|
||||
* @param itemObj A {@link android.media.browse.MediaBrowser.MediaItem} object.
|
||||
* @return An equivalent {@link MediaItem} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static MediaItem fromMediaItem(@Nullable Object itemObj) {
|
||||
if (itemObj == null) {
|
||||
if (itemObj == null || Build.VERSION.SDK_INT < 21) {
|
||||
return null;
|
||||
}
|
||||
MediaBrowser.MediaItem itemFwk = (MediaBrowser.MediaItem) itemObj;
|
||||
int flags = itemFwk.getFlags();
|
||||
int flags = Api21Impl.getFlags(itemFwk);
|
||||
MediaDescriptionCompat descriptionCompat =
|
||||
MediaDescriptionCompat.fromMediaDescription(itemFwk.getDescription());
|
||||
MediaDescriptionCompat.fromMediaDescription(Api21Impl.getDescription(itemFwk));
|
||||
return new MediaItem(descriptionCompat, flags);
|
||||
}
|
||||
|
||||
@ -474,12 +479,14 @@ public final class MediaBrowserCompat {
|
||||
* Creates a list of {@link MediaItem} objects from a framework {@link
|
||||
* android.media.browse.MediaBrowser.MediaItem} object list.
|
||||
*
|
||||
* <p>This method is only supported on API 21+. On API 20 and below, it returns null.
|
||||
*
|
||||
* @param itemList A list of {@link android.media.browse.MediaBrowser.MediaItem} objects.
|
||||
* @return An equivalent list of {@link MediaItem} objects, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<MediaItem> fromMediaItemList(@Nullable List<?> itemList) {
|
||||
if (itemList == null) {
|
||||
if (itemList == null || Build.VERSION.SDK_INT < 21) {
|
||||
return null;
|
||||
}
|
||||
List<MediaItem> items = new ArrayList<>(itemList.size());
|
||||
@ -594,7 +601,11 @@ public final class MediaBrowserCompat {
|
||||
@Nullable ConnectionCallbackInternal mConnectionCallbackInternal;
|
||||
|
||||
public ConnectionCallback() {
|
||||
mConnectionCallbackFwk = new ConnectionCallbackApi21();
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
mConnectionCallbackFwk = new ConnectionCallbackApi21();
|
||||
} else {
|
||||
mConnectionCallbackFwk = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -636,6 +647,7 @@ public final class MediaBrowserCompat {
|
||||
void onConnectionFailed();
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private class ConnectionCallbackApi21 extends MediaBrowser.ConnectionCallback {
|
||||
ConnectionCallbackApi21() {}
|
||||
|
||||
@ -667,7 +679,7 @@ public final class MediaBrowserCompat {
|
||||
|
||||
/** Callbacks for subscription related events. */
|
||||
public abstract static class SubscriptionCallback {
|
||||
@NonNull final MediaBrowser.SubscriptionCallback mSubscriptionCallbackFwk;
|
||||
@Nullable final MediaBrowser.SubscriptionCallback mSubscriptionCallbackFwk;
|
||||
final IBinder mToken;
|
||||
@Nullable WeakReference<Subscription> mSubscriptionRef;
|
||||
|
||||
@ -675,8 +687,10 @@ public final class MediaBrowserCompat {
|
||||
mToken = new Binder();
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
mSubscriptionCallbackFwk = new SubscriptionCallbackApi26();
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mSubscriptionCallbackFwk = new SubscriptionCallbackApi21();
|
||||
} else {
|
||||
mSubscriptionCallbackFwk = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -724,6 +738,7 @@ public final class MediaBrowserCompat {
|
||||
mSubscriptionRef = new WeakReference<>(subscription);
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private class SubscriptionCallbackApi21 extends MediaBrowser.SubscriptionCallback {
|
||||
SubscriptionCallbackApi21() {}
|
||||
|
||||
@ -1628,6 +1643,7 @@ public final class MediaBrowserCompat {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
static class MediaBrowserImplApi21
|
||||
implements MediaBrowserImpl,
|
||||
MediaBrowserServiceCallbackImpl,
|
||||
@ -1728,7 +1744,7 @@ public final class MediaBrowserCompat {
|
||||
if (mServiceBinderWrapper == null) {
|
||||
// TODO: When MediaBrowser is connected to framework's MediaBrowserService,
|
||||
// subscribe with options won't work properly.
|
||||
mBrowserFwk.subscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
mBrowserFwk.subscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
} else {
|
||||
try {
|
||||
mServiceBinderWrapper.addSubscription(
|
||||
@ -2076,9 +2092,9 @@ public final class MediaBrowserCompat {
|
||||
// This is to prevent ClassNotFoundException when options has Parcelable in it.
|
||||
if (mServiceBinderWrapper == null || mServiceVersion < SERVICE_VERSION_2) {
|
||||
if (options == null) {
|
||||
mBrowserFwk.subscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
mBrowserFwk.subscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
} else {
|
||||
mBrowserFwk.subscribe(parentId, options, callback.mSubscriptionCallbackFwk);
|
||||
mBrowserFwk.subscribe(parentId, options, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
}
|
||||
} else {
|
||||
super.subscribe(parentId, options, callback);
|
||||
@ -2093,7 +2109,7 @@ public final class MediaBrowserCompat {
|
||||
if (callback == null) {
|
||||
mBrowserFwk.unsubscribe(parentId);
|
||||
} else {
|
||||
mBrowserFwk.unsubscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
mBrowserFwk.unsubscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
}
|
||||
} else {
|
||||
super.unsubscribe(parentId, callback);
|
||||
@ -2450,4 +2466,19 @@ public final class MediaBrowserCompat {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static class Api21Impl {
|
||||
private Api21Impl() {}
|
||||
|
||||
@DoNotInline
|
||||
static MediaDescription getDescription(MediaBrowser.MediaItem item) {
|
||||
return item.getDescription();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static int getFlags(MediaBrowser.MediaItem item) {
|
||||
return item.getFlags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,6 +307,7 @@ public abstract class MediaBrowserServiceCompat extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
class MediaBrowserServiceImplApi21 implements MediaBrowserServiceImpl {
|
||||
final List<Bundle> mRootExtrasList = new ArrayList<>();
|
||||
@MonotonicNonNull MediaBrowserService mServiceFwk;
|
||||
@ -519,6 +520,7 @@ public abstract class MediaBrowserServiceCompat extends Service {
|
||||
return mCurConnection.browserInfo;
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
class MediaBrowserServiceApi21 extends MediaBrowserService {
|
||||
@SuppressWarnings("method.invocation.invalid") // Calling base method from constructor
|
||||
MediaBrowserServiceApi21(Context context) {
|
||||
@ -1266,6 +1268,7 @@ public abstract class MediaBrowserServiceCompat extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
static class ResultWrapper<T> {
|
||||
MediaBrowserService.Result mResultFwk;
|
||||
@ -1328,8 +1331,10 @@ public abstract class MediaBrowserServiceCompat extends Service {
|
||||
mImpl = new MediaBrowserServiceImplApi26();
|
||||
} else if (Build.VERSION.SDK_INT >= 23) {
|
||||
mImpl = new MediaBrowserServiceImplApi23();
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaBrowserServiceImplApi21();
|
||||
} else {
|
||||
mImpl = new MediaBrowserServiceImplBase();
|
||||
}
|
||||
mImpl.onCreate();
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import androidx.annotation.GuardedBy;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
@ -143,12 +142,9 @@ public final class MediaControllerCompat {
|
||||
.getWindow()
|
||||
.getDecorView()
|
||||
.setTag(R.id.media_controller_compat_view_tag, mediaController);
|
||||
MediaController controllerFwk = null;
|
||||
if (mediaController != null) {
|
||||
Object sessionTokenObj = mediaController.getSessionToken().getToken();
|
||||
controllerFwk = new MediaController(activity, (MediaSession.Token) sessionTokenObj);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
MediaControllerImplApi21.setMediaController(activity, mediaController);
|
||||
}
|
||||
activity.setMediaController(controllerFwk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,15 +162,10 @@ public final class MediaControllerCompat {
|
||||
Object tag = activity.getWindow().getDecorView().getTag(R.id.media_controller_compat_view_tag);
|
||||
if (tag instanceof MediaControllerCompat) {
|
||||
return (MediaControllerCompat) tag;
|
||||
} else {
|
||||
MediaController controllerFwk = activity.getMediaController();
|
||||
if (controllerFwk == null) {
|
||||
return null;
|
||||
}
|
||||
MediaSession.Token sessionTokenFwk = controllerFwk.getSessionToken();
|
||||
return new MediaControllerCompat(
|
||||
activity, MediaSessionCompat.Token.fromToken(sessionTokenFwk));
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
return MediaControllerImplApi21.getMediaController(activity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
||||
@ -230,8 +221,10 @@ public final class MediaControllerCompat {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
mImpl = new MediaControllerImplApi29(context, sessionToken);
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaControllerImplApi21(context, sessionToken);
|
||||
} else {
|
||||
mImpl = new MediaControllerImplBase(sessionToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,6 +635,8 @@ public final class MediaControllerCompat {
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.session.MediaController} object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @return The underlying {@link android.media.session.MediaController} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
@ -654,14 +649,19 @@ public final class MediaControllerCompat {
|
||||
* #registerCallback}
|
||||
*/
|
||||
public abstract static class Callback implements IBinder.DeathRecipient {
|
||||
@NonNull final MediaController.Callback mCallbackFwk;
|
||||
@Nullable final MediaController.Callback mCallbackFwk;
|
||||
@Nullable MessageHandler mHandler;
|
||||
@Nullable IMediaControllerCallback mIControllerCallback;
|
||||
|
||||
// Sharing this in constructor
|
||||
@SuppressWarnings({"assignment.type.incompatible", "argument.type.incompatible"})
|
||||
public Callback() {
|
||||
mCallbackFwk = new MediaControllerCallbackApi21(this);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
mCallbackFwk = new MediaControllerCallbackApi21(this);
|
||||
} else {
|
||||
mCallbackFwk = null;
|
||||
mIControllerCallback = new StubCompat(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -789,6 +789,7 @@ public final class MediaControllerCompat {
|
||||
}
|
||||
|
||||
// Callback methods in this class are run on handler which was given to registerCallback().
|
||||
@RequiresApi(21)
|
||||
private static class MediaControllerCallbackApi21 extends MediaController.Callback {
|
||||
private final WeakReference<MediaControllerCompat.Callback> mCallback;
|
||||
|
||||
@ -1973,6 +1974,7 @@ public final class MediaControllerCompat {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
static class MediaControllerImplApi21 implements MediaControllerImpl {
|
||||
protected final MediaController mControllerFwk;
|
||||
|
||||
@ -2000,7 +2002,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public final void registerCallback(Callback callback, Handler handler) {
|
||||
mControllerFwk.registerCallback(callback.mCallbackFwk, handler);
|
||||
mControllerFwk.registerCallback(checkNotNull(callback.mCallbackFwk), handler);
|
||||
synchronized (mLock) {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2022,7 +2024,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public final void unregisterCallback(Callback callback) {
|
||||
mControllerFwk.unregisterCallback(callback.mCallbackFwk);
|
||||
mControllerFwk.unregisterCallback(checkNotNull(callback.mCallbackFwk));
|
||||
synchronized (mLock) {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2149,7 +2151,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public int getRatingType() {
|
||||
if (android.os.Build.VERSION.SDK_INT == 21) {
|
||||
if (android.os.Build.VERSION.SDK_INT < 22) {
|
||||
try {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2302,6 +2304,27 @@ public final class MediaControllerCompat {
|
||||
mPendingCallbacks.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings("argument.type.incompatible") // Activity.setMediaController is not annotated
|
||||
static void setMediaController(Activity activity, MediaControllerCompat mediaControllerCompat) {
|
||||
MediaController controllerFwk = null;
|
||||
if (mediaControllerCompat != null) {
|
||||
Object sessionTokenObj = mediaControllerCompat.getSessionToken().getToken();
|
||||
controllerFwk = new MediaController(activity, (MediaSession.Token) sessionTokenObj);
|
||||
}
|
||||
activity.setMediaController(controllerFwk);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static MediaControllerCompat getMediaController(Activity activity) {
|
||||
MediaController controllerFwk = activity.getMediaController();
|
||||
if (controllerFwk == null) {
|
||||
return null;
|
||||
}
|
||||
MediaSession.Token sessionTokenFwk = controllerFwk.getSessionToken();
|
||||
return new MediaControllerCompat(
|
||||
activity, MediaSessionCompat.Token.fromToken(sessionTokenFwk));
|
||||
}
|
||||
|
||||
private static class ExtraBinderRequestResultReceiver extends ResultReceiver {
|
||||
private WeakReference<MediaControllerImplApi21> mMediaControllerImpl;
|
||||
|
||||
@ -2388,6 +2411,7 @@ public final class MediaControllerCompat {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
static class TransportControlsApi21 extends TransportControls {
|
||||
protected final MediaController.TransportControls mControlsFwk;
|
||||
|
||||
|
@ -294,7 +294,18 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
((MediaDescription) getMediaDescription()).writeToParcel(dest, flags);
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
dest.writeString(mMediaId);
|
||||
TextUtils.writeToParcel(mTitle, dest, flags);
|
||||
TextUtils.writeToParcel(mSubtitle, dest, flags);
|
||||
TextUtils.writeToParcel(mDescription, dest, flags);
|
||||
dest.writeParcelable(mIcon, flags);
|
||||
dest.writeParcelable(mIconUri, flags);
|
||||
dest.writeBundle(mExtras);
|
||||
dest.writeParcelable(mMediaUri, flags);
|
||||
} else {
|
||||
((MediaDescription) getMediaDescription()).writeToParcel(dest, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -305,19 +316,22 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.MediaDescription} object.
|
||||
*
|
||||
* <p>This method is only supported on {@link android.os.Build.VERSION_CODES#LOLLIPOP} and later.
|
||||
*
|
||||
* @return An equivalent {@link android.media.MediaDescription} object, or null if none.
|
||||
*/
|
||||
@RequiresApi(21)
|
||||
public Object getMediaDescription() {
|
||||
if (mDescriptionFwk != null) {
|
||||
return mDescriptionFwk;
|
||||
}
|
||||
MediaDescription.Builder bob = new MediaDescription.Builder()
|
||||
.setMediaId(mMediaId)
|
||||
.setTitle(mTitle)
|
||||
.setSubtitle(mSubtitle)
|
||||
.setDescription(mDescription)
|
||||
.setIconBitmap(mIcon)
|
||||
.setIconUri(mIconUri);
|
||||
MediaDescription.Builder bob = Api21Impl.createBuilder();
|
||||
Api21Impl.setMediaId(bob, mMediaId);
|
||||
Api21Impl.setTitle(bob, mTitle);
|
||||
Api21Impl.setSubtitle(bob, mSubtitle);
|
||||
Api21Impl.setDescription(bob, mDescription);
|
||||
Api21Impl.setIconBitmap(bob, mIcon);
|
||||
Api21Impl.setIconUri(bob, mIconUri);
|
||||
// Media URI was not added until API 23, so add it to the Bundle of extras to
|
||||
// ensure the data is not lost - this ensures that
|
||||
// fromMediaDescription(getMediaDescription(mediaDescriptionCompat)) returns
|
||||
@ -331,14 +345,14 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
extras = new Bundle(mExtras);
|
||||
}
|
||||
extras.putParcelable(DESCRIPTION_KEY_MEDIA_URI, mMediaUri);
|
||||
bob.setExtras(extras);
|
||||
Api21Impl.setExtras(bob, extras);
|
||||
} else {
|
||||
bob.setExtras(mExtras);
|
||||
Api21Impl.setExtras(bob, mExtras);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
Api23Impl.setMediaUri(bob, mMediaUri);
|
||||
}
|
||||
mDescriptionFwk = bob.build();
|
||||
mDescriptionFwk = Api21Impl.build(bob);
|
||||
|
||||
return mDescriptionFwk;
|
||||
}
|
||||
@ -346,22 +360,24 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
/**
|
||||
* Creates an instance from a framework {@link android.media.MediaDescription} object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @param descriptionObj A {@link android.media.MediaDescription} object, or null if none.
|
||||
* @return An equivalent {@link MediaMetadataCompat} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("deprecation")
|
||||
public static MediaDescriptionCompat fromMediaDescription(Object descriptionObj) {
|
||||
if (descriptionObj != null) {
|
||||
if (descriptionObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
Builder bob = new Builder();
|
||||
MediaDescription description = (MediaDescription) descriptionObj;
|
||||
bob.setMediaId(description.getMediaId());
|
||||
bob.setTitle(description.getTitle());
|
||||
bob.setSubtitle(description.getSubtitle());
|
||||
bob.setDescription(description.getDescription());
|
||||
bob.setIconBitmap(description.getIconBitmap());
|
||||
bob.setIconUri(description.getIconUri());
|
||||
Bundle extras = description.getExtras();
|
||||
bob.setMediaId(Api21Impl.getMediaId(description));
|
||||
bob.setTitle(Api21Impl.getTitle(description));
|
||||
bob.setSubtitle(Api21Impl.getSubtitle(description));
|
||||
bob.setDescription(Api21Impl.getDescription(description));
|
||||
bob.setIconBitmap(Api21Impl.getIconBitmap(description));
|
||||
bob.setIconUri(Api21Impl.getIconUri(description));
|
||||
Bundle extras = Api21Impl.getExtras(description);
|
||||
extras = MediaSessionCompat.unparcelWithClassLoader(extras);
|
||||
if (extras != null) {
|
||||
extras = new Bundle(extras);
|
||||
@ -403,8 +419,12 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
new Parcelable.Creator<MediaDescriptionCompat>() {
|
||||
@Override
|
||||
public MediaDescriptionCompat createFromParcel(Parcel in) {
|
||||
return checkNotNull(
|
||||
fromMediaDescription(MediaDescription.CREATOR.createFromParcel(in)));
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
return new MediaDescriptionCompat(in);
|
||||
} else {
|
||||
return checkNotNull(
|
||||
fromMediaDescription(MediaDescription.CREATOR.createFromParcel(in)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -526,6 +546,99 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static class Api21Impl {
|
||||
private Api21Impl() {}
|
||||
|
||||
@DoNotInline
|
||||
static MediaDescription.Builder createBuilder() {
|
||||
return new MediaDescription.Builder();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setMediaId(MediaDescription.Builder builder, @Nullable String mediaId) {
|
||||
builder.setMediaId(mediaId);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setTitle(MediaDescription.Builder builder, @Nullable CharSequence title) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setSubtitle(MediaDescription.Builder builder, @Nullable CharSequence subtitle) {
|
||||
builder.setSubtitle(subtitle);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setDescription(
|
||||
MediaDescription.Builder builder, @Nullable CharSequence description) {
|
||||
builder.setDescription(description);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setIconBitmap(MediaDescription.Builder builder, @Nullable Bitmap icon) {
|
||||
builder.setIconBitmap(icon);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setIconUri(MediaDescription.Builder builder, @Nullable Uri iconUri) {
|
||||
builder.setIconUri(iconUri);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setExtras(MediaDescription.Builder builder, @Nullable Bundle extras) {
|
||||
builder.setExtras(extras);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static MediaDescription build(MediaDescription.Builder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static String getMediaId(MediaDescription description) {
|
||||
return description.getMediaId();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static CharSequence getTitle(MediaDescription description) {
|
||||
return description.getTitle();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static CharSequence getSubtitle(MediaDescription description) {
|
||||
return description.getSubtitle();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static CharSequence getDescription(MediaDescription description) {
|
||||
return description.getDescription();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static Bitmap getIconBitmap(MediaDescription description) {
|
||||
return description.getIconBitmap();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static Uri getIconUri(MediaDescription description) {
|
||||
return description.getIconUri();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
@Nullable
|
||||
static Bundle getExtras(MediaDescription description) {
|
||||
return description.getExtras();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(23)
|
||||
private static class Api23Impl {
|
||||
private Api23Impl() {}
|
||||
|
@ -22,12 +22,14 @@ import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.MediaMetadata;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
import androidx.annotation.StringDef;
|
||||
import androidx.collection.ArrayMap;
|
||||
@ -555,12 +557,14 @@ public final class MediaMetadataCompat implements Parcelable {
|
||||
/**
|
||||
* Creates an instance from a framework {@link android.media.MediaMetadata} object.
|
||||
*
|
||||
* <p>This method is only supported on {@link android.os.Build.VERSION_CODES#LOLLIPOP} and later.
|
||||
*
|
||||
* @param metadataObj A {@link android.media.MediaMetadata} object, or null if none.
|
||||
* @return An equivalent {@link MediaMetadataCompat} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static MediaMetadataCompat fromMediaMetadata(@Nullable Object metadataObj) {
|
||||
if (metadataObj != null) {
|
||||
if (metadataObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
Parcel p = Parcel.obtain();
|
||||
((MediaMetadata) metadataObj).writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
@ -576,8 +580,11 @@ public final class MediaMetadataCompat implements Parcelable {
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.MediaMetadata} object.
|
||||
*
|
||||
* <p>This method is only supported on {@link android.os.Build.VERSION_CODES#LOLLIPOP} and later.
|
||||
*
|
||||
* @return An equivalent {@link android.media.MediaMetadata} object, or null if none.
|
||||
*/
|
||||
@RequiresApi(21)
|
||||
public Object getMediaMetadata() {
|
||||
if (mMetadataFwk == null) {
|
||||
Parcel p = Parcel.obtain();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -71,8 +71,10 @@ public final class MediaSessionManager {
|
||||
private MediaSessionManager(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
mImpl = new MediaSessionManagerImplApi28(context);
|
||||
} else {
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaSessionManagerImplApi21(context);
|
||||
} else {
|
||||
mImpl = new MediaSessionManagerImplBase(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,6 +373,7 @@ public final class MediaSessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static class MediaSessionManagerImplApi21 extends MediaSessionManagerImplBase {
|
||||
MediaSessionManagerImplApi21(Context context) {
|
||||
super(context);
|
||||
|
@ -840,14 +840,16 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
/**
|
||||
* Creates an instance from a framework {@link android.media.session.PlaybackState} object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @param stateObj A {@link android.media.session.PlaybackState} object, or null if none.
|
||||
* @return An equivalent {@link PlaybackStateCompat} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static PlaybackStateCompat fromPlaybackState(@Nullable Object stateObj) {
|
||||
if (stateObj != null) {
|
||||
if (stateObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
PlaybackState stateFwk = (PlaybackState) stateObj;
|
||||
List<PlaybackState.CustomAction> customActionFwks = stateFwk.getCustomActions();
|
||||
List<PlaybackState.CustomAction> customActionFwks = Api21Impl.getCustomActions(stateFwk);
|
||||
List<PlaybackStateCompat.CustomAction> customActions = null;
|
||||
if (customActionFwks != null) {
|
||||
customActions = new ArrayList<>(customActionFwks.size());
|
||||
@ -867,16 +869,16 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
}
|
||||
PlaybackStateCompat stateCompat =
|
||||
new PlaybackStateCompat(
|
||||
stateFwk.getState(),
|
||||
stateFwk.getPosition(),
|
||||
stateFwk.getBufferedPosition(),
|
||||
stateFwk.getPlaybackSpeed(),
|
||||
stateFwk.getActions(),
|
||||
Api21Impl.getState(stateFwk),
|
||||
Api21Impl.getPosition(stateFwk),
|
||||
Api21Impl.getBufferedPosition(stateFwk),
|
||||
Api21Impl.getPlaybackSpeed(stateFwk),
|
||||
Api21Impl.getActions(stateFwk),
|
||||
ERROR_CODE_UNKNOWN_ERROR,
|
||||
stateFwk.getErrorMessage(),
|
||||
stateFwk.getLastPositionUpdateTime(),
|
||||
Api21Impl.getErrorMessage(stateFwk),
|
||||
Api21Impl.getLastPositionUpdateTime(stateFwk),
|
||||
customActions,
|
||||
stateFwk.getActiveQueueItemId(),
|
||||
Api21Impl.getActiveQueueItemId(stateFwk),
|
||||
extras);
|
||||
stateCompat.mStateFwk = stateFwk;
|
||||
return stateCompat;
|
||||
@ -888,28 +890,30 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.session.PlaybackState} object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @return An equivalent {@link android.media.session.PlaybackState} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getPlaybackState() {
|
||||
if (mStateFwk == null) {
|
||||
PlaybackState.Builder builder = new PlaybackState.Builder()
|
||||
.setState(mState, mPosition, mSpeed, mUpdateTime)
|
||||
.setBufferedPosition(mBufferedPosition)
|
||||
.setActions(mActions)
|
||||
.setErrorMessage(mErrorMessage);
|
||||
if (mStateFwk == null && Build.VERSION.SDK_INT >= 21) {
|
||||
PlaybackState.Builder builder = Api21Impl.createBuilder();
|
||||
Api21Impl.setState(builder, mState, mPosition, mSpeed, mUpdateTime);
|
||||
Api21Impl.setBufferedPosition(builder, mBufferedPosition);
|
||||
Api21Impl.setActions(builder, mActions);
|
||||
Api21Impl.setErrorMessage(builder, mErrorMessage);
|
||||
for (PlaybackStateCompat.CustomAction customAction : mCustomActions) {
|
||||
PlaybackState.CustomAction action =
|
||||
(PlaybackState.CustomAction) customAction.getCustomAction();
|
||||
if (action != null) {
|
||||
builder.addCustomAction(action);
|
||||
Api21Impl.addCustomAction(builder, action);
|
||||
}
|
||||
}
|
||||
builder.setActiveQueueItemId(mActiveItemId);
|
||||
Api21Impl.setActiveQueueItemId(builder, mActiveItemId);
|
||||
if (Build.VERSION.SDK_INT >= 22) {
|
||||
Api22Impl.setExtras(builder, mExtras);
|
||||
}
|
||||
mStateFwk = builder.build();
|
||||
mStateFwk = Api21Impl.build(builder);
|
||||
}
|
||||
return mStateFwk;
|
||||
}
|
||||
@ -972,19 +976,22 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
* Creates an instance from a framework {@link android.media.session.PlaybackState.CustomAction}
|
||||
* object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @param customActionObj A {@link android.media.session.PlaybackState.CustomAction} object, or
|
||||
* null if none.
|
||||
* @return An equivalent {@link PlaybackStateCompat.CustomAction} object, or null if none.
|
||||
*/
|
||||
@RequiresApi(21)
|
||||
public static PlaybackStateCompat.CustomAction fromCustomAction(Object customActionObj) {
|
||||
PlaybackState.CustomAction customActionFwk = (PlaybackState.CustomAction) customActionObj;
|
||||
Bundle extras = customActionFwk.getExtras();
|
||||
Bundle extras = Api21Impl.getExtras(customActionFwk);
|
||||
MediaSessionCompat.ensureClassLoader(extras);
|
||||
PlaybackStateCompat.CustomAction customActionCompat =
|
||||
new PlaybackStateCompat.CustomAction(
|
||||
customActionFwk.getAction(),
|
||||
customActionFwk.getName(),
|
||||
customActionFwk.getIcon(),
|
||||
Api21Impl.getAction(customActionFwk),
|
||||
Api21Impl.getName(customActionFwk),
|
||||
Api21Impl.getIcon(customActionFwk),
|
||||
extras);
|
||||
customActionCompat.mCustomActionFwk = customActionFwk;
|
||||
return customActionCompat;
|
||||
@ -994,18 +1001,21 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
* Gets the underlying framework {@link android.media.session.PlaybackState.CustomAction}
|
||||
* object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @return An equivalent {@link android.media.session.PlaybackState.CustomAction} object, or
|
||||
* null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getCustomAction() {
|
||||
if (mCustomActionFwk != null) {
|
||||
if (mCustomActionFwk != null || Build.VERSION.SDK_INT < 21) {
|
||||
return mCustomActionFwk;
|
||||
}
|
||||
|
||||
return new PlaybackState.CustomAction.Builder(mAction, mName, mIcon)
|
||||
.setExtras(mExtras)
|
||||
.build();
|
||||
PlaybackState.CustomAction.Builder builder =
|
||||
Api21Impl.createCustomActionBuilder(mAction, mName, mIcon);
|
||||
Api21Impl.setExtras(builder, mExtras);
|
||||
return Api21Impl.build(builder);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<PlaybackStateCompat.CustomAction> CREATOR =
|
||||
@ -1391,6 +1401,142 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static class Api21Impl {
|
||||
private Api21Impl() {}
|
||||
|
||||
@DoNotInline
|
||||
static PlaybackState.Builder createBuilder() {
|
||||
return new PlaybackState.Builder();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setState(
|
||||
PlaybackState.Builder builder,
|
||||
int state,
|
||||
long position,
|
||||
float playbackSpeed,
|
||||
long updateTime) {
|
||||
builder.setState(state, position, playbackSpeed, updateTime);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setBufferedPosition(PlaybackState.Builder builder, long bufferedPosition) {
|
||||
builder.setBufferedPosition(bufferedPosition);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setActions(PlaybackState.Builder builder, long actions) {
|
||||
builder.setActions(actions);
|
||||
}
|
||||
|
||||
@SuppressWarnings("argument.type.incompatible") // Platform class not annotated as nullable
|
||||
@DoNotInline
|
||||
static void setErrorMessage(PlaybackState.Builder builder, @Nullable CharSequence error) {
|
||||
builder.setErrorMessage(error);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void addCustomAction(
|
||||
PlaybackState.Builder builder, PlaybackState.CustomAction customAction) {
|
||||
builder.addCustomAction(customAction);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static void setActiveQueueItemId(PlaybackState.Builder builder, long id) {
|
||||
builder.setActiveQueueItemId(id);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static List<PlaybackState.CustomAction> getCustomActions(PlaybackState state) {
|
||||
return state.getCustomActions();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static PlaybackState build(PlaybackState.Builder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static int getState(PlaybackState state) {
|
||||
return state.getState();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static long getPosition(PlaybackState state) {
|
||||
return state.getPosition();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static long getBufferedPosition(PlaybackState state) {
|
||||
return state.getBufferedPosition();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static float getPlaybackSpeed(PlaybackState state) {
|
||||
return state.getPlaybackSpeed();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static long getActions(PlaybackState state) {
|
||||
return state.getActions();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@DoNotInline
|
||||
static CharSequence getErrorMessage(PlaybackState state) {
|
||||
return state.getErrorMessage();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static long getLastPositionUpdateTime(PlaybackState state) {
|
||||
return state.getLastPositionUpdateTime();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static long getActiveQueueItemId(PlaybackState state) {
|
||||
return state.getActiveQueueItemId();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static PlaybackState.CustomAction.Builder createCustomActionBuilder(
|
||||
String action, CharSequence name, int icon) {
|
||||
return new PlaybackState.CustomAction.Builder(action, name, icon);
|
||||
}
|
||||
|
||||
@SuppressWarnings("argument.type.incompatible") // Platform class not annotated as nullable
|
||||
@DoNotInline
|
||||
static void setExtras(PlaybackState.CustomAction.Builder builder, @Nullable Bundle extras) {
|
||||
builder.setExtras(extras);
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static PlaybackState.CustomAction build(PlaybackState.CustomAction.Builder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@DoNotInline
|
||||
static Bundle getExtras(PlaybackState.CustomAction customAction) {
|
||||
return customAction.getExtras();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static String getAction(PlaybackState.CustomAction customAction) {
|
||||
return customAction.getAction();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static CharSequence getName(PlaybackState.CustomAction customAction) {
|
||||
return customAction.getName();
|
||||
}
|
||||
|
||||
@DoNotInline
|
||||
static int getIcon(PlaybackState.CustomAction customAction) {
|
||||
return customAction.getIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(22)
|
||||
private static class Api22Impl {
|
||||
private Api22Impl() {}
|
||||
|
@ -323,6 +323,8 @@ public final class RatingCompat implements Parcelable {
|
||||
/**
|
||||
* Creates an instance from a framework {@link android.media.Rating} object.
|
||||
*
|
||||
* <p>This method is only supported on API 19+.
|
||||
*
|
||||
* @param ratingObj A {@link android.media.Rating} object, or null if none.
|
||||
* @return An equivalent {@link RatingCompat} object, or null if none.
|
||||
*/
|
||||
@ -364,6 +366,8 @@ public final class RatingCompat implements Parcelable {
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.Rating} object.
|
||||
*
|
||||
* <p>This method is only supported on API 19+.
|
||||
*
|
||||
* @return An equivalent {@link android.media.Rating} object, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
|
@ -19,8 +19,10 @@ import static androidx.annotation.RestrictTo.Scope.LIBRARY;
|
||||
|
||||
import android.media.VolumeProvider;
|
||||
import android.os.Build;
|
||||
import androidx.annotation.DoNotInline;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -59,6 +61,7 @@ public abstract class VolumeProviderCompat {
|
||||
private final int mMaxVolume;
|
||||
@Nullable private final String mControlId;
|
||||
private int mCurrentVolume;
|
||||
@Nullable private Callback mCallback;
|
||||
|
||||
@Nullable private VolumeProvider mVolumeProviderFwk;
|
||||
|
||||
@ -129,7 +132,13 @@ public abstract class VolumeProviderCompat {
|
||||
*/
|
||||
public final void setCurrentVolume(int currentVolume) {
|
||||
mCurrentVolume = currentVolume;
|
||||
getVolumeProvider().setCurrentVolume(currentVolume);
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
VolumeProvider volumeProviderFwk = (VolumeProvider) getVolumeProvider();
|
||||
Api21Impl.setCurrentVolume(volumeProviderFwk, currentVolume);
|
||||
}
|
||||
if (mCallback != null) {
|
||||
mCallback.onVolumeChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,12 +166,24 @@ public abstract class VolumeProviderCompat {
|
||||
*/
|
||||
public void onAdjustVolume(int direction) {}
|
||||
|
||||
/**
|
||||
* Sets a callback to receive volume changes.
|
||||
*
|
||||
* <p>Used internally by the support library.
|
||||
*/
|
||||
public void setCallback(@Nullable Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the underlying framework {@link android.media.VolumeProvider} object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @return An equivalent {@link android.media.VolumeProvider} object, or null if none.
|
||||
*/
|
||||
public VolumeProvider getVolumeProvider() {
|
||||
@RequiresApi(21)
|
||||
public Object getVolumeProvider() {
|
||||
if (mVolumeProviderFwk == null) {
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
mVolumeProviderFwk =
|
||||
@ -194,4 +215,19 @@ public abstract class VolumeProviderCompat {
|
||||
}
|
||||
return mVolumeProviderFwk;
|
||||
}
|
||||
|
||||
/** Listens for changes to the volume. */
|
||||
public abstract static class Callback {
|
||||
public abstract void onVolumeChanged(VolumeProviderCompat volumeProvider);
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static class Api21Impl {
|
||||
private Api21Impl() {}
|
||||
|
||||
@DoNotInline
|
||||
static void setCurrentVolume(VolumeProvider volumeProvider, int currentVolume) {
|
||||
volumeProvider.setCurrentVolume(currentVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ import static org.hamcrest.core.IsNot.not;
|
||||
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SdkSuppress;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -50,7 +52,11 @@ public class AudioAttributesCompatTest {
|
||||
AudioAttributesCompat mNotificationLegacyAAC;
|
||||
|
||||
@Before
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
public void setUpApi21() {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
return;
|
||||
}
|
||||
mMediaAA =
|
||||
new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
@ -74,6 +80,7 @@ public class AudioAttributesCompatTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
public void testCreateWithAudioAttributesApi21() {
|
||||
assertThat(mMediaAACFromAA, not(equalTo(null)));
|
||||
assertThat((AudioAttributes) mMediaAACFromAA.unwrap(), equalTo(mMediaAA));
|
||||
@ -83,6 +90,7 @@ public class AudioAttributesCompatTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
public void testEqualityApi21() {
|
||||
assertThat("self equality", mMediaAACFromAA, equalTo(mMediaAACFromAA));
|
||||
assertThat("different things", mMediaAACFromAA, not(equalTo(mNotificationAAC)));
|
||||
@ -118,6 +126,7 @@ public class AudioAttributesCompatTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
public void testLegacyStreamTypeInferenceApi21() {
|
||||
assertThat(mMediaAACFromAA.getLegacyStreamType(), equalTo(AudioManager.STREAM_MUSIC));
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.media3.test.session.common.TestUtils;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SdkSuppress;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -29,6 +30,7 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MediaDescriptionCompatTest {
|
||||
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
@Test
|
||||
public void roundTripViaFrameworkObject_returnsEqualMediaUriAndExtras() {
|
||||
Uri mediaUri = Uri.parse("androidx://media/uri");
|
||||
@ -52,6 +54,7 @@ public class MediaDescriptionCompatTest {
|
||||
TestUtils.equals(createExtras(), restoredDescription2.getExtras());
|
||||
}
|
||||
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
@Test
|
||||
public void getMediaDescription_withMediaUri_doesNotTouchExtras() {
|
||||
MediaDescriptionCompat originalDescription =
|
||||
|
Loading…
x
Reference in New Issue
Block a user