|
|
|
@ -17,6 +17,15 @@
|
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
#define LOG_TAG "DrmUtils"
|
|
|
|
|
|
|
|
|
|
#include <android/hardware/drm/1.0/ICryptoFactory.h>
|
|
|
|
|
#include <android/hardware/drm/1.0/ICryptoPlugin.h>
|
|
|
|
|
#include <android/hardware/drm/1.1/ICryptoFactory.h>
|
|
|
|
|
#include <android/hardware/drm/1.2/ICryptoFactory.h>
|
|
|
|
|
#include <android/hidl/manager/1.0/IServiceManager.h>
|
|
|
|
|
#include <hidl/HidlSupport.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
|
#include <utils/Log.h>
|
|
|
|
|
#include <utils/String16.h>
|
|
|
|
|
#include <binder/IInterface.h>
|
|
|
|
|
#include <binder/IServiceManager.h>
|
|
|
|
@ -29,6 +38,12 @@
|
|
|
|
|
#include <mediadrm/IDrm.h>
|
|
|
|
|
#include <mediadrm/IMediaDrmService.h>
|
|
|
|
|
|
|
|
|
|
using HServiceManager = ::android::hidl::manager::V1_0::IServiceManager;
|
|
|
|
|
using ::android::hardware::hidl_array;
|
|
|
|
|
using ::android::hardware::hidl_string;
|
|
|
|
|
using ::android::hardware::hidl_vec;
|
|
|
|
|
using namespace ::android::hardware::drm;
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
namespace DrmUtils {
|
|
|
|
|
|
|
|
|
@ -67,6 +82,57 @@ sp<Iface> MakeObject(status_t *pstatus) {
|
|
|
|
|
return new Hal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Hal, typename V>
|
|
|
|
|
void MakeCryptoFactories(const uint8_t uuid[16], V &cryptoFactories) {
|
|
|
|
|
sp<HServiceManager> serviceManager = HServiceManager::getService();
|
|
|
|
|
if (serviceManager == nullptr) {
|
|
|
|
|
ALOGE("Failed to get service manager");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceManager->listByInterface(Hal::descriptor, [&](const hidl_vec<hidl_string> ®istered) {
|
|
|
|
|
for (const auto &instance : registered) {
|
|
|
|
|
auto factory = Hal::getService(instance);
|
|
|
|
|
if (factory != nullptr) {
|
|
|
|
|
ALOGI("found %s %s", Hal::descriptor, instance.c_str());
|
|
|
|
|
if (factory->isCryptoSchemeSupported(uuid)) {
|
|
|
|
|
cryptoFactories.push_back(factory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
return vec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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::ICryptoPlugin> MakeCryptoPlugin(const sp<::V1_0::ICryptoFactory> &factory,
|
|
|
|
|
const uint8_t uuid[16], const void *initData,
|
|
|
|
|
size_t initDataSize) {
|
|
|
|
|
sp<::V1_0::ICryptoPlugin> plugin;
|
|
|
|
|
factory->createPlugin(toHidlArray16(uuid), toHidlVec(initData, initDataSize),
|
|
|
|
|
[&](::V1_0::Status status, const sp<::V1_0::ICryptoPlugin> &hPlugin) {
|
|
|
|
|
if (status != ::V1_0::Status::OK) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
plugin = hPlugin;
|
|
|
|
|
});
|
|
|
|
|
return plugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
bool UseDrmService() {
|
|
|
|
@ -81,5 +147,22 @@ sp<ICrypto> MakeCrypto(status_t *pstatus) {
|
|
|
|
|
return MakeObject<ICrypto, CryptoHal>(pstatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<sp<::V1_0::ICryptoFactory>> MakeCryptoFactories(const uint8_t uuid[16]) {
|
|
|
|
|
std::vector<sp<::V1_0::ICryptoFactory>> cryptoFactories;
|
|
|
|
|
MakeCryptoFactories<::V1_0::ICryptoFactory>(uuid, cryptoFactories);
|
|
|
|
|
MakeCryptoFactories<::V1_1::ICryptoFactory>(uuid, cryptoFactories);
|
|
|
|
|
MakeCryptoFactories<::V1_2::ICryptoFactory>(uuid, cryptoFactories);
|
|
|
|
|
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)) {
|
|
|
|
|
plugins.push_back(MakeCryptoPlugin(factory, uuid, initData, initDataSize));
|
|
|
|
|
}
|
|
|
|
|
return plugins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace DrmUtils
|
|
|
|
|
} // namespace android
|
|
|
|
|