Improve Error Reporting

Adds more meaningful error reporting where possible to the DrmEngine.  Adds
translation of CDM and OEMCrypto errors to Android errors.

Bug: 8621516
Change-Id: Ibab8a8711c3929ed72870ec7e138cd42358d9fb3
This commit is contained in:
Jeff Tinker
2013-04-17 19:02:54 -07:00
parent 40abceaaed
commit ded298688c
9 changed files with 218 additions and 120 deletions

View File

@@ -12,6 +12,7 @@ LOCAL_C_INCLUDES := \
frameworks/native/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/include \
vendor/widevine/libwvdrmengine/include \
vendor/widevine/libwvdrmengine/mediacrypto/include \
LOCAL_MODULE := libwvdrmcryptoplugin

View File

@@ -5,6 +5,8 @@
#ifndef WV_CRYPTO_PLUGIN_H_
#define WV_CRYPTO_PLUGIN_H_
#include <stdint.h>
#include "media/hardware/CryptoAPI.h"
#include "media/stagefright/foundation/ABase.h"
#include "media/stagefright/foundation/AString.h"
@@ -26,13 +28,14 @@ class WVCryptoPlugin : public android::CryptoPlugin {
void* dstPtr, android::AString* errorDetailMsg);
private:
wvcdm::CdmSessionId configureTestMode(const void* data, size_t size);
DISALLOW_EVIL_CONSTRUCTORS(WVCryptoPlugin);
wvcdm::WvContentDecryptionModule* const mCDM;
bool mTestMode;
const wvcdm::CdmSessionId mSessionId;
wvcdm::CdmSessionId configureTestMode(const void* data, size_t size);
};
} // namespace wvdrm

View File

@@ -11,12 +11,13 @@
#include <string.h>
#include <string>
#include <vector>
#include <openssl/sha.h>
#include "mapErrors-inl.h"
#include "media/stagefright/MediaErrors.h"
#include "openssl/sha.h"
#include "utils/Errors.h"
#include "utils/String8.h"
#include "wv_cdm_constants.h"
#include "media/stagefright/MediaErrors.h"
namespace wvdrm {
@@ -26,11 +27,12 @@ using namespace wvcdm;
WVCryptoPlugin::WVCryptoPlugin(const void* data, size_t size,
WvContentDecryptionModule* cdm)
: mCDM(cdm),
: mCDM(cdm),
mTestMode(false),
mSessionId(configureTestMode(data, size)) {}
wvcdm::CdmSessionId WVCryptoPlugin::configureTestMode(const void* data, size_t size) {
wvcdm::CdmSessionId WVCryptoPlugin::configureTestMode(const void* data,
size_t size) {
wvcdm::CdmSessionId sessionId(static_cast<const char *>(data), size);
size_t index = sessionId.find("test_mode");
if (index != string::npos) {
@@ -40,7 +42,6 @@ wvcdm::CdmSessionId WVCryptoPlugin::configureTestMode(const void* data, size_t s
return sessionId;
}
bool WVCryptoPlugin::requiresSecureDecoderComponent(const char* mime) const {
if (!strncasecmp(mime, "video/", 6)) {
// Type is video, so query CDM to see if we require a secure decoder.
@@ -48,7 +49,7 @@ bool WVCryptoPlugin::requiresSecureDecoderComponent(const char* mime) const {
CdmResponseType res = mCDM->QueryStatus(&status);
if (res != wvcdm::NO_ERROR) {
if (!isCdmResponseTypeSuccess(res)) {
ALOGE("Error querying CDM status: %u", res);
return false;
}
@@ -70,7 +71,7 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
size_t numSubSamples, void* dstPtr,
AString* errorDetailMsg) {
if (mode != kMode_Unencrypted && mode != kMode_AES_CTR) {
return BAD_TYPE;
return ERROR_DRM_CANNOT_HANDLE;
}
// If the caller requested secure decrypt, verify that we can comply.
@@ -79,12 +80,12 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
CdmResponseType res = mCDM->QueryStatus(&status);
if (res != wvcdm::NO_ERROR) {
if (!isCdmResponseTypeSuccess(res)) {
ALOGE("Error querying CDM status: %u", res);
return PERMISSION_DENIED;
return ERROR_DRM_CANNOT_HANDLE;
} else if (status[QUERY_KEY_SECURITY_LEVEL] !=
QUERY_VALUE_SECURITY_LEVEL_L1) {
return PERMISSION_DENIED;
return ERROR_DRM_CANNOT_HANDLE;
}
}
@@ -102,7 +103,7 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
const SubSample &subSample = subSamples[i];
if (mode == kMode_Unencrypted && subSample.mNumBytesOfEncryptedData != 0) {
return -EINVAL;
return ERROR_DRM_DECRYPT;
}
// "Decrypt" any unencrypted data. Per the ISO-CENC standard, clear data
@@ -113,10 +114,10 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
subSample.mNumBytesOfClearData,
ivVector, 0, dest + offset);
if (res != wvcdm::NO_ERROR) {
if (!isCdmResponseTypeSuccess(res)) {
ALOGE("Decrypt error result in session %s during unencrypted block: %d",
mSessionId.c_str(), res);
return -EINVAL;
return mapCdmResponseType(res);
}
offset += subSample.mNumBytesOfClearData;
@@ -130,10 +131,10 @@ ssize_t WVCryptoPlugin::decrypt(bool secure, const uint8_t key[KEY_ID_SIZE],
subSample.mNumBytesOfEncryptedData,
ivVector, encrypted_offset % 16, dest + offset);
if (res != wvcdm::NO_ERROR) {
if (!isCdmResponseTypeSuccess(res)) {
ALOGE("Decrypt error result in session %s during encrypted block: %d",
mSessionId.c_str(), res);
return -EINVAL;
return mapCdmResponseType(res);
}
offset += subSample.mNumBytesOfEncryptedData;