diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index 065c79b8601fd..ad9a547bc3328 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -1419,6 +1419,16 @@ static jint android_media_AudioTrack_getDualMonoMode(JNIEnv *env, jobject thiz, return nativeToJavaStatus(status); } +static void android_media_AudioTrack_setPlayerIId(JNIEnv *env, jobject thiz, jint playerIId) { + sp track = getAudioTrack(env, thiz); + if (track == nullptr) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioTrack pointer for setPlayerIId()"); + } + ALOGV("%s: playerIId %d", __func__, playerIId); + track->setPlayerIId(playerIId); +} + // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- static const JNINativeMethod gMethods[] = { @@ -1496,6 +1506,7 @@ static const JNINativeMethod gMethods[] = { (void *)android_media_AudioTrack_getAudioDescriptionMixLeveldB}, {"native_set_dual_mono_mode", "(I)I", (void *)android_media_AudioTrack_setDualMonoMode}, {"native_get_dual_mono_mode", "([I)I", (void *)android_media_AudioTrack_getDualMonoMode}, + {"native_setPlayerIId", "(I)V", (void *)android_media_AudioTrack_setPlayerIId}, }; // field names found in android/media/AudioTrack.java diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index 7fb83f17a9d47..ae3c671108ed0 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -837,6 +837,7 @@ public class AudioTrack extends PlayerBase } baseRegisterPlayer(mSessionId); + native_setPlayerIId(mPlayerIId); // mPlayerIId now ready to send to native AudioTrack. } /** @@ -4203,6 +4204,20 @@ public class AudioTrack extends PlayerBase private native int native_set_dual_mono_mode(int dualMonoMode); private native int native_get_dual_mono_mode(int[] dualMonoMode); + /** + * Sets the audio service Player Interface Id. + * + * The playerIId does not change over the lifetime of the client + * Java AudioTrack and is set automatically on creation. + * + * This call informs the native AudioTrack for metrics logging purposes. + * + * @param id the value reported by AudioManager when registering the track. + * A value of -1 indicates invalid - the playerIId was never set. + * @throws IllegalStateException if AudioTrack not initialized. + */ + private native void native_setPlayerIId(int playerIId); + //--------------------------------------------------------- // Utility methods //------------------ diff --git a/media/java/android/media/PlayerBase.java b/media/java/android/media/PlayerBase.java index 4407efad60525..5d0f0aa8a921e 100644 --- a/media/java/android/media/PlayerBase.java +++ b/media/java/android/media/PlayerBase.java @@ -78,7 +78,7 @@ public abstract class PlayerBase { private final int mImplType; // uniquely identifies the Player Interface throughout the system (P I Id) - private int mPlayerIId = AudioPlaybackConfiguration.PLAYER_PIID_INVALID; + protected int mPlayerIId = AudioPlaybackConfiguration.PLAYER_PIID_INVALID; @GuardedBy("mLock") private int mState;