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

Commit 6a968710 authored by Jeff Tinker's avatar Jeff Tinker Committed by Android (Google) Code Review
Browse files

Merge "Add diagnostic error code to MediaDrm IllegalStateExceptions"

parents 72673558 d712e1a3
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -14490,6 +14490,11 @@ package android.media {
    method public java.lang.String getDefaultUrl();
  }
  public static final class MediaDrm.MediaDrmStateException extends java.lang.IllegalStateException {
    ctor public MediaDrm.MediaDrmStateException(int, java.lang.String);
    method public int getErrorCode();
  }
  public static abstract interface MediaDrm.OnEventListener {
    method public abstract void onEvent(android.media.MediaDrm, byte[], int, int, byte[]);
  }
+21 −0
Original line number Diff line number Diff line
@@ -180,6 +180,27 @@ public final class MediaDrm {
                getByteArrayFromUUID(uuid));
    }

    /**
     * Thrown when an unrecoverable failure occurs during a MediaDrm operation.
     * Extends java.lang.IllegalStateException with the addition of an error
     * code that may be useful in diagnosing the failure.
     */
    public static final class MediaDrmStateException extends java.lang.IllegalStateException {
        private final int mErrorCode;

        public MediaDrmStateException(int errorCode, String detailMessage) {
            super(detailMessage);
            mErrorCode = errorCode;
        }

        /**
         * Retrieve the associated error code
         */
        public int getErrorCode() {
            return mErrorCode;
        }
    }

    /**
     * Register a callback to be invoked when an event occurs
     *
+19 −2
Original line number Diff line number Diff line
@@ -110,6 +110,11 @@ struct CertificateFields {
    jfieldID certificateData;
};

struct StateExceptionFields {
    jmethodID init;
    jclass classId;
};

struct fields_t {
    jfieldID context;
    jmethodID post_event;
@@ -121,6 +126,7 @@ struct fields_t {
    IteratorFields iterator;
    EntryFields entry;
    CertificateFields certificate;
    StateExceptionFields stateException;
    jclass certificateClassId;
    jclass hashmapClassId;
    jclass arraylistClassId;
@@ -212,6 +218,14 @@ void JNIDrmListener::notify(DrmPlugin::EventType eventType, int extra,
    }
}

static void throwStateException(JNIEnv *env, const char *msg, status_t err) {
    ALOGE("Illegal state exception: %s (%d)", msg, err);

    jobject exception = env->NewObject(gFields.stateException.classId,
            gFields.stateException.init, static_cast<int>(err),
            env->NewStringUTF(msg));
    env->Throw(static_cast<jthrowable>(exception));
}

static bool throwExceptionAsNecessary(
        JNIEnv *env, status_t err, const char *msg = NULL) {
@@ -275,8 +289,7 @@ static bool throwExceptionAsNecessary(
                msg = errbuf.string();
            }
        }
        ALOGE("Illegal state exception: %s", msg);
        jniThrowException(env, "java/lang/IllegalStateException", msg);
        throwStateException(env, msg, err);
        return true;
    }
    return false;
@@ -608,6 +621,10 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) {

    FIND_CLASS(clazz, "java/util/ArrayList");
    gFields.arraylistClassId = static_cast<jclass>(env->NewGlobalRef(clazz));

    FIND_CLASS(clazz, "android/media/MediaDrm$MediaDrmStateException");
    GET_METHOD_ID(gFields.stateException.init, clazz, "<init>", "(ILjava/lang/String;)V");
    gFields.stateException.classId = static_cast<jclass>(env->NewGlobalRef(clazz));
}

static void android_media_MediaDrm_native_setup(