summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2014-08-14 18:05:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-08-13 01:30:58 +0000
commit1d2a1c917f46b6854e91f9867a20abb76ecb794d (patch)
treec1dc60df7163852ccb5d3b3c90aa732a676d723b
parentb1a50f2dff3d2d24c3567e2be67e7a4bc87a9b31 (diff)
parent0dac35af2c6aa42bcd181981b041747cfd1afa5f (diff)
Merge "Pipe caller's identity through volume methods" into lmp-dev
-rw-r--r--media/java/android/media/AudioManagerInternal.java34
-rw-r--r--media/java/android/media/AudioService.java38
-rw-r--r--media/java/android/media/session/ISessionController.aidl4
-rw-r--r--media/java/android/media/session/MediaController.java4
-rw-r--r--services/core/java/com/android/server/media/MediaSessionRecord.java24
-rw-r--r--services/core/java/com/android/server/media/MediaSessionService.java3
6 files changed, 90 insertions, 17 deletions
diff --git a/media/java/android/media/AudioManagerInternal.java b/media/java/android/media/AudioManagerInternal.java
new file mode 100644
index 000000000000..6f1bdef87303
--- /dev/null
+++ b/media/java/android/media/AudioManagerInternal.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2014 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;
+
+import com.android.server.LocalServices;
+
+/**
+ * Class for system services to access extra AudioManager functionality. The
+ * AudioService is responsible for registering an implementation with
+ * {@link LocalServices}.
+ *
+ * @hide
+ */
+public abstract class AudioManagerInternal {
+
+ public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
+ String callingPackage, int uid);
+
+ public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
+ String callingPackage, int uid);
+}
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index c757b38d3887..0af24576012b 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -79,6 +79,7 @@ import android.view.WindowManager;
import com.android.internal.telephony.ITelephony;
import com.android.internal.util.XmlUtils;
+import com.android.server.LocalServices;
import org.xmlpull.v1.XmlPullParserException;
@@ -630,6 +631,7 @@ public class AudioService extends IAudioService.Stub {
mMasterVolumeRamp = context.getResources().getIntArray(
com.android.internal.R.array.config_masterVolumeRamp);
+ LocalServices.addService(AudioManagerInternal.class, new AudioServiceInternal());
}
public void systemReady() {
@@ -924,6 +926,11 @@ public class AudioService extends IAudioService.Stub {
/** @see AudioManager#adjustStreamVolume(int, int, int) */
public void adjustStreamVolume(int streamType, int direction, int flags,
String callingPackage) {
+ adjustStreamVolume(streamType, direction, flags, callingPackage, Binder.getCallingUid());
+ }
+
+ private void adjustStreamVolume(int streamType, int direction, int flags,
+ String callingPackage, int uid) {
if (mUseFixedVolume) {
return;
}
@@ -952,8 +959,8 @@ public class AudioService extends IAudioService.Stub {
return;
}
- if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
- callingPackage) != AppOpsManager.MODE_ALLOWED) {
+ if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
+ != AppOpsManager.MODE_ALLOWED) {
return;
}
@@ -1129,6 +1136,11 @@ public class AudioService extends IAudioService.Stub {
/** @see AudioManager#setStreamVolume(int, int, int) */
public void setStreamVolume(int streamType, int index, int flags, String callingPackage) {
+ setStreamVolume(streamType, index, flags, callingPackage, Binder.getCallingUid());
+ }
+
+ private void setStreamVolume(int streamType, int index, int flags, String callingPackage,
+ int uid) {
if (mUseFixedVolume) {
return;
}
@@ -1147,8 +1159,8 @@ public class AudioService extends IAudioService.Stub {
return;
}
- if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
- callingPackage) != AppOpsManager.MODE_ALLOWED) {
+ if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
+ != AppOpsManager.MODE_ALLOWED) {
return;
}
@@ -5288,6 +5300,24 @@ public class AudioService extends IAudioService.Stub {
}
}
+ /**
+ * Interface for system components to get some extra functionality through
+ * LocalServices.
+ */
+ final class AudioServiceInternal extends AudioManagerInternal {
+ @Override
+ public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
+ String callingPackage, int uid) {
+ adjustStreamVolume(streamType, direction, flags, callingPackage, uid);
+ }
+
+ @Override
+ public void setStreamVolumeForUid(int streamType, int direction, int flags,
+ String callingPackage, int uid) {
+ setStreamVolume(streamType, direction, flags, callingPackage, uid);
+ }
+ }
+
//==========================================================================================
// Audio policy management
//==========================================================================================
diff --git a/media/java/android/media/session/ISessionController.aidl b/media/java/android/media/session/ISessionController.aidl
index 3518458fe706..5764bd15cc10 100644
--- a/media/java/android/media/session/ISessionController.aidl
+++ b/media/java/android/media/session/ISessionController.aidl
@@ -48,8 +48,8 @@ interface ISessionController {
PendingIntent getLaunchPendingIntent();
long getFlags();
ParcelableVolumeInfo getVolumeAttributes();
- void adjustVolume(int direction, int flags);
- void setVolumeTo(int value, int flags);
+ void adjustVolume(int direction, int flags, String packageName);
+ void setVolumeTo(int value, int flags, String packageName);
IMediaRouterDelegate createMediaRouterDelegate(IMediaRouterStateCallback callback);
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java
index 4f83441520ca..63c85f885215 100644
--- a/media/java/android/media/session/MediaController.java
+++ b/media/java/android/media/session/MediaController.java
@@ -311,7 +311,7 @@ public final class MediaController {
*/
public void setVolumeTo(int value, int flags) {
try {
- mSessionBinder.setVolumeTo(value, flags);
+ mSessionBinder.setVolumeTo(value, flags, mContext.getPackageName());
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling setVolumeTo.", e);
}
@@ -332,7 +332,7 @@ public final class MediaController {
*/
public void adjustVolume(int direction, int flags) {
try {
- mSessionBinder.adjustVolume(direction, flags);
+ mSessionBinder.adjustVolume(direction, flags, mContext.getPackageName());
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
}
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 22bd49f94022..f820a3c6f92e 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 0514f48fc6d0..1221aa4af10f 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 {