Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba7f46d1 authored by Hyundo Moon's avatar Hyundo Moon Committed by Android (Google) Code Review
Browse files

Merge "Remove SessionLink"

parents 65d986c9 24f366b7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@ import android.media.session.IActiveSessionsListener;
import android.media.session.ICallback;
import android.media.session.IOnMediaKeyListener;
import android.media.session.IOnVolumeKeyLongPressListener;
import android.media.session.ISession;
import android.media.session.ISession2TokensListener;
import android.media.session.MediaSession;
import android.media.session.SessionCallbackLink;
import android.media.session.SessionLink;
import android.os.Bundle;
import android.view.KeyEvent;

@@ -34,7 +34,7 @@ import android.view.KeyEvent;
 * @hide
 */
interface ISessionManager {
    SessionLink createSession(String packageName, in SessionCallbackLink sessionCb, String tag,
    ISession createSession(String packageName, in SessionCallbackLink sessionCb, String tag,
            in Bundle sessionInfo, int userId);
    void notifySession2Created(in Session2Token sessionToken);
    List<MediaSession.Token> getSessions(in ComponentName compName, int userId);
+4 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.service.media.MediaBrowserService;
import android.text.TextUtils;
@@ -163,11 +164,11 @@ public final class MediaSession {
                .getSystemService(Context.MEDIA_SESSION_SERVICE);
        try {
            SessionCallbackLink cbLink = new SessionCallbackLink(context);
            SessionLink sessionLink = manager.createSession(cbLink, tag, sessionInfo);
            mImpl = new MediaSessionEngine(context, sessionLink, cbLink);
            ISession binder = manager.createSession(cbLink, tag, sessionInfo);
            mImpl = new MediaSessionEngine(context, binder, cbLink);
            mMaxBitmapSize = context.getResources().getDimensionPixelSize(
                    com.android.internal.R.dimen.config_mediaMetadataBitmapMaxSize);
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            throw new RuntimeException("Remote error creating session.", e);
        }
    }
+39 −37
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Intent;
import android.media.AudioAttributes;
import android.media.MediaDescription;
import android.media.MediaMetadata;
import android.media.MediaParceledListSlice;
import android.media.Rating;
import android.media.VolumeProvider;
import android.media.session.MediaSessionManager.RemoteUserInfo;
@@ -34,6 +35,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.service.media.MediaBrowserService;
import android.text.TextUtils;
@@ -55,7 +57,7 @@ public final class MediaSessionEngine implements AutoCloseable {

    private final MediaSession.Token mSessionToken;
    private final MediaController mController;
    private final SessionLink mSessionLink;
    private final ISession mBinder;

    private CallbackMessageHandler mCallbackHandler;
    private VolumeProvider mVolumeProvider;
@@ -70,14 +72,14 @@ public final class MediaSessionEngine implements AutoCloseable {
     * finished with the session.
     *
     * @param context The context to use to create the session.
     * @param sessionLink A session link for the binder of MediaSessionRecord
     * @param binder A session binder
     */
    public MediaSessionEngine(@NonNull Context context, @NonNull SessionLink sessionLink,
            @NonNull SessionCallbackLink cbLink) {
        mSessionLink = sessionLink;
    public MediaSessionEngine(@NonNull Context context, @NonNull ISession binder,
            @NonNull SessionCallbackLink cbLink) throws RemoteException {
        mBinder = binder;

        cbLink.setSessionEngine(this);
        mSessionToken = new MediaSession.Token(mSessionLink.getController());
        mSessionToken = new MediaSession.Token(mBinder.getController());
        mController = new MediaController(context, mSessionToken);
    }

@@ -134,8 +136,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setSessionActivity(@Nullable PendingIntent pi) {
        try {
            mSessionLink.setLaunchPendingIntent(pi);
        } catch (RuntimeException e) {
            mBinder.setLaunchPendingIntent(pi);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setLaunchPendingIntent.", e);
        }
    }
@@ -150,8 +152,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setMediaButtonReceiver(@Nullable PendingIntent mbr) {
        try {
            mSessionLink.setMediaButtonReceiver(mbr);
        } catch (RuntimeException e) {
            mBinder.setMediaButtonReceiver(mbr);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setMediaButtonReceiver.", e);
        }
    }
@@ -163,8 +165,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setFlags(int flags) {
        try {
            mSessionLink.setFlags(flags);
        } catch (RuntimeException e) {
            mBinder.setFlags(flags);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setFlags.", e);
        }
    }
@@ -185,8 +187,8 @@ public final class MediaSessionEngine implements AutoCloseable {
            throw new IllegalArgumentException("Attributes cannot be null for local playback.");
        }
        try {
            mSessionLink.setPlaybackToLocal(attributes);
        } catch (RuntimeException e) {
            mBinder.setPlaybackToLocal(attributes);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToLocal.", e);
        }
    }
@@ -217,10 +219,10 @@ public final class MediaSessionEngine implements AutoCloseable {
        });

        try {
            mSessionLink.setPlaybackToRemote(volumeProvider.getVolumeControl(),
            mBinder.setPlaybackToRemote(volumeProvider.getVolumeControl(),
                    volumeProvider.getMaxVolume());
            mSessionLink.setCurrentVolume(volumeProvider.getCurrentVolume());
        } catch (RuntimeException e) {
            mBinder.setCurrentVolume(volumeProvider.getCurrentVolume());
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToRemote.", e);
        }
    }
@@ -238,9 +240,9 @@ public final class MediaSessionEngine implements AutoCloseable {
            return;
        }
        try {
            mSessionLink.setActive(active);
            mBinder.setActive(active);
            mActive = active;
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setActive.", e);
        }
    }
@@ -267,8 +269,8 @@ public final class MediaSessionEngine implements AutoCloseable {
            throw new IllegalArgumentException("event cannot be null or empty");
        }
        try {
            mSessionLink.sendEvent(event, extras);
        } catch (RuntimeException e) {
            mBinder.sendEvent(event, extras);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error sending event", e);
        }
    }
@@ -280,8 +282,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void close() {
        try {
            mSessionLink.destroySession();
        } catch (RuntimeException e) {
            mBinder.destroySession();
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error releasing session: ", e);
        }
    }
@@ -316,8 +318,8 @@ public final class MediaSessionEngine implements AutoCloseable {
    public void setPlaybackState(@Nullable PlaybackState state) {
        mPlaybackState = state;
        try {
            mSessionLink.setPlaybackState(state);
        } catch (RuntimeException e) {
            mBinder.setPlaybackState(state);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Dead object in setPlaybackState.", e);
        }
    }
@@ -344,8 +346,8 @@ public final class MediaSessionEngine implements AutoCloseable {
        String metadataDescription = "size=" + fields + ", description=" + description;

        try {
            mSessionLink.setMetadata(metadata, duration, metadataDescription);
        } catch (RuntimeException e) {
            mBinder.setMetadata(metadata, duration, metadataDescription);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Dead object in setPlaybackState.", e);
        }
    }
@@ -363,8 +365,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setQueue(@Nullable List<MediaSession.QueueItem> queue) {
        try {
            mSessionLink.setQueue(queue);
        } catch (RuntimeException e) {
            mBinder.setQueue(queue == null ? null : new MediaParceledListSlice(queue));
        } catch (RemoteException e) {
            Log.wtf("Dead object in setQueue.", e);
        }
    }
@@ -378,8 +380,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setQueueTitle(@Nullable CharSequence title) {
        try {
            mSessionLink.setQueueTitle(title);
        } catch (RuntimeException e) {
            mBinder.setQueueTitle(title);
        } catch (RemoteException e) {
            Log.wtf("Dead object in setQueueTitle.", e);
        }
    }
@@ -399,8 +401,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setRatingType(int type) {
        try {
            mSessionLink.setRatingType(type);
        } catch (RuntimeException e) {
            mBinder.setRatingType(type);
        } catch (RemoteException e) {
            Log.e(TAG, "Error in setRatingType.", e);
        }
    }
@@ -414,8 +416,8 @@ public final class MediaSessionEngine implements AutoCloseable {
     */
    public void setExtras(@Nullable Bundle extras) {
        try {
            mSessionLink.setExtras(extras);
        } catch (RuntimeException e) {
            mBinder.setExtras(extras);
        } catch (RemoteException e) {
            Log.wtf("Dead object in setExtras.", e);
        }
    }
@@ -464,8 +466,8 @@ public final class MediaSessionEngine implements AutoCloseable {
            }
        }
        try {
            mSessionLink.setCurrentVolume(provider.getCurrentVolume());
        } catch (RuntimeException e) {
            mBinder.setCurrentVolume(provider.getCurrentVolume());
        } catch (RemoteException e) {
            Log.e(TAG, "Error in notifyVolumeChanged", e);
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public final class MediaSessionManager {
     * @hide
     */
    @NonNull
    public SessionLink createSession(@NonNull SessionCallbackLink cbStub, @NonNull String tag,
    public ISession createSession(@NonNull SessionCallbackLink cbStub, @NonNull String tag,
            @Nullable Bundle sessionInfo) {
        try {
            return mService.createSession(mContext.getPackageName(), cbStub, tag, sessionInfo,
+0 −19
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.session;

parcelable SessionLink;
Loading