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

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

Merge "Remove ControllerLink"

parents f7a0b284 8b1f9759
Loading
Loading
Loading
Loading
+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 ControllerLink;
+0 −1042

File deleted.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ import android.app.PendingIntent;
import android.media.AudioAttributes;
import android.media.MediaMetadata;
import android.media.MediaParceledListSlice;
import android.media.session.ControllerLink;
import android.media.session.ISessionController;
import android.media.session.PlaybackState;
import android.media.session.MediaSession;
import android.os.Bundle;
@@ -31,7 +31,7 @@ import android.os.ResultReceiver;
 */
interface ISession {
    void sendEvent(String event, in Bundle data);
    ControllerLink getController();
    ISessionController getController();
    void setFlags(int flags);
    void setActive(boolean active);
    void setMediaButtonReceiver(in PendingIntent mbr);
+47 −44
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaMetadata;
import android.media.MediaParceledListSlice;
import android.media.Rating;
import android.media.VolumeProvider;
import android.media.session.MediaSession.QueueItem;
@@ -34,6 +35,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.text.TextUtils;
import android.util.Log;
@@ -67,7 +69,7 @@ public final class MediaController {
    private static final int MSG_UPDATE_EXTRAS = 7;
    private static final int MSG_DESTROYED = 8;

    private final ControllerLink mSessionBinder;
    private final ISessionController mSessionBinder;

    private final MediaSession.Token mToken;
    private final Context mContext;
@@ -95,10 +97,10 @@ public final class MediaController {
        if (token == null) {
            throw new IllegalArgumentException("token shouldn't be null");
        }
        if (token.getControllerLink() == null) {
            throw new IllegalArgumentException("token.getControllerLink() shouldn't be null");
        if (token.getBinder() == null) {
            throw new IllegalArgumentException("token.getBinder() shouldn't be null");
        }
        mSessionBinder = token.getControllerLink();
        mSessionBinder = token.getBinder();
        mTransportControls = new TransportControls();
        mToken = token;
        mContext = context;
@@ -131,7 +133,7 @@ public final class MediaController {
        }
        try {
            return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub, keyEvent);
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            // System is dead. =(
        }
        return false;
@@ -145,7 +147,7 @@ public final class MediaController {
    public @Nullable PlaybackState getPlaybackState() {
        try {
            return mSessionBinder.getPlaybackState();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getPlaybackState.", e);
            return null;
        }
@@ -159,7 +161,7 @@ public final class MediaController {
    public @Nullable MediaMetadata getMetadata() {
        try {
            return mSessionBinder.getMetadata();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getMetadata.", e);
            return null;
        }
@@ -173,8 +175,9 @@ public final class MediaController {
     */
    public @Nullable List<MediaSession.QueueItem> getQueue() {
        try {
            return mSessionBinder.getQueue();
        } catch (RuntimeException e) {
            MediaParceledListSlice list = mSessionBinder.getQueue();
            return list == null ? null : list.getList();
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getQueue.", e);
        }
        return null;
@@ -186,7 +189,7 @@ public final class MediaController {
    public @Nullable CharSequence getQueueTitle() {
        try {
            return mSessionBinder.getQueueTitle();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getQueueTitle", e);
        }
        return null;
@@ -198,7 +201,7 @@ public final class MediaController {
    public @Nullable Bundle getExtras() {
        try {
            return mSessionBinder.getExtras();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getExtras", e);
        }
        return null;
@@ -221,7 +224,7 @@ public final class MediaController {
    public int getRatingType() {
        try {
            return mSessionBinder.getRatingType();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getRatingType.", e);
            return Rating.RATING_NONE;
        }
@@ -235,7 +238,7 @@ public final class MediaController {
    public long getFlags() {
        try {
            return mSessionBinder.getFlags();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getFlags.", e);
        }
        return 0;
@@ -249,7 +252,7 @@ public final class MediaController {
    public @Nullable PlaybackInfo getPlaybackInfo() {
        try {
            return mSessionBinder.getVolumeAttributes();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getAudioInfo.", e);
        }
        return null;
@@ -264,7 +267,7 @@ public final class MediaController {
    public @Nullable PendingIntent getSessionActivity() {
        try {
            return mSessionBinder.getLaunchPendingIntent();
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling getPendingIntent.", e);
        }
        return null;
@@ -297,7 +300,7 @@ public final class MediaController {
            //       AppOpsManager usages.
            mSessionBinder.setVolumeTo(mContext.getPackageName(), mContext.getOpPackageName(),
                    mCbStub, value, flags);
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling setVolumeTo.", e);
        }
    }
@@ -322,7 +325,7 @@ public final class MediaController {
            //       AppOpsManager usages.
            mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(),
                    mCbStub, direction, flags);
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
        }
    }
@@ -388,7 +391,7 @@ public final class MediaController {
        }
        try {
            mSessionBinder.sendCommand(mContext.getPackageName(), mCbStub, command, args, cb);
        } catch (RuntimeException e) {
        } catch (RemoteException e) {
            Log.d(TAG, "Dead object in sendCommand.", e);
        }
    }
@@ -402,7 +405,7 @@ public final class MediaController {
        if (mPackageName == null) {
            try {
                mPackageName = mSessionBinder.getPackageName();
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.d(TAG, "Dead object in getPackageName.", e);
            }
        }
@@ -419,7 +422,7 @@ public final class MediaController {
        if (mSessionInfo == null) {
            try {
                mSessionInfo = mSessionBinder.getSessionInfo();
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.d(TAG, "Dead object in getSessionInfo.", e);
            }
        }
@@ -436,7 +439,7 @@ public final class MediaController {
        if (mTag == null) {
            try {
                mTag = mSessionBinder.getTag();
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.d(TAG, "Dead object in getTag.", e);
            }
        }
@@ -446,7 +449,7 @@ public final class MediaController {
    /*
     * @hide
     */
    ControllerLink getSessionBinder() {
    ISessionController getSessionBinder() {
        return mSessionBinder;
    }

@@ -456,7 +459,7 @@ public final class MediaController {
    @UnsupportedAppUsage
    public boolean controlsSameSession(MediaController other) {
        if (other == null) return false;
        return mSessionBinder.getBinder() == other.getSessionBinder().getBinder();
        return mSessionBinder.asBinder() == other.getSessionBinder().asBinder();
    }

    private void addCallbackLocked(Callback cb, Handler handler) {
@@ -472,7 +475,7 @@ public final class MediaController {
            try {
                mSessionBinder.registerCallback(mContext.getPackageName(), mCbStub);
                mCbRegistered = true;
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "Dead object in registerCallback", e);
            }
        }
@@ -491,7 +494,7 @@ public final class MediaController {
        if (mCbRegistered && mCallbacks.size() == 0) {
            try {
                mSessionBinder.unregisterCallback(mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "Dead object in removeCallbackLocked");
            }
            mCbRegistered = false;
@@ -618,7 +621,7 @@ public final class MediaController {
        public void prepare() {
            try {
                mSessionBinder.prepare(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare.", e);
            }
        }
@@ -643,7 +646,7 @@ public final class MediaController {
            try {
                mSessionBinder.prepareFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                        extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e);
            }
        }
@@ -670,7 +673,7 @@ public final class MediaController {
            try {
                mSessionBinder.prepareFromSearch(mContext.getPackageName(), mCbStub, query,
                        extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + query + ").", e);
            }
        }
@@ -694,7 +697,7 @@ public final class MediaController {
            }
            try {
                mSessionBinder.prepareFromUri(mContext.getPackageName(), mCbStub, uri, extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + uri + ").", e);
            }
        }
@@ -705,7 +708,7 @@ public final class MediaController {
        public void play() {
            try {
                mSessionBinder.play(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play.", e);
            }
        }
@@ -725,7 +728,7 @@ public final class MediaController {
            try {
                mSessionBinder.playFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                        extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + mediaId + ").", e);
            }
        }
@@ -747,7 +750,7 @@ public final class MediaController {
            }
            try {
                mSessionBinder.playFromSearch(mContext.getPackageName(), mCbStub, query, extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + query + ").", e);
            }
        }
@@ -766,7 +769,7 @@ public final class MediaController {
            }
            try {
                mSessionBinder.playFromUri(mContext.getPackageName(), mCbStub, uri, extras);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + uri + ").", e);
            }
        }
@@ -778,7 +781,7 @@ public final class MediaController {
        public void skipToQueueItem(long id) {
            try {
                mSessionBinder.skipToQueueItem(mContext.getPackageName(), mCbStub, id);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e);
            }
        }
@@ -790,7 +793,7 @@ public final class MediaController {
        public void pause() {
            try {
                mSessionBinder.pause(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling pause.", e);
            }
        }
@@ -802,7 +805,7 @@ public final class MediaController {
        public void stop() {
            try {
                mSessionBinder.stop(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling stop.", e);
            }
        }
@@ -815,7 +818,7 @@ public final class MediaController {
        public void seekTo(long pos) {
            try {
                mSessionBinder.seekTo(mContext.getPackageName(), mCbStub, pos);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling seekTo.", e);
            }
        }
@@ -827,7 +830,7 @@ public final class MediaController {
        public void fastForward() {
            try {
                mSessionBinder.fastForward(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling fastForward.", e);
            }
        }
@@ -838,7 +841,7 @@ public final class MediaController {
        public void skipToNext() {
            try {
                mSessionBinder.next(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling next.", e);
            }
        }
@@ -850,7 +853,7 @@ public final class MediaController {
        public void rewind() {
            try {
                mSessionBinder.rewind(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling rewind.", e);
            }
        }
@@ -861,7 +864,7 @@ public final class MediaController {
        public void skipToPrevious() {
            try {
                mSessionBinder.previous(mContext.getPackageName(), mCbStub);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling previous.", e);
            }
        }
@@ -876,7 +879,7 @@ public final class MediaController {
        public void setRating(Rating rating) {
            try {
                mSessionBinder.rate(mContext.getPackageName(), mCbStub, rating);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling rate.", e);
            }
        }
@@ -889,7 +892,7 @@ public final class MediaController {
        public void setPlaybackSpeed(float speed) {
            try {
                mSessionBinder.setPlaybackSpeed(mContext.getPackageName(), mCbStub, speed);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling setPlaybackSpeed.", e);
            }
        }
@@ -924,7 +927,7 @@ public final class MediaController {
            }
            try {
                mSessionBinder.sendCustomAction(mContext.getPackageName(), mCbStub, action, args);
            } catch (RuntimeException e) {
            } catch (RemoteException e) {
                Log.d(TAG, "Dead object in sendCustomAction.", e);
            }
        }
+13 −11
Original line number Diff line number Diff line
@@ -445,19 +445,19 @@ public final class MediaSession {
    public static final class Token implements Parcelable {

        private final int mUid;
        private final ControllerLink mControllerLink;
        private final ISessionController mBinder;

        /**
         * @hide
         */
        public Token(ControllerLink controllerLink) {
        public Token(ISessionController binder) {
            mUid = Process.myUid();
            mControllerLink = controllerLink;
            mBinder = binder;
        }

        Token(Parcel in) {
            mUid = in.readInt();
            mControllerLink = in.readParcelable(null);
            mBinder = ISessionController.Stub.asInterface(in.readStrongBinder());
        }

        @Override
@@ -468,15 +468,14 @@ public final class MediaSession {
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mUid);
            dest.writeParcelable(mControllerLink, flags);
            dest.writeStrongBinder(mBinder.asBinder());
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = mUid;
            result = prime * result + ((mControllerLink == null)
                    ? 0 : mControllerLink.getBinder().hashCode());
            result = prime * result + (mBinder == null ? 0 : mBinder.asBinder().hashCode());
            return result;
        }

@@ -492,7 +491,10 @@ public final class MediaSession {
            if (mUid != other.mUid) {
                return false;
            }
            return Objects.equals(mControllerLink, other.mControllerLink);
            if (mBinder == null || other.mBinder == null) {
                return mBinder == other.mBinder;
            }
            return Objects.equals(mBinder.asBinder(), other.mBinder.asBinder());
        }

        /**
@@ -504,11 +506,11 @@ public final class MediaSession {
        }

        /**
         * Gets the controller link in this token.
         * Gets the controller binder in this token.
         * @hide
         */
        public ControllerLink getControllerLink() {
            return mControllerLink;
        public ISessionController getBinder() {
            return mBinder;
        }

        public static final @android.annotation.NonNull Parcelable.Creator<Token> CREATOR =
Loading