Loading media/java/android/media/session/ISessionController.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -47,9 +47,9 @@ interface ISessionController { PendingIntent getLaunchPendingIntent(); long getFlags(); ParcelableVolumeInfo getVolumeAttributes(); void adjustVolume(String packageName, in ControllerCallbackLink caller, void adjustVolume(String packageName, String opPackageName, in ControllerCallbackLink caller, boolean asSystemService, int direction, int flags); void setVolumeTo(String packageName, in ControllerCallbackLink caller, void setVolumeTo(String packageName, String opPackageName, in ControllerCallbackLink caller, int value, int flags); // These commands are for the TransportControls Loading media/java/android/media/session/ISessionManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -35,9 +35,10 @@ interface ISessionManager { List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags); void dispatchVolumeKeyEvent(String packageName, String opPackageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, String opPackageName, int suggestedStream, int delta, int flags); void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName, int userId); void removeSessionsListener(in IActiveSessionsListener listener); Loading media/java/android/media/session/MediaController.java +42 −28 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ public final class MediaController { return false; } try { return mSessionBinder.sendMediaButton(mContext.getOpPackageName(), mCbStub, return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub, asSystemService, keyEvent); } catch (RemoteException e) { // System is dead. =( Loading Loading @@ -187,8 +187,12 @@ public final class MediaController { break; } try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true, direction, AudioManager.FLAG_SHOW_UI); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, true, direction, AudioManager.FLAG_SHOW_UI); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy", e); } Loading @@ -198,8 +202,11 @@ public final class MediaController { final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE | AudioManager.FLAG_FROM_KEY; try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true, 0, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, true, 0, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy", e); } Loading Loading @@ -365,7 +372,11 @@ public final class MediaController { */ public void setVolumeTo(int value, int flags) { try { mSessionBinder.setVolumeTo(mContext.getOpPackageName(), mCbStub, value, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.setVolumeTo(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, value, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling setVolumeTo.", e); } Loading @@ -386,8 +397,11 @@ public final class MediaController { */ public void adjustVolume(int direction, int flags) { try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, false, direction, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, false, direction, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy.", e); } Loading Loading @@ -453,7 +467,7 @@ public final class MediaController { throw new IllegalArgumentException("command cannot be null or empty"); } try { mSessionBinder.sendCommand(mContext.getOpPackageName(), mCbStub, command, args, cb); mSessionBinder.sendCommand(mContext.getPackageName(), mCbStub, command, args, cb); } catch (RemoteException e) { Log.d(TAG, "Dead object in sendCommand.", e); } Loading Loading @@ -519,7 +533,7 @@ public final class MediaController { if (!mCbRegistered) { try { mSessionBinder.registerCallbackListener(mContext.getOpPackageName(), mCbStub); mSessionBinder.registerCallbackListener(mContext.getPackageName(), mCbStub); mCbRegistered = true; } catch (RemoteException e) { Log.e(TAG, "Dead object in registerCallback", e); Loading Loading @@ -666,7 +680,7 @@ public final class MediaController { */ public void prepare() { try { mSessionBinder.prepare(mContext.getOpPackageName(), mCbStub); mSessionBinder.prepare(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare.", e); } Loading @@ -690,7 +704,7 @@ public final class MediaController { "You must specify a non-empty String for prepareFromMediaId."); } try { mSessionBinder.prepareFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId, mSessionBinder.prepareFromMediaId(mContext.getPackageName(), mCbStub, mediaId, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e); Loading @@ -717,7 +731,7 @@ public final class MediaController { query = ""; } try { mSessionBinder.prepareFromSearch(mContext.getOpPackageName(), mCbStub, query, mSessionBinder.prepareFromSearch(mContext.getPackageName(), mCbStub, query, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + query + ").", e); Loading @@ -742,7 +756,7 @@ public final class MediaController { "You must specify a non-empty Uri for prepareFromUri."); } try { mSessionBinder.prepareFromUri(mContext.getOpPackageName(), mCbStub, uri, extras); mSessionBinder.prepareFromUri(mContext.getPackageName(), mCbStub, uri, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + uri + ").", e); } Loading @@ -753,7 +767,7 @@ public final class MediaController { */ public void play() { try { mSessionBinder.play(mContext.getOpPackageName(), mCbStub); mSessionBinder.play(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play.", e); } Loading @@ -772,7 +786,7 @@ public final class MediaController { "You must specify a non-empty String for playFromMediaId."); } try { mSessionBinder.playFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId, mSessionBinder.playFromMediaId(mContext.getPackageName(), mCbStub, mediaId, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + mediaId + ").", e); Loading @@ -795,7 +809,7 @@ public final class MediaController { query = ""; } try { mSessionBinder.playFromSearch(mContext.getOpPackageName(), mCbStub, query, extras); mSessionBinder.playFromSearch(mContext.getPackageName(), mCbStub, query, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + query + ").", e); } Loading @@ -814,7 +828,7 @@ public final class MediaController { "You must specify a non-empty Uri for playFromUri."); } try { mSessionBinder.playFromUri(mContext.getOpPackageName(), mCbStub, uri, extras); mSessionBinder.playFromUri(mContext.getPackageName(), mCbStub, uri, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + uri + ").", e); } Loading @@ -826,7 +840,7 @@ public final class MediaController { */ public void skipToQueueItem(long id) { try { mSessionBinder.skipToQueueItem(mContext.getOpPackageName(), mCbStub, id); mSessionBinder.skipToQueueItem(mContext.getPackageName(), mCbStub, id); } catch (RemoteException e) { Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e); } Loading @@ -838,7 +852,7 @@ public final class MediaController { */ public void pause() { try { mSessionBinder.pause(mContext.getOpPackageName(), mCbStub); mSessionBinder.pause(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling pause.", e); } Loading @@ -850,7 +864,7 @@ public final class MediaController { */ public void stop() { try { mSessionBinder.stop(mContext.getOpPackageName(), mCbStub); mSessionBinder.stop(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling stop.", e); } Loading @@ -863,7 +877,7 @@ public final class MediaController { */ public void seekTo(long pos) { try { mSessionBinder.seekTo(mContext.getOpPackageName(), mCbStub, pos); mSessionBinder.seekTo(mContext.getPackageName(), mCbStub, pos); } catch (RemoteException e) { Log.wtf(TAG, "Error calling seekTo.", e); } Loading @@ -875,7 +889,7 @@ public final class MediaController { */ public void fastForward() { try { mSessionBinder.fastForward(mContext.getOpPackageName(), mCbStub); mSessionBinder.fastForward(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling fastForward.", e); } Loading @@ -886,7 +900,7 @@ public final class MediaController { */ public void skipToNext() { try { mSessionBinder.next(mContext.getOpPackageName(), mCbStub); mSessionBinder.next(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling next.", e); } Loading @@ -898,7 +912,7 @@ public final class MediaController { */ public void rewind() { try { mSessionBinder.rewind(mContext.getOpPackageName(), mCbStub); mSessionBinder.rewind(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling rewind.", e); } Loading @@ -909,7 +923,7 @@ public final class MediaController { */ public void skipToPrevious() { try { mSessionBinder.previous(mContext.getOpPackageName(), mCbStub); mSessionBinder.previous(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling previous.", e); } Loading @@ -924,7 +938,7 @@ public final class MediaController { */ public void setRating(Rating rating) { try { mSessionBinder.rate(mContext.getOpPackageName(), mCbStub, rating); mSessionBinder.rate(mContext.getPackageName(), mCbStub, rating); } catch (RemoteException e) { Log.wtf(TAG, "Error calling rate.", e); } Loading Loading @@ -959,7 +973,7 @@ public final class MediaController { throw new IllegalArgumentException("CustomAction cannot be null."); } try { mSessionBinder.sendCustomAction(mContext.getOpPackageName(), mCbStub, action, args); mSessionBinder.sendCustomAction(mContext.getPackageName(), mCbStub, action, args); } catch (RemoteException e) { Log.d(TAG, "Dead object in sendCustomAction.", e); } Loading media/java/android/media/session/MediaSessionManager.java +5 −5 Original line number Diff line number Diff line Loading @@ -312,7 +312,7 @@ public final class MediaSessionManager { private void dispatchMediaKeyEventInternal(boolean asSystemService, @NonNull KeyEvent keyEvent, boolean needWakeLock) { try { mService.dispatchMediaKeyEvent(mContext.getOpPackageName(), asSystemService, keyEvent, mService.dispatchMediaKeyEvent(mContext.getPackageName(), asSystemService, keyEvent, needWakeLock); } catch (RemoteException e) { Log.e(TAG, "Failed to send key event.", e); Loading Loading @@ -348,8 +348,8 @@ public final class MediaSessionManager { private void dispatchVolumeKeyEventInternal(boolean asSystemService, @NonNull KeyEvent keyEvent, int stream, boolean musicOnly) { try { mService.dispatchVolumeKeyEvent(mContext.getOpPackageName(), asSystemService, keyEvent, stream, musicOnly); mService.dispatchVolumeKeyEvent(mContext.getPackageName(), mContext.getOpPackageName(), asSystemService, keyEvent, stream, musicOnly); } catch (RemoteException e) { Log.e(TAG, "Failed to send volume key event.", e); } Loading @@ -369,8 +369,8 @@ public final class MediaSessionManager { */ public void dispatchAdjustVolume(int suggestedStream, int direction, int flags) { try { mService.dispatchAdjustVolume(mContext.getOpPackageName(), suggestedStream, direction, flags); mService.dispatchAdjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), suggestedStream, direction, flags); } catch (RemoteException e) { Log.e(TAG, "Failed to send adjust volume.", e); } Loading services/core/java/com/android/server/media/MediaSessionRecord.java +43 −21 Original line number Diff line number Diff line Loading @@ -236,6 +236,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { * {@link AudioManager#ADJUST_SAME}. * * @param packageName The package that made the original volume request. * @param opPackageName The op package that made the original volume request. * @param pid The pid that made the original volume request. * @param uid The uid that made the original volume request. * @param caller caller binder. can be {@code null} if it's from the volume key. Loading @@ -248,7 +249,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { * @param flags Any of the flags from {@link AudioManager}. * @param useSuggested True to use adjustSuggestedStreamVolume instead of */ public void adjustVolume(String packageName, int pid, int uid, public void adjustVolume(String packageName, String opPackageName, int pid, int uid, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags, boolean useSuggested) { int previousFlagPlaySound = flags & AudioManager.FLAG_PLAY_SOUND; Loading @@ -258,8 +259,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { // Adjust the volume with a handler not to be blocked by other system service. int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); postAdjustLocalVolume(stream, direction, flags, packageName, uid, asSystemService, useSuggested, previousFlagPlaySound); postAdjustLocalVolume(stream, direction, flags, opPackageName, pid, uid, asSystemService, useSuggested, previousFlagPlaySound); } else { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { // Nothing to do, the volume cannot be changed Loading Loading @@ -290,11 +291,23 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } } private void setVolumeTo(String packageName, int pid, int uid, private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, ControllerCallbackLink caller, int value, int flags) { if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); mAudioManagerInternal.setStreamVolumeForUid(stream, value, flags, packageName, uid); final int volumeValue = value; mHandler.post(new Runnable() { @Override public void run() { try { mAudioManagerInternal.setStreamVolumeForUid(stream, volumeValue, flags, opPackageName, uid); } catch (IllegalArgumentException | SecurityException e) { Log.e(TAG, "Cannot set volume: stream=" + stream + ", value=" + volumeValue + ", flags=" + flags, e); } } }); } else { if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { // Nothing to do. The volume can't be set directly. Loading Loading @@ -465,11 +478,19 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } private void postAdjustLocalVolume(final int stream, final int direction, final int flags, final String callingPackageName, final int callingUid, final boolean asSystemService, final boolean useSuggested, final int previousFlagPlaySound) { final String packageName = asSystemService ? mContext.getOpPackageName() : callingPackageName; final int uid = asSystemService ? Process.SYSTEM_UID : callingUid; final String callingOpPackageName, final int callingPid, final int callingUid, final boolean asSystemService, final boolean useSuggested, final int previousFlagPlaySound) { // Must use opPackageName for adjusting volumes with UID. final String opPackageName; final int uid; if (asSystemService) { opPackageName = mContext.getOpPackageName(); uid = Process.SYSTEM_UID; } else { opPackageName = callingOpPackageName; uid = callingUid; } mHandler.post(new Runnable() { @Override public void run() { Loading @@ -477,19 +498,19 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { if (useSuggested) { if (AudioSystem.isStreamActive(stream, 0)) { mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction, flags, packageName, uid); direction, flags, opPackageName, uid); } else { mAudioManagerInternal.adjustSuggestedStreamVolumeForUid( AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags | previousFlagPlaySound, packageName, uid); flags | previousFlagPlaySound, opPackageName, uid); } } else { mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags, packageName, uid); opPackageName, uid); } } catch (IllegalArgumentException | SecurityException e) { Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream=" + stream + ", flags=" + flags + ", packageName=" + packageName + stream + ", flags=" + flags + ", opPackageName=" + opPackageName + ", uid=" + uid + ", useSuggested=" + useSuggested + ", previousFlagPlaySound=" + previousFlagPlaySound, e); } Loading Loading @@ -1256,27 +1277,28 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } @Override public void adjustVolume(String packageName, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags) { public void adjustVolume(String packageName, String opPackageName, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags) { int pid = Binder.getCallingPid(); int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { MediaSessionRecord.this.adjustVolume(packageName, pid, uid, caller, asSystemService, direction, flags, false /* useSuggested */); MediaSessionRecord.this.adjustVolume(packageName, opPackageName, pid, uid, caller, asSystemService, direction, flags, false /* useSuggested */); } finally { Binder.restoreCallingIdentity(token); } } @Override public void setVolumeTo(String packageName, ControllerCallbackLink caller, int value, int flags) { public void setVolumeTo(String packageName, String opPackageName, ControllerCallbackLink caller, int value, int flags) { int pid = Binder.getCallingPid(); int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { MediaSessionRecord.this.setVolumeTo(packageName, pid, uid, caller, value, flags); MediaSessionRecord.this.setVolumeTo(packageName, opPackageName, pid, uid, caller, value, flags); } finally { Binder.restoreCallingIdentity(token); } Loading Loading
media/java/android/media/session/ISessionController.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -47,9 +47,9 @@ interface ISessionController { PendingIntent getLaunchPendingIntent(); long getFlags(); ParcelableVolumeInfo getVolumeAttributes(); void adjustVolume(String packageName, in ControllerCallbackLink caller, void adjustVolume(String packageName, String opPackageName, in ControllerCallbackLink caller, boolean asSystemService, int direction, int flags); void setVolumeTo(String packageName, in ControllerCallbackLink caller, void setVolumeTo(String packageName, String opPackageName, in ControllerCallbackLink caller, int value, int flags); // These commands are for the TransportControls Loading
media/java/android/media/session/ISessionManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -35,9 +35,10 @@ interface ISessionManager { List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags); void dispatchVolumeKeyEvent(String packageName, String opPackageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, String opPackageName, int suggestedStream, int delta, int flags); void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName, int userId); void removeSessionsListener(in IActiveSessionsListener listener); Loading
media/java/android/media/session/MediaController.java +42 −28 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ public final class MediaController { return false; } try { return mSessionBinder.sendMediaButton(mContext.getOpPackageName(), mCbStub, return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub, asSystemService, keyEvent); } catch (RemoteException e) { // System is dead. =( Loading Loading @@ -187,8 +187,12 @@ public final class MediaController { break; } try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true, direction, AudioManager.FLAG_SHOW_UI); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, true, direction, AudioManager.FLAG_SHOW_UI); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy", e); } Loading @@ -198,8 +202,11 @@ public final class MediaController { final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE | AudioManager.FLAG_FROM_KEY; try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, true, 0, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, true, 0, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy", e); } Loading Loading @@ -365,7 +372,11 @@ public final class MediaController { */ public void setVolumeTo(int value, int flags) { try { mSessionBinder.setVolumeTo(mContext.getOpPackageName(), mCbStub, value, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.setVolumeTo(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, value, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling setVolumeTo.", e); } Loading @@ -386,8 +397,11 @@ public final class MediaController { */ public void adjustVolume(int direction, int flags) { try { mSessionBinder.adjustVolume(mContext.getOpPackageName(), mCbStub, false, direction, flags); // Note: Need both package name and OP package name. Package name is used for // RemoteUserInfo, and OP package name is used for AudioService's internal // AppOpsManager usages. mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), mCbStub, false, direction, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy.", e); } Loading Loading @@ -453,7 +467,7 @@ public final class MediaController { throw new IllegalArgumentException("command cannot be null or empty"); } try { mSessionBinder.sendCommand(mContext.getOpPackageName(), mCbStub, command, args, cb); mSessionBinder.sendCommand(mContext.getPackageName(), mCbStub, command, args, cb); } catch (RemoteException e) { Log.d(TAG, "Dead object in sendCommand.", e); } Loading Loading @@ -519,7 +533,7 @@ public final class MediaController { if (!mCbRegistered) { try { mSessionBinder.registerCallbackListener(mContext.getOpPackageName(), mCbStub); mSessionBinder.registerCallbackListener(mContext.getPackageName(), mCbStub); mCbRegistered = true; } catch (RemoteException e) { Log.e(TAG, "Dead object in registerCallback", e); Loading Loading @@ -666,7 +680,7 @@ public final class MediaController { */ public void prepare() { try { mSessionBinder.prepare(mContext.getOpPackageName(), mCbStub); mSessionBinder.prepare(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare.", e); } Loading @@ -690,7 +704,7 @@ public final class MediaController { "You must specify a non-empty String for prepareFromMediaId."); } try { mSessionBinder.prepareFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId, mSessionBinder.prepareFromMediaId(mContext.getPackageName(), mCbStub, mediaId, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e); Loading @@ -717,7 +731,7 @@ public final class MediaController { query = ""; } try { mSessionBinder.prepareFromSearch(mContext.getOpPackageName(), mCbStub, query, mSessionBinder.prepareFromSearch(mContext.getPackageName(), mCbStub, query, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + query + ").", e); Loading @@ -742,7 +756,7 @@ public final class MediaController { "You must specify a non-empty Uri for prepareFromUri."); } try { mSessionBinder.prepareFromUri(mContext.getOpPackageName(), mCbStub, uri, extras); mSessionBinder.prepareFromUri(mContext.getPackageName(), mCbStub, uri, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling prepare(" + uri + ").", e); } Loading @@ -753,7 +767,7 @@ public final class MediaController { */ public void play() { try { mSessionBinder.play(mContext.getOpPackageName(), mCbStub); mSessionBinder.play(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play.", e); } Loading @@ -772,7 +786,7 @@ public final class MediaController { "You must specify a non-empty String for playFromMediaId."); } try { mSessionBinder.playFromMediaId(mContext.getOpPackageName(), mCbStub, mediaId, mSessionBinder.playFromMediaId(mContext.getPackageName(), mCbStub, mediaId, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + mediaId + ").", e); Loading @@ -795,7 +809,7 @@ public final class MediaController { query = ""; } try { mSessionBinder.playFromSearch(mContext.getOpPackageName(), mCbStub, query, extras); mSessionBinder.playFromSearch(mContext.getPackageName(), mCbStub, query, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + query + ").", e); } Loading @@ -814,7 +828,7 @@ public final class MediaController { "You must specify a non-empty Uri for playFromUri."); } try { mSessionBinder.playFromUri(mContext.getOpPackageName(), mCbStub, uri, extras); mSessionBinder.playFromUri(mContext.getPackageName(), mCbStub, uri, extras); } catch (RemoteException e) { Log.wtf(TAG, "Error calling play(" + uri + ").", e); } Loading @@ -826,7 +840,7 @@ public final class MediaController { */ public void skipToQueueItem(long id) { try { mSessionBinder.skipToQueueItem(mContext.getOpPackageName(), mCbStub, id); mSessionBinder.skipToQueueItem(mContext.getPackageName(), mCbStub, id); } catch (RemoteException e) { Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e); } Loading @@ -838,7 +852,7 @@ public final class MediaController { */ public void pause() { try { mSessionBinder.pause(mContext.getOpPackageName(), mCbStub); mSessionBinder.pause(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling pause.", e); } Loading @@ -850,7 +864,7 @@ public final class MediaController { */ public void stop() { try { mSessionBinder.stop(mContext.getOpPackageName(), mCbStub); mSessionBinder.stop(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling stop.", e); } Loading @@ -863,7 +877,7 @@ public final class MediaController { */ public void seekTo(long pos) { try { mSessionBinder.seekTo(mContext.getOpPackageName(), mCbStub, pos); mSessionBinder.seekTo(mContext.getPackageName(), mCbStub, pos); } catch (RemoteException e) { Log.wtf(TAG, "Error calling seekTo.", e); } Loading @@ -875,7 +889,7 @@ public final class MediaController { */ public void fastForward() { try { mSessionBinder.fastForward(mContext.getOpPackageName(), mCbStub); mSessionBinder.fastForward(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling fastForward.", e); } Loading @@ -886,7 +900,7 @@ public final class MediaController { */ public void skipToNext() { try { mSessionBinder.next(mContext.getOpPackageName(), mCbStub); mSessionBinder.next(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling next.", e); } Loading @@ -898,7 +912,7 @@ public final class MediaController { */ public void rewind() { try { mSessionBinder.rewind(mContext.getOpPackageName(), mCbStub); mSessionBinder.rewind(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling rewind.", e); } Loading @@ -909,7 +923,7 @@ public final class MediaController { */ public void skipToPrevious() { try { mSessionBinder.previous(mContext.getOpPackageName(), mCbStub); mSessionBinder.previous(mContext.getPackageName(), mCbStub); } catch (RemoteException e) { Log.wtf(TAG, "Error calling previous.", e); } Loading @@ -924,7 +938,7 @@ public final class MediaController { */ public void setRating(Rating rating) { try { mSessionBinder.rate(mContext.getOpPackageName(), mCbStub, rating); mSessionBinder.rate(mContext.getPackageName(), mCbStub, rating); } catch (RemoteException e) { Log.wtf(TAG, "Error calling rate.", e); } Loading Loading @@ -959,7 +973,7 @@ public final class MediaController { throw new IllegalArgumentException("CustomAction cannot be null."); } try { mSessionBinder.sendCustomAction(mContext.getOpPackageName(), mCbStub, action, args); mSessionBinder.sendCustomAction(mContext.getPackageName(), mCbStub, action, args); } catch (RemoteException e) { Log.d(TAG, "Dead object in sendCustomAction.", e); } Loading
media/java/android/media/session/MediaSessionManager.java +5 −5 Original line number Diff line number Diff line Loading @@ -312,7 +312,7 @@ public final class MediaSessionManager { private void dispatchMediaKeyEventInternal(boolean asSystemService, @NonNull KeyEvent keyEvent, boolean needWakeLock) { try { mService.dispatchMediaKeyEvent(mContext.getOpPackageName(), asSystemService, keyEvent, mService.dispatchMediaKeyEvent(mContext.getPackageName(), asSystemService, keyEvent, needWakeLock); } catch (RemoteException e) { Log.e(TAG, "Failed to send key event.", e); Loading Loading @@ -348,8 +348,8 @@ public final class MediaSessionManager { private void dispatchVolumeKeyEventInternal(boolean asSystemService, @NonNull KeyEvent keyEvent, int stream, boolean musicOnly) { try { mService.dispatchVolumeKeyEvent(mContext.getOpPackageName(), asSystemService, keyEvent, stream, musicOnly); mService.dispatchVolumeKeyEvent(mContext.getPackageName(), mContext.getOpPackageName(), asSystemService, keyEvent, stream, musicOnly); } catch (RemoteException e) { Log.e(TAG, "Failed to send volume key event.", e); } Loading @@ -369,8 +369,8 @@ public final class MediaSessionManager { */ public void dispatchAdjustVolume(int suggestedStream, int direction, int flags) { try { mService.dispatchAdjustVolume(mContext.getOpPackageName(), suggestedStream, direction, flags); mService.dispatchAdjustVolume(mContext.getPackageName(), mContext.getOpPackageName(), suggestedStream, direction, flags); } catch (RemoteException e) { Log.e(TAG, "Failed to send adjust volume.", e); } Loading
services/core/java/com/android/server/media/MediaSessionRecord.java +43 −21 Original line number Diff line number Diff line Loading @@ -236,6 +236,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { * {@link AudioManager#ADJUST_SAME}. * * @param packageName The package that made the original volume request. * @param opPackageName The op package that made the original volume request. * @param pid The pid that made the original volume request. * @param uid The uid that made the original volume request. * @param caller caller binder. can be {@code null} if it's from the volume key. Loading @@ -248,7 +249,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { * @param flags Any of the flags from {@link AudioManager}. * @param useSuggested True to use adjustSuggestedStreamVolume instead of */ public void adjustVolume(String packageName, int pid, int uid, public void adjustVolume(String packageName, String opPackageName, int pid, int uid, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags, boolean useSuggested) { int previousFlagPlaySound = flags & AudioManager.FLAG_PLAY_SOUND; Loading @@ -258,8 +259,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { // Adjust the volume with a handler not to be blocked by other system service. int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); postAdjustLocalVolume(stream, direction, flags, packageName, uid, asSystemService, useSuggested, previousFlagPlaySound); postAdjustLocalVolume(stream, direction, flags, opPackageName, pid, uid, asSystemService, useSuggested, previousFlagPlaySound); } else { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { // Nothing to do, the volume cannot be changed Loading Loading @@ -290,11 +291,23 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } } private void setVolumeTo(String packageName, int pid, int uid, private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, ControllerCallbackLink caller, int value, int flags) { if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); mAudioManagerInternal.setStreamVolumeForUid(stream, value, flags, packageName, uid); final int volumeValue = value; mHandler.post(new Runnable() { @Override public void run() { try { mAudioManagerInternal.setStreamVolumeForUid(stream, volumeValue, flags, opPackageName, uid); } catch (IllegalArgumentException | SecurityException e) { Log.e(TAG, "Cannot set volume: stream=" + stream + ", value=" + volumeValue + ", flags=" + flags, e); } } }); } else { if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { // Nothing to do. The volume can't be set directly. Loading Loading @@ -465,11 +478,19 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } private void postAdjustLocalVolume(final int stream, final int direction, final int flags, final String callingPackageName, final int callingUid, final boolean asSystemService, final boolean useSuggested, final int previousFlagPlaySound) { final String packageName = asSystemService ? mContext.getOpPackageName() : callingPackageName; final int uid = asSystemService ? Process.SYSTEM_UID : callingUid; final String callingOpPackageName, final int callingPid, final int callingUid, final boolean asSystemService, final boolean useSuggested, final int previousFlagPlaySound) { // Must use opPackageName for adjusting volumes with UID. final String opPackageName; final int uid; if (asSystemService) { opPackageName = mContext.getOpPackageName(); uid = Process.SYSTEM_UID; } else { opPackageName = callingOpPackageName; uid = callingUid; } mHandler.post(new Runnable() { @Override public void run() { Loading @@ -477,19 +498,19 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { if (useSuggested) { if (AudioSystem.isStreamActive(stream, 0)) { mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction, flags, packageName, uid); direction, flags, opPackageName, uid); } else { mAudioManagerInternal.adjustSuggestedStreamVolumeForUid( AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags | previousFlagPlaySound, packageName, uid); flags | previousFlagPlaySound, opPackageName, uid); } } else { mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags, packageName, uid); opPackageName, uid); } } catch (IllegalArgumentException | SecurityException e) { Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream=" + stream + ", flags=" + flags + ", packageName=" + packageName + stream + ", flags=" + flags + ", opPackageName=" + opPackageName + ", uid=" + uid + ", useSuggested=" + useSuggested + ", previousFlagPlaySound=" + previousFlagPlaySound, e); } Loading Loading @@ -1256,27 +1277,28 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } @Override public void adjustVolume(String packageName, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags) { public void adjustVolume(String packageName, String opPackageName, ControllerCallbackLink caller, boolean asSystemService, int direction, int flags) { int pid = Binder.getCallingPid(); int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { MediaSessionRecord.this.adjustVolume(packageName, pid, uid, caller, asSystemService, direction, flags, false /* useSuggested */); MediaSessionRecord.this.adjustVolume(packageName, opPackageName, pid, uid, caller, asSystemService, direction, flags, false /* useSuggested */); } finally { Binder.restoreCallingIdentity(token); } } @Override public void setVolumeTo(String packageName, ControllerCallbackLink caller, int value, int flags) { public void setVolumeTo(String packageName, String opPackageName, ControllerCallbackLink caller, int value, int flags) { int pid = Binder.getCallingPid(); int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { MediaSessionRecord.this.setVolumeTo(packageName, pid, uid, caller, value, flags); MediaSessionRecord.this.setVolumeTo(packageName, opPackageName, pid, uid, caller, value, flags); } finally { Binder.restoreCallingIdentity(token); } Loading