From eada5376d9c34f77bd3ba86a2ea674e3bde5e961 Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Tue, 21 May 2013 12:48:14 -0700 Subject: Improve exception error messages to help diagnose app errors bug: 9072051 Change-Id: I45057951d1a62b1b4a996e85f01601239e1b7161 --- media/jni/android_media_MediaDrm.cpp | 102 ++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 32 deletions(-) (limited to 'media/jni') diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp index ec88949..3d7784d 100644 --- a/media/jni/android_media_MediaDrm.cpp +++ b/media/jni/android_media_MediaDrm.cpp @@ -128,7 +128,8 @@ JNIDrmListener::JNIDrmListener(JNIEnv* env, jobject thiz, jobject weak_thiz) jclass clazz = env->GetObjectClass(thiz); if (clazz == NULL) { ALOGE("Can't find android/media/MediaDrm"); - jniThrowException(env, "java/lang/Exception", NULL); + jniThrowException(env, "java/lang/Exception", + "Can't find android/media/MediaDrm"); return; } mClass = (jclass)env->NewGlobalRef(clazz); @@ -408,13 +409,15 @@ static KeyedVector HashMapToKeyedVector(JNIEnv *env, jobject & if (entry) { jobject obj = env->CallObjectMethod(entry, gFields.entry.getKey); if (!env->IsInstanceOf(obj, clazz)) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "HashMap key is not a String"); } jstring jkey = static_cast(obj); obj = env->CallObjectMethod(entry, gFields.entry.getValue); if (!env->IsInstanceOf(obj, clazz)) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "HashMap value is not a String"); } jstring jvalue = static_cast(obj); @@ -486,12 +489,12 @@ static sp setDrm( static bool CheckSession(JNIEnv *env, const sp &drm, jbyteArray const &jsessionId) { if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", "MediaDrm obj is null"); return false; } if (jsessionId == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", "sessionId is null"); return false; } return true; @@ -557,14 +560,15 @@ static void android_media_MediaDrm_native_setup( jobject weak_this, jbyteArray uuidObj) { if (uuidObj == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", "uuid is null"); return; } Vector uuid = JByteArrayToVector(env, uuidObj); if (uuid.size() != 16) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "invalid UUID size, expected 16 bytes"); return; } @@ -604,7 +608,7 @@ static jboolean android_media_MediaDrm_isCryptoSchemeSupportedNative( jniThrowException( env, "java/lang/IllegalArgumentException", - NULL); + "invalid UUID size, expected 16 bytes"); return false; } @@ -616,7 +620,8 @@ static jbyteArray android_media_MediaDrm_openSession( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return NULL; } @@ -712,7 +717,8 @@ static jbyteArray android_media_MediaDrm_provideKeyResponse( Vector sessionId(JByteArrayToVector(env, jsessionId)); if (jresponse == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "key response is null"); return NULL; } Vector response(JByteArrayToVector(env, jresponse)); @@ -729,7 +735,8 @@ static void android_media_MediaDrm_removeKeys( sp drm = GetDrm(env, thiz); if (jkeysetId == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "keySetId is null"); return; } @@ -788,7 +795,8 @@ static jobject android_media_MediaDrm_getProvisionRequest( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return NULL; } @@ -824,12 +832,14 @@ static void android_media_MediaDrm_provideProvisionResponse( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return; } if (jresponse == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "provision response is null"); return; } @@ -845,7 +855,8 @@ static jobject android_media_MediaDrm_getSecureStops( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return NULL; } @@ -865,7 +876,8 @@ static void android_media_MediaDrm_releaseSecureStops( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return; } @@ -881,12 +893,14 @@ static jstring android_media_MediaDrm_getPropertyString( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return NULL; } if (jname == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "property name String is null"); return NULL; } @@ -907,12 +921,14 @@ static jbyteArray android_media_MediaDrm_getPropertyByteArray( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return NULL; } if (jname == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "property name String is null"); return NULL; } @@ -933,12 +949,20 @@ static void android_media_MediaDrm_setPropertyString( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return; } - if (jname == NULL || jvalue == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + if (jname == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "property name String is null"); + return; + } + + if (jvalue == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "property value String is null"); return; } @@ -955,12 +979,20 @@ static void android_media_MediaDrm_setPropertyByteArray( sp drm = GetDrm(env, thiz); if (drm == NULL) { - jniThrowException(env, "java/lang/IllegalStateException", NULL); + jniThrowException(env, "java/lang/IllegalStateException", + "MediaDrm obj is null"); return; } - if (jname == NULL || jvalue == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + if (jname == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "property name String is null"); + return; + } + + if (jvalue == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", + "property value byte array is null"); return; } @@ -983,7 +1015,8 @@ static void android_media_MediaDrm_setCipherAlgorithmNative( } if (jalgorithm == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "algorithm String is null"); return; } @@ -1006,7 +1039,8 @@ static void android_media_MediaDrm_setMacAlgorithmNative( } if (jalgorithm == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "algorithm String is null"); return; } @@ -1030,7 +1064,8 @@ static jbyteArray android_media_MediaDrm_encryptNative( } if (jkeyId == NULL || jinput == NULL || jiv == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "required argument is null"); return NULL; } @@ -1058,7 +1093,8 @@ static jbyteArray android_media_MediaDrm_decryptNative( } if (jkeyId == NULL || jinput == NULL || jiv == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "required argument is null"); return NULL; } @@ -1085,7 +1121,8 @@ static jbyteArray android_media_MediaDrm_signNative( } if (jkeyId == NULL || jmessage == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "required argument is null"); return NULL; } @@ -1112,7 +1149,8 @@ static jboolean android_media_MediaDrm_verifyNative( } if (jkeyId == NULL || jmessage == NULL || jsignature == NULL) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + jniThrowException(env, "java/lang/IllegalArgumentException", + "required argument is null"); return false; } -- cgit v1.1