summaryrefslogtreecommitdiffstats
path: root/media/jni/android_media_MediaCrypto.cpp
diff options
context:
space:
mode:
authorJeff Tinker <jtinker@google.com>2015-04-10 04:05:25 -0700
committerJeff Tinker <jtinker@google.com>2015-04-10 04:15:15 -0700
commit6f6ef118a791c0f888db4addc6543e1f67700ead (patch)
treec4ba12ff540e0353f53da76e092bc2ae7969a767 /media/jni/android_media_MediaCrypto.cpp
parent74797f843c209520e6cc5b74249e3e118556a61b (diff)
downloadframeworks_base-6f6ef118a791c0f888db4addc6543e1f67700ead.zip
frameworks_base-6f6ef118a791c0f888db4addc6543e1f67700ead.tar.gz
frameworks_base-6f6ef118a791c0f888db4addc6543e1f67700ead.tar.bz2
Add a method to associate MediaDrm session with MediaCrypto
Previously, to associate a MediaDrm session with MediaCrypto, the MediaDrm sessionId was passed as initData to the MediaCrypto constructor. This is not ideal for two reasons: it's pretty obscure and you can't change the association without tearing down the MediaCodec/MediaCrypto and starting all over. Use cases like key rotation require being able to update the MediaDrm session post-construction. This CL addresses both of these issues. bug: 19570317 Change-Id: Ie3d3eda16651b598cdd41f2180074a43cb6c0884
Diffstat (limited to 'media/jni/android_media_MediaCrypto.cpp')
-rw-r--r--media/jni/android_media_MediaCrypto.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/media/jni/android_media_MediaCrypto.cpp b/media/jni/android_media_MediaCrypto.cpp
index d2216fb..a9accb0 100644
--- a/media/jni/android_media_MediaCrypto.cpp
+++ b/media/jni/android_media_MediaCrypto.cpp
@@ -140,6 +140,15 @@ sp<ICrypto> JCrypto::GetCrypto(JNIEnv *env, jobject obj) {
return jcrypto->mCrypto;
}
+// JNI conversion utilities
+static Vector<uint8_t> JByteArrayToVector(JNIEnv *env, jbyteArray const &byteArray) {
+ Vector<uint8_t> vector;
+ size_t length = env->GetArrayLength(byteArray);
+ vector.insertAt((size_t)0, length);
+ env->GetByteArrayRegion(byteArray, 0, length, (jbyte *)vector.editArray());
+ return vector;
+}
+
} // namespace android
using namespace android;
@@ -274,6 +283,37 @@ static jboolean android_media_MediaCrypto_requiresSecureDecoderComponent(
return result ? JNI_TRUE : JNI_FALSE;
}
+static void android_media_MediaCrypto_setMediaDrmSession(
+ JNIEnv *env, jobject thiz, jbyteArray jsessionId) {
+ if (jsessionId == NULL) {
+ jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+ return;
+ }
+
+ sp<ICrypto> crypto = JCrypto::GetCrypto(env, thiz);
+
+ if (crypto == NULL) {
+ jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+ return;
+ }
+
+ Vector<uint8_t> sessionId(JByteArrayToVector(env, jsessionId));
+
+ status_t err = crypto->setMediaDrmSession(sessionId);
+
+ String8 msg("setMediaDrmSession failed");
+ if (err == ERROR_DRM_SESSION_NOT_OPENED) {
+ msg += ": session not opened";
+ } else if (err == ERROR_UNSUPPORTED) {
+ msg += ": not supported by this crypto scheme";
+ } else if (err == NO_INIT) {
+ msg += ": crypto plugin not initialized";
+ } else if (err != OK) {
+ msg.appendFormat(": general failure (%d)", err);
+ }
+ jniThrowException(env, "android/media/MediaCryptoException", msg.string());
+}
+
static JNINativeMethod gMethods[] = {
{ "release", "()V", (void *)android_media_MediaCrypto_release },
{ "native_init", "()V", (void *)android_media_MediaCrypto_native_init },
@@ -289,6 +329,9 @@ static JNINativeMethod gMethods[] = {
{ "requiresSecureDecoderComponent", "(Ljava/lang/String;)Z",
(void *)android_media_MediaCrypto_requiresSecureDecoderComponent },
+
+ { "setMediaDrmSession", "([B)V",
+ (void *)android_media_MediaCrypto_setMediaDrmSession },
};
int register_android_media_Crypto(JNIEnv *env) {