From f196b630887104fb02cdba542471532ea5b6e542 Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Sat, 30 Jul 2022 01:50:48 +0000 Subject: [PATCH] Call AIBinder_setRequestingSid from createBinder override function AIBinder_setRequestingSid must be called first upon creation of a binder object before AIBinder_getCallingSid is called. Call AIBinder_setRequestingSid in the createBinder override function for WVDrmFactory, WVDrmPlugin and WVCryptoPlugin classes. Test: Play TV streaming Test: adb shell dumpsys android.hardware.drm.IDrmFactory/widevine -a Bug: 237613676 Change-Id: I9dde4715ba2003deb463bd75b23e1ebc2f22a764 (cherry picked from commit 6797b8eb8a7118a1400859327044d6467ec5c5f7) --- libwvdrmengine/aidl_include/WVDrmFactory.h | 2 ++ libwvdrmengine/aidl_src/WVDrmFactory.cpp | 9 +++++++-- libwvdrmengine/aidl_src/service.cpp | 1 - libwvdrmengine/aidl_src/serviceLazy.cpp | 1 - libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h | 2 ++ libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp | 7 +++++++ libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h | 2 ++ libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp | 6 ++++++ 8 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libwvdrmengine/aidl_include/WVDrmFactory.h b/libwvdrmengine/aidl_include/WVDrmFactory.h index 7dcf0a00..2606ae99 100644 --- a/libwvdrmengine/aidl_include/WVDrmFactory.h +++ b/libwvdrmengine/aidl_include/WVDrmFactory.h @@ -48,6 +48,8 @@ struct WVDrmFactory : public ::aidl::android::hardware::drm::BnDrmFactory { private: WVDRM_DISALLOW_COPY_AND_ASSIGN(WVDrmFactory); + ::ndk::SpAIBinder createBinder() override; + static WVGenericCryptoInterface sOemCryptoInterface; static bool areSpoidsEnabled(); diff --git a/libwvdrmengine/aidl_src/WVDrmFactory.cpp b/libwvdrmengine/aidl_src/WVDrmFactory.cpp index 4d953cba..5dde7b4f 100644 --- a/libwvdrmengine/aidl_src/WVDrmFactory.cpp +++ b/libwvdrmengine/aidl_src/WVDrmFactory.cpp @@ -46,6 +46,13 @@ bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) { return isWidevineUUID(in_uuid.uuid.data()); } + +::ndk::SpAIBinder WVDrmFactory::createBinder() { + auto binder = BnDrmFactory::createBinder(); + AIBinder_setRequestingSid(binder.get(), true); + return binder; +} + ::ndk::ScopedAStatus WVDrmFactory::createCryptoPlugin( const ::aidl::android::hardware::drm::Uuid& in_uuid, const std::vector& in_initData, @@ -66,7 +73,6 @@ bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) { 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); } @@ -99,7 +105,6 @@ bool WVDrmFactory::isCryptoSchemeSupported(const Uuid& in_uuid) { getCDM(), in_appPackageName.c_str(), &sOemCryptoInterface, areSpoidsEnabled()); - AIBinder_setRequestingSid(plugin->asBinder().get(), true); *_aidl_return = plugin; return toNdkScopedAStatus(Status::OK); } diff --git a/libwvdrmengine/aidl_src/service.cpp b/libwvdrmengine/aidl_src/service.cpp index d6f39630..d30ad182 100644 --- a/libwvdrmengine/aidl_src/service.cpp +++ b/libwvdrmengine/aidl_src/service.cpp @@ -30,7 +30,6 @@ int main(int /* argc */, char** /* argv */) { ABinderProcess_setThreadPoolMaxThreadCount(8); std::shared_ptr drmFactory = createDrmFactory(); - AIBinder_setRequestingSid(drmFactory->asBinder().get(), true); const std::string drmInstance = std::string(WVDrmFactory::descriptor) + "/widevine"; diff --git a/libwvdrmengine/aidl_src/serviceLazy.cpp b/libwvdrmengine/aidl_src/serviceLazy.cpp index 0bbb00d9..53312dab 100644 --- a/libwvdrmengine/aidl_src/serviceLazy.cpp +++ b/libwvdrmengine/aidl_src/serviceLazy.cpp @@ -30,7 +30,6 @@ int main(int /* argc */, char** /* argv */) { ABinderProcess_setThreadPoolMaxThreadCount(8); std::shared_ptr drmFactory = createDrmFactory(); - AIBinder_setRequestingSid(drmFactory->asBinder().get(), true); const std::string drmInstance = std::string(WVDrmFactory::descriptor) + "/widevine"; diff --git a/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h b/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h index b3f9a5d6..4ad8244e 100644 --- a/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h +++ b/libwvdrmengine/mediacrypto/aidl_include/WVCryptoPlugin.h @@ -69,6 +69,8 @@ struct WVCryptoPlugin : public ::aidl::android::hardware::drm::BnCryptoPlugin { ::android::sp const mCDM; uint32_t mUserId; + ::ndk::SpAIBinder createBinder() override; + ::aidl::android::hardware::drm::Status attemptDecrypt( const wvcdm::CdmDecryptionParametersV16& params, bool haveEncryptedSubsamples, std::string* errorDetailMsg); diff --git a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp index d2f4ab49..044eaf63 100644 --- a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp @@ -9,6 +9,7 @@ #include "WVCryptoPlugin.h" #include +#include #include #include @@ -288,6 +289,12 @@ SharedBufferBase::~SharedBufferBase() { return toNdkScopedAStatus(Status::OK, detailedError); } +::ndk::SpAIBinder WVCryptoPlugin::createBinder() { + auto binder = BnCryptoPlugin::createBinder(); + AIBinder_setRequestingSid(binder.get(), true); + return binder; +} + Status WVCryptoPlugin::attemptDecrypt(const CdmDecryptionParametersV16& params, bool hasProtectedData, std::string* errorDetailMsg) { diff --git a/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h b/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h index a66c1a52..f45a4939 100644 --- a/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h +++ b/libwvdrmengine/mediadrm/aidl_include/WVDrmPlugin.h @@ -406,6 +406,8 @@ struct WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin, std::string mAppPackageName; + ::ndk::SpAIBinder createBinder() override; + Status queryProperty(const std::string& property, std::string& stringValue) const; diff --git a/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp index 1a89edca..9afcc155 100644 --- a/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/aidl_src/WVDrmPlugin.cpp @@ -1851,6 +1851,12 @@ Status WVDrmPlugin::queryProperty(RequestedSecurityLevel securityLevel, return mapCdmResponseType(res); } +::ndk::SpAIBinder WVDrmPlugin::createBinder() { + auto binder = BnDrmPlugin::createBinder(); + AIBinder_setRequestingSid(binder.get(), true); + return binder; +} + Status WVDrmPlugin::queryProperty(const std::string& property, vector& vector_value) const { std::string string_value;