diff --git a/drm/1.0/default/CryptoFactory.cpp b/drm/1.0/default/CryptoFactory.cpp index e46233de2e..13cad67207 100644 --- a/drm/1.0/default/CryptoFactory.cpp +++ b/drm/1.0/default/CryptoFactory.cpp @@ -15,10 +15,11 @@ */ #define LOG_TAG "android.hardware.drm@1.0-impl" +#include + #include "CryptoFactory.h" #include "CryptoPlugin.h" #include "TypeConvert.h" -#include namespace android { namespace hardware { @@ -26,45 +27,63 @@ namespace drm { namespace V1_0 { namespace implementation { - CryptoFactory::CryptoFactory() : - loader("/vendor/lib/mediadrm", "createCryptoFactory") { - } +CryptoFactory::CryptoFactory() : + trebleLoader("/vendor/lib/hw", "createCryptoFactory"), + legacyLoader("/vendor/lib/mediadrm", "createCryptoFactory") { +} - // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow. - Return CryptoFactory::isCryptoSchemeSupported( - const hidl_array& uuid) { - for (size_t i = 0; i < loader.factoryCount(); i++) { - if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { - return true; - } - } - return false; - } +// Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow. +Return CryptoFactory::isCryptoSchemeSupported( + const hidl_array& uuid) { + return isCryptoSchemeSupported(trebleLoader, uuid) || + isCryptoSchemeSupported(legacyLoader, uuid); +} - Return CryptoFactory::createPlugin(const hidl_array& uuid, - const hidl_vec& initData, createPlugin_cb _hidl_cb) { - for (size_t i = 0; i < loader.factoryCount(); i++) { - if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { - android::CryptoPlugin *legacyPlugin = NULL; - status_t status = loader.getFactory(i)->createPlugin(uuid.data(), - initData.data(), initData.size(), &legacyPlugin); - CryptoPlugin *newPlugin = NULL; - if (legacyPlugin == NULL) { - ALOGE("Crypto legacy HAL: failed to create crypto plugin"); - } else { - newPlugin = new CryptoPlugin(legacyPlugin); +Return CryptoFactory::createPlugin(const hidl_array& uuid, + const hidl_vec& initData, createPlugin_cb _hidl_cb) { + sp plugin = createTreblePlugin(uuid, initData); + if (plugin == nullptr) { + plugin = createLegacyPlugin(uuid, initData); + } + _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin); + return Void(); +} + +sp CryptoFactory::createTreblePlugin(const hidl_array& uuid, + const hidl_vec& initData) { + sp plugin; + for (size_t i = 0; i < trebleLoader.factoryCount(); i++) { + Return hResult = trebleLoader.getFactory(i)->createPlugin(uuid, initData, + [&](Status status, const sp& hPlugin) { + if (status == Status::OK) { + plugin = hPlugin; + } } - _hidl_cb(toStatus(status), newPlugin); - return Void(); - } + ); + if (plugin != nullptr) { + return plugin; } - _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); - return Void(); } + return nullptr; +} - ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) { - return new CryptoFactory(); +sp CryptoFactory::createLegacyPlugin(const hidl_array& uuid, + const hidl_vec& initData) { + android::CryptoPlugin *legacyPlugin = nullptr; + for (size_t i = 0; i < legacyLoader.factoryCount(); i++) { + legacyLoader.getFactory(i)->createPlugin(uuid.data(), + initData.data(), initData.size(), &legacyPlugin); + if (legacyPlugin) { + return new CryptoPlugin(legacyPlugin); + } } + return nullptr; +} + + +ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) { + return new CryptoFactory(); +} } // namespace implementation } // namespace V1_0 diff --git a/drm/1.0/default/CryptoFactory.h b/drm/1.0/default/CryptoFactory.h index 412b5576c5..d774406efd 100644 --- a/drm/1.0/default/CryptoFactory.h +++ b/drm/1.0/default/CryptoFactory.h @@ -41,8 +41,7 @@ struct CryptoFactory : public ICryptoFactory { CryptoFactory(); virtual ~CryptoFactory() {} - // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow. - + // Methods from ::android::hardware::drmn::V1_0::ICryptoFactory follow. Return isCryptoSchemeSupported(const hidl_array& uuid) override; @@ -51,7 +50,27 @@ struct CryptoFactory : public ICryptoFactory { override; private: - android::PluginLoader loader; + template Return isCryptoSchemeSupported( + const L& loader, const hidl_array& uuid) { + for (size_t i = 0; i < loader.factoryCount(); i++) { + if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { + return true; + } + } + return false; + } + + sp createTreblePlugin(const hidl_array& uuid, + const hidl_vec& initData); + + sp createLegacyPlugin(const hidl_array& uuid, + const hidl_vec& initData); + + typedef android::PluginLoader PluginLoader; + PluginLoader trebleLoader; + + typedef android::PluginLoader LegacyLoader; + LegacyLoader legacyLoader; CryptoFactory(const CryptoFactory &) = delete; void operator=(const CryptoFactory &) = delete; diff --git a/drm/1.0/default/DrmFactory.cpp b/drm/1.0/default/DrmFactory.cpp index b6f642fd7c..d7a7c6dccc 100644 --- a/drm/1.0/default/DrmFactory.cpp +++ b/drm/1.0/default/DrmFactory.cpp @@ -15,10 +15,11 @@ */ #define LOG_TAG "android.hardware.drm@1.0-impl" +#include + #include "DrmFactory.h" #include "DrmPlugin.h" #include "TypeConvert.h" -#include namespace android { namespace hardware { @@ -26,56 +27,65 @@ namespace drm { namespace V1_0 { namespace implementation { - DrmFactory::DrmFactory() : - loader("/vendor/lib/mediadrm", "createDrmFactory") { +DrmFactory::DrmFactory() : + trebleLoader("/vendor/lib/hw", "createDrmFactory"), + legacyLoader("/vendor/lib/mediadrm", "createDrmFactory") { +} + +// Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. +Return DrmFactory::isCryptoSchemeSupported( + const hidl_array& uuid) { + return isCryptoSchemeSupported(trebleLoader, uuid) || + isCryptoSchemeSupported(legacyLoader, uuid); +} + +Return DrmFactory::isContentTypeSupported ( + const hidl_string& mimeType) { + return isContentTypeSupported(trebleLoader, mimeType) || + isContentTypeSupported(legacyLoader, mimeType); +} + +Return DrmFactory::createPlugin(const hidl_array& uuid, + createPlugin_cb _hidl_cb) { + sp plugin = createTreblePlugin(uuid); + if (plugin == nullptr) { + plugin = createLegacyPlugin(uuid); } + _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin); + return Void(); +} - // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. - Return DrmFactory::isCryptoSchemeSupported ( - const hidl_array& uuid) { - for (size_t i = 0; i < loader.factoryCount(); i++) { - if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { - return true; - } - } - return false; - } - - Return DrmFactory::isContentTypeSupported ( - const hidl_string& mimeType) { - for (size_t i = 0; i < loader.factoryCount(); i++) { - if (loader.getFactory(i)->isContentTypeSupported(String8(mimeType.c_str()))) { - return true; - } - } - return false; - } - - Return DrmFactory::createPlugin(const hidl_array& uuid, - createPlugin_cb _hidl_cb) { - - for (size_t i = 0; i < loader.factoryCount(); i++) { - if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { - android::DrmPlugin *legacyPlugin = NULL; - status_t status = loader.getFactory(i)->createDrmPlugin( - uuid.data(), &legacyPlugin); - DrmPlugin *newPlugin = NULL; - if (legacyPlugin == NULL) { - ALOGE("Drm legacy HAL: failed to create drm plugin"); - } else { - newPlugin = new DrmPlugin(legacyPlugin); +sp DrmFactory::createTreblePlugin(const hidl_array& uuid) { + sp plugin; + for (size_t i = 0; i < trebleLoader.factoryCount(); i++) { + Return hResult = trebleLoader.getFactory(i)->createPlugin(uuid, + [&](Status status, const sp& hPlugin) { + if (status == Status::OK) { + plugin = hPlugin; + } } - _hidl_cb(toStatus(status), newPlugin); - return Void(); - } + ); + if (plugin != nullptr) { + return plugin; } - _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); - return Void(); } + return nullptr; +} - IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) { - return new DrmFactory(); +sp DrmFactory::createLegacyPlugin(const hidl_array& uuid) { + android::DrmPlugin *legacyPlugin = nullptr; + for (size_t i = 0; i < legacyLoader.factoryCount(); i++) { + legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin); + if (legacyPlugin) { + return new DrmPlugin(legacyPlugin); + } } + return nullptr; +} + +IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) { + return new DrmFactory(); +} } // namespace implementation } // namespace V1_0 diff --git a/drm/1.0/default/DrmFactory.h b/drm/1.0/default/DrmFactory.h index 78b7f6e316..3291ea26ab 100644 --- a/drm/1.0/default/DrmFactory.h +++ b/drm/1.0/default/DrmFactory.h @@ -42,18 +42,43 @@ struct DrmFactory : public IDrmFactory { virtual ~DrmFactory() {} // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. - Return isCryptoSchemeSupported(const hidl_array& uuid) override; - Return isContentTypeSupported(const hidl_string &mimeType) + Return isContentTypeSupported(const hidl_string& mimeType) override; Return createPlugin(const hidl_array& uuid, - createPlugin_cb _hidl_cb) override; - + createPlugin_cb _hidl_cb) override; private: - android::PluginLoader loader; + template Return isCryptoSchemeSupported( + const L& loader, const hidl_array& uuid) { + for (size_t i = 0; i < loader.factoryCount(); i++) { + if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { + return true; + } + } + return false; + } + + template Return isContentTypeSupported( + const L& loader, const hidl_string& mimeType) { + for (size_t i = 0; i < loader.factoryCount(); i++) { + if (loader.getFactory(i)->isContentTypeSupported(S(mimeType))) { + return true; + } + } + return false; + } + + sp createTreblePlugin(const hidl_array& uuid); + sp createLegacyPlugin(const hidl_array& uuid); + + typedef android::PluginLoader PluginLoader; + PluginLoader trebleLoader; + + typedef android::PluginLoader LegacyLoader; + LegacyLoader legacyLoader; DrmFactory(const DrmFactory &) = delete; void operator=(const DrmFactory &) = delete;