From f7568b5ee96b3d80721c76ab3d47f1368a99bf98 Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Wed, 17 Apr 2013 14:24:40 -0700 Subject: Improve error handling for DRM errors reported by plugins Change-Id: I25df78f16379b32c54189949daa3ab9c91187375 related-to-bug: 8621516 --- media/jni/android_media_MediaDrm.cpp | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'media') diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp index d9d466e..d1b499e 100644 --- a/media/jni/android_media_MediaDrm.cpp +++ b/media/jni/android_media_MediaDrm.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace android { @@ -191,10 +192,62 @@ void JNIDrmListener::notify(DrmPlugin::EventType eventType, int extra, static bool throwExceptionAsNecessary( JNIEnv *env, status_t err, const char *msg = NULL) { + const char *drmMessage = NULL; + + switch(err) { + case ERROR_DRM_UNKNOWN: + drmMessage = "General DRM error"; + break; + case ERROR_DRM_NO_LICENSE: + drmMessage = "No license"; + break; + case ERROR_DRM_LICENSE_EXPIRED: + drmMessage = "License expired"; + break; + case ERROR_DRM_SESSION_NOT_OPENED: + drmMessage = "Session not opened"; + break; + case ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED: + drmMessage = "Not initialized"; + break; + case ERROR_DRM_DECRYPT: + drmMessage = "Decrypt error"; + break; + case ERROR_DRM_CANNOT_HANDLE: + drmMessage = "Unsupported scheme or data format"; + break; + case ERROR_DRM_TAMPER_DETECTED: + drmMessage = "Invalid state"; + break; + case ERROR_DRM_NOT_PROVISIONED: + drmMessage = "Not provisioned"; + break; + case ERROR_DRM_DEVICE_REVOKED: + drmMessage = "Device revoked"; + break; + default: + break; + } + + String8 vendorMessage; + if (err >= ERROR_DRM_VENDOR_MIN && err <= ERROR_DRM_VENDOR_MAX) { + vendorMessage.format("DRM vendor-defined error: %d", err); + drmMessage = vendorMessage.string(); + } + if (err == BAD_VALUE) { jniThrowException(env, "java/lang/IllegalArgumentException", msg); return true; } else if (err != OK) { + String8 errbuf; + if (drmMessage != NULL) { + if (msg == NULL) { + msg = drmMessage; + } else { + errbuf.format("%s: %s", msg, drmMessage); + msg = errbuf.string(); + } + } jniThrowException(env, "java/lang/IllegalStateException", msg); return true; } -- cgit v1.1