Merge "Pass AttributionSource from Context to native AudioTrack"
This commit is contained in:
committed by
Android (Google) Code Review
commit
b56a3cdf91
@@ -19,18 +19,18 @@
|
||||
|
||||
#include "android_media_AudioTrack.h"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <android-base/macros.h>
|
||||
#include <android_os_Parcel.h>
|
||||
#include <binder/MemoryBase.h>
|
||||
#include <binder/MemoryHeapBase.h>
|
||||
#include <media/AudioParameter.h>
|
||||
#include <media/AudioSystem.h>
|
||||
#include <media/AudioTrack.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <android-base/macros.h>
|
||||
#include <binder/MemoryHeapBase.h>
|
||||
#include <binder/MemoryBase.h>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "android_media_AudioAttributes.h"
|
||||
#include "android_media_AudioErrors.h"
|
||||
@@ -41,8 +41,7 @@
|
||||
#include "android_media_MediaMetricsJNI.h"
|
||||
#include "android_media_PlaybackParams.h"
|
||||
#include "android_media_VolumeShaper.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -245,9 +244,10 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
jobject jaa, jintArray jSampleRate,
|
||||
jint channelPositionMask, jint channelIndexMask,
|
||||
jint audioFormat, jint buffSizeInBytes, jint memoryMode,
|
||||
jintArray jSession, jlong nativeAudioTrack,
|
||||
jboolean offload, jint encapsulationMode,
|
||||
jobject tunerConfiguration, jstring opPackageName) {
|
||||
jintArray jSession, jobject jAttributionSource,
|
||||
jlong nativeAudioTrack, jboolean offload,
|
||||
jint encapsulationMode, jobject tunerConfiguration,
|
||||
jstring opPackageName) {
|
||||
ALOGV("sampleRates=%p, channel mask=%x, index mask=%x, audioFormat(Java)=%d, buffSize=%d,"
|
||||
" nativeAudioTrack=0x%" PRIX64 ", offload=%d encapsulationMode=%d tuner=%p",
|
||||
jSampleRate, channelPositionMask, channelIndexMask, audioFormat, buffSizeInBytes,
|
||||
@@ -323,10 +323,9 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
|
||||
// create the native AudioTrack object
|
||||
ScopedUtfChars opPackageNameStr(env, opPackageName);
|
||||
// TODO b/182469354: make consistent with AudioRecord
|
||||
AttributionSourceState attributionSource;
|
||||
attributionSource.packageName = std::string(opPackageNameStr.c_str());
|
||||
attributionSource.token = sp<BBinder>::make();
|
||||
|
||||
android::content::AttributionSourceState attributionSource;
|
||||
attributionSource.readFromParcel(parcelForJavaObject(env, jAttributionSource));
|
||||
lpTrack = sp<AudioTrack>::make(attributionSource);
|
||||
|
||||
// read the AudioAttributes values
|
||||
@@ -382,7 +381,7 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
offload ? AudioTrack::TRANSFER_SYNC_NOTIF_CALLBACK
|
||||
: AudioTrack::TRANSFER_SYNC,
|
||||
(offload || encapsulationMode) ? &offloadInfo : NULL,
|
||||
AttributionSourceState(), // default uid, pid values
|
||||
attributionSource, // Passed from Java
|
||||
paa.get());
|
||||
break;
|
||||
|
||||
@@ -401,14 +400,14 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
format, // word length, PCM
|
||||
nativeChannelMask, frameCount, AUDIO_OUTPUT_FLAG_NONE,
|
||||
lpJniStorage,
|
||||
0, // notificationFrames == 0 since not using EVENT_MORE_DATA
|
||||
// to feed the AudioTrack
|
||||
iMem, // shared mem
|
||||
true, // thread can call Java
|
||||
sessionId, // audio session ID
|
||||
0, // notificationFrames == 0 since not using EVENT_MORE_DATA
|
||||
// to feed the AudioTrack
|
||||
iMem, // shared mem
|
||||
true, // thread can call Java
|
||||
sessionId, // audio session ID
|
||||
AudioTrack::TRANSFER_SHARED,
|
||||
nullptr , // default offloadInfo
|
||||
AttributionSourceState(), // default uid, pid values
|
||||
nullptr, // default offloadInfo
|
||||
attributionSource, // Passed from Java
|
||||
paa.get());
|
||||
break;
|
||||
}
|
||||
@@ -1456,7 +1455,8 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"native_pause", "()V", (void *)android_media_AudioTrack_pause},
|
||||
{"native_flush", "()V", (void *)android_media_AudioTrack_flush},
|
||||
{"native_setup",
|
||||
"(Ljava/lang/Object;Ljava/lang/Object;[IIIIII[IJZILjava/lang/Object;Ljava/lang/String;)I",
|
||||
"(Ljava/lang/Object;Ljava/lang/Object;[IIIIII[ILandroid/os/Parcel;"
|
||||
"JZILjava/lang/Object;Ljava/lang/String;)I",
|
||||
(void *)android_media_AudioTrack_setup},
|
||||
{"native_finalize", "()V", (void *)android_media_AudioTrack_finalize},
|
||||
{"native_release", "()V", (void *)android_media_AudioTrack_release},
|
||||
|
||||
@@ -28,6 +28,8 @@ import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.AttributionSource;
|
||||
import android.content.AttributionSource.ScopedParcelState;
|
||||
import android.content.Context;
|
||||
import android.media.audiopolicy.AudioMix;
|
||||
import android.media.audiopolicy.AudioMixingRule;
|
||||
@@ -39,6 +41,7 @@ import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Parcel;
|
||||
import android.os.PersistableBundle;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
@@ -822,15 +825,20 @@ public class AudioTrack extends PlayerBase
|
||||
int[] session = new int[1];
|
||||
session[0] = resolvePlaybackSessionId(context, sessionId);
|
||||
|
||||
AttributionSource attributionSource = context == null
|
||||
? AttributionSource.myAttributionSource() : context.getAttributionSource();
|
||||
|
||||
// native initialization
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this), mAttributes,
|
||||
sampleRate, mChannelMask, mChannelIndexMask, mAudioFormat,
|
||||
mNativeBufferSizeInBytes, mDataLoadMode, session, 0 /*nativeTrackInJavaObj*/,
|
||||
offload, encapsulationMode, tunerConfiguration,
|
||||
getCurrentOpPackageName());
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
try (ScopedParcelState attributionSourceState = attributionSource.asScopedParcelState()) {
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this), mAttributes,
|
||||
sampleRate, mChannelMask, mChannelIndexMask, mAudioFormat,
|
||||
mNativeBufferSizeInBytes, mDataLoadMode, session,
|
||||
attributionSourceState.getParcel(), 0 /*nativeTrackInJavaObj*/, offload,
|
||||
encapsulationMode, tunerConfiguration, getCurrentOpPackageName());
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code " + initResult + " when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
}
|
||||
}
|
||||
|
||||
mSampleRate = sampleRate[0];
|
||||
@@ -902,23 +910,27 @@ public class AudioTrack extends PlayerBase
|
||||
// *Native* AudioTrack, so the attributes parameters to native_setup() are ignored.
|
||||
int[] session = { 0 };
|
||||
int[] rates = { 0 };
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this),
|
||||
null /*mAttributes - NA*/,
|
||||
rates /*sampleRate - NA*/,
|
||||
0 /*mChannelMask - NA*/,
|
||||
0 /*mChannelIndexMask - NA*/,
|
||||
0 /*mAudioFormat - NA*/,
|
||||
0 /*mNativeBufferSizeInBytes - NA*/,
|
||||
0 /*mDataLoadMode - NA*/,
|
||||
session,
|
||||
nativeTrackInJavaObj,
|
||||
false /*offload*/,
|
||||
ENCAPSULATION_MODE_NONE,
|
||||
null /* tunerConfiguration */,
|
||||
"" /* opPackagename */);
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
try (ScopedParcelState attributionSourceState =
|
||||
AttributionSource.myAttributionSource().asScopedParcelState()) {
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this),
|
||||
null /*mAttributes - NA*/,
|
||||
rates /*sampleRate - NA*/,
|
||||
0 /*mChannelMask - NA*/,
|
||||
0 /*mChannelIndexMask - NA*/,
|
||||
0 /*mAudioFormat - NA*/,
|
||||
0 /*mNativeBufferSizeInBytes - NA*/,
|
||||
0 /*mDataLoadMode - NA*/,
|
||||
session,
|
||||
attributionSourceState.getParcel(),
|
||||
nativeTrackInJavaObj,
|
||||
false /*offload*/,
|
||||
ENCAPSULATION_MODE_NONE,
|
||||
null /* tunerConfiguration */,
|
||||
"" /* opPackagename */);
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code " + initResult + " when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
}
|
||||
}
|
||||
|
||||
mSessionId = session[0];
|
||||
@@ -4371,9 +4383,9 @@ public class AudioTrack extends PlayerBase
|
||||
private native final int native_setup(Object /*WeakReference<AudioTrack>*/ audiotrack_this,
|
||||
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,
|
||||
@NonNull String opPackageName);
|
||||
int buffSizeInBytes, int mode, int[] sessionId, @NonNull Parcel attributionSource,
|
||||
long nativeAudioTrack, boolean offload, int encapsulationMode,
|
||||
Object tunerConfiguration, @NonNull String opPackageName);
|
||||
|
||||
private native final void native_finalize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user