From 485f11483ce203f788e9bbdf10f10059b3ad67b0 Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Thu, 18 May 2017 09:01:42 -0700 Subject: [PATCH] Replace toStatus indirection. CdmResponseType are mapped to android::status_t, then map to hidl android::hardware::drm::V1_0::Status. This CL removes the indirection by mapping cdm errors to hidl Status. Test: Play Movies (pin and streaming) Test: Netflix (download and streaming) Test: libwvdrmmediacrypto_hidl_test and libwvdrmdrmplugin_hidl_test Test: GtsMediaTestCases module Test: Vts - VtsHalDrmV1_0Target bug: 34682447 Change-Id: I0b04f47871f5e4898e7297831d5fceab52e0f7f9 --- libwvdrmengine/Android.mk | 29 -- libwvdrmengine/include_hidl/TypeConvert.h | 2 - libwvdrmengine/include_hidl/mapErrors-inl.h | 330 ++++++++++++++++++ libwvdrmengine/mediacrypto/Android.mk | 3 +- .../mediacrypto/include_hidl/WVCryptoPlugin.h | 2 +- .../mediacrypto/src_hidl/WVCryptoPlugin.cpp | 21 +- libwvdrmengine/mediacrypto/test/Android.mk | 4 - .../mediadrm/include_hidl/WVDrmPlugin.h | 27 +- .../mediadrm/src_hidl/WVDrmPlugin.cpp | 247 ++++++------- libwvdrmengine/mediadrm/test/Android.mk | 4 - .../mediadrm/test/WVDrmPlugin_test.cpp | 14 +- libwvdrmengine/src_hidl/TypeConvert.cpp | 79 ----- 12 files changed, 491 insertions(+), 271 deletions(-) create mode 100644 libwvdrmengine/include_hidl/mapErrors-inl.h delete mode 100644 libwvdrmengine/src_hidl/TypeConvert.cpp diff --git a/libwvdrmengine/Android.mk b/libwvdrmengine/Android.mk index c9cf07f1..c974aa4e 100644 --- a/libwvdrmengine/Android.mk +++ b/libwvdrmengine/Android.mk @@ -109,30 +109,6 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \ include $(BUILD_STATIC_LIBRARY) -# ----------------------------------------------------------------------------- -# Builds libwidevinehidl_utils.a -# -include $(CLEAR_VARS) - -LOCAL_MODULE := libwidevinehidl_utils -LOCAL_PROPRIETARY_MODULE := true - -LOCAL_MODULE_CLASS := STATIC_LIBRARIES - -LOCAL_C_INCLUDES := \ - vendor/widevine/libwvdrmengine/include_hidl - -LOCAL_SRC_FILES := \ - src_hidl/TypeConvert.cpp - -LOCAL_HEADER_LIBRARIES := \ - libstagefright_headers - -LOCAL_SHARED_LIBRARIES := \ - android.hardware.drm@1.0 - -include $(BUILD_STATIC_LIBRARY) - # ----------------------------------------------------------------------------- # Builds libwvdrmengine.so # @@ -226,11 +202,6 @@ LOCAL_STATIC_LIBRARIES := \ libwvdrmdrmplugin_hidl \ libwvlevel3 \ -# When the GNU linker sees a library, it discards all symbols that it doesn't -# need. libwidevinehidl_utils must come after both libwvdrmcryptoplugin and -# libwvdrmdrmplugin. -LOCAL_STATIC_LIBRARIES += libwidevinehidl_utils - LOCAL_SHARED_LIBRARIES := \ android.hardware.drm@1.0 \ android.hidl.memory@1.0 \ diff --git a/libwvdrmengine/include_hidl/TypeConvert.h b/libwvdrmengine/include_hidl/TypeConvert.h index c3cac776..dada0b26 100644 --- a/libwvdrmengine/include_hidl/TypeConvert.h +++ b/libwvdrmengine/include_hidl/TypeConvert.h @@ -70,8 +70,6 @@ template std::vector toVector( return vec; } -Status toStatus(status_t mediaError); - } // namespace widevine } // namespace V1_0 } // namespace drm diff --git a/libwvdrmengine/include_hidl/mapErrors-inl.h b/libwvdrmengine/include_hidl/mapErrors-inl.h new file mode 100644 index 00000000..df2f41c0 --- /dev/null +++ b/libwvdrmengine/include_hidl/mapErrors-inl.h @@ -0,0 +1,330 @@ +// +// Copyright 2017 Google Inc. All Rights Reserved. +// + +#ifndef WV_MAP_ERRORS_H_ +#define WV_MAP_ERRORS_H_ + +#include "media/stagefright/MediaErrors.h" +#include "utils/Errors.h" +#include "wv_cdm_types.h" +#include "WVErrors.h" + +namespace wvdrm { + +using ::android::hardware::drm::V1_0::Status; + +static Status mapCdmResponseType(wvcdm::CdmResponseType res) { + switch (res) { + case wvcdm::KEY_ADDED: + case wvcdm::KEY_MESSAGE: + case wvcdm::KEY_CANCELED: + // KEY_ADDED, KEY_MESSAGE, and KEY_CANCELLED are all alternative + // success messages for certain CDM methods instead of NO_ERROR. + case wvcdm::NO_ERROR: + return Status::OK; + + case wvcdm::DECRYPT_NOT_READY: + case wvcdm::KEY_NOT_FOUND_IN_SESSION: + case wvcdm::NEED_KEY: + return Status::ERROR_DRM_NO_LICENSE; + + case wvcdm::NEED_PROVISIONING: + return Status::ERROR_DRM_NOT_PROVISIONED; + + case wvcdm::DEVICE_REVOKED: + return Status::ERROR_DRM_DEVICE_REVOKED; + + case wvcdm::INSUFFICIENT_CRYPTO_RESOURCES: + return Status::ERROR_DRM_RESOURCE_BUSY; + + case wvcdm::RELEASE_USAGE_INFO_ERROR: + case wvcdm::RELEASE_USAGE_INFO_FAILED: + return Status::ERROR_DRM_INVALID_STATE; + + case wvcdm::SESSION_NOT_FOUND_FOR_DECRYPT: + case wvcdm::SESSION_NOT_FOUND_1: + case wvcdm::SESSION_NOT_FOUND_2: + case wvcdm::SESSION_NOT_FOUND_3: + case wvcdm::SESSION_NOT_FOUND_4: + case wvcdm::SESSION_NOT_FOUND_5: + case wvcdm::SESSION_NOT_FOUND_6: + case wvcdm::SESSION_NOT_FOUND_7: + case wvcdm::SESSION_NOT_FOUND_8: + case wvcdm::SESSION_NOT_FOUND_9: + case wvcdm::SESSION_NOT_FOUND_10: + return Status::ERROR_DRM_SESSION_NOT_OPENED; + + case wvcdm::DECRYPT_ERROR: + case wvcdm::SECURE_BUFFER_REQUIRED: + return Status::ERROR_DRM_CANNOT_HANDLE; + + case wvcdm::ANALOG_OUTPUT_ERROR: + case wvcdm::KEY_PROHIBITED_FOR_SECURITY_LEVEL: + case wvcdm::INSUFFICIENT_OUTPUT_PROTECTION: + return Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION; + + // The following cases follow the order in wv_cdm_types.h + // to make it easier to keep track of newly defined errors. + case wvcdm::KEY_ERROR: + case wvcdm::ADD_KEY_ERROR: + case wvcdm::CERT_PROVISIONING_GET_KEYBOX_ERROR_1: + case wvcdm::CERT_PROVISIONING_GET_KEYBOX_ERROR_2: + case wvcdm::CERT_PROVISIONING_INVALID_CERT_TYPE: + case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_1: + case wvcdm::CERT_PROVISIONING_NONCE_GENERATION_ERROR: + case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_3: + case wvcdm::CERT_PROVISIONING_REQUEST_ERROR_4: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_1: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_2: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_3: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_4: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_5: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_6: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_7: + case wvcdm::CERT_PROVISIONING_RESPONSE_ERROR_8: + case wvcdm::CRYPTO_SESSION_OPEN_ERROR_1: + case wvcdm::CRYPTO_SESSION_OPEN_ERROR_2: + case wvcdm::CRYPTO_SESSION_OPEN_ERROR_3: + case wvcdm::CRYPTO_SESSION_OPEN_ERROR_4: + case wvcdm::CRYPTO_SESSION_OPEN_ERROR_5: + case wvcdm::DEVICE_CERTIFICATE_ERROR_1: + case wvcdm::DEVICE_CERTIFICATE_ERROR_2: + case wvcdm::DEVICE_CERTIFICATE_ERROR_3: + case wvcdm::DEVICE_CERTIFICATE_ERROR_4: + case wvcdm::EMPTY_KEY_DATA_1: + case wvcdm::EMPTY_KEY_DATA_2: + case wvcdm::EMPTY_KEYSET_ID: + case wvcdm::EMPTY_KEYSET_ID_ENG_1: + case wvcdm::EMPTY_KEYSET_ID_ENG_2: + case wvcdm::EMPTY_KEYSET_ID_ENG_3: + case wvcdm::EMPTY_KEYSET_ID_ENG_4: + case wvcdm::EMPTY_LICENSE_RENEWAL: + case wvcdm::EMPTY_LICENSE_RESPONSE_1: + case wvcdm::EMPTY_LICENSE_RESPONSE_2: + case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_1: + case wvcdm::EMPTY_PROVISIONING_RESPONSE: + case wvcdm::EMPTY_SESSION_ID: + case wvcdm::GENERATE_DERIVED_KEYS_ERROR: + case wvcdm::LICENSE_RENEWAL_NONCE_GENERATION_ERROR: + case wvcdm::GENERATE_USAGE_REPORT_ERROR: + case wvcdm::GET_LICENSE_ERROR: + case wvcdm::GET_RELEASED_LICENSE_ERROR: + case wvcdm::GET_USAGE_INFO_ERROR_1: + case wvcdm::GET_USAGE_INFO_ERROR_2: + case wvcdm::GET_USAGE_INFO_ERROR_3: + case wvcdm::GET_USAGE_INFO_ERROR_4: + case wvcdm::INIT_DATA_NOT_FOUND: + case wvcdm::INVALID_CRYPTO_SESSION_1: + case wvcdm::INVALID_CRYPTO_SESSION_2: + case wvcdm::INVALID_CRYPTO_SESSION_3: + case wvcdm::INVALID_CRYPTO_SESSION_4: + case wvcdm::INVALID_CRYPTO_SESSION_5: + case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_1: + case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_2: + case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_3: + case wvcdm::INVALID_DECRYPT_PARAMETERS_ENG_4: + case wvcdm::INVALID_DEVICE_CERTIFICATE_TYPE: + case wvcdm::INVALID_KEY_SYSTEM: + case wvcdm::INVALID_LICENSE_RESPONSE: + case wvcdm::INVALID_LICENSE_TYPE: + case wvcdm::INVALID_PARAMETERS_ENG_1: + case wvcdm::INVALID_PARAMETERS_ENG_2: + case wvcdm::INVALID_PARAMETERS_ENG_3: + case wvcdm::INVALID_PARAMETERS_ENG_4: + case wvcdm::INVALID_PARAMETERS_LIC_1: + case wvcdm::INVALID_PARAMETERS_LIC_2: + case wvcdm::INVALID_PROVISIONING_PARAMETERS_1: + case wvcdm::INVALID_PROVISIONING_PARAMETERS_2: + case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_1: + case wvcdm::INVALID_PROVISIONING_REQUEST_PARAM_2: + case wvcdm::INVALID_QUERY_KEY: + case wvcdm::INVALID_SESSION_ID: + case wvcdm::KEY_REQUEST_ERROR_1: + case wvcdm::KEY_SIZE_ERROR: + case wvcdm::KEYSET_ID_NOT_FOUND_1: + case wvcdm::KEYSET_ID_NOT_FOUND_2: + case wvcdm::KEYSET_ID_NOT_FOUND_3: + case wvcdm::LICENSE_ID_NOT_FOUND: + case wvcdm::LICENSE_PARSER_INIT_ERROR: + case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_1: + case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_2: + case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_3: + case wvcdm::LICENSE_RESPONSE_NOT_SIGNED: + case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_1: + case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_2: + case wvcdm::LICENSE_RESPONSE_PARSE_ERROR_3: + case wvcdm::LOAD_KEY_ERROR: + case wvcdm::NO_CONTENT_KEY: + case wvcdm::REFRESH_KEYS_ERROR: + case wvcdm::RELEASE_ALL_USAGE_INFO_ERROR_1: + case wvcdm::RELEASE_ALL_USAGE_INFO_ERROR_2: + case wvcdm::RELEASE_KEY_ERROR: + case wvcdm::RELEASE_KEY_REQUEST_ERROR: + case wvcdm::RELEASE_LICENSE_ERROR_1: + case wvcdm::RELEASE_LICENSE_ERROR_2: + case wvcdm::RENEW_KEY_ERROR_1: + case wvcdm::RENEW_KEY_ERROR_2: + case wvcdm::LICENSE_RENEWAL_SIGNING_ERROR: + case wvcdm::RESTORE_OFFLINE_LICENSE_ERROR_2: + case wvcdm::SESSION_INIT_ERROR_1: + case wvcdm::SESSION_INIT_ERROR_2: + case wvcdm::SESSION_KEYS_NOT_FOUND: + case wvcdm::SIGNATURE_NOT_FOUND: + case wvcdm::STORE_LICENSE_ERROR_1: + case wvcdm::STORE_LICENSE_ERROR_2: + case wvcdm::STORE_USAGE_INFO_ERROR: + case wvcdm::UNPROVISION_ERROR_1: + case wvcdm::UNPROVISION_ERROR_2: + case wvcdm::UNPROVISION_ERROR_3: + case wvcdm::UNPROVISION_ERROR_4: + case wvcdm::UNSUPPORTED_INIT_DATA: + case wvcdm::USAGE_INFO_NOT_FOUND: + case wvcdm::LICENSE_RENEWAL_SERVICE_CERTIFICATE_GENERATION_ERROR: + case wvcdm::PARSE_SERVICE_CERTIFICATE_ERROR: + case wvcdm::SERVICE_CERTIFICATE_TYPE_ERROR: + case wvcdm::CLIENT_ID_GENERATE_RANDOM_ERROR: + case wvcdm::CLIENT_ID_AES_INIT_ERROR: + case wvcdm::CLIENT_ID_AES_ENCRYPT_ERROR: + case wvcdm::CLIENT_ID_RSA_INIT_ERROR: + case wvcdm::CLIENT_ID_RSA_ENCRYPT_ERROR: + case wvcdm::INVALID_QUERY_STATUS: + case wvcdm::LICENSE_PARSER_NOT_INITIALIZED_4: + case wvcdm::INVALID_PARAMETERS_LIC_3: + case wvcdm::INVALID_PARAMETERS_LIC_4: + case wvcdm::INVALID_PARAMETERS_LIC_6: + case wvcdm::INVALID_PARAMETERS_LIC_7: + case wvcdm::LICENSE_REQUEST_SERVICE_CERTIFICATE_GENERATION_ERROR: + case wvcdm::CENC_INIT_DATA_UNAVAILABLE: + case wvcdm::PREPARE_CENC_CONTENT_ID_FAILED: + case wvcdm::WEBM_INIT_DATA_UNAVAILABLE: + case wvcdm::PREPARE_WEBM_CONTENT_ID_FAILED: + case wvcdm::UNSUPPORTED_INIT_DATA_FORMAT: + case wvcdm::LICENSE_REQUEST_NONCE_GENERATION_ERROR: + case wvcdm::LICENSE_REQUEST_SIGNING_ERROR: + case wvcdm::EMPTY_LICENSE_REQUEST: + case wvcdm::DUPLICATE_SESSION_ID_SPECIFIED: + case wvcdm::LICENSE_RENEWAL_PROHIBITED: + case wvcdm::EMPTY_PROVISIONING_CERTIFICATE_2: + case wvcdm::OFFLINE_LICENSE_PROHIBITED: + case wvcdm::STORAGE_PROHIBITED: + case wvcdm::EMPTY_KEYSET_ID_ENG_5: + case wvcdm::SESSION_NOT_FOUND_11: + case wvcdm::LOAD_USAGE_INFO_FILE_ERROR: + case wvcdm::LOAD_USAGE_INFO_MISSING: + case wvcdm::SESSION_FILE_HANDLE_INIT_ERROR: + case wvcdm::INCORRECT_CRYPTO_MODE: + case wvcdm::INVALID_PARAMETERS_ENG_5: + case wvcdm::SESSION_NOT_FOUND_12: + case wvcdm::KEY_NOT_FOUND_1: + case wvcdm::KEY_NOT_FOUND_2: + case wvcdm::KEY_CONFLICT_1: + case wvcdm::INVALID_PARAMETERS_ENG_6: + case wvcdm::INVALID_PARAMETERS_ENG_7: + case wvcdm::INVALID_PARAMETERS_ENG_8: + case wvcdm::INVALID_PARAMETERS_ENG_9: + case wvcdm::INVALID_PARAMETERS_ENG_10: + case wvcdm::INVALID_PARAMETERS_ENG_11: + case wvcdm::INVALID_PARAMETERS_ENG_12: + case wvcdm::SESSION_NOT_FOUND_13: + case wvcdm::SESSION_NOT_FOUND_14: + case wvcdm::SESSION_NOT_FOUND_15: + case wvcdm::SESSION_NOT_FOUND_16: + case wvcdm::KEY_NOT_FOUND_3: + case wvcdm::KEY_NOT_FOUND_4: + case wvcdm::KEY_NOT_FOUND_5: + case wvcdm::KEY_NOT_FOUND_6: + case wvcdm::INVALID_SESSION_1: + case wvcdm::NO_DEVICE_KEY_1: + case wvcdm::NO_CONTENT_KEY_2: + case wvcdm::INSUFFICIENT_CRYPTO_RESOURCES_2: + case wvcdm::INVALID_PARAMETERS_ENG_13: + case wvcdm::INVALID_PARAMETERS_ENG_14: + case wvcdm::INVALID_PARAMETERS_ENG_15: + case wvcdm::INVALID_PARAMETERS_ENG_16: + case wvcdm::DEVICE_CERTIFICATE_ERROR_5: + case wvcdm::CERT_PROVISIONING_CLIENT_TOKEN_ERROR_1: + case wvcdm::CERT_PROVISIONING_CLIENT_TOKEN_ERROR_2: + case wvcdm::LICENSING_CLIENT_TOKEN_ERROR_1: + case wvcdm::UNKNOWN_SELECT_KEY_ERROR_1: + case wvcdm::UNKNOWN_SELECT_KEY_ERROR_2: + case wvcdm::CREATE_USAGE_TABLE_ERROR: + case wvcdm::LOAD_USAGE_HEADER_GENERATION_SKEW: + case wvcdm::LOAD_USAGE_HEADER_SIGNATURE_FAILURE: + case wvcdm::LOAD_USAGE_HEADER_BAD_MAGIC: + case wvcdm::LOAD_USAGE_HEADER_UNKNOWN_ERROR: + case wvcdm::INVALID_PARAMETERS_ENG_17: + case wvcdm::INVALID_PARAMETERS_ENG_18: + case wvcdm::INSUFFICIENT_CRYPTO_RESOURCES_3: + case wvcdm::CREATE_USAGE_ENTRY_UNKNOWN_ERROR: + case wvcdm::LOAD_USAGE_ENTRY_GENERATION_SKEW: + case wvcdm::LOAD_USAGE_ENTRY_SIGNATURE_FAILURE: + case wvcdm::LOAD_USAGE_ENTRY_UNKNOWN_ERROR: + case wvcdm::INVALID_PARAMETERS_ENG_19: + case wvcdm::INVALID_PARAMETERS_ENG_20: + case wvcdm::UPDATE_USAGE_ENTRY_UNKNOWN_ERROR: + case wvcdm::INVALID_PARAMETERS_ENG_21: + case wvcdm::SHRINK_USAGE_TABLER_HEADER_UNKNOWN_ERROR: + case wvcdm::MOVE_USAGE_ENTRY_UNKNOWN_ERROR: + case wvcdm::COPY_OLD_USAGE_ENTRY_UNKNOWN_ERROR: + case wvcdm::INVALID_PARAMETERS_ENG_22: + case wvcdm::STORE_LICENSE_ERROR_4: + case wvcdm::LIST_LICENSES_ERROR: + case wvcdm::INVALID_PARAMETERS_ENG_23: + case wvcdm::USAGE_INFORMATION_SUPPORT_FAILED: + case wvcdm::USAGE_SUPPORT_GET_API_FAILED: + case wvcdm::UNEXPECTED_EMPTY_USAGE_ENTRY: + case wvcdm::INVALID_USAGE_ENTRY_NUMBER_MODIFICATION: + case wvcdm::USAGE_INVALID_NEW_ENTRY: + case wvcdm::USAGE_INVALID_PARAMETERS_1: + case wvcdm::USAGE_RETRIEVE_LICENSE_FAILED: + case wvcdm::USAGE_RETRIEVE_USAGE_INFO_FAILED: + case wvcdm::USAGE_RETRIEVE_INVALID_STORAGE_TYPE: + case wvcdm::USAGE_ENTRY_NUMBER_MISMATCH: + case wvcdm::USAGE_STORE_LICENSE_FAILED: + case wvcdm::USAGE_STORE_USAGE_INFO_FAILED: + case wvcdm::USAGE_INVALID_LOAD_ENTRY: + case wvcdm::RELEASE_ALL_USAGE_INFO_ERROR_4: + case wvcdm::RELEASE_ALL_USAGE_INFO_ERROR_5: + case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_1: + case wvcdm::INCORRECT_USAGE_SUPPORT_TYPE_2: + case wvcdm::NO_USAGE_ENTRIES: + case wvcdm::LIST_USAGE_ERROR_1: + case wvcdm::LIST_USAGE_ERROR_2: + case wvcdm::DELETE_USAGE_ERROR_1: + case wvcdm::DELETE_USAGE_ERROR_2: + case wvcdm::DELETE_USAGE_ERROR_3: + case wvcdm::PRIVACY_MODE_ERROR_1: + case wvcdm::PRIVACY_MODE_ERROR_2: + case wvcdm::PRIVACY_MODE_ERROR_3: + case wvcdm::EMPTY_RESPONSE_ERROR_1: + case wvcdm::INVALID_PARAMETERS_ENG_24: + case wvcdm::PARSE_RESPONSE_ERROR_1: + case wvcdm::PARSE_RESPONSE_ERROR_2: + case wvcdm::PARSE_RESPONSE_ERROR_3: + case wvcdm::PARSE_RESPONSE_ERROR_4: + ALOGW("Returns UNKNOWN error for legacy status: %d", res); + return Status::ERROR_DRM_UNKNOWN; + + case wvcdm::UNKNOWN_ERROR: + case wvcdm::UNUSED_1: + case wvcdm::UNUSED_2: + case wvcdm::UNUSED_3: + case wvcdm::UNUSED_4: + case wvcdm::UNUSED_5: + case wvcdm::UNUSED_6: + return Status::ERROR_DRM_UNKNOWN; + } + + // Return here instead of as a default case so that the compiler will warn + // us if we forget to include an enum member in the switch statement. + return Status::ERROR_DRM_UNKNOWN; +} + +static inline bool isCdmResponseTypeSuccess(wvcdm::CdmResponseType res) { + return mapCdmResponseType(res) == Status::OK; +} + +} // namespace wvdrm + +#endif // WV_MAP_ERRORS_H_ diff --git a/libwvdrmengine/mediacrypto/Android.mk b/libwvdrmengine/mediacrypto/Android.mk index 8f83f7c1..8cf087b6 100644 --- a/libwvdrmengine/mediacrypto/Android.mk +++ b/libwvdrmengine/mediacrypto/Android.mk @@ -60,8 +60,7 @@ LOCAL_HEADER_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libcdm_protos \ - libcrypto \ - libwidevinehidl_utils \ + libcrypto LOCAL_SHARED_LIBRARIES := \ android.hardware.drm@1.0 \ diff --git a/libwvdrmengine/mediacrypto/include_hidl/WVCryptoPlugin.h b/libwvdrmengine/mediacrypto/include_hidl/WVCryptoPlugin.h index d3ff9914..1ea1fd4a 100644 --- a/libwvdrmengine/mediacrypto/include_hidl/WVCryptoPlugin.h +++ b/libwvdrmengine/mediacrypto/include_hidl/WVCryptoPlugin.h @@ -68,7 +68,7 @@ struct WVCryptoPlugin : public ICryptoPlugin { sp const mCDM; - android::status_t attemptDecrypt( + Status attemptDecrypt( const wvcdm::CdmDecryptionParameters& params, bool haveEncryptedSubsamples, std::string* errorDetailMsg); static wvcdm::CdmResponseType countEncryptedBlocksInPatternedRange( diff --git a/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp index b6abfc23..075f6d88 100644 --- a/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp @@ -30,12 +30,9 @@ namespace V1_0 { namespace widevine { using ::android::hardware::drm::V1_0::BufferType; -using ::android::hardware::drm::V1_0::widevine::toStatus; using ::android::hardware::drm::V1_0::widevine::toVector; using ::android::hardware::Void; -using android::status_t; - using wvcdm::CdmDecryptionParameters; using wvcdm::CdmQueryMap; using wvcdm::CdmResponseType; @@ -258,10 +255,10 @@ Return WVCryptoPlugin::decrypt( params.decrypt_buffer_offset = bufferOffset; params.subsample_flags = clearFlags; - status_t res = attemptDecrypt(params, haveEncryptedSubsamples, + Status res = attemptDecrypt(params, haveEncryptedSubsamples, &errorDetailMsg); - if (res != android::OK) { - _hidl_cb(toStatus(res), 0, errorDetailMsg.c_str()); + if (res != Status::OK) { + _hidl_cb(res, 0, errorDetailMsg.c_str()); return Void(); } bufferOffset += subSample.numBytesOfClearData; @@ -277,10 +274,10 @@ Return WVCryptoPlugin::decrypt( params.decrypt_buffer_offset = bufferOffset; params.subsample_flags = encryptedFlags; - status_t res = attemptDecrypt(params, haveEncryptedSubsamples, + Status res = attemptDecrypt(params, haveEncryptedSubsamples, &errorDetailMsg); - if (res != android::OK) { - _hidl_cb(toStatus(res), 0, errorDetailMsg.c_str()); + if (res != Status::OK) { + _hidl_cb(res, 0, errorDetailMsg.c_str()); return Void(); } @@ -331,14 +328,14 @@ Return WVCryptoPlugin::decrypt( return Void(); } -status_t WVCryptoPlugin::attemptDecrypt(const CdmDecryptionParameters& params, +Status WVCryptoPlugin::attemptDecrypt(const CdmDecryptionParameters& params, bool haveEncryptedSubsamples, std::string* errorDetailMsg) { CdmResponseType res = mCDM->Decrypt(mSessionId, haveEncryptedSubsamples, params); if (isCdmResponseTypeSuccess(res)) { - return android::OK; + return Status::OK; } else { ALOGE("Decrypt error result in session %s during %s block: %d", mSessionId.c_str(), @@ -381,7 +378,7 @@ status_t WVCryptoPlugin::attemptDecrypt(const CdmDecryptionParameters& params, return mapCdmResponseType(res); } else { // Swallow the specifics of other errors to obscure decrypt internals. - return kErrorCDMGeneric; + return Status::ERROR_DRM_UNKNOWN; } } } diff --git a/libwvdrmengine/mediacrypto/test/Android.mk b/libwvdrmengine/mediacrypto/test/Android.mk index a383c666..7793584b 100644 --- a/libwvdrmengine/mediacrypto/test/Android.mk +++ b/libwvdrmengine/mediacrypto/test/Android.mk @@ -86,10 +86,6 @@ LOCAL_STATIC_LIBRARIES := \ libwvlevel3 \ libwvdrmcryptoplugin_hidl \ -# When the GNU linker sees a library, it discards all symbols that it doesn't -# need. libwidevinehidl_utils must come after libwvdrmcryptoplugin. -LOCAL_STATIC_LIBRARIES += libwidevinehidl_utils - LOCAL_SHARED_LIBRARIES := \ android.hardware.drm@1.0 \ android.hidl.memory@1.0 \ diff --git a/libwvdrmengine/mediadrm/include_hidl/WVDrmPlugin.h b/libwvdrmengine/mediadrm/include_hidl/WVDrmPlugin.h index 1aa89a46..80ac5669 100644 --- a/libwvdrmengine/mediadrm/include_hidl/WVDrmPlugin.h +++ b/libwvdrmengine/mediadrm/include_hidl/WVDrmPlugin.h @@ -39,7 +39,6 @@ using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::sp; -using android::status_t; using std::map; using wvcdm::CdmIdentifier; using wvcdm::CdmKeyStatusMap; @@ -180,7 +179,7 @@ struct WVDrmPlugin : public IDrmPlugin, IDrmPluginListener, bool hasNewUsableKey) override; // The following methods do not use hidl interface, it is used internally. - virtual status_t unprovisionDevice(); + virtual Status unprovisionDevice(); virtual void OnSessionRenewalNeeded(const CdmSessionId& cdmSessionId); @@ -316,14 +315,14 @@ struct WVDrmPlugin : public IDrmPlugin, IDrmPluginListener, // calls into the CDM in order to identify which CDM instance should receive // the call. Calling this will seal the CDM Identifier Builder, thus making // it an error to change the origin. - status_t getCdmIdentifier(CdmIdentifier* identifier); + Status getCdmIdentifier(CdmIdentifier* identifier); // Gets the application-safe device-unique ID. On non-SPOID devices, this is // the device-unique ID from OEMCrypto. On SPOID devices, this is the SPOID. // On SPOID devices, calling this will seal the CDM Identifier Builder, thus // making it an error to change the origin. - status_t getDeviceUniqueId(std::string* id); - status_t getProvisioningUniqueId(std::string* id); + Status getDeviceUniqueId(std::string* id); + Status getProvisioningUniqueId(std::string* id); const std::string& origin() const { return mCdmIdentifier.origin; } bool set_origin(const std::string& id); @@ -338,13 +337,13 @@ struct WVDrmPlugin : public IDrmPlugin, IDrmPluginListener, std::string mAppPackageName; const WVDrmPlugin& mParent; - status_t calculateSpoid(); + Status calculateSpoid(); // Gets the device-unique ID from OEMCrypto. This must be private, since // this value must not be exposed to applications on SPOID devices. Code // outside this class should use getDeviceUniqueId() to get the // application-safe device-unique ID. - status_t getOemcryptoDeviceId(std::string* id); + Status getOemcryptoDeviceId(std::string* id); } mCdmIdentifierBuilder; sp const mCDM; @@ -352,27 +351,27 @@ struct WVDrmPlugin : public IDrmPlugin, IDrmPluginListener, map mCryptoSessions; sp mListener; - status_t queryProperty(const std::string& property, + Status queryProperty(const std::string& property, std::string& stringValue) const; - status_t queryProperty(wvcdm::SecurityLevel securityLevel, + Status queryProperty(wvcdm::SecurityLevel securityLevel, const std::string& property, std::string& stringValue) const; - status_t queryProperty(const std::string& property, + Status queryProperty(const std::string& property, std::vector& vector_value) const; - status_t mapAndNotifyOfCdmResponseType(const std::vector& sessionId, + Status mapAndNotifyOfCdmResponseType(const std::vector& sessionId, CdmResponseType res); - status_t mapAndNotifyOfOEMCryptoResult(const std::vector& sessionId, + Status mapAndNotifyOfOEMCryptoResult(const std::vector& sessionId, OEMCryptoResult res); - status_t mapOEMCryptoResult(OEMCryptoResult res); + Status mapOEMCryptoResult(OEMCryptoResult res); bool initDataResemblesPSSH(const std::vector& initData); - status_t unprovision(const CdmIdentifier& identifier); + Status unprovision(const CdmIdentifier& identifier); }; } // namespace widevine diff --git a/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp index 505ef377..2bbca746 100644 --- a/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp @@ -38,7 +38,7 @@ using ::android::hardware::drm::V1_0::KeyStatusType; using ::android::hardware::drm::V1_0::KeyType; using ::android::hardware::drm::V1_0::Status; using ::android::hardware::drm::V1_0::widevine::toHidlVec; -using ::android::hardware::drm::V1_0::widevine::toStatus; + using ::android::hardware::drm::V1_0::widevine::toVector; using ::android::hardware::Void; @@ -123,13 +123,13 @@ WVDrmPlugin::~WVDrmPlugin() { } Return WVDrmPlugin::openSession(openSession_cb _hidl_cb) { - status_t status = android::OK; + Status status = Status::OK; std::vector sessionId; CdmIdentifier identifier; status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), toHidlVec(sessionId)); + if (status != Status::OK) { + _hidl_cb(status, toHidlVec(sessionId)); return Void(); } @@ -140,7 +140,7 @@ Return WVDrmPlugin::openSession(openSession_cb _hidl_cb) { if (!isCdmResponseTypeSuccess(res)) { status = mapAndNotifyOfCdmResponseType(sessionId, res); - _hidl_cb(toStatus(status), toHidlVec(sessionId)); + _hidl_cb(status, toHidlVec(sessionId)); return Void(); } @@ -175,10 +175,11 @@ Return WVDrmPlugin::openSession(openSession_cb _hidl_cb) { } else { // We got a failure that did not give us an error code, such as a failure // of AttachEventListener() or the key being missing from the map. - status = kErrorCDMGeneric; + ALOGW("Returns UNKNOWN error for legacy status kErrorCDMGeneric"); + status = Status::ERROR_DRM_UNKNOWN; } } - _hidl_cb(toStatus(status), toHidlVec(sessionId)); + _hidl_cb(status, toHidlVec(sessionId)); return Void(); } @@ -210,15 +211,15 @@ Return WVDrmPlugin::getKeyRequest( return Void(); } KeyRequestType requestType = KeyRequestType::UNKNOWN; - status_t status = android::OK; + Status status = Status::OK; std::string defaultUrl; std::vector request; const std::vector scopeId = toVector(scope); CdmIdentifier identifier; status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), toHidlVec(request), requestType, + if (status != Status::OK) { + _hidl_cb(status, toHidlVec(request), requestType, defaultUrl.c_str()); return Void(); } @@ -313,7 +314,7 @@ Return WVDrmPlugin::getKeyRequest( // For all other requests, we have a session ID. status = mapAndNotifyOfCdmResponseType(scopeId, res); } - _hidl_cb(toStatus(status), toHidlVec(request), requestType, + _hidl_cb(status, toHidlVec(request), requestType, defaultUrl.c_str()); return Void(); } @@ -356,7 +357,7 @@ Return WVDrmPlugin::provideKeyResponse( keySetId = StrToVector(cdmKeySetId); } - status_t status = android::OK; + Status status = Status::OK; if (isRelease) { // When releasing keys, we do not have a session ID. status = mapCdmResponseType(res); @@ -367,10 +368,10 @@ Return WVDrmPlugin::provideKeyResponse( // return the error. This is because "NEED_KEY" from AddKey() is an // expected behavior when sending a privacy certificate. if (res == wvcdm::NEED_KEY && mPropertySet.use_privacy_mode()) { - status = android::OK; + status = Status::OK; } } - _hidl_cb(toStatus(status), toHidlVec(keySetId)); + _hidl_cb(status, toHidlVec(keySetId)); return Void(); } @@ -384,7 +385,7 @@ Return WVDrmPlugin::removeKeys(const hidl_vec& sessionId) { CdmResponseType res = mCDM->RemoveKeys(cdmSessionId); - return toStatus(mapAndNotifyOfCdmResponseType(sId, res)); + return mapAndNotifyOfCdmResponseType(sId, res); } Return WVDrmPlugin::restoreKeys(const hidl_vec& sessionId, @@ -400,16 +401,16 @@ Return WVDrmPlugin::restoreKeys(const hidl_vec& sessionId, CdmResponseType res = mCDM->RestoreKey(cdmSessionId, cdmKeySetId); - return toStatus(mapAndNotifyOfCdmResponseType(sId, res)); + return mapAndNotifyOfCdmResponseType(sId, res); } Return WVDrmPlugin::queryKeyStatus(const hidl_vec& sessionId, queryKeyStatus_cb _hidl_cb) { - if (sessionId.size() == 0) { - _hidl_cb(Status::BAD_VALUE, hidl_vec()); - return Void(); - } + if (sessionId.size() == 0) { + _hidl_cb(Status::BAD_VALUE, hidl_vec()); + return Void(); + } const std::vector sId = toVector(sessionId); CdmSessionId cdmSessionId(sId.begin(), sId.end()); CdmQueryMap cdmLicenseInfo; @@ -432,7 +433,7 @@ Return WVDrmPlugin::restoreKeys(const hidl_vec& sessionId, } } - _hidl_cb(toStatus(mapCdmResponseType(res)), toHidlVec(infoMapVec)); + _hidl_cb(mapCdmResponseType(res), toHidlVec(infoMapVec)); return Void(); } @@ -440,14 +441,14 @@ Return WVDrmPlugin::restoreKeys(const hidl_vec& sessionId, const hidl_string& certificateType, const hidl_string& certificateAuthority, getProvisionRequest_cb _hidl_cb) { - status_t status = android::OK; + Status status = Status::OK; std::string defaultUrl; std::vector request; CdmIdentifier identifier; status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), toHidlVec(request), hidl_string(defaultUrl)); + if (status != Status::OK) { + _hidl_cb(status, toHidlVec(request), hidl_string(defaultUrl)); return Void(); } @@ -470,7 +471,7 @@ Return WVDrmPlugin::restoreKeys(const hidl_vec& sessionId, defaultUrl.assign(cdmDefaultUrl.data(), cdmDefaultUrl.size()); } - _hidl_cb(toStatus(mapCdmResponseType(res)), toHidlVec(request), + _hidl_cb(mapCdmResponseType(res), toHidlVec(request), hidl_string(defaultUrl)); return Void(); } @@ -488,19 +489,20 @@ Return WVDrmPlugin::provideProvisionResponse( std::vector wrappedKey; CdmIdentifier identifier; - status_t status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), toHidlVec(certificate), toHidlVec(wrappedKey)); + Status status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); + if (status != Status::OK) { + _hidl_cb(status, toHidlVec(certificate), toHidlVec(wrappedKey)); } CdmProvisioningResponse cdmResponse(resp.begin(), resp.end()); if (cdmResponse == kSpecialUnprovisionResponse) { if (identifier == kDefaultCdmIdentifier) { - _hidl_cb(toStatus(kErrorNoOriginSpecified), toHidlVec(certificate), + ALOGW("Returns UNKNOWN error for legacy status kErrorNoOriginSpecified"); + _hidl_cb(Status::ERROR_DRM_UNKNOWN, toHidlVec(certificate), toHidlVec(wrappedKey)); return Void(); } - _hidl_cb(toStatus(unprovision(identifier)), + _hidl_cb(unprovision(identifier), toHidlVec(certificate), toHidlVec(wrappedKey)); return Void(); @@ -514,13 +516,13 @@ Return WVDrmPlugin::provideProvisionResponse( wrappedKey = StrToVector(cdmWrappedKey); } - _hidl_cb(toStatus(mapCdmResponseType(res)), toHidlVec(certificate), + _hidl_cb(mapCdmResponseType(res), toHidlVec(certificate), toHidlVec(wrappedKey)); return Void(); } } -status_t WVDrmPlugin::unprovisionDevice() { +Status WVDrmPlugin::unprovisionDevice() { return unprovision(kDefaultCdmIdentifier); } @@ -536,9 +538,9 @@ Return WVDrmPlugin::getSecureStop( SecureStop secureStop; CdmIdentifier identifier; - status_t status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), secureStop); + Status status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); + if (status != Status::OK) { + _hidl_cb(status, secureStop); return Void(); } @@ -558,7 +560,7 @@ Return WVDrmPlugin::getSecureStop( secureStop.opaqueData = toHidlVec(cdmStopVec); } - _hidl_cb(toStatus(mapCdmResponseType(res)), secureStop); + _hidl_cb(mapCdmResponseType(res), secureStop); return Void(); } @@ -568,9 +570,9 @@ Return WVDrmPlugin::getSecureStops(getSecureStops_cb _hidl_cb) { std::vector secureStopsVec; CdmIdentifier identifier; - status_t status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - _hidl_cb(toStatus(status), toHidlVec(secureStopsVec)); + Status status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); + if (status != Status::OK) { + _hidl_cb(status, toHidlVec(secureStopsVec)); return Void(); } @@ -595,21 +597,21 @@ Return WVDrmPlugin::getSecureStops(getSecureStops_cb _hidl_cb) { secureStopsVec.push_back(secureStop); } - _hidl_cb(toStatus(mapCdmResponseType(res)), toHidlVec(secureStopsVec)); + _hidl_cb(mapCdmResponseType(res), toHidlVec(secureStopsVec)); return Void(); } Return WVDrmPlugin::releaseAllSecureStops() { CdmIdentifier identifier; - status_t status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - return toStatus(status); + Status status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); + if (status != Status::OK) { + return status; } CdmResponseType res = mCDM->ReleaseAllUsageInfo(mPropertySet.app_id(), identifier); - return toStatus(mapCdmResponseType(res)); + return mapCdmResponseType(res); } Return WVDrmPlugin::releaseSecureStop( @@ -620,20 +622,20 @@ Return WVDrmPlugin::releaseSecureStop( } CdmIdentifier identifier; - status_t status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); - if (status != android::OK) { - return toStatus(status); + Status status = mCdmIdentifierBuilder.getCdmIdentifier(&identifier); + if (status != Status::OK) { + return status; } const std::vector ssRelease = toVector(secureStopId); CdmUsageInfoReleaseMessage cdmMessage(ssRelease.begin(), ssRelease.end()); CdmResponseType res = mCDM->ReleaseUsageInfo(cdmMessage, identifier); - return toStatus(mapCdmResponseType(res)); + return mapCdmResponseType(res); } Return WVDrmPlugin::getPropertyString(const hidl_string& propertyName, getPropertyString_cb _hidl_cb) { - status_t status = android::OK; + Status status = Status::OK; std::string name(propertyName.c_str()); std::string value; @@ -689,10 +691,10 @@ Return WVDrmPlugin::getPropertyString(const hidl_string& propertyName, status = queryProperty(wvcdm::QUERY_KEY_SRM_UPDATE_SUPPORT, value); } else { ALOGE("App requested unknown string property %s", name.c_str()); - status = android::ERROR_DRM_CANNOT_HANDLE; + status = Status::ERROR_DRM_CANNOT_HANDLE; } - _hidl_cb(toStatus(status), value.c_str()); + _hidl_cb(status, value.c_str()); return Void(); } @@ -700,20 +702,20 @@ Return WVDrmPlugin::getPropertyByteArray( const hidl_string& propertyName, getPropertyByteArray_cb _hidl_cb) { - status_t status = android::OK; + Status status = Status::OK; std::string name(propertyName.c_str()); std::vector value; if (name == "deviceUniqueId") { std::string id; status = mCdmIdentifierBuilder.getDeviceUniqueId(&id); - if (status == android::OK) { + if (status == Status::OK) { value = StrToVector(id); } } else if (name == "provisioningUniqueId") { std::string id; status = mCdmIdentifierBuilder.getProvisioningUniqueId(&id); - if (status == android::OK) { + if (status == Status::OK) { value = StrToVector(id); } } else if (name == "serviceCertificate") { @@ -724,10 +726,10 @@ Return WVDrmPlugin::getPropertyByteArray( value = StrToVector(metrics_value); } else { ALOGE("App requested unknown byte array property %s", name.c_str()); - status = android::ERROR_DRM_CANNOT_HANDLE; + status = Status::ERROR_DRM_CANNOT_HANDLE; } - _hidl_cb(toStatus(status), toHidlVec(value)); + _hidl_cb(status, toHidlVec(value)); return Void(); } @@ -743,11 +745,11 @@ Return WVDrmPlugin::setPropertyString(const hidl_string& propertyName, } else if (_value == wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1.c_str()) { // We must be sure we CAN set the security level to L1. std::string current_security_level; - status_t status = queryProperty( + Status status = queryProperty( wvcdm::kLevelDefault, wvcdm::QUERY_KEY_SECURITY_LEVEL, current_security_level); - if (status != android::OK) { - return toStatus(status); + if (status != Status::OK) { + return status; } if (current_security_level != wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1) { ALOGE("App requested L1 security on a non-L1 device."); @@ -763,7 +765,8 @@ Return WVDrmPlugin::setPropertyString(const hidl_string& propertyName, } } else { ALOGE("App tried to change security level while sessions are open."); - return toStatus(kErrorSessionIsOpen); + ALOGW("Returns UNKNOWN error for legacy status kErrorSessionIsOpen"); + return Status::ERROR_DRM_UNKNOWN; } } else if (name == "privacyMode") { if (_value == kEnable) { @@ -786,19 +789,22 @@ Return WVDrmPlugin::setPropertyString(const hidl_string& propertyName, } } else { ALOGE("App tried to change key sharing while sessions are open."); - return toStatus(kErrorSessionIsOpen); + ALOGW("Returns UNKNOWN error for legacy status kErrorSessionIsOpen"); + return Status::ERROR_DRM_UNKNOWN; } } else if (name == "appId") { if (mCryptoSessions.size() == 0) { mPropertySet.set_app_id(_value.c_str()); } else { ALOGE("App tried to set the application id while sessions are opened."); - return toStatus(kErrorSessionIsOpen); + ALOGW("Returns UNKNOWN error for legacy status kErrorSessionIsOpen"); + return Status::ERROR_DRM_UNKNOWN; } } else if (name == "origin") { if (mCryptoSessions.size() != 0) { ALOGE("App tried to set the origin while sessions are opened."); - return toStatus(kErrorSessionIsOpen); + ALOGW("Returns UNKNOWN error for legacy status kErrorSessionIsOpen"); + return Status::ERROR_DRM_UNKNOWN; } else { if (!mCdmIdentifierBuilder.set_origin(_value.c_str())) { return Status::BAD_VALUE; @@ -902,7 +908,8 @@ Return WVDrmPlugin::encrypt( const CryptoSession& cryptoSession = mCryptoSessions[cdmSessionId]; if (cryptoSession.cipherAlgorithm() == kInvalidCryptoAlgorithm) { - _hidl_cb(toStatus(android::NO_INIT), toHidlVec(output)); + ALOGW("Returns UNKNOWN error for legacy status NO_INIT"); + _hidl_cb(Status::ERROR_DRM_UNKNOWN, toHidlVec(output)); return Void(); } @@ -912,7 +919,7 @@ Return WVDrmPlugin::encrypt( if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(output)); return Void(); } @@ -929,7 +936,7 @@ Return WVDrmPlugin::encrypt( _hidl_cb(Status::OK, toHidlVec(output)); } else { ALOGE("OEMCrypto_Generic_Encrypt failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(output)); } return Void(); @@ -954,7 +961,8 @@ Return WVDrmPlugin::decrypt( const CryptoSession& cryptoSession = mCryptoSessions[cdmSessionId]; if (cryptoSession.cipherAlgorithm() == kInvalidCryptoAlgorithm) { - _hidl_cb(toStatus(android::NO_INIT), toHidlVec(output)); + ALOGW("Returns UNKNOWN error for legacy status NO_INIT"); + _hidl_cb(Status::ERROR_DRM_UNKNOWN, toHidlVec(output)); return Void(); } @@ -964,7 +972,7 @@ Return WVDrmPlugin::decrypt( if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(output)); return Void(); } @@ -981,7 +989,7 @@ Return WVDrmPlugin::decrypt( _hidl_cb(Status::OK, toHidlVec(output)); } else { ALOGE("OEMCrypto_Generic_Decrypt failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(output)); } return Void(); @@ -1005,7 +1013,8 @@ Return WVDrmPlugin::sign( const CryptoSession& cryptoSession = mCryptoSessions[cdmSessionId]; if (cryptoSession.macAlgorithm() == kInvalidCryptoAlgorithm) { - _hidl_cb(toStatus(android::NO_INIT), toHidlVec(signature)); + ALOGW("Returns UNKNOWN error for legacy status NO_INIT"); + _hidl_cb(Status::ERROR_DRM_UNKNOWN, toHidlVec(signature)); return Void(); } @@ -1015,7 +1024,7 @@ Return WVDrmPlugin::sign( if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(signature)); return Void(); } @@ -1031,7 +1040,7 @@ Return WVDrmPlugin::sign( ALOGE("OEMCrypto_Generic_Sign failed with %u when requesting signature " "size", res); if (res != OEMCrypto_SUCCESS) { - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(signature)); } else { _hidl_cb(Status::ERROR_DRM_UNKNOWN, toHidlVec(signature)); @@ -1049,7 +1058,7 @@ Return WVDrmPlugin::sign( _hidl_cb(Status::OK, toHidlVec(signature)); } else { ALOGE("OEMCrypto_Generic_Sign failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), toHidlVec(signature)); } return Void(); @@ -1074,7 +1083,8 @@ Return WVDrmPlugin::verify( const CryptoSession& cryptoSession = mCryptoSessions[cdmSessionId]; if (cryptoSession.macAlgorithm() == kInvalidCryptoAlgorithm) { - _hidl_cb(toStatus(android::NO_INIT), match); + ALOGW("Returns UNKNOWN error for legacy status NO_INIT"); + _hidl_cb(Status::ERROR_DRM_UNKNOWN, match); return Void(); } @@ -1084,7 +1094,7 @@ Return WVDrmPlugin::verify( if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_SelectKey failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), match); + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), match); return Void(); } @@ -1102,7 +1112,7 @@ Return WVDrmPlugin::verify( _hidl_cb(Status::OK, match); } else { ALOGE("OEMCrypto_Generic_Verify failed with %u", res); - _hidl_cb(toStatus(mapAndNotifyOfOEMCryptoResult(sId, res)), match); + _hidl_cb(mapAndNotifyOfOEMCryptoResult(sId, res), match); } return Void(); } @@ -1143,7 +1153,7 @@ Return WVDrmPlugin::signRSA( if (res != OEMCrypto_SUCCESS) { ALOGE("OEMCrypto_GenerateRSASignature failed with %u", res); - _hidl_cb(toStatus(mapOEMCryptoResult(res)), toHidlVec(signature)); + _hidl_cb(mapOEMCryptoResult(res), toHidlVec(signature)); return Void(); } @@ -1233,7 +1243,7 @@ void WVDrmPlugin::OnExpirationUpdate(const CdmSessionId& cdmSessionId, sendExpirationUpdate(toHidlVec(sessionId), newExpiryTimeMilliseconds); } -status_t WVDrmPlugin::queryProperty(const std::string& property, +Status WVDrmPlugin::queryProperty(const std::string& property, std::string& stringValue) const { SecurityLevel securityLevel = mPropertySet.security_level().compare( @@ -1243,7 +1253,7 @@ status_t WVDrmPlugin::queryProperty(const std::string& property, return queryProperty(securityLevel, property, stringValue); } -status_t WVDrmPlugin::queryProperty(SecurityLevel securityLevel, +Status WVDrmPlugin::queryProperty(SecurityLevel securityLevel, const std::string& property, std::string& stringValue) const { CdmResponseType res = @@ -1255,16 +1265,16 @@ status_t WVDrmPlugin::queryProperty(SecurityLevel securityLevel, return mapCdmResponseType(res); } -status_t WVDrmPlugin::queryProperty(const std::string& property, +Status WVDrmPlugin::queryProperty(const std::string& property, std::vector& vector_value) const { std::string string_value; - status_t status = queryProperty(property, string_value); - if (status != android::OK) return status; + Status status = queryProperty(property, string_value); + if (status != Status::OK) return status; vector_value = StrToVector(string_value); - return android::OK; + return Status::OK; } -status_t WVDrmPlugin::mapAndNotifyOfCdmResponseType( +Status WVDrmPlugin::mapAndNotifyOfCdmResponseType( const std::vector& sessionId, CdmResponseType res) { @@ -1278,7 +1288,7 @@ status_t WVDrmPlugin::mapAndNotifyOfCdmResponseType( return mapCdmResponseType(res); } -status_t WVDrmPlugin::mapAndNotifyOfOEMCryptoResult( +Status WVDrmPlugin::mapAndNotifyOfOEMCryptoResult( const std::vector& sessionId, OEMCryptoResult res) { @@ -1289,31 +1299,34 @@ status_t WVDrmPlugin::mapAndNotifyOfOEMCryptoResult( return mapOEMCryptoResult(res); } -status_t WVDrmPlugin::mapOEMCryptoResult(OEMCryptoResult res) { +Status WVDrmPlugin::mapOEMCryptoResult(OEMCryptoResult res) { switch (res) { case OEMCrypto_SUCCESS: - return android::OK; + return Status::OK; + case OEMCrypto_ERROR_SIGNATURE_FAILURE: - return android::ERROR_DRM_TAMPER_DETECTED; - case OEMCrypto_ERROR_SHORT_BUFFER: - return kErrorIncorrectBufferSize; + return Status::ERROR_DRM_INVALID_STATE; + case OEMCrypto_ERROR_NO_DEVICE_KEY: - return android::ERROR_DRM_NOT_PROVISIONED; + return Status::ERROR_DRM_NOT_PROVISIONED; + case OEMCrypto_ERROR_INVALID_SESSION: - return android::ERROR_DRM_SESSION_NOT_OPENED; + return Status::ERROR_DRM_SESSION_NOT_OPENED; + case OEMCrypto_ERROR_TOO_MANY_SESSIONS: - return android::ERROR_DRM_RESOURCE_BUSY; - case OEMCrypto_ERROR_INVALID_RSA_KEY: - return kErrorInvalidKey; case OEMCrypto_ERROR_INSUFFICIENT_RESOURCES: - return android::ERROR_DRM_RESOURCE_BUSY; + return Status::ERROR_DRM_RESOURCE_BUSY; + case OEMCrypto_ERROR_NOT_IMPLEMENTED: - return android::ERROR_DRM_CANNOT_HANDLE; + return Status::ERROR_DRM_CANNOT_HANDLE; + + case OEMCrypto_ERROR_INVALID_RSA_KEY: + case OEMCrypto_ERROR_SHORT_BUFFER: + ALOGW("Returns UNKNOWN error for legacy status: %d", res); case OEMCrypto_ERROR_UNKNOWN_FAILURE: case OEMCrypto_ERROR_OPEN_SESSION_FAILED: - return android::ERROR_DRM_UNKNOWN; default: - return android::UNKNOWN_ERROR; + return Status::ERROR_DRM_UNKNOWN; } } @@ -1342,7 +1355,7 @@ bool WVDrmPlugin::initDataResemblesPSSH(const std::vector& initData) { return id == kPsshTag; } -status_t WVDrmPlugin::unprovision(const CdmIdentifier& identifier) { +Status WVDrmPlugin::unprovision(const CdmIdentifier& identifier) { CdmResponseType res1 = mCDM->Unprovision(wvcdm::kSecurityLevelL1, identifier); CdmResponseType res3 = mCDM->Unprovision(wvcdm::kSecurityLevelL3, identifier); if (!isCdmResponseTypeSuccess(res1)) @@ -1364,44 +1377,44 @@ WVDrmPlugin::CdmIdentifierBuilder::CdmIdentifierBuilder( mAppPackageName(appPackageName), mParent(parent) {} -status_t WVDrmPlugin::CdmIdentifierBuilder::getCdmIdentifier( +Status WVDrmPlugin::CdmIdentifierBuilder::getCdmIdentifier( CdmIdentifier* identifier) { if (!mIsIdentifierSealed) { - status_t res = calculateSpoid(); - if (res != android::OK) return res; + Status res = calculateSpoid(); + if (res != Status::OK) return res; mIsIdentifierSealed = true; } *identifier = mCdmIdentifier; - return android::OK; + return Status::OK; } -status_t WVDrmPlugin::CdmIdentifierBuilder::getDeviceUniqueId(std::string* id) { +Status WVDrmPlugin::CdmIdentifierBuilder::getDeviceUniqueId(std::string* id) { if (mUseSpoid) { CdmIdentifier identifier; - status_t res = getCdmIdentifier(&identifier); - if (res != android::OK) return res; + Status res = getCdmIdentifier(&identifier); + if (res != Status::OK) return res; *id = identifier.spoid; - return android::OK; + return Status::OK; } else { return getOemcryptoDeviceId(id); } } -status_t WVDrmPlugin::CdmIdentifierBuilder::getProvisioningUniqueId(std::string* id) { +Status WVDrmPlugin::CdmIdentifierBuilder::getProvisioningUniqueId(std::string* id) { if (mUseSpoid) { // To fake a provisioning-unique ID on SPOID devices where we can't expose // the real provisioning-unique ID, we just use the SPOID and invert all the // bits. - status_t res = getDeviceUniqueId(id); - if (res != android::OK) return res; + Status res = getDeviceUniqueId(id); + if (res != Status::OK) return res; for (char& c : *id) { c = ~c; } - return android::OK; + return Status::OK; } else { return mParent.queryProperty(wvcdm::QUERY_KEY_PROVISIONING_ID, *id); } @@ -1413,11 +1426,11 @@ bool WVDrmPlugin::CdmIdentifierBuilder::set_origin(const std::string& id) { return true; } -status_t WVDrmPlugin::CdmIdentifierBuilder::calculateSpoid() { +Status WVDrmPlugin::CdmIdentifierBuilder::calculateSpoid() { if (mUseSpoid) { std::string deviceId; - status_t res = getOemcryptoDeviceId(&deviceId); - if (res != android::OK) return res; + Status res = getOemcryptoDeviceId(&deviceId); + if (res != Status::OK) return res; uint8_t hash[SHA256_DIGEST_LENGTH]; SHA256_CTX ctx; @@ -1430,10 +1443,10 @@ status_t WVDrmPlugin::CdmIdentifierBuilder::calculateSpoid() { mCdmIdentifier.spoid = std::string(reinterpret_cast(hash), SHA256_DIGEST_LENGTH); } - return android::OK; + return Status::OK; } -status_t WVDrmPlugin::CdmIdentifierBuilder::getOemcryptoDeviceId( +Status WVDrmPlugin::CdmIdentifierBuilder::getOemcryptoDeviceId( std::string* id) { return mParent.queryProperty(wvcdm::QUERY_KEY_DEVICE_ID, *id); } diff --git a/libwvdrmengine/mediadrm/test/Android.mk b/libwvdrmengine/mediadrm/test/Android.mk index 1a123fbf..7ecd9f6f 100644 --- a/libwvdrmengine/mediadrm/test/Android.mk +++ b/libwvdrmengine/mediadrm/test/Android.mk @@ -87,10 +87,6 @@ LOCAL_STATIC_LIBRARIES := \ libwvlevel3 \ libwvdrmdrmplugin_hidl \ -# When the GNU linker sees a library, it discards all symbols that it doesn't -# need. libwidevinehidl_utils must come after libwvdrmdrmplugin. -LOCAL_STATIC_LIBRARIES += libwidevinehidl_utils - LOCAL_SHARED_LIBRARIES := \ android.hardware.drm@1.0 \ android.hidl.memory@1.0 \ diff --git a/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp b/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp index 48c4f3e9..1d0d8985 100644 --- a/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp +++ b/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp @@ -813,8 +813,8 @@ TEST_F(WVDrmPluginTest, UnprovisionsDevice) { .Times(1); WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - status_t res = plugin.unprovisionDevice(); - ASSERT_EQ(android::OK, res); + Status res = plugin.unprovisionDevice(); + ASSERT_EQ(Status::OK, res); } TEST_F(WVDrmPluginTest, MuxesUnprovisioningErrors) { @@ -834,12 +834,12 @@ TEST_F(WVDrmPluginTest, MuxesUnprovisioningErrors) { .WillOnce(testing::Return(wvcdm::UNKNOWN_ERROR)); WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - status_t res = plugin.unprovisionDevice(); - ASSERT_NE(android::OK, res); + Status res = plugin.unprovisionDevice(); + ASSERT_NE(Status::OK, res); res = plugin.unprovisionDevice(); - ASSERT_NE(android::OK, res); + ASSERT_NE(Status::OK, res); res = plugin.unprovisionDevice(); - ASSERT_NE(android::OK, res); + ASSERT_NE(Status::OK, res); } TEST_F(WVDrmPluginTest, UnprovisionsOrigin) { @@ -2364,7 +2364,7 @@ TEST_F(WVDrmPluginTest, CanSetSessionSharing) { } WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - status_t res; + Status res; // Test turning on session sharing Status status = plugin.setPropertyString(hidl_string("sessionSharing"), diff --git a/libwvdrmengine/src_hidl/TypeConvert.cpp b/libwvdrmengine/src_hidl/TypeConvert.cpp deleted file mode 100644 index ddf4afa0..00000000 --- a/libwvdrmengine/src_hidl/TypeConvert.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "TypeConvert.h" - -#include - -namespace android { -namespace hardware { -namespace drm { -namespace V1_0 { -namespace widevine { - -Status toStatus(status_t mediaError) { - Status status; - switch(mediaError) { - case android::OK: - status = Status::OK; - break; - case android::ERROR_DRM_NO_LICENSE: - status = Status::ERROR_DRM_NO_LICENSE; - break; - case android::ERROR_DRM_LICENSE_EXPIRED: - status = Status::ERROR_DRM_LICENSE_EXPIRED; - break; - case android::ERROR_DRM_SESSION_NOT_OPENED: - status = Status::ERROR_DRM_SESSION_NOT_OPENED; - break; - case android::ERROR_DRM_CANNOT_HANDLE: - status = Status::ERROR_DRM_CANNOT_HANDLE; - break; - case android::ERROR_DRM_TAMPER_DETECTED: - status = Status::ERROR_DRM_INVALID_STATE; - break; - case android::BAD_VALUE: - status = Status::BAD_VALUE; - break; - case android::ERROR_DRM_NOT_PROVISIONED: - status = Status::ERROR_DRM_NOT_PROVISIONED; - break; - case android::ERROR_DRM_RESOURCE_BUSY: - status = Status::ERROR_DRM_RESOURCE_BUSY; - break; - case android::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION: - status = Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION; - break; - case android::ERROR_DRM_DEVICE_REVOKED: - status = Status::ERROR_DRM_DEVICE_REVOKED; - break; - case android::ERROR_DRM_DECRYPT: - status = Status::ERROR_DRM_DECRYPT; - break; - default: - ALOGW("Unable to convert legacy status: %d, defaulting to UNKNOWN", - mediaError); - status = Status::ERROR_DRM_UNKNOWN; - break; - } - return status; -} - -} // namespace widevine -} // namespace V1_0 -} // namespace drm -} // namespace hardware -} // namespace android