Merge "media jni: fix CryptoException error code to string"

This commit is contained in:
Treehugger Robot
2022-05-16 09:17:03 +00:00
committed by Gerrit Code Review

View File

@@ -1294,45 +1294,46 @@ static void throwCryptoException(JNIEnv *env, status_t err, const char *msg,
std::string defaultMsg = "Unknown Error"; std::string defaultMsg = "Unknown Error";
/* translate OS errors to Java API CryptoException errorCodes (which are positive) */ /* translate OS errors to Java API CryptoException errorCodes (which are positive) */
jint jerr = 0;
switch (err) { switch (err) {
case ERROR_DRM_NO_LICENSE: case ERROR_DRM_NO_LICENSE:
err = gCryptoErrorCodes.cryptoErrorNoKey; jerr = gCryptoErrorCodes.cryptoErrorNoKey;
defaultMsg = "Crypto key not available"; defaultMsg = "Crypto key not available";
break; break;
case ERROR_DRM_LICENSE_EXPIRED: case ERROR_DRM_LICENSE_EXPIRED:
err = gCryptoErrorCodes.cryptoErrorKeyExpired; jerr = gCryptoErrorCodes.cryptoErrorKeyExpired;
defaultMsg = "License expired"; defaultMsg = "License expired";
break; break;
case ERROR_DRM_RESOURCE_BUSY: case ERROR_DRM_RESOURCE_BUSY:
err = gCryptoErrorCodes.cryptoErrorResourceBusy; jerr = gCryptoErrorCodes.cryptoErrorResourceBusy;
defaultMsg = "Resource busy or unavailable"; defaultMsg = "Resource busy or unavailable";
break; break;
case ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION: case ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
err = gCryptoErrorCodes.cryptoErrorInsufficientOutputProtection; jerr = gCryptoErrorCodes.cryptoErrorInsufficientOutputProtection;
defaultMsg = "Required output protections are not active"; defaultMsg = "Required output protections are not active";
break; break;
case ERROR_DRM_SESSION_NOT_OPENED: case ERROR_DRM_SESSION_NOT_OPENED:
err = gCryptoErrorCodes.cryptoErrorSessionNotOpened; jerr = gCryptoErrorCodes.cryptoErrorSessionNotOpened;
defaultMsg = "Attempted to use a closed session"; defaultMsg = "Attempted to use a closed session";
break; break;
case ERROR_DRM_INSUFFICIENT_SECURITY: case ERROR_DRM_INSUFFICIENT_SECURITY:
err = gCryptoErrorCodes.cryptoErrorInsufficientSecurity; jerr = gCryptoErrorCodes.cryptoErrorInsufficientSecurity;
defaultMsg = "Required security level is not met"; defaultMsg = "Required security level is not met";
break; break;
case ERROR_DRM_CANNOT_HANDLE: case ERROR_DRM_CANNOT_HANDLE:
err = gCryptoErrorCodes.cryptoErrorUnsupportedOperation; jerr = gCryptoErrorCodes.cryptoErrorUnsupportedOperation;
defaultMsg = "Operation not supported in this configuration"; defaultMsg = "Operation not supported in this configuration";
break; break;
case ERROR_DRM_FRAME_TOO_LARGE: case ERROR_DRM_FRAME_TOO_LARGE:
err = gCryptoErrorCodes.cryptoErrorFrameTooLarge; jerr = gCryptoErrorCodes.cryptoErrorFrameTooLarge;
defaultMsg = "Decrytped frame exceeds size of output buffer"; defaultMsg = "Decrytped frame exceeds size of output buffer";
break; break;
case ERROR_DRM_SESSION_LOST_STATE: case ERROR_DRM_SESSION_LOST_STATE:
err = gCryptoErrorCodes.cryptoErrorLostState; jerr = gCryptoErrorCodes.cryptoErrorLostState;
defaultMsg = "Session state was lost, open a new session and retry"; defaultMsg = "Session state was lost, open a new session and retry";
break; break;
default: /* Other negative DRM error codes go out best-effort. */ default: /* Other negative DRM error codes go out best-effort. */
err = MediaErrorToJavaError(err); jerr = MediaErrorToJavaError(err);
defaultMsg = StrCryptoError(err); defaultMsg = StrCryptoError(err);
break; break;
} }
@@ -1344,7 +1345,7 @@ static void throwCryptoException(JNIEnv *env, status_t err, const char *msg,
jstring msgObj = env->NewStringUTF(msgStr.c_str()); jstring msgObj = env->NewStringUTF(msgStr.c_str());
jthrowable exception = jthrowable exception =
(jthrowable)env->NewObject(clazz.get(), constructID, err, msgObj); (jthrowable)env->NewObject(clazz.get(), constructID, jerr, msgObj);
env->Throw(exception); env->Throw(exception);
} }