summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorSvet Ganov <svetoslavganov@google.com>2015-04-29 19:55:31 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-29 19:55:31 +0000
commit0dbaba6c3a7ae0a45e2305a21b0ef5decbde59a4 (patch)
treef69aa58f9b349ab7307c4fe77765af682c5cf733 /media
parente58e0e50efa429b47985acedf3ec7d8d5745ea95 (diff)
parent5e47c802ef1ac9437b012bc70701ffaf048cb399 (diff)
downloadframeworks_base-0dbaba6c3a7ae0a45e2305a21b0ef5decbde59a4.zip
frameworks_base-0dbaba6c3a7ae0a45e2305a21b0ef5decbde59a4.tar.gz
frameworks_base-0dbaba6c3a7ae0a45e2305a21b0ef5decbde59a4.tar.bz2
am 5e47c802: am 56867804: Merge "Respect the record audio app op - framework" into mnc-dev
* commit '5e47c802ef1ac9437b012bc70701ffaf048cb399': Respect the record audio app op - framework
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioRecord.java17
-rw-r--r--media/java/android/media/MediaRecorder.java16
-rw-r--r--media/java/android/media/RemoteDisplay.java13
-rw-r--r--media/java/android/media/audiofx/AudioEffect.java18
-rw-r--r--media/java/android/media/audiofx/Visualizer.java18
-rw-r--r--media/jni/android_media_MediaRecorder.cpp11
-rw-r--r--media/jni/audioeffect/android_media_AudioEffect.cpp10
-rw-r--r--media/jni/audioeffect/android_media_Visualizer.cpp11
8 files changed, 92 insertions, 22 deletions
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index 201a796..d5e6b3e 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -26,6 +26,8 @@ import java.util.Iterator;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.app.ActivityThread;
+import android.app.Application;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -378,7 +380,7 @@ public class AudioRecord
int initResult = native_setup( new WeakReference<AudioRecord>(this),
mAudioAttributes, mSampleRate, mChannelMask, mChannelIndexMask,
mAudioFormat, mNativeBufferSizeInBytes,
- session);
+ session, getMyOpPackageName());
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing native AudioRecord object.");
return; // with mState == STATE_UNINITIALIZED
@@ -1321,7 +1323,6 @@ public class AudioRecord
return native_set_pos_update_period(periodInFrames);
}
-
//--------------------------------------------------------------------------
// Explicit Routing
//--------------------
@@ -1451,7 +1452,7 @@ public class AudioRecord
private native final int native_setup(Object audiorecord_this,
Object /*AudioAttributes*/ attributes,
int sampleRate, int channelMask, int channelIndexMask, int audioFormat,
- int buffSizeInBytes, int[] sessionId);
+ int buffSizeInBytes, int[] sessionId, String opPackageName);
// TODO remove: implementation calls directly into implementation of native_release()
private native final void native_finalize();
@@ -1500,4 +1501,14 @@ public class AudioRecord
Log.e(TAG, msg);
}
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 78fd9f0..1b054cc 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -18,6 +18,7 @@ package android.media;
import android.annotation.SystemApi;
import android.app.ActivityThread;
+import android.app.Application;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Looper;
@@ -111,7 +112,7 @@ public class MediaRecorder
/* Native setup requires a weak reference to our object.
* It's easier to create it here than in C++.
*/
- native_setup(new WeakReference<MediaRecorder>(this), packageName);
+ native_setup(new WeakReference<MediaRecorder>(this), packageName, getMyOpPackageName());
}
/**
@@ -1080,7 +1081,7 @@ public class MediaRecorder
private static native final void native_init();
private native final void native_setup(Object mediarecorder_this,
- String clientName) throws IllegalStateException;
+ String clientName, String opPackageName) throws IllegalStateException;
private native final void native_finalize();
@@ -1088,4 +1089,15 @@ public class MediaRecorder
@Override
protected void finalize() { native_finalize(); }
+
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/java/android/media/RemoteDisplay.java b/media/java/android/media/RemoteDisplay.java
index 4e937a5..5add65a 100644
--- a/media/java/android/media/RemoteDisplay.java
+++ b/media/java/android/media/RemoteDisplay.java
@@ -37,17 +37,19 @@ public final class RemoteDisplay {
private final CloseGuard mGuard = CloseGuard.get();
private final Listener mListener;
private final Handler mHandler;
+ private final String mOpPackageName;
private long mPtr;
- private native long nativeListen(String iface);
+ private native long nativeListen(String iface, String opPackageName);
private native void nativeDispose(long ptr);
private native void nativePause(long ptr);
private native void nativeResume(long ptr);
- private RemoteDisplay(Listener listener, Handler handler) {
+ private RemoteDisplay(Listener listener, Handler handler, String opPackageName) {
mListener = listener;
mHandler = handler;
+ mOpPackageName = opPackageName;
}
@Override
@@ -66,7 +68,8 @@ public final class RemoteDisplay {
* @param listener The listener to invoke when displays are connected or disconnected.
* @param handler The handler on which to invoke the listener.
*/
- public static RemoteDisplay listen(String iface, Listener listener, Handler handler) {
+ public static RemoteDisplay listen(String iface, Listener listener, Handler handler,
+ String opPackageName) {
if (iface == null) {
throw new IllegalArgumentException("iface must not be null");
}
@@ -77,7 +80,7 @@ public final class RemoteDisplay {
throw new IllegalArgumentException("handler must not be null");
}
- RemoteDisplay display = new RemoteDisplay(listener, handler);
+ RemoteDisplay display = new RemoteDisplay(listener, handler, opPackageName);
display.startListening(iface);
return display;
}
@@ -113,7 +116,7 @@ public final class RemoteDisplay {
}
private void startListening(String iface) {
- mPtr = nativeListen(iface);
+ mPtr = nativeListen(iface, mOpPackageName);
if (mPtr == 0) {
throw new IllegalStateException("Could not start listening for "
+ "remote display connection on \"" + iface + "\"");
diff --git a/media/java/android/media/audiofx/AudioEffect.java b/media/java/android/media/audiofx/AudioEffect.java
index a8b9686..9fc90df 100644
--- a/media/java/android/media/audiofx/AudioEffect.java
+++ b/media/java/android/media/audiofx/AudioEffect.java
@@ -18,6 +18,8 @@ package android.media.audiofx;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.app.ActivityThread;
+import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -395,7 +397,7 @@ public class AudioEffect {
// native initialization
int initResult = native_setup(new WeakReference<AudioEffect>(this),
type.toString(), uuid.toString(), priority, audioSession, id,
- desc);
+ desc, getMyOpPackageName());
if (initResult != SUCCESS && initResult != ALREADY_EXISTS) {
Log.e(TAG, "Error code " + initResult
+ " when initializing AudioEffect.");
@@ -1217,7 +1219,8 @@ public class AudioEffect {
private static native final void native_init();
private native final int native_setup(Object audioeffect_this, String type,
- String uuid, int priority, int audioSession, int[] id, Object[] desc);
+ String uuid, int priority, int audioSession, int[] id, Object[] desc,
+ String opPackageName);
private native final void native_finalize();
@@ -1356,4 +1359,15 @@ public class AudioEffect {
}
return b;
}
+
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioEffect outside of an app");
+ }
}
diff --git a/media/java/android/media/audiofx/Visualizer.java b/media/java/android/media/audiofx/Visualizer.java
index 24c74ac..0c48063 100644
--- a/media/java/android/media/audiofx/Visualizer.java
+++ b/media/java/android/media/audiofx/Visualizer.java
@@ -16,6 +16,8 @@
package android.media.audiofx;
+import android.app.ActivityThread;
+import android.app.Application;
import android.util.Log;
import java.lang.ref.WeakReference;
import android.os.Handler;
@@ -206,7 +208,8 @@ public class Visualizer {
synchronized (mStateLock) {
mState = STATE_UNINITIALIZED;
// native initialization
- int result = native_setup(new WeakReference<Visualizer>(this), audioSession, id);
+ int result = native_setup(new WeakReference<Visualizer>(this), audioSession, id,
+ getMyOpPackageName());
if (result != SUCCESS && result != ALREADY_EXISTS) {
Log.e(TAG, "Error code "+result+" when initializing Visualizer.");
switch (result) {
@@ -716,7 +719,8 @@ public class Visualizer {
private native final int native_setup(Object audioeffect_this,
int audioSession,
- int[] id);
+ int[] id,
+ String opPackageName);
private native final void native_finalize();
@@ -766,5 +770,15 @@ public class Visualizer {
}
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 8b7d40d..02297fc 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -31,6 +31,8 @@
#include <media/mediarecorder.h>
#include <utils/threads.h>
+#include <ScopedUtfChars.h>
+
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
@@ -444,11 +446,13 @@ android_media_MediaRecorder_native_init(JNIEnv *env)
static void
android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jstring packageName)
+ jstring packageName, jstring opPackageName)
{
ALOGV("setup");
- sp<MediaRecorder> mr = new MediaRecorder();
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
+ sp<MediaRecorder> mr = new MediaRecorder(String16(opPackageNameStr.c_str()));
if (mr == NULL) {
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
return;
@@ -506,7 +510,8 @@ static JNINativeMethod gMethods[] = {
{"native_reset", "()V", (void *)android_media_MediaRecorder_native_reset},
{"release", "()V", (void *)android_media_MediaRecorder_release},
{"native_init", "()V", (void *)android_media_MediaRecorder_native_init},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;)V", (void *)android_media_MediaRecorder_native_setup},
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V",
+ (void *)android_media_MediaRecorder_native_setup},
{"native_finalize", "()V", (void *)android_media_MediaRecorder_native_finalize},
};
diff --git a/media/jni/audioeffect/android_media_AudioEffect.cpp b/media/jni/audioeffect/android_media_AudioEffect.cpp
index c364d46..96b72a2 100644
--- a/media/jni/audioeffect/android_media_AudioEffect.cpp
+++ b/media/jni/audioeffect/android_media_AudioEffect.cpp
@@ -25,6 +25,8 @@
#include <android_runtime/AndroidRuntime.h>
#include "media/AudioEffect.h"
+#include <ScopedUtfChars.h>
+
using namespace android;
#define AUDIOEFFECT_SUCCESS 0
@@ -249,7 +251,8 @@ android_media_AudioEffect_native_init(JNIEnv *env)
static jint
android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId, jobjectArray javadesc)
+ jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId,
+ jobjectArray javadesc, jstring opPackageName)
{
ALOGV("android_media_AudioEffect_native_setup");
AudioEffectJniStorage* lpJniStorage = NULL;
@@ -267,6 +270,8 @@ android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_t
jstring jdescName;
jstring jdescImplementor;
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
if (type != NULL) {
typeStr = env->GetStringUTFChars(type, NULL);
if (typeStr == NULL) { // Out of memory
@@ -312,6 +317,7 @@ android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_t
// create the native AudioEffect object
lpAudioEffect = new AudioEffect(typeStr,
+ String16(opPackageNameStr.c_str()),
uuidStr,
priority,
effectCallback,
@@ -868,7 +874,7 @@ android_media_AudioEffect_native_queryPreProcessings(JNIEnv *env, jclass clazz _
// Dalvik VM type signatures
static JNINativeMethod gMethods[] = {
{"native_init", "()V", (void *)android_media_AudioEffect_native_init},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;)I",
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;Ljava/lang/String;)I",
(void *)android_media_AudioEffect_native_setup},
{"native_finalize", "()V", (void *)android_media_AudioEffect_native_finalize},
{"native_release", "()V", (void *)android_media_AudioEffect_native_release},
diff --git a/media/jni/audioeffect/android_media_Visualizer.cpp b/media/jni/audioeffect/android_media_Visualizer.cpp
index 460277f..abc681e 100644
--- a/media/jni/audioeffect/android_media_Visualizer.cpp
+++ b/media/jni/audioeffect/android_media_Visualizer.cpp
@@ -26,6 +26,8 @@
#include <utils/threads.h>
#include "media/Visualizer.h"
+#include <ScopedUtfChars.h>
+
using namespace android;
#define VISUALIZER_SUCCESS 0
@@ -331,7 +333,7 @@ static void android_media_visualizer_effect_callback(int32_t event,
static jint
android_media_visualizer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jint sessionId, jintArray jId)
+ jint sessionId, jintArray jId, jstring opPackageName)
{
ALOGV("android_media_visualizer_native_setup");
visualizerJniStorage* lpJniStorage = NULL;
@@ -339,6 +341,8 @@ android_media_visualizer_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
Visualizer* lpVisualizer = NULL;
jint* nId = NULL;
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
lpJniStorage = new visualizerJniStorage();
if (lpJniStorage == NULL) {
ALOGE("setup: Error creating JNI Storage");
@@ -362,7 +366,8 @@ android_media_visualizer_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
}
// create the native Visualizer object
- lpVisualizer = new Visualizer(0,
+ lpVisualizer = new Visualizer(String16(opPackageNameStr.c_str()),
+ 0,
android_media_visualizer_effect_callback,
lpJniStorage,
sessionId);
@@ -662,7 +667,7 @@ android_media_setPeriodicCapture(JNIEnv *env, jobject thiz, jint rate, jboolean
// Dalvik VM type signatures
static JNINativeMethod gMethods[] = {
{"native_init", "()V", (void *)android_media_visualizer_native_init},
- {"native_setup", "(Ljava/lang/Object;I[I)I",
+ {"native_setup", "(Ljava/lang/Object;I[ILjava/lang/String;)I",
(void *)android_media_visualizer_native_setup},
{"native_finalize", "()V", (void *)android_media_visualizer_native_finalize},
{"native_release", "()V", (void *)android_media_visualizer_native_release},