From 9654d29be65f983a31697da74dd10bf124fd7e2a Mon Sep 17 00:00:00 2001 From: Edwin Date: Tue, 8 Feb 2022 16:16:12 -0800 Subject: [PATCH] Widevine drm aidl: address API review Interface update in change 16810770 Bug: 214410088 Test: atest VtsAidlHalDrmTargetTest Change-Id: I19da51ef75952f5ff6c7c02e0393f574e69ee30b --- libwvdrmengine/Android.bp | 1 - libwvdrmengine/aidl_include/Utils.h | 11 +- .../aidl_include/WVCreatePluginFactories.h | 2 - libwvdrmengine/aidl_include/WVCryptoFactory.h | 45 ------ libwvdrmengine/aidl_include/WVDrmFactory.h | 21 ++- .../aidl_src/WVCreatePluginFactories.cpp | 4 - libwvdrmengine/aidl_src/WVCryptoFactory.cpp | 65 -------- libwvdrmengine/aidl_src/WVDrmFactory.cpp | 74 ++++----- .../android.hardware.drm-service.widevine.rc | 1 - libwvdrmengine/aidl_src/service.cpp | 11 -- ..._android.hardware.drm-service.widevine.xml | 1 - .../mediacrypto/aidl_include/WVCryptoPlugin.h | 19 +-- .../mediacrypto/aidl_src/WVCryptoPlugin.cpp | 147 +++++++++--------- .../mediadrm/aidl_include/WVDrmPlugin.h | 2 - .../mediadrm/aidl_src/WVDrmPlugin.cpp | 38 ++--- 15 files changed, 150 insertions(+), 292 deletions(-) delete mode 100644 libwvdrmengine/aidl_include/WVCryptoFactory.h delete mode 100644 libwvdrmengine/aidl_src/WVCryptoFactory.cpp diff --git a/libwvdrmengine/Android.bp b/libwvdrmengine/Android.bp index 10cbe49f..0d0cf195 100644 --- a/libwvdrmengine/Android.bp +++ b/libwvdrmengine/Android.bp @@ -468,7 +468,6 @@ cc_library_shared { "src/WVUUID.cpp", "aidl_src/wv_metrics.cpp", "aidl_src/WVCreatePluginFactories.cpp", - "aidl_src/WVCryptoFactory.cpp", "aidl_src/WVDrmFactory.cpp", ], diff --git a/libwvdrmengine/aidl_include/Utils.h b/libwvdrmengine/aidl_include/Utils.h index 4479386b..6349a5cf 100644 --- a/libwvdrmengine/aidl_include/Utils.h +++ b/libwvdrmengine/aidl_include/Utils.h @@ -36,12 +36,17 @@ inline ::aidl::android::hardware::drm::LogPriority toAidlLogPriority( } inline ::ndk::ScopedAStatus toNdkScopedAStatus( - ::aidl::android::hardware::drm::Status status) { + ::aidl::android::hardware::drm::Status status, const char* msg = nullptr) { if (::aidl::android::hardware::drm::Status::OK == status) return ::ndk::ScopedAStatus::ok(); else { - return ::ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(status)); + auto err = static_cast(status); + if (msg) { + return ::ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(err, + msg); + } else { + return ::ndk::ScopedAStatus::fromServiceSpecificError(err); + } } } diff --git a/libwvdrmengine/aidl_include/WVCreatePluginFactories.h b/libwvdrmengine/aidl_include/WVCreatePluginFactories.h index 26b1fcc9..f1d691b4 100644 --- a/libwvdrmengine/aidl_include/WVCreatePluginFactories.h +++ b/libwvdrmengine/aidl_include/WVCreatePluginFactories.h @@ -7,7 +7,6 @@ #ifndef WV_CREATE_PLUGIN_FACTORIES_H_ #define WV_CREATE_PLUGIN_FACTORIES_H_ -#include "WVCryptoFactory.h" #include "WVDrmFactory.h" namespace wvdrm { @@ -16,7 +15,6 @@ namespace drm { namespace widevine { std::shared_ptr createDrmFactory(); -std::shared_ptr createCryptoFactory(); } // namespace widevine } // namespace drm diff --git a/libwvdrmengine/aidl_include/WVCryptoFactory.h b/libwvdrmengine/aidl_include/WVCryptoFactory.h deleted file mode 100644 index 1e895ff6..00000000 --- a/libwvdrmengine/aidl_include/WVCryptoFactory.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine License -// Agreement. -// - -#ifndef WV_CRYPTO_FACTORY_H_ -#define WV_CRYPTO_FACTORY_H_ - -#include -#include -#include - -#include "WVTypes.h" - -namespace wvdrm { -namespace hardware { -namespace drm { -namespace widevine { - -struct WVCryptoFactory : public ::aidl::android::hardware::drm::BnCryptoFactory { - public: - WVCryptoFactory() {} - virtual ~WVCryptoFactory() {} - - ::ndk::ScopedAStatus createPlugin( - const ::aidl::android::hardware::drm::Uuid& in_uuid, - const std::vector& in_initData, - std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>* - _aidl_return) override; - - ::ndk::ScopedAStatus isCryptoSchemeSupported( - const ::aidl::android::hardware::drm::Uuid& in_uuid, - bool* _aidl_return) override; - - private: - WVDRM_DISALLOW_COPY_AND_ASSIGN(WVCryptoFactory); -}; - -} // namespace widevine -} // namespace drm -} // namespace hardware -} // namespace wvdrm - -#endif // WV_CRYPTO_FACTORY_H_ diff --git a/libwvdrmengine/aidl_include/WVDrmFactory.h b/libwvdrmengine/aidl_include/WVDrmFactory.h index f136fa3d..394964a8 100644 --- a/libwvdrmengine/aidl_include/WVDrmFactory.h +++ b/libwvdrmengine/aidl_include/WVDrmFactory.h @@ -23,29 +23,26 @@ struct WVDrmFactory : public ::aidl::android::hardware::drm::BnDrmFactory { WVDrmFactory() {} virtual ~WVDrmFactory() {} - ::ndk::ScopedAStatus createPlugin( + ::ndk::ScopedAStatus createDrmPlugin( const ::aidl::android::hardware::drm::Uuid& in_uuid, const std::string& in_appPackageName, std::shared_ptr<::aidl::android::hardware::drm::IDrmPlugin>* _aidl_return) override; + ::ndk::ScopedAStatus createCryptoPlugin( + const ::aidl::android::hardware::drm::Uuid& in_uuid, + const std::vector& in_initData, + std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>* + _aidl_return) override; + ::ndk::ScopedAStatus getSupportedCryptoSchemes( - std::vector<::aidl::android::hardware::drm::Uuid>* _aidl_return) override; + ::aidl::android::hardware::drm::CryptoSchemes* _aidl_return) override; - ::ndk::ScopedAStatus isContentTypeSupported(const std::string& in_mimeType, - bool* _aidl_return) override; - - // This overloaded method is not part of the AIDL interface, it is provided + // This method is not part of the AIDL interface, it is provided // for Widevine CDM. bool isCryptoSchemeSupported( const ::aidl::android::hardware::drm::Uuid& in_uuid); - ::ndk::ScopedAStatus isCryptoSchemeSupported( - const ::aidl::android::hardware::drm::Uuid& in_uuid, - const std::string& in_mimeType, - ::aidl::android::hardware::drm::SecurityLevel in_securityLevel, - bool* _aidl_return) override; - binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; private: diff --git a/libwvdrmengine/aidl_src/WVCreatePluginFactories.cpp b/libwvdrmengine/aidl_src/WVCreatePluginFactories.cpp index e27382ee..e0e28a31 100644 --- a/libwvdrmengine/aidl_src/WVCreatePluginFactories.cpp +++ b/libwvdrmengine/aidl_src/WVCreatePluginFactories.cpp @@ -15,10 +15,6 @@ std::shared_ptr createDrmFactory() { return std::make_shared(); } -std::shared_ptr createCryptoFactory() { - return std::make_shared(); -} - } // namespace widevine } // namespace drm } // namespace hardware diff --git a/libwvdrmengine/aidl_src/WVCryptoFactory.cpp b/libwvdrmengine/aidl_src/WVCryptoFactory.cpp deleted file mode 100644 index 905a04f9..00000000 --- a/libwvdrmengine/aidl_src/WVCryptoFactory.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine License -// Agreement. -// - -//#define LOG_NDEBUG 0 -#define LOG_TAG "WVCdm" -#include "WVCryptoFactory.h" - -#include -#include -#include - -#include "Utils.h" -#include "WVCDMSingleton.h" -#include "WVCryptoPlugin.h" -#include "WVUUID.h" - -namespace wvdrm { -namespace hardware { -namespace drm { -namespace widevine { - -using ::aidl::android::hardware::drm::Status; -using ::aidl::android::hardware::drm::Uuid; - -::ndk::ScopedAStatus WVCryptoFactory::isCryptoSchemeSupported( - const Uuid& in_uuid, bool* _aidl_return) { - *_aidl_return = isWidevineUUID(in_uuid.uuid.data()); - return ::ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus WVCryptoFactory::createPlugin( - const ::aidl::android::hardware::drm::Uuid& in_uuid, - const std::vector& in_initData, - std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>* - _aidl_return) { - const auto& self = android::IPCThreadState::self(); - const char* sid = self->getCallingSid(); - sid = sid ? (std::strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr"; - ALOGI("[%s] calling %s", sid, __PRETTY_FUNCTION__); - - bool isSupported = false; - isCryptoSchemeSupported(in_uuid, &isSupported); - if (!isSupported) { - ALOGE( - "Widevine Drm HAL: failed to create crypto plugin, " - "invalid crypto scheme"); - *_aidl_return = nullptr; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); - } - - std::shared_ptr plugin = - ::ndk::SharedRefBase::make(in_initData.data(), - in_initData.size(), getCDM()); - AIBinder_setRequestingSid(plugin->asBinder().get(), true); - *_aidl_return = std::move(plugin); - return toNdkScopedAStatus(Status::OK); -} - -} // namespace widevine -} // namespace drm -} // namespace hardware -} // namespace wvdrm diff --git a/libwvdrmengine/aidl_src/WVDrmFactory.cpp b/libwvdrmengine/aidl_src/WVDrmFactory.cpp index 7e7c5f55..f080b1fd 100644 --- a/libwvdrmengine/aidl_src/WVDrmFactory.cpp +++ b/libwvdrmengine/aidl_src/WVDrmFactory.cpp @@ -15,6 +15,7 @@ #include "Utils.h" #include "WVCDMSingleton.h" +#include "WVCryptoPlugin.h" #include "WVDrmPlugin.h" #include "WVUUID.h" #include "android-base/properties.h" @@ -31,6 +32,7 @@ namespace widevine { using std::string; using std::vector; +using ::aidl::android::hardware::drm::CryptoSchemes; using ::aidl::android::hardware::drm::SecurityLevel; using ::aidl::android::hardware::drm::Status; using ::aidl::android::hardware::drm::Uuid; @@ -41,40 +43,33 @@ bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) { return isWidevineUUID(in_uuid.uuid.data()); } -::ndk::ScopedAStatus WVDrmFactory::isCryptoSchemeSupported( - const Uuid& in_uuid, const string& in_mimeType, - SecurityLevel in_securityLevel, bool* _aidl_return) { - bool isMimeTypeSupported = false; - isContentTypeSupported(in_mimeType, &isMimeTypeSupported); - if (!isWidevineUUID(in_uuid.uuid.data()) || !isMimeTypeSupported) { - *_aidl_return = false; - return ::ndk::ScopedAStatus::ok(); +::ndk::ScopedAStatus WVDrmFactory::createCryptoPlugin( + const ::aidl::android::hardware::drm::Uuid& in_uuid, + const std::vector& in_initData, + std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>* + _aidl_return) { + const auto& self = android::IPCThreadState::self(); + const char* sid = self->getCallingSid(); + sid = sid ? (std::strstr(sid, "mediadrmserver") ? sid : "app") : "nullptr"; + ALOGI("[%s] calling %s", sid, __PRETTY_FUNCTION__); + + if (!isCryptoSchemeSupported(in_uuid)) { + ALOGE( + "Widevine Drm HAL: failed to create crypto plugin, " + "invalid crypto scheme"); + *_aidl_return = nullptr; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); } - if (wvcdm::WvContentDecryptionModule::IsSecurityLevelSupported( - wvcdm::kSecurityLevelL1)) { - if (wvcdm::WvContentDecryptionModule::IsAudio(in_mimeType)) { - if (in_securityLevel < SecurityLevel::HW_SECURE_ALL) { - *_aidl_return = true; - return ::ndk::ScopedAStatus::ok(); - } - } else { - *_aidl_return = true; - return ::ndk::ScopedAStatus::ok(); - } - } - *_aidl_return = in_securityLevel <= SecurityLevel::SW_SECURE_DECODE; - return ::ndk::ScopedAStatus::ok(); + std::shared_ptr plugin = + ::ndk::SharedRefBase::make(in_initData.data(), + in_initData.size(), getCDM()); + AIBinder_setRequestingSid(plugin->asBinder().get(), true); + *_aidl_return = std::move(plugin); + return toNdkScopedAStatus(Status::OK); } -::ndk::ScopedAStatus WVDrmFactory::isContentTypeSupported( - const string& in_mimeType, bool* _aidl_return) { - *_aidl_return = - wvcdm::WvContentDecryptionModule::IsSupported(in_mimeType.c_str()); - return ::ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus WVDrmFactory::createPlugin( +::ndk::ScopedAStatus WVDrmFactory::createDrmPlugin( const Uuid& in_uuid, const string& in_appPackageName, std::shared_ptr<::aidl::android::hardware::drm::IDrmPlugin>* _aidl_return) { const auto& self = ::android::IPCThreadState::self(); @@ -130,13 +125,22 @@ int32_t WVDrmFactory::firstApiLevel() { } ::ndk::ScopedAStatus WVDrmFactory::getSupportedCryptoSchemes( - vector* _aidl_return) { - vector schemes; - Uuid scheme; + CryptoSchemes* _aidl_return) { + CryptoSchemes schemes{}; for (const auto& uuid : wvdrm::getSupportedCryptoSchemes()) { - scheme.uuid.assign(uuid.begin(), uuid.end()); - schemes.push_back(scheme); + schemes.uuids.push_back({uuid}); } + schemes.minLevel = schemes.maxLevel = SecurityLevel::SW_SECURE_CRYPTO; + if (wvcdm::WvContentDecryptionModule::IsSecurityLevelSupported( + wvcdm::kSecurityLevelL1)) { + schemes.maxLevel = SecurityLevel::HW_SECURE_ALL; + } + + schemes.mimeTypes = { + wvcdm::ISO_BMFF_VIDEO_MIME_TYPE, wvcdm::ISO_BMFF_AUDIO_MIME_TYPE, + wvcdm::WEBM_VIDEO_MIME_TYPE, wvcdm::WEBM_AUDIO_MIME_TYPE, + wvcdm::CENC_INIT_DATA_FORMAT, wvcdm::HLS_INIT_DATA_FORMAT, + wvcdm::WEBM_INIT_DATA_FORMAT}; *_aidl_return = schemes; return ::ndk::ScopedAStatus::ok(); } diff --git a/libwvdrmengine/aidl_src/android.hardware.drm-service.widevine.rc b/libwvdrmengine/aidl_src/android.hardware.drm-service.widevine.rc index 3a8c1aae..17f891bc 100644 --- a/libwvdrmengine/aidl_src/android.hardware.drm-service.widevine.rc +++ b/libwvdrmengine/aidl_src/android.hardware.drm-service.widevine.rc @@ -2,7 +2,6 @@ on property:init.svc.mediadrm=running mkdir /data/vendor/mediadrm 0770 media mediadrm service vendor.drm-widevine-hal /vendor/bin/hw/android.hardware.drm-service.widevine - interface aidl android.hardware.drm::ICryptoFactory/widevine interface aidl android.hardware.drm::IDrmFactory/widevine class hal user media diff --git a/libwvdrmengine/aidl_src/service.cpp b/libwvdrmengine/aidl_src/service.cpp index 4c65d192..5670fae2 100644 --- a/libwvdrmengine/aidl_src/service.cpp +++ b/libwvdrmengine/aidl_src/service.cpp @@ -22,12 +22,9 @@ #include #include "WVCreatePluginFactories.h" -#include "WVCryptoFactory.h" #include "WVDrmFactory.h" -using ::wvdrm::hardware::drm::widevine::createCryptoFactory; using ::wvdrm::hardware::drm::widevine::createDrmFactory; -using ::wvdrm::hardware::drm::widevine::WVCryptoFactory; using ::wvdrm::hardware::drm::widevine::WVDrmFactory; int main(int /* argc */, char** /* argv */) { @@ -41,13 +38,5 @@ int main(int /* argc */, char** /* argv */) { CHECK(status == STATUS_OK) << "Failed to add Widevine Factory HAL, status=" << status; - std::shared_ptr cryptoFactory = createCryptoFactory(); - const std::string cryptoInstance = - std::string(WVCryptoFactory::descriptor) + "/widevine"; - status = AServiceManager_addService(cryptoFactory->asBinder().get(), - cryptoInstance.c_str()); - CHECK(status == STATUS_OK) - << "Failed to add Widevine Crypto HAL, status=" << status; - ABinderProcess_joinThreadPool(); } diff --git a/libwvdrmengine/manifest_android.hardware.drm-service.widevine.xml b/libwvdrmengine/manifest_android.hardware.drm-service.widevine.xml index 6d68ff35..914783fd 100644 --- a/libwvdrmengine/manifest_android.hardware.drm-service.widevine.xml +++ b/libwvdrmengine/manifest_android.hardware.drm-service.widevine.xml @@ -17,7 +17,6 @@ android.hardware.drm 1 - ICryptoFactory/widevine IDrmFactory/widevine diff --git a/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h b/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h index b1da2eec..b3f9a5d6 100644 --- a/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h +++ b/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h @@ -26,7 +26,7 @@ namespace widevine { struct SharedBufferBase { uint8_t* mBase; int64_t mSize; - SharedBufferBase(const ::aidl::android::hardware::common::Ashmem& mem); + SharedBufferBase(const ::aidl::android::hardware::drm::SharedBuffer& mem); ~SharedBufferBase(); }; @@ -45,20 +45,11 @@ struct WVCryptoPlugin : public ::aidl::android::hardware::drm::BnCryptoPlugin { const std::vector& in_sessionId) override; ::ndk::ScopedAStatus setSharedBufferBase( - const ::aidl::android::hardware::common::Ashmem& in_base, - int32_t in_bufferId) override; + const ::aidl::android::hardware::drm::SharedBuffer& in_base) override; ::ndk::ScopedAStatus decrypt( - bool in_secure, const std::vector& in_keyId, - const std::vector& in_iv, - ::aidl::android::hardware::drm::Mode in_mode, - const ::aidl::android::hardware::drm::Pattern& in_pattern, - const std::vector<::aidl::android::hardware::drm::SubSample>& - in_subSamples, - const ::aidl::android::hardware::drm::SharedBuffer& in_source, - int64_t in_offset, - const ::aidl::android::hardware::drm::DestinationBuffer& in_destination, - ::aidl::android::hardware::drm::DecryptResult* _aidl_return) override; + const ::aidl::android::hardware::drm::DecryptArgs& in_args, + int32_t* _aidl_return) override; ::ndk::ScopedAStatus getLogMessages( std::vector<::aidl::android::hardware::drm::LogMessage>* _aidl_return) @@ -90,4 +81,4 @@ struct WVCryptoPlugin : public ::aidl::android::hardware::drm::BnCryptoPlugin { } // namespace hardware } // namespace wvdrm -#endif // WV_CRYPTO_PLUGIN_H_ +#endif // WV_CRYPTO_PLUGIN_H_ diff --git a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp index be00c3cf..4e9a39d1 100644 --- a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp @@ -28,7 +28,7 @@ namespace hardware { namespace drm { namespace widevine { -using ::aidl::android::hardware::drm::BufferType; +using ::aidl::android::hardware::drm::DestinationBuffer; using ::aidl::android::hardware::drm::Mode; using ::aidl::android::hardware::drm::SharedBuffer; using ::aidl::android::hardware::drm::Status; @@ -64,15 +64,16 @@ WVCryptoPlugin::~WVCryptoPlugin() { } SharedBufferBase::SharedBufferBase( - const ::aidl::android::hardware::common::Ashmem& mem) + const ::aidl::android::hardware::drm::SharedBuffer& mem) : mBase(nullptr), mSize(mem.size) { - if (mem.fd.get() < 0) { + if (mem.handle.fds.empty()) { return; } - auto addr = mmap(nullptr, mem.size, PROT_READ | PROT_WRITE, MAP_SHARED, - mem.fd.get(), 0); + auto fd = mem.handle.fds[0].get(); + auto addr = + mmap(nullptr, mem.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { - ALOGE("mmap err: fd %d; errno %s", mem.fd.get(), strerror(errno)); + ALOGE("mmap err: fd %d; errno %s", fd, strerror(errno)); } else { mBase = static_cast(addr); } @@ -129,97 +130,99 @@ SharedBufferBase::~SharedBufferBase() { } ::ndk::ScopedAStatus WVCryptoPlugin::setSharedBufferBase( - const ::aidl::android::hardware::common::Ashmem& in_base, - int32_t in_bufferId) { + const ::aidl::android::hardware::drm::SharedBuffer& in_base) { std::lock_guard shared_buffer_lock(mSharedBufferLock); - mSharedBufferMap[in_bufferId] = std::make_shared(in_base); + mSharedBufferMap[in_base.bufferId] = + std::make_shared(in_base); return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus WVCryptoPlugin::decrypt( - bool in_secure, const std::vector& in_keyId, - const std::vector& in_iv, - ::aidl::android::hardware::drm::Mode in_mode, - const ::aidl::android::hardware::drm::Pattern& in_pattern, - const std::vector& in_subSamples, - const ::aidl::android::hardware::drm::SharedBuffer& in_source, - int64_t in_offset, - const ::aidl::android::hardware::drm::DestinationBuffer& in_destination, - ::aidl::android::hardware::drm::DecryptResult* _aidl_return) { - _aidl_return->bytesWritten = 0; + const ::aidl::android::hardware::drm::DecryptArgs& in_args, + int32_t* _aidl_return) { + const char* detailedError = ""; + *_aidl_return = 0; // bytes decrypted uint8_t* srcPtr = nullptr; void* destPtr = nullptr; // Convert parameters to the form the CDM wishes to consume them in. - const KeyId cryptoKey(reinterpret_cast(in_keyId.data()), + const KeyId cryptoKey(reinterpret_cast(in_args.keyId.data()), wvcdm::KEY_ID_SIZE); // start scope for lock_guard { std::lock_guard lock(mSharedBufferLock); - if (mSharedBufferMap.find(in_source.bufferId) == mSharedBufferMap.end()) { - _aidl_return->detailedError = "source decrypt buffer base not set"; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + if (mSharedBufferMap.find(in_args.source.bufferId) == + mSharedBufferMap.end()) { + detailedError = "source decrypt buffer base not set"; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, detailedError); } - if (in_destination.type == BufferType::SHARED_MEMORY) { - const SharedBuffer& dest = in_destination.nonsecureMemory; + const auto NON_SECURE = DestinationBuffer::Tag::nonsecureMemory; + if (in_args.destination.getTag() == NON_SECURE) { + const SharedBuffer& dest = in_args.destination.get(); if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) { - _aidl_return->detailedError = "destination decrypt buffer base not set"; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + detailedError = "destination decrypt buffer base not set"; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, + detailedError); } } - if (in_mode != Mode::UNENCRYPTED && in_mode != Mode::AES_CTR && - in_mode != Mode::AES_CBC) { - _aidl_return->detailedError = + if (in_args.mode != Mode::UNENCRYPTED && in_args.mode != Mode::AES_CTR && + in_args.mode != Mode::AES_CBC) { + detailedError = "The requested encryption mode is not supported by Widevine CDM."; - return toNdkScopedAStatus(Status::BAD_VALUE); - } else if (in_mode == Mode::AES_CTR && - (in_pattern.encryptBlocks != 0 || in_pattern.skipBlocks != 0)) { - _aidl_return->detailedError = - "The 'cens' schema is not supported by Widevine CDM."; - return toNdkScopedAStatus(Status::BAD_VALUE); + return toNdkScopedAStatus(Status::BAD_VALUE, detailedError); + } else if (in_args.mode == Mode::AES_CTR && + (in_args.pattern.encryptBlocks != 0 || + in_args.pattern.skipBlocks != 0)) { + detailedError = "The 'cens' schema is not supported by Widevine CDM."; + return toNdkScopedAStatus(Status::BAD_VALUE, detailedError); } - auto src = mSharedBufferMap[in_source.bufferId]; + auto src = mSharedBufferMap[in_args.source.bufferId]; if (src->mBase == nullptr) { - _aidl_return->detailedError = "source is a nullptr"; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + detailedError = "source is a nullptr"; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, detailedError); } size_t totalSrcSize = 0; - if (__builtin_add_overflow(in_source.offset, in_offset, &totalSrcSize) || - __builtin_add_overflow(totalSrcSize, in_source.size, &totalSrcSize) || + if (__builtin_add_overflow(in_args.source.offset, in_args.offset, + &totalSrcSize) || + __builtin_add_overflow(totalSrcSize, in_args.source.size, + &totalSrcSize) || totalSrcSize > src->mSize) { android_errorWriteLog(0x534e4554, "176496160"); - _aidl_return->detailedError = "invalid source buffer size"; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + detailedError = "invalid source buffer size"; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, detailedError); } - srcPtr = src->mBase + in_source.offset + in_offset; + srcPtr = src->mBase + in_args.source.offset + in_args.offset; - if (in_destination.type == BufferType::SHARED_MEMORY) { - const SharedBuffer& destBuffer = in_destination.nonsecureMemory; + if (in_args.destination.getTag() == NON_SECURE) { + const SharedBuffer& destBuffer = in_args.destination.get(); auto dest = mSharedBufferMap[destBuffer.bufferId]; if (dest->mBase == nullptr) { - _aidl_return->detailedError = "destination is a nullptr"; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + detailedError = "destination is a nullptr"; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, + detailedError); } size_t totalDstSize = 0; if (__builtin_add_overflow(destBuffer.offset, destBuffer.size, &totalDstSize) || totalDstSize > dest->mSize) { android_errorWriteLog(0x534e4554, "176444622"); - _aidl_return->detailedError = "invalid buffer size"; - return toNdkScopedAStatus(Status::ERROR_DRM_FRAME_TOO_LARGE); + detailedError = "invalid buffer size"; + return toNdkScopedAStatus(Status::ERROR_DRM_FRAME_TOO_LARGE, + detailedError); } - destPtr = static_cast(dest->mBase + - in_destination.nonsecureMemory.offset); - } else if (in_destination.type == BufferType::NATIVE_HANDLE) { - native_handle_t* handle = - android::makeFromAidl(in_destination.secureMemory); + destPtr = static_cast( + dest->mBase + in_args.destination.get().offset); + } else if (in_args.destination.getTag() == + DestinationBuffer::Tag::secureMemory) { + native_handle_t* handle = android::makeFromAidl( + in_args.destination.get()); destPtr = static_cast(handle); } } // lock_guard scope @@ -227,14 +230,14 @@ SharedBufferBase::~SharedBufferBase() { // Set up the decrypt params CdmDecryptionParametersV16 params; params.key_id = cryptoKey; - params.is_secure = in_secure; - if (in_mode == Mode::AES_CTR) { + params.is_secure = in_args.secure; + if (in_args.mode == Mode::AES_CTR) { params.cipher_mode = wvcdm::kCipherModeCtr; - } else if (in_mode == Mode::AES_CBC) { + } else if (in_args.mode == Mode::AES_CBC) { params.cipher_mode = wvcdm::kCipherModeCbc; } - params.pattern.encrypt_blocks = in_pattern.encryptBlocks; - params.pattern.skip_blocks = in_pattern.skipBlocks; + params.pattern.encrypt_blocks = in_args.pattern.encryptBlocks; + params.pattern.skip_blocks = in_args.pattern.skipBlocks; // Set up the sample // Android's API only supports one at a time @@ -243,16 +246,17 @@ SharedBufferBase::~SharedBufferBase() { sample.encrypt_buffer = srcPtr; sample.decrypt_buffer = destPtr; sample.decrypt_buffer_offset = 0; - sample.iv = in_iv; + sample.iv = in_args.iv; // Set up the subsamples // We abuse std::transform() here to also do some side-effects: Tallying the // total size of the sample and checking if any of the data is protected. size_t totalSize = 0; bool hasProtectedData = false; - sample.subsamples.reserve(in_subSamples.size()); + sample.subsamples.reserve(in_args.subSamples.size()); std::transform( - in_subSamples.data(), in_subSamples.data() + in_subSamples.size(), + in_args.subSamples.data(), + in_args.subSamples.data() + in_args.subSamples.size(), std::back_inserter(sample.subsamples), [&](const SubSample& subSample) -> CdmDecryptionSubsample { totalSize += @@ -265,23 +269,22 @@ SharedBufferBase::~SharedBufferBase() { sample.encrypt_buffer_length = totalSize; sample.decrypt_buffer_size = totalSize; - if (in_mode == Mode::UNENCRYPTED && hasProtectedData) { - _aidl_return->detailedError = - "Protected ranges found in allegedly clear data."; - return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE); + if (in_args.mode == Mode::UNENCRYPTED && hasProtectedData) { + detailedError = "Protected ranges found in allegedly clear data."; + return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE, detailedError); } // Decrypt std::string errorDetailMsg; Status res = attemptDecrypt(params, hasProtectedData, &errorDetailMsg); if (res != Status::OK) { - _aidl_return->detailedError = errorDetailMsg; - return toNdkScopedAStatus(res); + detailedError = errorDetailMsg.data(); + return toNdkScopedAStatus(res, detailedError); } - _aidl_return->bytesWritten = totalSize; - _aidl_return->detailedError = errorDetailMsg; - return toNdkScopedAStatus(Status::OK); + *_aidl_return = totalSize; // return bytes decrypted + detailedError = errorDetailMsg.data(); + return toNdkScopedAStatus(Status::OK, detailedError); } Status WVCryptoPlugin::attemptDecrypt(const CdmDecryptionParametersV16& params, diff --git a/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h b/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h index ae44f496..a66c1a52 100644 --- a/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h +++ b/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h @@ -140,8 +140,6 @@ struct WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin, const std::string& in_mime, ::aidl::android::hardware::drm::SecurityLevel in_level, bool* _aidl_return) override; - ::ndk::ScopedAStatus requiresSecureDecoderDefault( - const std::string& in_mime, bool* _aidl_return) override; ::ndk::ScopedAStatus restoreKeys( const std::vector& in_sessionId, const ::aidl::android::hardware::drm::KeySetId& in_keySetId) override; diff --git a/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp index 1a52cc5b..f3660d98 100644 --- a/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp @@ -118,13 +118,13 @@ KeyStatusType ConvertFromCdmKeyStatus(CdmKeyStatus keyStatus) { case wvcdm::kKeyStatusExpired: return KeyStatusType::EXPIRED; case wvcdm::kKeyStatusOutputNotAllowed: - return KeyStatusType::OUTPUTNOTALLOWED; + return KeyStatusType::OUTPUT_NOT_ALLOWED; case wvcdm::kKeyStatusPending: case wvcdm::kKeyStatusUsableInFuture: - return KeyStatusType::USABLEINFUTURE; + return KeyStatusType::USABLE_IN_FUTURE; case wvcdm::kKeyStatusInternalError: default: - return KeyStatusType::INTERNALERROR; + return KeyStatusType::INTERNAL_ERROR; } } @@ -1762,28 +1762,18 @@ void WVDrmPlugin::sendSessionLostState(const vector& in_sessionId) { ::ndk::ScopedAStatus WVDrmPlugin::requiresSecureDecoder( const std::string& in_mime, SecurityLevel in_level, bool* _aidl_return) { if (!strncasecmp(in_mime.c_str(), "video/", 6)) { - // Type is video, so check level to see if we require a secure decoder. - *_aidl_return = in_level == SecurityLevel::HW_SECURE_ALL || - in_level == SecurityLevel::HW_SECURE_DECODE; - } else { - // Type is not video, so never require a secure decoder. - *_aidl_return = false; - } - return ::ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus WVDrmPlugin::requiresSecureDecoderDefault( - const std::string& in_mime, bool* _aidl_return) { - if (!strncasecmp(in_mime.c_str(), "video/", 6)) { - // Type is video, so check level to see if we require a secure decoder. - std::string level(mPropertySet.security_level()); - - if (level == kResetSecurityLevel) { - mCDM->QueryStatus(wvcdm::kLevelDefault, wvcdm::QUERY_KEY_SECURITY_LEVEL, - &level); + if (in_level == SecurityLevel::DEFAULT) { + std::string level(mPropertySet.security_level()); + if (level == kResetSecurityLevel) { + mCDM->QueryStatus(wvcdm::kLevelDefault, wvcdm::QUERY_KEY_SECURITY_LEVEL, + &level); + } + *_aidl_return = level == wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1; + } else { + // Type is video, so check level to see if we require a secure decoder. + *_aidl_return = in_level == SecurityLevel::HW_SECURE_ALL || + in_level == SecurityLevel::HW_SECURE_DECODE; } - - *_aidl_return = level == wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1; } else { // Type is not video, so never require a secure decoder. *_aidl_return = false;