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

Commit c06e10e2 authored by Adam Stone's avatar Adam Stone
Browse files

Add definition and stub for getMetrics.

This adds a stub for supporting retrieving metrics from the MediaDrm
interface.

BUG: 64001676

Test: Ran the new CTS unit test added in a related CL.

Change-Id: I84cafb79dd6e6f860b058a58fb52113a4e699f7d
parent fc027600
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.PersistableBundle;
import android.util.Log;
import dalvik.system.CloseGuard;
import java.lang.annotation.Retention;
@@ -1201,7 +1202,6 @@ public final class MediaDrm implements AutoCloseable {
    public native void setPropertyByteArray(@NonNull @ArrayProperty
            String propertyName, @NonNull byte[] value);


    private static final native void setCipherAlgorithmNative(
            @NonNull MediaDrm drm, @NonNull byte[] sessionId, @NonNull String algorithm);

@@ -1227,6 +1227,25 @@ public final class MediaDrm implements AutoCloseable {
            @NonNull MediaDrm drm, @NonNull byte[] sessionId,
            @NonNull byte[] keyId, @NonNull byte[] message, @NonNull byte[] signature);

    /**
     * Return Metrics data about the current MediaDrm instance.
     *
     * @return a {@link PersistableBundle} containing the set of attributes and values
     * available for this instance of MediaDrm.
     * The attributes are described in {@link MetricsConstants}.
     *
     * Additional vendor-specific fields may also be present in
     * the return value.
     *
     * @hide - not part of the public API at this time
     */
    public PersistableBundle getMetrics() {
        PersistableBundle bundle = getMetricsNative();
        return bundle;
    }

    private native PersistableBundle getMetricsNative();

    /**
     * In addition to supporting decryption of DASH Common Encrypted Media, the
     * MediaDrm APIs provide the ability to securely deliver session keys from
@@ -1531,4 +1550,22 @@ public final class MediaDrm implements AutoCloseable {
        System.loadLibrary("media_jni");
        native_init();
    }

    /**
     * Definitions for the metrics that are reported via the
     * {@link #getMetrics} call.
     *
     * @hide - not part of the public API at this time
     */
    public final static class MetricsConstants
    {
        private MetricsConstants() {}

        /**
         * This is a placeholder metric. More metrics will be added.
         * <P>
         * TODO: Add the full set of metrics constants.
         */
        public static final String TEMPORARY = "/drm/mediadrm/dummymetric";
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <utils/Log.h>

#include "android_media_MediaDrm.h"
#include "android_media_MediaMetricsJNI.h"

#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
@@ -1603,6 +1604,31 @@ static jboolean android_media_MediaDrm_verifyNative(
    return match;
}

static jobject
android_media_MediaDrm_native_getMetrics(JNIEnv *env, jobject thiz)
{
    sp<IDrm> drm = GetDrm(env, thiz);
    if (drm == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException",
                          "MediaDrm obj is null");
        return NULL;
    }

    // Retrieve current metrics snapshot from drm.
    MediaAnalyticsItem item ;
    status_t err = drm->getMetrics(&item);
    if (err != OK) {
        ALOGE("getMetrics failed: %d", (int)err);
        return (jobject) NULL;
    }

    jobject mybundle = MediaMetricsJNI::writeMetricsToBundle(env, &item, NULL);
    if (mybundle == NULL) {
        ALOGE("getMetrics metric conversion failed");
    }

    return mybundle;
}

static jbyteArray android_media_MediaDrm_signRSANative(
    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
@@ -1739,6 +1765,9 @@ static const JNINativeMethod gMethods[] = {

    { "signRSANative", "(Landroid/media/MediaDrm;[BLjava/lang/String;[B[B)[B",
      (void *)android_media_MediaDrm_signRSANative },

    { "getMetricsNative", "()Landroid/os/PersistableBundle;",
      (void *)android_media_MediaDrm_native_getMetrics },
};

int register_android_media_Drm(JNIEnv *env) {