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

Commit de682285 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaController: Use Context#getPackageName() for RemoteUserInfo

Bug: 111817607, Bug: 111817367
Test: Manual test, incluing the scenario at b/110525559
Change-Id: I1e5f7ba4d04d7b1f414cbdcd723e208f0fea29c3
parent f25675d3
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -48,9 +48,9 @@ interface ISessionController {
    PendingIntent getLaunchPendingIntent();
    PendingIntent getLaunchPendingIntent();
    long getFlags();
    long getFlags();
    ParcelableVolumeInfo getVolumeAttributes();
    ParcelableVolumeInfo getVolumeAttributes();
    void adjustVolume(String packageName, ISessionControllerCallback caller,
    void adjustVolume(String packageName, String opPackageName, ISessionControllerCallback caller,
            boolean asSystemService, int direction, int flags);
            boolean asSystemService, int direction, int flags);
    void setVolumeTo(String packageName, ISessionControllerCallback caller,
    void setVolumeTo(String packageName, String opPackageName, ISessionControllerCallback caller,
            int value, int flags);
            int value, int flags);


    // These commands are for the TransportControls
    // These commands are for the TransportControls
+4 −12
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@ package android.media.session;


import android.content.ComponentName;
import android.content.ComponentName;
import android.media.IRemoteVolumeController;
import android.media.IRemoteVolumeController;
import android.media.ISessionTokensListener;
import android.media.session.IActiveSessionsListener;
import android.media.session.IActiveSessionsListener;
import android.media.session.ICallback;
import android.media.session.ICallback;
import android.media.session.IOnMediaKeyListener;
import android.media.session.IOnMediaKeyListener;
@@ -36,9 +35,10 @@ interface ISessionManager {
    List<IBinder> getSessions(in ComponentName compName, int userId);
    List<IBinder> getSessions(in ComponentName compName, int userId);
    void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
    void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
            boolean needWakeLock);
            boolean needWakeLock);
    void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
    void dispatchVolumeKeyEvent(String packageName, String opPackageName, boolean asSystemService,
            int stream, boolean musicOnly);
            in KeyEvent keyEvent, int stream, boolean musicOnly);
    void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags);
    void dispatchAdjustVolume(String packageName, String opPackageName, int suggestedStream,
            int delta, int flags);
    void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName,
    void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName,
            int userId);
            int userId);
    void removeSessionsListener(in IActiveSessionsListener listener);
    void removeSessionsListener(in IActiveSessionsListener listener);
@@ -55,12 +55,4 @@ interface ISessionManager {


    // MediaSession2
    // MediaSession2
    boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid);
    boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid);
    boolean createSession2(in Bundle sessionToken);
    void destroySession2(in Bundle sessionToken);
    List<Bundle> getSessionTokens(boolean activeSessionOnly, boolean sessionServiceOnly,
            String packageName);

    void addSessionTokensListener(in ISessionTokensListener listener, int userId,
            String packageName);
    void removeSessionTokensListener(in ISessionTokensListener listener, String packageName);
}
}
+30 −28
Original line number Original line Diff line number Diff line
@@ -153,7 +153,7 @@ public final class MediaController {
            return false;
            return false;
        }
        }
        try {
        try {
            return mSessionBinder.sendMediaButton(mContext.getOpPackageName(), mCbStub,
            return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub,
                    asSystemService, keyEvent);
                    asSystemService, keyEvent);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            // System is dead. =(
            // System is dead. =(
@@ -186,8 +186,9 @@ public final class MediaController {
                        break;
                        break;
                }
                }
                try {
                try {
                    mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true,
                    mSessionBinder.adjustVolume(mContext.getPackageName(),
                            direction, AudioManager.FLAG_SHOW_UI);
                            mContext.getOpPackageName(), mCbStub, true, direction,
                            AudioManager.FLAG_SHOW_UI);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                }
                }
@@ -197,8 +198,8 @@ public final class MediaController {
                final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE
                final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE
                        | AudioManager.FLAG_FROM_KEY;
                        | AudioManager.FLAG_FROM_KEY;
                try {
                try {
                    mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true, 0,
                    mSessionBinder.adjustVolume(mContext.getPackageName(),
                            flags);
                            mContext.getOpPackageName(), mCbStub, true, 0, flags);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                }
                }
