Add aidl interface support for Drm Framework
This change intends to make DrmHal/CryptoHal layer support aidl
interface implemented plugins.
Test: CtsMediaDrmTestCases, GtsMediaTestCases
Bug: 200055138
Bug: 170964303
Change-Id: I7056adf184acf1463cb4fc85e1c95ac88c2097f6
diff --git a/drm/libmediadrm/DrmUtils.cpp b/drm/libmediadrm/DrmUtils.cpp
index 0b117a3..bca292d 100644
--- a/drm/libmediadrm/DrmUtils.cpp
+++ b/drm/libmediadrm/DrmUtils.cpp
@@ -32,10 +32,10 @@
#include <android/hidl/manager/1.2/IServiceManager.h>
#include <hidl/HidlSupport.h>
+#include <cutils/properties.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/String16.h>
-#include <cutils/properties.h>
#include <mediadrm/CryptoHal.h>
#include <mediadrm/DrmHal.h>
@@ -57,10 +57,10 @@
namespace {
-template<typename Hal>
-Hal *MakeObject(status_t *pstatus) {
+template <typename Hal>
+Hal* MakeObject(status_t* pstatus) {
status_t err = OK;
- status_t &status = pstatus ? *pstatus : err;
+ status_t& status = pstatus ? *pstatus : err;
auto obj = new Hal();
status = obj->initCheck();
if (status != OK && status != NO_INIT) {
@@ -70,43 +70,44 @@
}
template <typename Hal, typename V, typename M>
-void MakeHidlFactories(const uint8_t uuid[16], V &factories, M& instances) {
+void MakeHidlFactories(const uint8_t uuid[16], V& factories, M& instances) {
sp<HServiceManager> serviceManager = HServiceManager::getService();
if (serviceManager == nullptr) {
LOG2BE("Failed to get service manager");
return;
}
- serviceManager->listManifestByInterface(Hal::descriptor, [&](const hidl_vec<hidl_string> ®istered) {
- for (const auto &instance : registered) {
- auto factory = Hal::getService(instance);
- if (factory != nullptr) {
- instances[instance.c_str()] = Hal::descriptor;
- if (!uuid) {
- factories.push_back(factory);
- continue;
+ serviceManager->listManifestByInterface(
+ Hal::descriptor, [&](const hidl_vec<hidl_string>& registered) {
+ for (const auto& instance : registered) {
+ auto factory = Hal::getService(instance);
+ if (factory != nullptr) {
+ instances[instance.c_str()] = Hal::descriptor;
+ if (!uuid) {
+ factories.push_back(factory);
+ continue;
+ }
+ auto supported = factory->isCryptoSchemeSupported(uuid);
+ if (!supported.isOk()) {
+ LOG2BE(uuid, "isCryptoSchemeSupported txn failed: %s",
+ supported.description().c_str());
+ continue;
+ }
+ if (supported) {
+ factories.push_back(factory);
+ }
+ }
}
- auto supported = factory->isCryptoSchemeSupported(uuid);
- if (!supported.isOk()) {
- LOG2BE(uuid, "isCryptoSchemeSupported txn failed: %s",
- supported.description().c_str());
- continue;
- }
- if (supported) {
- factories.push_back(factory);
- }
- }
- }
- });
+ });
}
template <typename Hal, typename V>
-void MakeHidlFactories(const uint8_t uuid[16], V &factories) {
+void MakeHidlFactories(const uint8_t uuid[16], V& factories) {
std::map<std::string, std::string> instances;
MakeHidlFactories<Hal>(uuid, factories, instances);
}
-hidl_vec<uint8_t> toHidlVec(const void *ptr, size_t size) {
+hidl_vec<uint8_t> toHidlVec(const void* ptr, size_t size) {
hidl_vec<uint8_t> vec(size);
if (ptr != nullptr) {
memcpy(vec.data(), ptr, size);
@@ -114,19 +115,19 @@
return vec;
}
-hidl_array<uint8_t, 16> toHidlArray16(const uint8_t *ptr) {
+hidl_array<uint8_t, 16> toHidlArray16(const uint8_t* ptr) {
if (ptr == nullptr) {
return hidl_array<uint8_t, 16>();
}
return hidl_array<uint8_t, 16>(ptr);
}
-sp<::V1_0::IDrmPlugin> MakeDrmPlugin(const sp<::V1_0::IDrmFactory> &factory,
- const uint8_t uuid[16], const char *appPackageName) {
+sp<::V1_0::IDrmPlugin> MakeDrmPlugin(const sp<::V1_0::IDrmFactory>& factory, const uint8_t uuid[16],
+ const char* appPackageName) {
sp<::V1_0::IDrmPlugin> plugin;
auto err = factory->createPlugin(
toHidlArray16(uuid), hidl_string(appPackageName),
- [&](::V1_0::Status status, const sp<::V1_0::IDrmPlugin> &hPlugin) {
+ [&](::V1_0::Status status, const sp<::V1_0::IDrmPlugin>& hPlugin) {
if (status != ::V1_0::Status::OK) {
LOG2BE(uuid, "MakeDrmPlugin failed: %d", status);
return;
@@ -141,13 +142,13 @@
}
}
-sp<::V1_0::ICryptoPlugin> MakeCryptoPlugin(const sp<::V1_0::ICryptoFactory> &factory,
- const uint8_t uuid[16], const void *initData,
+sp<::V1_0::ICryptoPlugin> MakeCryptoPlugin(const sp<::V1_0::ICryptoFactory>& factory,
+ const uint8_t uuid[16], const void* initData,
size_t initDataSize) {
sp<::V1_0::ICryptoPlugin> plugin;
auto err = factory->createPlugin(
toHidlArray16(uuid), toHidlVec(initData, initDataSize),
- [&](::V1_0::Status status, const sp<::V1_0::ICryptoPlugin> &hPlugin) {
+ [&](::V1_0::Status status, const sp<::V1_0::ICryptoPlugin>& hPlugin) {
if (status != ::V1_0::Status::OK) {
LOG2BE(uuid, "MakeCryptoPlugin failed: %d", status);
return;
@@ -162,17 +163,17 @@
}
}
-} // namespace
+} // namespace
bool UseDrmService() {
return property_get_bool("mediadrm.use_mediadrmserver", true);
}
-sp<IDrm> MakeDrm(status_t *pstatus) {
+sp<IDrm> MakeDrm(status_t* pstatus) {
return MakeObject<DrmHal>(pstatus);
}
-sp<ICrypto> MakeCrypto(status_t *pstatus) {
+sp<ICrypto> MakeCrypto(status_t* pstatus) {
return MakeObject<CryptoHal>(pstatus);
}
@@ -191,9 +192,9 @@
}
std::vector<sp<::V1_0::IDrmPlugin>> MakeDrmPlugins(const uint8_t uuid[16],
- const char *appPackageName) {
+ const char* appPackageName) {
std::vector<sp<::V1_0::IDrmPlugin>> plugins;
- for (const auto &factory : MakeDrmFactories(uuid)) {
+ for (const auto& factory : MakeDrmFactories(uuid)) {
plugins.push_back(MakeDrmPlugin(factory, uuid, appPackageName));
}
return plugins;
@@ -209,10 +210,11 @@
return cryptoFactories;
}
-std::vector<sp<ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16], const void *initData,
- size_t initDataSize) {
- std::vector<sp<ICryptoPlugin>> plugins;
- for (const auto &factory : MakeCryptoFactories(uuid)) {
+std::vector<sp<::V1_0::ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16],
+ const void* initData,
+ size_t initDataSize) {
+ std::vector<sp<::V1_0::ICryptoPlugin>> plugins;
+ for (const auto& factory : MakeCryptoFactories(uuid)) {
plugins.push_back(MakeCryptoPlugin(factory, uuid, initData, initDataSize));
}
return plugins;
@@ -220,90 +222,90 @@
status_t toStatusT_1_4(::V1_4::Status status) {
switch (status) {
- case ::V1_4::Status::OK:
- return OK;
- case ::V1_4::Status::BAD_VALUE:
- return BAD_VALUE;
- case ::V1_4::Status::ERROR_DRM_CANNOT_HANDLE:
- return ERROR_DRM_CANNOT_HANDLE;
- case ::V1_4::Status::ERROR_DRM_DECRYPT:
- return ERROR_DRM_DECRYPT;
- case ::V1_4::Status::ERROR_DRM_DEVICE_REVOKED:
- return ERROR_DRM_DEVICE_REVOKED;
- case ::V1_4::Status::ERROR_DRM_FRAME_TOO_LARGE:
- return ERROR_DRM_FRAME_TOO_LARGE;
- case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
- return ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION;
- case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_SECURITY:
- return ERROR_DRM_INSUFFICIENT_SECURITY;
- case ::V1_4::Status::ERROR_DRM_INVALID_STATE:
- return ERROR_DRM_INVALID_STATE;
- case ::V1_4::Status::ERROR_DRM_LICENSE_EXPIRED:
- return ERROR_DRM_LICENSE_EXPIRED;
- case ::V1_4::Status::ERROR_DRM_NO_LICENSE:
- return ERROR_DRM_NO_LICENSE;
- case ::V1_4::Status::ERROR_DRM_NOT_PROVISIONED:
- return ERROR_DRM_NOT_PROVISIONED;
- case ::V1_4::Status::ERROR_DRM_RESOURCE_BUSY:
- return ERROR_DRM_RESOURCE_BUSY;
- case ::V1_4::Status::ERROR_DRM_RESOURCE_CONTENTION:
- return ERROR_DRM_RESOURCE_CONTENTION;
- case ::V1_4::Status::ERROR_DRM_SESSION_LOST_STATE:
- return ERROR_DRM_SESSION_LOST_STATE;
- case ::V1_4::Status::ERROR_DRM_SESSION_NOT_OPENED:
- return ERROR_DRM_SESSION_NOT_OPENED;
+ case ::V1_4::Status::OK:
+ return OK;
+ case ::V1_4::Status::BAD_VALUE:
+ return BAD_VALUE;
+ case ::V1_4::Status::ERROR_DRM_CANNOT_HANDLE:
+ return ERROR_DRM_CANNOT_HANDLE;
+ case ::V1_4::Status::ERROR_DRM_DECRYPT:
+ return ERROR_DRM_DECRYPT;
+ case ::V1_4::Status::ERROR_DRM_DEVICE_REVOKED:
+ return ERROR_DRM_DEVICE_REVOKED;
+ case ::V1_4::Status::ERROR_DRM_FRAME_TOO_LARGE:
+ return ERROR_DRM_FRAME_TOO_LARGE;
+ case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
+ return ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION;
+ case ::V1_4::Status::ERROR_DRM_INSUFFICIENT_SECURITY:
+ return ERROR_DRM_INSUFFICIENT_SECURITY;
+ case ::V1_4::Status::ERROR_DRM_INVALID_STATE:
+ return ERROR_DRM_INVALID_STATE;
+ case ::V1_4::Status::ERROR_DRM_LICENSE_EXPIRED:
+ return ERROR_DRM_LICENSE_EXPIRED;
+ case ::V1_4::Status::ERROR_DRM_NO_LICENSE:
+ return ERROR_DRM_NO_LICENSE;
+ case ::V1_4::Status::ERROR_DRM_NOT_PROVISIONED:
+ return ERROR_DRM_NOT_PROVISIONED;
+ case ::V1_4::Status::ERROR_DRM_RESOURCE_BUSY:
+ return ERROR_DRM_RESOURCE_BUSY;
+ case ::V1_4::Status::ERROR_DRM_RESOURCE_CONTENTION:
+ return ERROR_DRM_RESOURCE_CONTENTION;
+ case ::V1_4::Status::ERROR_DRM_SESSION_LOST_STATE:
+ return ERROR_DRM_SESSION_LOST_STATE;
+ case ::V1_4::Status::ERROR_DRM_SESSION_NOT_OPENED:
+ return ERROR_DRM_SESSION_NOT_OPENED;
- // New in S / drm@1.4:
- case ::V1_4::Status::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
- return ERROR_DRM_ZERO_SUBSAMPLES;
- case ::V1_4::Status::CRYPTO_LIBRARY_ERROR:
- return ERROR_DRM_CRYPTO_LIBRARY;
- case ::V1_4::Status::GENERAL_OEM_ERROR:
- return ERROR_DRM_GENERIC_OEM;
- case ::V1_4::Status::GENERAL_PLUGIN_ERROR:
- return ERROR_DRM_GENERIC_PLUGIN;
- case ::V1_4::Status::INIT_DATA_INVALID:
- return ERROR_DRM_INIT_DATA;
- case ::V1_4::Status::KEY_NOT_LOADED:
- return ERROR_DRM_KEY_NOT_LOADED;
- case ::V1_4::Status::LICENSE_PARSE_ERROR:
- return ERROR_DRM_LICENSE_PARSE;
- case ::V1_4::Status::LICENSE_POLICY_ERROR:
- return ERROR_DRM_LICENSE_POLICY;
- case ::V1_4::Status::LICENSE_RELEASE_ERROR:
- return ERROR_DRM_LICENSE_RELEASE;
- case ::V1_4::Status::LICENSE_REQUEST_REJECTED:
- return ERROR_DRM_LICENSE_REQUEST_REJECTED;
- case ::V1_4::Status::LICENSE_RESTORE_ERROR:
- return ERROR_DRM_LICENSE_RESTORE;
- case ::V1_4::Status::LICENSE_STATE_ERROR:
- return ERROR_DRM_LICENSE_STATE;
- case ::V1_4::Status::MALFORMED_CERTIFICATE:
- return ERROR_DRM_CERTIFICATE_MALFORMED;
- case ::V1_4::Status::MEDIA_FRAMEWORK_ERROR:
- return ERROR_DRM_MEDIA_FRAMEWORK;
- case ::V1_4::Status::MISSING_CERTIFICATE:
- return ERROR_DRM_CERTIFICATE_MISSING;
- case ::V1_4::Status::PROVISIONING_CERTIFICATE_ERROR:
- return ERROR_DRM_PROVISIONING_CERTIFICATE;
- case ::V1_4::Status::PROVISIONING_CONFIGURATION_ERROR:
- return ERROR_DRM_PROVISIONING_CONFIG;
- case ::V1_4::Status::PROVISIONING_PARSE_ERROR:
- return ERROR_DRM_PROVISIONING_PARSE;
- case ::V1_4::Status::PROVISIONING_REQUEST_REJECTED:
- return ERROR_DRM_PROVISIONING_REQUEST_REJECTED;
- case ::V1_4::Status::RETRYABLE_PROVISIONING_ERROR:
- return ERROR_DRM_PROVISIONING_RETRY;
- case ::V1_4::Status::SECURE_STOP_RELEASE_ERROR:
- return ERROR_DRM_SECURE_STOP_RELEASE;
- case ::V1_4::Status::STORAGE_READ_FAILURE:
- return ERROR_DRM_STORAGE_READ;
- case ::V1_4::Status::STORAGE_WRITE_FAILURE:
- return ERROR_DRM_STORAGE_WRITE;
+ // New in S / drm@1.4:
+ case ::V1_4::Status::CANNOT_DECRYPT_ZERO_SUBSAMPLES:
+ return ERROR_DRM_ZERO_SUBSAMPLES;
+ case ::V1_4::Status::CRYPTO_LIBRARY_ERROR:
+ return ERROR_DRM_CRYPTO_LIBRARY;
+ case ::V1_4::Status::GENERAL_OEM_ERROR:
+ return ERROR_DRM_GENERIC_OEM;
+ case ::V1_4::Status::GENERAL_PLUGIN_ERROR:
+ return ERROR_DRM_GENERIC_PLUGIN;
+ case ::V1_4::Status::INIT_DATA_INVALID:
+ return ERROR_DRM_INIT_DATA;
+ case ::V1_4::Status::KEY_NOT_LOADED:
+ return ERROR_DRM_KEY_NOT_LOADED;
+ case ::V1_4::Status::LICENSE_PARSE_ERROR:
+ return ERROR_DRM_LICENSE_PARSE;
+ case ::V1_4::Status::LICENSE_POLICY_ERROR:
+ return ERROR_DRM_LICENSE_POLICY;
+ case ::V1_4::Status::LICENSE_RELEASE_ERROR:
+ return ERROR_DRM_LICENSE_RELEASE;
+ case ::V1_4::Status::LICENSE_REQUEST_REJECTED:
+ return ERROR_DRM_LICENSE_REQUEST_REJECTED;
+ case ::V1_4::Status::LICENSE_RESTORE_ERROR:
+ return ERROR_DRM_LICENSE_RESTORE;
+ case ::V1_4::Status::LICENSE_STATE_ERROR:
+ return ERROR_DRM_LICENSE_STATE;
+ case ::V1_4::Status::MALFORMED_CERTIFICATE:
+ return ERROR_DRM_CERTIFICATE_MALFORMED;
+ case ::V1_4::Status::MEDIA_FRAMEWORK_ERROR:
+ return ERROR_DRM_MEDIA_FRAMEWORK;
+ case ::V1_4::Status::MISSING_CERTIFICATE:
+ return ERROR_DRM_CERTIFICATE_MISSING;
+ case ::V1_4::Status::PROVISIONING_CERTIFICATE_ERROR:
+ return ERROR_DRM_PROVISIONING_CERTIFICATE;
+ case ::V1_4::Status::PROVISIONING_CONFIGURATION_ERROR:
+ return ERROR_DRM_PROVISIONING_CONFIG;
+ case ::V1_4::Status::PROVISIONING_PARSE_ERROR:
+ return ERROR_DRM_PROVISIONING_PARSE;
+ case ::V1_4::Status::PROVISIONING_REQUEST_REJECTED:
+ return ERROR_DRM_PROVISIONING_REQUEST_REJECTED;
+ case ::V1_4::Status::RETRYABLE_PROVISIONING_ERROR:
+ return ERROR_DRM_PROVISIONING_RETRY;
+ case ::V1_4::Status::SECURE_STOP_RELEASE_ERROR:
+ return ERROR_DRM_SECURE_STOP_RELEASE;
+ case ::V1_4::Status::STORAGE_READ_FAILURE:
+ return ERROR_DRM_STORAGE_READ;
+ case ::V1_4::Status::STORAGE_WRITE_FAILURE:
+ return ERROR_DRM_STORAGE_WRITE;
- case ::V1_4::Status::ERROR_DRM_UNKNOWN:
- default:
- return ERROR_DRM_UNKNOWN;
+ case ::V1_4::Status::ERROR_DRM_UNKNOWN:
+ default:
+ return ERROR_DRM_UNKNOWN;
}
return ERROR_DRM_UNKNOWN;
}
@@ -312,20 +314,34 @@
char logPriorityToChar(::V1_4::LogPriority priority) {
char p = 'U';
switch (priority) {
- case ::V1_4::LogPriority::VERBOSE: p = 'V'; break;
- case ::V1_4::LogPriority::DEBUG: p = 'D'; break;
- case ::V1_4::LogPriority::INFO: p = 'I'; break;
- case ::V1_4::LogPriority::WARN: p = 'W'; break;
- case ::V1_4::LogPriority::ERROR: p = 'E'; break;
- case ::V1_4::LogPriority::FATAL: p = 'F'; break;
- default: p = 'U'; break;
+ case ::V1_4::LogPriority::VERBOSE:
+ p = 'V';
+ break;
+ case ::V1_4::LogPriority::DEBUG:
+ p = 'D';
+ break;
+ case ::V1_4::LogPriority::INFO:
+ p = 'I';
+ break;
+ case ::V1_4::LogPriority::WARN:
+ p = 'W';
+ break;
+ case ::V1_4::LogPriority::ERROR:
+ p = 'E';
+ break;
+ case ::V1_4::LogPriority::FATAL:
+ p = 'F';
+ break;
+ default:
+ p = 'U';
+ break;
}
return p;
}
} // namespace
-std::string GetExceptionMessage(status_t err, const char *msg,
- const Vector<::V1_4::LogMessage> &logs) {
+std::string GetExceptionMessage(status_t err, const char* msg,
+ const Vector<::V1_4::LogMessage>& logs) {
std::string ruler("==============================");
std::string header("Beginning of DRM Plugin Log");
std::string footer("End of DRM Plugin Log");
@@ -355,7 +371,7 @@
return msg8.c_str();
}
-void LogBuffer::addLog(const ::V1_4::LogMessage &log) {
+void LogBuffer::addLog(const ::V1_4::LogMessage& log) {
std::unique_lock<std::mutex> lock(mMutex);
mBuffer.push_back(log);
while (mBuffer.size() > MAX_CAPACITY) {