Loading drm/libmediadrm/DrmUtils.cpp +83 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,15 @@ //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #define LOG_TAG "DrmUtils" #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 <utils/String16.h> #include <binder/IInterface.h> #include <binder/IInterface.h> #include <binder/IServiceManager.h> #include <binder/IServiceManager.h> Loading @@ -29,6 +38,12 @@ #include <mediadrm/IDrm.h> #include <mediadrm/IDrm.h> #include <mediadrm/IMediaDrmService.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 android { namespace DrmUtils { namespace DrmUtils { Loading Loading @@ -67,6 +82,57 @@ sp<Iface> MakeObject(status_t *pstatus) { return new Hal(); 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 } // namespace bool UseDrmService() { bool UseDrmService() { Loading @@ -81,5 +147,22 @@ sp<ICrypto> MakeCrypto(status_t *pstatus) { return MakeObject<ICrypto, CryptoHal>(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 DrmUtils } // namespace android } // namespace android drm/libmediadrm/interface/mediadrm/DrmUtils.h +9 −0 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,13 @@ #ifndef ANDROID_DRMUTILS_H #ifndef ANDROID_DRMUTILS_H #define ANDROID_DRMUTILS_H #define ANDROID_DRMUTILS_H #include <android/hardware/drm/1.0/ICryptoFactory.h> #include <utils/Errors.h> // for status_t #include <utils/Errors.h> // for status_t #include <utils/StrongPointer.h> #include <utils/StrongPointer.h> #include <binder/Parcel.h> #include <binder/Parcel.h> #include <vector> using namespace ::android::hardware::drm; namespace android { namespace android { Loading Loading @@ -77,6 +81,11 @@ void WriteKeysChange( obj.writeInt32(hasNewUsableKey); obj.writeInt32(hasNewUsableKey); } } std::vector<sp<::V1_0::ICryptoFactory>> MakeCryptoFactories(const uint8_t uuid[16]); std::vector<sp<::V1_0::ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16], const void *initData, size_t initDataSize); } // namespace DrmUtils } // namespace DrmUtils } // namespace android } // namespace android Loading Loading
drm/libmediadrm/DrmUtils.cpp +83 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,15 @@ //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #define LOG_TAG "DrmUtils" #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 <utils/String16.h> #include <binder/IInterface.h> #include <binder/IInterface.h> #include <binder/IServiceManager.h> #include <binder/IServiceManager.h> Loading @@ -29,6 +38,12 @@ #include <mediadrm/IDrm.h> #include <mediadrm/IDrm.h> #include <mediadrm/IMediaDrmService.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 android { namespace DrmUtils { namespace DrmUtils { Loading Loading @@ -67,6 +82,57 @@ sp<Iface> MakeObject(status_t *pstatus) { return new Hal(); 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 } // namespace bool UseDrmService() { bool UseDrmService() { Loading @@ -81,5 +147,22 @@ sp<ICrypto> MakeCrypto(status_t *pstatus) { return MakeObject<ICrypto, CryptoHal>(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 DrmUtils } // namespace android } // namespace android
drm/libmediadrm/interface/mediadrm/DrmUtils.h +9 −0 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,13 @@ #ifndef ANDROID_DRMUTILS_H #ifndef ANDROID_DRMUTILS_H #define ANDROID_DRMUTILS_H #define ANDROID_DRMUTILS_H #include <android/hardware/drm/1.0/ICryptoFactory.h> #include <utils/Errors.h> // for status_t #include <utils/Errors.h> // for status_t #include <utils/StrongPointer.h> #include <utils/StrongPointer.h> #include <binder/Parcel.h> #include <binder/Parcel.h> #include <vector> using namespace ::android::hardware::drm; namespace android { namespace android { Loading Loading @@ -77,6 +81,11 @@ void WriteKeysChange( obj.writeInt32(hasNewUsableKey); obj.writeInt32(hasNewUsableKey); } } std::vector<sp<::V1_0::ICryptoFactory>> MakeCryptoFactories(const uint8_t uuid[16]); std::vector<sp<::V1_0::ICryptoPlugin>> MakeCryptoPlugins(const uint8_t uuid[16], const void *initData, size_t initDataSize); } // namespace DrmUtils } // namespace DrmUtils } // namespace android } // namespace android Loading