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_2 {
31 namespace clearkey {
32 
isCryptoSchemeSupported(const hidl_array<uint8_t,16> & uuid)33 Return<bool> CryptoFactory::isCryptoSchemeSupported(
34     const hidl_array<uint8_t, 16> &uuid)
35 {
36     return clearkeydrm::isClearKeyUUID(uuid.data());
37 }
38 
createPlugin(const hidl_array<uint8_t,16> & uuid,const hidl_vec<uint8_t> & initData,createPlugin_cb _hidl_cb)39 Return<void> CryptoFactory::createPlugin(
40     const hidl_array<uint8_t, 16> &uuid,
41     const hidl_vec<uint8_t> &initData,
42     createPlugin_cb _hidl_cb) {
43 
44     if (!isCryptoSchemeSupported(uuid.data())) {
45         ALOGE("Clearkey Drm HAL: failed to create clearkey plugin, " \
46                 "invalid crypto scheme");
47         _hidl_cb(Status::BAD_VALUE, nullptr);
48         return Void();
49     }
50 
51     CryptoPlugin *cryptoPlugin = new CryptoPlugin(initData);
52     Status status = cryptoPlugin->getInitStatus();
53     if (status == Status::OK) {
54         _hidl_cb(Status::OK, cryptoPlugin);
55     } else {
56         delete cryptoPlugin;
57         _hidl_cb(status, nullptr);
58     }
59     return Void();
60 }
61 
62 } // namespace clearkey
63 } // namespace V1_2
64 } // namespace drm
65 } // namespace hardware
66 } // namespace android
67 
68