1 #define LOG_TAG "castkey-DrmFactory"
2
3 #include <utils/Log.h>
4
5 #include "DrmFactory.h"
6
7 #include "DrmPlugin.h"
8 #include "Utils.h"
9
10 namespace aidl {
11 namespace android {
12 namespace hardware {
13 namespace drm {
14 namespace castkey {
15
16 namespace {
17
18 const std::array<uint8_t, 16> kCastKeyUUID{
19 0xBC, 0xB4, 0x81, 0xCB, 0xA1, 0xD5, 0x42, 0xAF,
20 0xB1, 0xE3, 0x7B, 0xFF, 0x14, 0x73, 0xEB, 0x85
21 };
22
isCastKeyUUID(const uint8_t uuid[16])23 bool isCastKeyUUID(const uint8_t uuid[16]) {
24 return !memcmp(uuid, kCastKeyUUID.data(), 16);
25 }
26
27 }
28
29 using std::string;
30 using std::vector;
31
32 using ::aidl::android::hardware::drm::Status;
33 using ::aidl::android::hardware::drm::Uuid;
34 using namespace castkeydrm;
35
createDrmPlugin(const Uuid & in_uuid,const string & in_appPackageName,std::shared_ptr<::aidl::android::hardware::drm::IDrmPlugin> * _aidl_return)36 ::ndk::ScopedAStatus DrmFactory::createDrmPlugin(
37 const Uuid& in_uuid, const string& in_appPackageName,
38 std::shared_ptr<::aidl::android::hardware::drm::IDrmPlugin>* _aidl_return) {
39 UNUSED(in_appPackageName);
40 if (!isCastKeyUUID(in_uuid.uuid.data())) {
41 ALOGE("Castkey Drm HAL: failed to create drm plugin, "
42 "invalid crypto scheme");
43 *_aidl_return = nullptr;
44 return toNdkScopedAStatus(Status::BAD_VALUE);
45 }
46 std::shared_ptr<DrmPlugin> plugin =
47 ::ndk::SharedRefBase::make<DrmPlugin>();
48 *_aidl_return = plugin;
49 return toNdkScopedAStatus(Status::OK);
50 }
51
createCryptoPlugin(const Uuid & in_uuid,const std::vector<uint8_t> & in_initData,std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin> * _aidl_return)52 ::ndk::ScopedAStatus DrmFactory::createCryptoPlugin(
53 const Uuid& in_uuid, const std::vector<uint8_t>& in_initData,
54 std::shared_ptr<::aidl::android::hardware::drm::ICryptoPlugin>* _aidl_return) {
55 UNUSED(in_uuid);
56 UNUSED(in_initData);
57 UNUSED(_aidl_return);
58 return toNdkScopedAStatus(Status::ERROR_DRM_CANNOT_HANDLE);
59 }
60
getSupportedCryptoSchemes(CryptoSchemes * _aidl_return)61 ::ndk::ScopedAStatus DrmFactory::getSupportedCryptoSchemes(CryptoSchemes* _aidl_return) {
62 CryptoSchemes schemes{};
63 schemes.uuids.push_back({kCastKeyUUID});
64 *_aidl_return = schemes;
65 return toNdkScopedAStatus(Status::OK);
66 }
67
dump(int fd,const char ** args,uint32_t numArgs)68 binder_status_t DrmFactory::dump(int fd, const char** args, uint32_t numArgs) {
69 UNUSED(args);
70 UNUSED(numArgs);
71 if (fd < 0) {
72 ALOGE("%s: negative fd", __FUNCTION__);
73 return STATUS_BAD_VALUE;
74 }
75 return STATUS_OK;
76 }
77
78 } // namespace castkey
79 } // namespace drm
80 } // namespace hardware
81 } // namespace android
82 } // namespace aidl
83