Loading media/java/android/media/MediaSession2.java +15 −1 Original line number Diff line number Diff line Loading @@ -464,7 +464,21 @@ public class MediaSession2 implements AutoCloseable { if (mId == null) { mId = ""; } return new MediaSession2(mContext, mId, mSessionActivity, mCallbackExecutor, mCallback); MediaSession2 session2 = new MediaSession2(mContext, mId, mSessionActivity, mCallbackExecutor, mCallback); // Notify framework about the newly create session after the constructor is finished. // Otherwise, framework may access the session before the initialization is finished. try { MediaSessionManager manager = (MediaSessionManager) mContext.getSystemService( Context.MEDIA_SESSION_SERVICE); manager.notifySession2Created(session2.getSessionToken()); } catch (Exception e) { session2.close(); throw e; } return session2; } } Loading media/java/android/media/Session2Token.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; parcelable Session2Token; media/java/android/media/Session2Token.java +3 −2 Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ public final class Session2Token implements Parcelable { private final ComponentName mComponentName; /** * Constructor for the token. * Constructor for the token with type {@link #TYPE_SESSION_SERVICE} or * {@link #TYPE_LIBRARY_SERVICE}. * * @param context The context. * @param serviceComponent The component name of the service. Loading @@ -119,7 +120,7 @@ public final class Session2Token implements Parcelable { final int uid = getUid(manager, serviceComponent.getPackageName()); // TODO: Uncomment below to stop hardcode type. final int type = TYPE_SESSION; final int type = TYPE_SESSION_SERVICE; // final int type; // if (isInterfaceDeclared(manager, MediaLibraryService2.SERVICE_INTERFACE, // serviceComponent)) { Loading media/java/android/media/session/ISessionManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.media.session; import android.content.ComponentName; import android.media.IRemoteVolumeController; import android.media.Session2Token; import android.media.session.IActiveSessionsListener; import android.media.session.ICallback; import android.media.session.IOnMediaKeyListener; Loading @@ -32,6 +33,7 @@ import android.view.KeyEvent; */ interface ISessionManager { ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId); void notifySession2Created(in Session2Token sessionToken); List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); Loading media/java/android/media/session/MediaSessionManager.java +26 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.content.ComponentName; import android.content.Context; import android.media.AudioManager; import android.media.IRemoteVolumeController; import android.media.MediaSession2; import android.media.Session2Token; import android.media.browse.MediaBrowser; import android.os.Handler; import android.os.IBinder; Loading Loading @@ -101,6 +103,30 @@ public final class MediaSessionManager { return mService.createSession(mContext.getPackageName(), cbStub, tag, userId); } /** * Notifies that a new {@link MediaSession2} with type {@link Session2Token#TYPE_SESSION} is * created. * <p> * Do not use this API directly, but create a new instance through the * {@link MediaSession2.Builder} instead. * * @param token newly created session2 token * @hide */ public void notifySession2Created(@NonNull Session2Token token) { if (token == null) { throw new IllegalArgumentException("token shouldn't be null"); } if (token.getType() != Session2Token.TYPE_SESSION) { throw new IllegalArgumentException("token's type should be TYPE_SESSION"); } try { mService.notifySession2Created(token); } catch (RemoteException e) { e.rethrowFromSystemServer(); } } /** * Get a list of controllers for all ongoing sessions. The controllers will * be provided in priority order with the most important controller at index Loading Loading
media/java/android/media/MediaSession2.java +15 −1 Original line number Diff line number Diff line Loading @@ -464,7 +464,21 @@ public class MediaSession2 implements AutoCloseable { if (mId == null) { mId = ""; } return new MediaSession2(mContext, mId, mSessionActivity, mCallbackExecutor, mCallback); MediaSession2 session2 = new MediaSession2(mContext, mId, mSessionActivity, mCallbackExecutor, mCallback); // Notify framework about the newly create session after the constructor is finished. // Otherwise, framework may access the session before the initialization is finished. try { MediaSessionManager manager = (MediaSessionManager) mContext.getSystemService( Context.MEDIA_SESSION_SERVICE); manager.notifySession2Created(session2.getSessionToken()); } catch (Exception e) { session2.close(); throw e; } return session2; } } Loading
media/java/android/media/Session2Token.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; parcelable Session2Token;
media/java/android/media/Session2Token.java +3 −2 Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ public final class Session2Token implements Parcelable { private final ComponentName mComponentName; /** * Constructor for the token. * Constructor for the token with type {@link #TYPE_SESSION_SERVICE} or * {@link #TYPE_LIBRARY_SERVICE}. * * @param context The context. * @param serviceComponent The component name of the service. Loading @@ -119,7 +120,7 @@ public final class Session2Token implements Parcelable { final int uid = getUid(manager, serviceComponent.getPackageName()); // TODO: Uncomment below to stop hardcode type. final int type = TYPE_SESSION; final int type = TYPE_SESSION_SERVICE; // final int type; // if (isInterfaceDeclared(manager, MediaLibraryService2.SERVICE_INTERFACE, // serviceComponent)) { Loading
media/java/android/media/session/ISessionManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.media.session; import android.content.ComponentName; import android.media.IRemoteVolumeController; import android.media.Session2Token; import android.media.session.IActiveSessionsListener; import android.media.session.ICallback; import android.media.session.IOnMediaKeyListener; Loading @@ -32,6 +33,7 @@ import android.view.KeyEvent; */ interface ISessionManager { ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId); void notifySession2Created(in Session2Token sessionToken); List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); Loading
media/java/android/media/session/MediaSessionManager.java +26 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.content.ComponentName; import android.content.Context; import android.media.AudioManager; import android.media.IRemoteVolumeController; import android.media.MediaSession2; import android.media.Session2Token; import android.media.browse.MediaBrowser; import android.os.Handler; import android.os.IBinder; Loading Loading @@ -101,6 +103,30 @@ public final class MediaSessionManager { return mService.createSession(mContext.getPackageName(), cbStub, tag, userId); } /** * Notifies that a new {@link MediaSession2} with type {@link Session2Token#TYPE_SESSION} is * created. * <p> * Do not use this API directly, but create a new instance through the * {@link MediaSession2.Builder} instead. * * @param token newly created session2 token * @hide */ public void notifySession2Created(@NonNull Session2Token token) { if (token == null) { throw new IllegalArgumentException("token shouldn't be null"); } if (token.getType() != Session2Token.TYPE_SESSION) { throw new IllegalArgumentException("token's type should be TYPE_SESSION"); } try { mService.notifySession2Created(token); } catch (RemoteException e) { e.rethrowFromSystemServer(); } } /** * Get a list of controllers for all ongoing sessions. The controllers will * be provided in priority order with the most important controller at index Loading