Add package name when creating AudioTrack.
The package name will be used when starting external vibration. The package name will be sent to vibrator service to check if the application has the permission to start vibration, Bug: 165910728 Bug: 162343845 Test: atest AudioTrackTest MediaPlayerTest Test: start audio-coupled-haptic playback Change-Id: I04b4711d11ab5f0f0716ea4c5e1c0f754fe834bb Merged-In: I04b4711d11ab5f0f0716ea4c5e1c0f754fe834bb
This commit is contained in:
@@ -807,7 +807,8 @@ public class AudioTrack extends PlayerBase
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this), mAttributes,
|
||||
sampleRate, mChannelMask, mChannelIndexMask, mAudioFormat,
|
||||
mNativeBufferSizeInBytes, mDataLoadMode, session, 0 /*nativeTrackInJavaObj*/,
|
||||
offload, encapsulationMode, tunerConfiguration);
|
||||
offload, encapsulationMode, tunerConfiguration,
|
||||
getCurrentOpPackageName());
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
@@ -893,7 +894,8 @@ public class AudioTrack extends PlayerBase
|
||||
nativeTrackInJavaObj,
|
||||
false /*offload*/,
|
||||
ENCAPSULATION_MODE_NONE,
|
||||
null /* tunerConfiguration */);
|
||||
null /* tunerConfiguration */,
|
||||
"" /* opPackagename */);
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
@@ -4062,7 +4064,8 @@ public class AudioTrack extends PlayerBase
|
||||
Object /*AudioAttributes*/ attributes,
|
||||
int[] sampleRate, int channelMask, int channelIndexMask, int audioFormat,
|
||||
int buffSizeInBytes, int mode, int[] sessionId, long nativeAudioTrack,
|
||||
boolean offload, int encapsulationMode, Object tunerConfiguration);
|
||||
boolean offload, int encapsulationMode, Object tunerConfiguration,
|
||||
@NonNull String opPackageName);
|
||||
|
||||
private native final void native_finalize();
|
||||
|
||||
|
||||
@@ -672,7 +672,8 @@ public class MediaPlayer extends PlayerBase
|
||||
/* Native setup requires a weak reference to our object.
|
||||
* It's easier to create it here than in C++.
|
||||
*/
|
||||
native_setup(new WeakReference<MediaPlayer>(this));
|
||||
native_setup(new WeakReference<MediaPlayer>(this),
|
||||
getCurrentOpPackageName());
|
||||
|
||||
baseRegisterPlayer();
|
||||
}
|
||||
@@ -2378,7 +2379,7 @@ public class MediaPlayer extends PlayerBase
|
||||
private native final int native_setMetadataFilter(Parcel request);
|
||||
|
||||
private static native final void native_init();
|
||||
private native final void native_setup(Object mediaplayer_this);
|
||||
private native void native_setup(Object mediaplayerThis, @NonNull String opPackageName);
|
||||
private native final void native_finalize();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.os.Parcelable;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
@@ -622,4 +623,8 @@ public abstract class PlayerBase {
|
||||
Log.w(className, "See the documentation of " + opName + " for what to use instead with " +
|
||||
"android.media.AudioAttributes to qualify your playback use case");
|
||||
}
|
||||
|
||||
protected String getCurrentOpPackageName() {
|
||||
return TextUtils.emptyIfNull(ActivityThread.currentOpPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <utils/threads.h>
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include "android_runtime/AndroidRuntime.h"
|
||||
#include "android_runtime/android_view_Surface.h"
|
||||
#include "android_runtime/Log.h"
|
||||
@@ -944,10 +945,12 @@ android_media_MediaPlayer_native_init(JNIEnv *env)
|
||||
}
|
||||
|
||||
static void
|
||||
android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
|
||||
android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
|
||||
jstring opPackageName)
|
||||
{
|
||||
ALOGV("native_setup");
|
||||
sp<MediaPlayer> mp = new MediaPlayer();
|
||||
ScopedUtfChars opPackageNameStr(env, opPackageName);
|
||||
sp<MediaPlayer> mp = new MediaPlayer(opPackageNameStr.c_str());
|
||||
if (mp == NULL) {
|
||||
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
|
||||
return;
|
||||
@@ -1403,7 +1406,7 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"native_setMetadataFilter", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_setMetadataFilter},
|
||||
{"native_getMetadata", "(ZZLandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_getMetadata},
|
||||
{"native_init", "()V", (void *)android_media_MediaPlayer_native_init},
|
||||
{"native_setup", "(Ljava/lang/Object;)V", (void *)android_media_MediaPlayer_native_setup},
|
||||
{"native_setup", "(Ljava/lang/Object;Ljava/lang/String;)V",(void *)android_media_MediaPlayer_native_setup},
|
||||
{"native_finalize", "()V", (void *)android_media_MediaPlayer_native_finalize},
|
||||
{"getAudioSessionId", "()I", (void *)android_media_MediaPlayer_get_audio_session_id},
|
||||
{"setAudioSessionId", "(I)V", (void *)android_media_MediaPlayer_set_audio_session_id},
|
||||
|
||||
Reference in New Issue
Block a user