Use ParceledListSlice in MediaSessionManager#getSession2Tokens

Bug: 126474946
Test: atest CtsMediaTestCases:android.media.cts.MediaSession2Test;
      atest CtsMediaTestCases:android.media.cts.MediaController2Test;
      atest CtsMediaTestCases:android.media.cts.MediaSession2ServiceTest;
      atest CtsMediaTestCases:android.media.cts.MediaSessionManagerTest;
Change-Id: Ia364853d6cf638ab7128c64693b6a8cc6063036a
diff --git a/media/java/android/media/session/ISessionManager.aidl b/media/java/android/media/session/ISessionManager.aidl
index e073a4e..a67a37e 100644
--- a/media/java/android/media/session/ISessionManager.aidl
+++ b/media/java/android/media/session/ISessionManager.aidl
@@ -16,6 +16,7 @@
 package android.media.session;
 
 import android.content.ComponentName;
+import android.content.pm.ParceledListSlice;
 import android.media.IRemoteVolumeController;
 import android.media.Session2Token;
 import android.media.session.IActiveSessionsListener;
@@ -38,7 +39,7 @@
             in Bundle sessionInfo, int userId);
     void notifySession2Created(in Session2Token sessionToken);
     List<MediaSession.Token> getSessions(in ComponentName compName, int userId);
-    List<Session2Token> getSession2Tokens(int userId);
+    ParceledListSlice getSession2Tokens(int userId);
     void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
             boolean needWakeLock);
     boolean dispatchMediaKeyEventToSessionAsSystemService(String packageName,
diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java
index 51e3a4d..569d11e 100644
--- a/media/java/android/media/session/MediaSessionManager.java
+++ b/media/java/android/media/session/MediaSessionManager.java
@@ -24,6 +24,7 @@
 import android.annotation.UnsupportedAppUsage;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.pm.ParceledListSlice;
 import android.media.AudioManager;
 import android.media.IRemoteVolumeController;
 import android.media.MediaSession2;
@@ -218,7 +219,8 @@
     @NonNull
     public List<Session2Token> getSession2Tokens(int userId) {
         try {
-            return mService.getSession2Tokens(userId);
+            ParceledListSlice slice = mService.getSession2Tokens(userId);
+            return slice == null ? new ArrayList<>() : slice.getList();
         } catch (RemoteException e) {
             Log.e(TAG, "Failed to get session tokens", e);
         }
diff --git a/services/core/java/com/android/server/media/MediaSessionServiceImpl.java b/services/core/java/com/android/server/media/MediaSessionServiceImpl.java
index fdb499b..aa886c2 100644
--- a/services/core/java/com/android/server/media/MediaSessionServiceImpl.java
+++ b/services/core/java/com/android/server/media/MediaSessionServiceImpl.java
@@ -33,6 +33,7 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ParceledListSlice;
 import android.content.pm.ServiceInfo;
 import android.content.pm.UserInfo;
 import android.database.ContentObserver;
@@ -1072,7 +1073,7 @@
         }
 
         @Override
-        public List<Session2Token> getSession2Tokens(int userId) {
+        public ParceledListSlice getSession2Tokens(int userId) {
             final int pid = Binder.getCallingPid();
             final int uid = Binder.getCallingUid();
             final long token = Binder.clearCallingIdentity();
@@ -1087,7 +1088,7 @@
                 synchronized (mLock) {
                     result = getSession2TokensLocked(resolvedUserId);
                 }
-                return result;
+                return new ParceledListSlice(result);
             } finally {
                 Binder.restoreCallingIdentity(token);
             }