• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "hidl_ClearKeyCryptoFactory"
19 #include <utils/Log.h>
20 
21 #include "CryptoFactory.h"
22 
23 #include "ClearKeyUUID.h"
24 #include "CryptoPlugin.h"
25 #include "TypeConvert.h"
26 
27 namespace android {
28 namespace hardware {
29 namespace drm {
30 namespace V1_4 {
31 namespace clearkey {
32 
33 using ::android::hardware::drm::V1_0::Status;
34 using ::android::hardware::drm::V1_4::clearkey::CryptoPlugin;
35 
isCryptoSchemeSupported(const hidl_array<uint8_t,16> & uuid)36 Return<bool> CryptoFactory::isCryptoSchemeSupported(
37     const hidl_array<uint8_t, 16> &uuid)
38 {
39     return clearkeydrm::isClearKeyUUID(uuid.data());
40 }
41 
createPlugin(const hidl_array<uint8_t,16> & uuid,const hidl_vec<uint8_t> & initData,createPlugin_cb _hidl_cb)42 Return<void> CryptoFactory::createPlugin(
43     const hidl_array<uint8_t, 16> &uuid,
44     const hidl_vec<uint8_t> &initData,
45     createPlugin_cb _hidl_cb) {
46 
47     if (!isCryptoSchemeSupported(uuid.data())) {
48         ALOGE("Clearkey Drm HAL: failed to create clearkey plugin, " \
49                 "invalid crypto scheme");
50         _hidl_cb(Status::BAD_VALUE, nullptr);
51         return Void();
52     }
53 
54     CryptoPlugin *cryptoPlugin = new CryptoPlugin(initData);
55     Status status = cryptoPlugin->getInitStatus();
56     if (status == Status::OK) {
57         _hidl_cb(Status::OK, cryptoPlugin);
58     } else {
59         delete cryptoPlugin;
60         _hidl_cb(status, nullptr);
61     }
62     return Void();
63 }
64 
65 } // namespace clearkey
66 } // namespace V1_4
67 } // namespace drm
68 } // namespace hardware
69 } // namespace android
70 
71