diff options
author | RoboErik <epastern@google.com> | 2014-08-14 18:05:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-13 01:30:58 +0000 |
commit | 1d2a1c917f46b6854e91f9867a20abb76ecb794d (patch) | |
tree | c1dc60df7163852ccb5d3b3c90aa732a676d723b /services/core/java/com/android/server/media | |
parent | b1a50f2dff3d2d24c3567e2be67e7a4bc87a9b31 (diff) | |
parent | 0dac35af2c6aa42bcd181981b041747cfd1afa5f (diff) | |
download | frameworks_base-1d2a1c917f46b6854e91f9867a20abb76ecb794d.zip frameworks_base-1d2a1c917f46b6854e91f9867a20abb76ecb794d.tar.gz frameworks_base-1d2a1c917f46b6854e91f9867a20abb76ecb794d.tar.bz2 |
Merge "Pipe caller's identity through volume methods" into lmp-dev
Diffstat (limited to 'services/core/java/com/android/server/media')
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionRecord.java | 24 | ||||
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java index 22bd49f..f820a3c 100644 --- a/services/core/java/com/android/server/media/MediaSessionRecord.java +++ b/services/core/java/com/android/server/media/MediaSessionRecord.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ParceledListSlice; import android.media.AudioManager; +import android.media.AudioManagerInternal; import android.media.MediaMetadata; import android.media.Rating; import android.media.VolumeProvider; @@ -52,6 +53,8 @@ import android.util.Log; import android.util.Slog; import android.view.KeyEvent; +import com.android.server.LocalServices; + import java.io.PrintWriter; import java.util.ArrayList; import java.util.UUID; @@ -111,6 +114,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { // Volume handling fields private AudioAttributes mAudioAttrs; private AudioManager mAudioManager; + private AudioManagerInternal mAudioManagerInternal; private int mVolumeType = MediaSession.PLAYBACK_TYPE_LOCAL; private int mVolumeControlType = VolumeProvider.VOLUME_CONTROL_ABSOLUTE; private int mMaxVolume = 0; @@ -134,6 +138,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { mService = service; mHandler = new MessageHandler(handler.getLooper()); mAudioManager = (AudioManager) service.getContext().getSystemService(Context.AUDIO_SERVICE); + mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class); mAudioAttrs = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(); } @@ -227,7 +232,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { * * @param direction The direction to adjust volume in. */ - public void adjustVolume(int direction, int flags) { + public void adjustVolume(int direction, int flags, String packageName, int uid) { if (isPlaybackActive(false)) { flags &= ~AudioManager.FLAG_PLAY_SOUND; } @@ -238,7 +243,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } if (mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL) { int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); - mAudioManager.adjustStreamVolume(stream, direction, flags); + mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags, packageName, + uid); } else { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { // Nothing to do, the volume cannot be changed @@ -262,10 +268,10 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } } - public void setVolumeTo(int value, int flags) { + public void setVolumeTo(int value, int flags, String packageName, int uid) { if (mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL) { int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs); - mAudioManager.setStreamVolume(stream, value, flags); + mAudioManagerInternal.setStreamVolumeForUid(stream, value, flags, packageName, uid); } else { if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { // Nothing to do. The volume can't be set directly. @@ -1018,20 +1024,22 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } @Override - public void adjustVolume(int direction, int flags) { + public void adjustVolume(int direction, int flags, String packageName) { + int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { - MediaSessionRecord.this.adjustVolume(direction, flags); + MediaSessionRecord.this.adjustVolume(direction, flags, packageName, uid); } finally { Binder.restoreCallingIdentity(token); } } @Override - public void setVolumeTo(int value, int flags) { + public void setVolumeTo(int value, int flags, String packageName) { + int uid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); try { - MediaSessionRecord.this.setVolumeTo(value, flags); + MediaSessionRecord.this.setVolumeTo(value, flags, packageName, uid); } finally { Binder.restoreCallingIdentity(token); } diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 0514f48..1221aa4 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -812,7 +812,8 @@ public class MediaSessionService extends SystemService implements Monitor { Log.e(TAG, "Error adjusting default volume.", e); } } else { - session.adjustVolume(direction, flags); + session.adjustVolume(direction, flags, getContext().getPackageName(), + UserHandle.myUserId()); if (session.getPlaybackType() == MediaSession.PLAYBACK_TYPE_REMOTE && mRvc != null) { try { |