@@ -367,7 +368,8 @@ public final class MediaController {
     */
     */
    public void setVolumeTo(int value, int flags) {
    public void setVolumeTo(int value, int flags) {
        try {
        try {
            mSessionBinder.setVolumeTo(mContext.getOpPackageName(), mCbStub, value, flags);
            mSessionBinder.setVolumeTo(mContext.getPackageName(), mContext.getOpPackageName(),
                    mCbStub, value, flags);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling setVolumeTo.", e);
            Log.wtf(TAG, "Error calling setVolumeTo.", e);
        }
        }
@@ -388,8 +390,8 @@ public final class MediaController {
     */
     */
    public void adjustVolume(int direction, int flags) {
    public void adjustVolume(int direction, int flags) {
        try {
        try {
            mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, false, direction,
            mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(),
                    flags);
                    mCbStub, false, direction, flags);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
            Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
        }
        }
@@ -455,7 +457,7 @@ public final class MediaController {
            throw new IllegalArgumentException("command cannot be null or empty");
            throw new IllegalArgumentException("command cannot be null or empty");
        }
        }
        try {
        try {
            mSessionBinder.sendCommand(mContext.getOpPackageName(), mCbStub, command, args, cb);
            mSessionBinder.sendCommand(mContext.getPackageName(), mCbStub, command, args, cb);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.d(TAG, "Dead object in sendCommand.", e);
            Log.d(TAG, "Dead object in sendCommand.", e);
        }
        }
@@ -521,7 +523,7 @@ public final class MediaController {


        if (!mCbRegistered) {
        if (!mCbRegistered) {
            try {
            try {
                mSessionBinder.registerCallbackListener(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.registerCallbackListener(mContext.getPackageName(), mCbStub);
                mCbRegistered = true;
                mCbRegistered = true;
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "Dead object in registerCallback", e);
                Log.e(TAG, "Dead object in registerCallback", e);
@@ -668,7 +670,7 @@ public final class MediaController {
         */
         */
        public void prepare() {
        public void prepare() {
            try {
            try {
                mSessionBinder.prepare(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.prepare(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare.", e);
                Log.wtf(TAG, "Error calling prepare.", e);
            }
            }
@@ -692,7 +694,7 @@ public final class MediaController {
                        "You must specify a non-empty String for prepareFromMediaId.");
                        "You must specify a non-empty String for prepareFromMediaId.");
            }
            }
            try {
            try {
                mSessionBinder.prepareFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId,
                mSessionBinder.prepareFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                        extras);
                        extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e);
                Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e);
@@ -719,7 +721,7 @@ public final class MediaController {
                query = "";
                query = "";
            }
            }
            try {
            try {
                mSessionBinder.prepareFromSearch(mContext.getOpPackageName(), mCbStub, query,
                mSessionBinder.prepareFromSearch(mContext.getPackageName(), mCbStub, query,
                        extras);
                        extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + query + ").", e);
                Log.wtf(TAG, "Error calling prepare(" + query + ").", e);
@@ -744,7 +746,7 @@ public final class MediaController {
                        "You must specify a non-empty Uri for prepareFromUri.");
                        "You must specify a non-empty Uri for prepareFromUri.");
            }
            }
            try {
            try {
                mSessionBinder.prepareFromUri(mContext.getOpPackageName(), mCbStub, uri, extras);
                mSessionBinder.prepareFromUri(mContext.getPackageName(), mCbStub, uri, extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling prepare(" + uri + ").", e);
                Log.wtf(TAG, "Error calling prepare(" + uri + ").", e);
            }
            }
@@ -755,7 +757,7 @@ public final class MediaController {
         */
         */
        public void play() {
        public void play() {
            try {
            try {
                mSessionBinder.play(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.play(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play.", e);
                Log.wtf(TAG, "Error calling play.", e);
            }
            }
@@ -774,7 +776,7 @@ public final class MediaController {
                        "You must specify a non-empty String for playFromMediaId.");
                        "You must specify a non-empty String for playFromMediaId.");
            }
            }
            try {
            try {
                mSessionBinder.playFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId,
                mSessionBinder.playFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                        extras);
                        extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + mediaId + ").", e);
                Log.wtf(TAG, "Error calling play(" + mediaId + ").", e);
@@ -797,7 +799,7 @@ public final class MediaController {
                query = "";
                query = "";
            }
            }
            try {
            try {
                mSessionBinder.playFromSearch(mContext.getOpPackageName(), mCbStub, query, extras);
                mSessionBinder.playFromSearch(mContext.getPackageName(), mCbStub, query, extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + query + ").", e);
                Log.wtf(TAG, "Error calling play(" + query + ").", e);
            }
            }
@@ -816,7 +818,7 @@ public final class MediaController {
                        "You must specify a non-empty Uri for playFromUri.");
                        "You must specify a non-empty Uri for playFromUri.");
            }
            }
            try {
            try {
                mSessionBinder.playFromUri(mContext.getOpPackageName(), mCbStub, uri, extras);
                mSessionBinder.playFromUri(mContext.getPackageName(), mCbStub, uri, extras);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling play(" + uri + ").", e);
                Log.wtf(TAG, "Error calling play(" + uri + ").", e);
            }
            }
@@ -828,7 +830,7 @@ public final class MediaController {
         */
         */
        public void skipToQueueItem(long id) {
        public void skipToQueueItem(long id) {
            try {
            try {
                mSessionBinder.skipToQueueItem(mContext.getOpPackageName(), mCbStub, id);
                mSessionBinder.skipToQueueItem(mContext.getPackageName(), mCbStub, id);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e);
                Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e);
            }
            }
@@ -840,7 +842,7 @@ public final class MediaController {
         */
         */
        public void pause() {
        public void pause() {
            try {
            try {
                mSessionBinder.pause(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.pause(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling pause.", e);
                Log.wtf(TAG, "Error calling pause.", e);
            }
            }
@@ -852,7 +854,7 @@ public final class MediaController {
         */
         */
        public void stop() {
        public void stop() {
            try {
            try {
                mSessionBinder.stop(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.stop(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling stop.", e);
                Log.wtf(TAG, "Error calling stop.", e);
            }
            }
@@ -865,7 +867,7 @@ public final class MediaController {
         */
         */
        public void seekTo(long pos) {
        public void seekTo(long pos) {
            try {
            try {
                mSessionBinder.seekTo(mContext.getOpPackageName(), mCbStub, pos);
                mSessionBinder.seekTo(mContext.getPackageName(), mCbStub, pos);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling seekTo.", e);
                Log.wtf(TAG, "Error calling seekTo.", e);
            }
            }
@@ -877,7 +879,7 @@ public final class MediaController {
         */
         */
        public void fastForward() {
        public void fastForward() {
            try {
            try {
                mSessionBinder.fastForward(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.fastForward(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling fastForward.", e);
                Log.wtf(TAG, "Error calling fastForward.", e);
            }
            }
@@ -888,7 +890,7 @@ public final class MediaController {
         */
         */
        public void skipToNext() {
        public void skipToNext() {
            try {
            try {
                mSessionBinder.next(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.next(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling next.", e);
                Log.wtf(TAG, "Error calling next.", e);
            }
            }
@@ -900,7 +902,7 @@ public final class MediaController {
         */
         */
        public void rewind() {
        public void rewind() {
            try {
            try {
                mSessionBinder.rewind(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.rewind(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling rewind.", e);
                Log.wtf(TAG, "Error calling rewind.", e);
            }
            }
@@ -911,7 +913,7 @@ public final class MediaController {
         */
         */
        public void skipToPrevious() {
        public void skipToPrevious() {
            try {
            try {
                mSessionBinder.previous(mContext.getOpPackageName(), mCbStub);
                mSessionBinder.previous(mContext.getPackageName(), mCbStub);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling previous.", e);
                Log.wtf(TAG, "Error calling previous.", e);
            }
            }
@@ -926,7 +928,7 @@ public final class MediaController {
         */
         */
        public void setRating(Rating rating) {
        public void setRating(Rating rating) {
            try {
            try {
                mSessionBinder.rate(mContext.getOpPackageName(), mCbStub, rating);
                mSessionBinder.rate(mContext.getPackageName(), mCbStub, rating);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.wtf(TAG, "Error calling rate.", e);
                Log.wtf(TAG, "Error calling rate.", e);
            }
            }
@@ -961,7 +963,7 @@ public final class MediaController {
                throw new IllegalArgumentException("CustomAction cannot be null.");
                throw new IllegalArgumentException("CustomAction cannot be null.");
            }
            }
            try {
            try {
                mSessionBinder.sendCustomAction(mContext.getOpPackageName(), mCbStub, action, args);
                mSessionBinder.sendCustomAction(mContext.getPackageName(), mCbStub, action, args);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.d(TAG, "Dead object in sendCustomAction.", e);
                Log.d(TAG, "Dead object in sendCustomAction.", e);
            }
            }