Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 850d0685 authored by Andy Hung's avatar Andy Hung
Browse files

MediaMetrics: Send playerIId to native AudioTrack

Test: adb shell dumpsys media.metrics
Bug: 180541541
Change-Id: Ie538b4f0966c3c9aecaa74c6aa2e0173956e2d38
parent d145f376
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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<AudioTrack> 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
+15 −0
Original line number Diff line number Diff line
@@ -837,6 +837,7 @@ public class AudioTrack extends PlayerBase
        }

        baseRegisterPlayer(mSessionId);
        native_setPlayerIId(mPlayerIId); // mPlayerIId now ready to send to native AudioTrack.
    }

    /**
@@ -4201,6 +4202,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
    //------------------
+1 −1
Original line number Diff line number Diff line
@@ -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;