summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvet Ganov <svetoslavganov@google.com>2015-04-28 12:02:09 -0700
committerSvet Ganov <svetoslavganov@google.com>2015-04-28 12:02:09 -0700
commitc2d55f13a21fe6a288601deab6832c704c998781 (patch)
tree1dc2a6526140beb12ee9536603b245704fa0f130
parentcf38b8464007ebf626fc0d61a646491fc3d794cd (diff)
downloadvoip-c2d55f13a21fe6a288601deab6832c704c998781.tar.gz
Respect the record audio app op - voip
Change-Id: I751e85cc444f4e5e2a0d31d132fcaafdb9828e15
-rw-r--r--src/java/android/net/rtp/AudioGroup.java18
-rw-r--r--src/jni/rtp/AudioGroup.cpp20
2 files changed, 30 insertions, 8 deletions
diff --git a/src/java/android/net/rtp/AudioGroup.java b/src/java/android/net/rtp/AudioGroup.java
index 30a664c..da74bd6 100644
--- a/src/java/android/net/rtp/AudioGroup.java
+++ b/src/java/android/net/rtp/AudioGroup.java
@@ -16,6 +16,8 @@
package android.net.rtp;
+import android.app.ActivityThread;
+import android.app.Application;
import android.media.AudioManager;
import java.util.HashMap;
@@ -151,7 +153,8 @@ public class AudioGroup {
codec.rtpmap, codec.fmtp);
long id = nativeAdd(stream.getMode(), stream.getSocket(),
stream.getRemoteAddress().getHostAddress(),
- stream.getRemotePort(), codecSpec, stream.getDtmfType());
+ stream.getRemotePort(), codecSpec, stream.getDtmfType(),
+ getMyOpPackageName());
mStreams.put(stream, id);
} catch (NullPointerException e) {
throw new IllegalStateException(e);
@@ -160,7 +163,7 @@ public class AudioGroup {
}
private native long nativeAdd(int mode, int socket, String remoteAddress,
- int remotePort, String codecSpec, int dtmfType);
+ int remotePort, String codecSpec, int dtmfType, String opPackageName);
// Package-private method used by AudioStream.join().
synchronized void remove(AudioStream stream) {
@@ -203,4 +206,15 @@ public class AudioGroup {
nativeRemove(0L);
super.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/src/jni/rtp/AudioGroup.cpp b/src/jni/rtp/AudioGroup.cpp
index 5dce123..713f0f8 100644
--- a/src/jni/rtp/AudioGroup.cpp
+++ b/src/jni/rtp/AudioGroup.cpp
@@ -45,6 +45,8 @@
#include <audio_effects/effect_aec.h>
#include <system/audio.h>
+#include <ScopedUtfChars.h>
+
#include "jni.h"
#include "JNIHelp.h"
@@ -471,7 +473,7 @@ void AudioStream::decode(int tick)
class AudioGroup
{
public:
- AudioGroup();
+ AudioGroup(const String16 &opPackageName);
~AudioGroup();
bool set(int sampleRate, int sampleCount);
@@ -496,6 +498,8 @@ private:
int mEventQueue;
volatile int mDtmfEvent;
+ String16 mOpPackageName;
+
int mMode;
int mSampleRate;
int mSampleCount;
@@ -543,8 +547,9 @@ private:
sp<DeviceThread> mDeviceThread;
};
-AudioGroup::AudioGroup()
+AudioGroup::AudioGroup(const String16 &opPackageName)
{
+ mOpPackageName = opPackageName;
mMode = ON_HOLD;
mChain = NULL;
mEventQueue = -1;
@@ -806,7 +811,7 @@ bool AudioGroup::DeviceThread::threadLoop()
// Initialize AudioTrack and AudioRecord.
sp<AudioTrack> track = new AudioTrack();
- sp<AudioRecord> record = new AudioRecord();
+ sp<AudioRecord> record = new AudioRecord(mGroup->mOpPackageName);
if (track->set(AUDIO_STREAM_VOICE_CALL, sampleRate, AUDIO_FORMAT_PCM_16_BIT,
AUDIO_CHANNEL_OUT_MONO, output, AUDIO_OUTPUT_FLAG_NONE, NULL /*callback_t*/,
NULL /*user*/, 0 /*notificationFrames*/, 0 /*sharedBuffer*/,
@@ -836,6 +841,7 @@ bool AudioGroup::DeviceThread::threadLoop()
if (mode == ECHO_SUPPRESSION) {
if (mGroup->platformHasAec()) {
aec = new AudioEffect(FX_IID_AEC,
+ mGroup->mOpPackageName,
NULL,
0,
0,
@@ -938,7 +944,7 @@ static jfieldID gMode;
jlong add(JNIEnv *env, jobject thiz, jint mode,
jint socket, jstring jRemoteAddress, jint remotePort,
- jstring jCodecSpec, jint dtmfType)
+ jstring jCodecSpec, jint dtmfType, jstring opPackageNameStr)
{
AudioCodec *codec = NULL;
AudioStream *stream = NULL;
@@ -966,6 +972,8 @@ jlong add(JNIEnv *env, jobject thiz, jint mode,
return 0;
}
+ ScopedUtfChars opPackageName(env, opPackageNameStr);
+
// Create audio codec.
int codecType = -1;
char codecName[16];
@@ -995,7 +1003,7 @@ jlong add(JNIEnv *env, jobject thiz, jint mode,
group = (AudioGroup *)env->GetLongField(thiz, gNative);
if (!group) {
int mode = env->GetIntField(thiz, gMode);
- group = new AudioGroup;
+ group = new AudioGroup(String16(opPackageName.c_str()));
if (!group->set(8000, 256) || !group->setMode(mode)) {
jniThrowException(env, "java/lang/IllegalStateException",
"cannot initialize audio group");
@@ -1051,7 +1059,7 @@ void sendDtmf(JNIEnv *env, jobject thiz, jint event)
}
JNINativeMethod gMethods[] = {
- {"nativeAdd", "(IILjava/lang/String;ILjava/lang/String;I)J", (void *)add},
+ {"nativeAdd", "(IILjava/lang/String;ILjava/lang/String;I;LJava/lang/String;)J", (void *)add},
{"nativeRemove", "(J)V", (void *)remove},
{"nativeSetMode", "(I)V", (void *)setMode},
{"nativeSendDtmf", "(I)V", (void *)sendDtmf},