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

Commit e9990d89 authored by Adam Stone's avatar Adam Stone Committed by Android (Google) Code Review
Browse files

Merge changes I94ff9d4d,I84cafb79

* changes:
  Add CounterMetric and a single use case.
  Add definition and stub for getMetrics.
parents e3ff0712 e7d25597
Loading
Loading
Loading
Loading
+47 −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,31 @@ 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() {}

        /**
         * Key to extract the number of successful {@link #openSession} calls
         * from the {@link PersistableBundle} returned by a
         * {@link #getMetrics} call.
         */
        public static final String OPEN_SESSION_OK_COUNT
            = "/drm/mediadrm/open_session/ok/count";

        /**
         * Key to extract the number of failed {@link #openSession} calls
         * from the {@link PersistableBundle} returned by a
         * {@link #getMetrics} call.
         */
        public static final String OPEN_SESSION_ERROR_COUNT
            = "/drm/mediadrm/open_session/error/count";
    }
}
+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) {