[go: nahoru, domu]

Create MediaSessionCompat.Token with session2 token if specified on SDK<21

Test: Ran following commands with SDK 16 and 30
      $ ./gradlew media:media:connectedCheck
      $ ./gradlew media2:media2-session:connectedCheck
      $ media/version-compat-tests/runtest.sh 4
      $ media2/session/version-compat-tests/runtest.sh 4
Change-Id: I20cc8f39820c781ecd780a6d5d00e04468f9fb6f
diff --git a/media/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java b/media/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
index 10d92562..982bcf6 100644
--- a/media/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
+++ b/media/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
@@ -571,11 +571,14 @@
             setCallback(new Callback() {}, handler);
             mImpl.setMediaButtonReceiver(mbrIntent);
         } else if (android.os.Build.VERSION.SDK_INT >= 19) {
-            mImpl = new MediaSessionImplApi19(context, tag, mbrComponent, mbrIntent, sessionInfo);
+            mImpl = new MediaSessionImplApi19(context, tag, mbrComponent, mbrIntent,
+                    session2Token, sessionInfo);
         } else if (android.os.Build.VERSION.SDK_INT >= 18) {
-            mImpl = new MediaSessionImplApi18(context, tag, mbrComponent, mbrIntent, sessionInfo);
+            mImpl = new MediaSessionImplApi18(context, tag, mbrComponent, mbrIntent,
+                    session2Token, sessionInfo);
         } else {
-            mImpl = new MediaSessionImplBase(context, tag, mbrComponent, mbrIntent, sessionInfo);
+            mImpl = new MediaSessionImplBase(context, tag, mbrComponent, mbrIntent, session2Token,
+                    sessionInfo);
         }
         mController = new MediaControllerCompat(context, this);
 
@@ -2408,7 +2411,7 @@
         };
 
         public MediaSessionImplBase(Context context, String tag, ComponentName mbrComponent,
-                PendingIntent mbrIntent, Bundle sessionInfo) {
+                PendingIntent mbrIntent, VersionedParcelable session2Token, Bundle sessionInfo) {
             if (mbrComponent == null) {
                 throw new IllegalArgumentException(
                         "MediaButtonReceiver component may not be null");
@@ -2421,7 +2424,7 @@
             mMediaButtonReceiverComponentName = mbrComponent;
             mMediaButtonReceiverIntent = mbrIntent;
             mStub = new MediaSessionStub();
-            mToken = new Token(mStub);
+            mToken = new Token(mStub, /* extraBinder= */ null, session2Token);
 
             mRatingType = RatingCompat.RATING_NONE;
             mVolumeType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
@@ -3599,8 +3602,8 @@
         private static boolean sIsMbrPendingIntentSupported = true;
 
         MediaSessionImplApi18(Context context, String tag, ComponentName mbrComponent,
-                PendingIntent mbrIntent, Bundle sessionInfo) {
-            super(context, tag, mbrComponent, mbrIntent, sessionInfo);
+                PendingIntent mbrIntent, VersionedParcelable session2Token, Bundle sessionInfo) {
+            super(context, tag, mbrComponent, mbrIntent, session2Token, sessionInfo);
         }
 
         @Override
@@ -3683,8 +3686,8 @@
     @RequiresApi(19)
     static class MediaSessionImplApi19 extends MediaSessionImplApi18 {
         MediaSessionImplApi19(Context context, String tag, ComponentName mbrComponent,
-                PendingIntent mbrIntent, Bundle sessionInfo) {
-            super(context, tag, mbrComponent, mbrIntent, sessionInfo);
+                PendingIntent mbrIntent, VersionedParcelable session2Token, Bundle sessionInfo) {
+            super(context, tag, mbrComponent, mbrIntent, session2Token, sessionInfo);
         }
 
         @Override