blob: 935786ddf6fd4b77e45587c5eac52606cbe2e32a [file] [log] [blame]
Jeff Tinkerb075caa2016-12-06 23:15:20 -08001/*
2 * Copyright (C) 2016 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 */
Jeff Tinker972a3e32017-01-23 14:02:50 -080016#define LOG_TAG "android.hardware.drm@1.0-impl"
Jeff Tinkerb075caa2016-12-06 23:15:20 -080017
18#include "CryptoFactory.h"
19#include "CryptoPlugin.h"
John W. Brucefcde9ff2017-03-23 22:40:17 -070020#include "LegacyPluginPath.h"
Jeff Tinkerb075caa2016-12-06 23:15:20 -080021#include "TypeConvert.h"
Jeff Tinker9a33bb22017-02-14 21:04:31 +000022#include <utils/Log.h>
Jeff Tinkerb075caa2016-12-06 23:15:20 -080023
24namespace android {
25namespace hardware {
26namespace drm {
Jeff Tinkerb075caa2016-12-06 23:15:20 -080027namespace V1_0 {
28namespace implementation {
29
Jeff Tinker9a33bb22017-02-14 21:04:31 +000030 CryptoFactory::CryptoFactory() :
John W. Brucefcde9ff2017-03-23 22:40:17 -070031 loader(getDrmPluginPath(), "createCryptoFactory") {
Jeff Tinkerfbf36502017-01-24 06:58:26 -080032 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080033
Jeff Tinker9a33bb22017-02-14 21:04:31 +000034 // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow.
35 Return<bool> CryptoFactory::isCryptoSchemeSupported(
36 const hidl_array<uint8_t, 16>& uuid) {
37 for (size_t i = 0; i < loader.factoryCount(); i++) {
38 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
39 return true;
40 }
41 }
42 return false;
43 }
44
45 Return<void> CryptoFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
46 const hidl_vec<uint8_t>& initData, createPlugin_cb _hidl_cb) {
47 for (size_t i = 0; i < loader.factoryCount(); i++) {
48 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
49 android::CryptoPlugin *legacyPlugin = NULL;
50 status_t status = loader.getFactory(i)->createPlugin(uuid.data(),
51 initData.data(), initData.size(), &legacyPlugin);
52 CryptoPlugin *newPlugin = NULL;
53 if (legacyPlugin == NULL) {
54 ALOGE("Crypto legacy HAL: failed to create crypto plugin");
55 } else {
56 newPlugin = new CryptoPlugin(legacyPlugin);
Jeff Tinkerb075caa2016-12-06 23:15:20 -080057 }
Jeff Tinker9a33bb22017-02-14 21:04:31 +000058 _hidl_cb(toStatus(status), newPlugin);
59 return Void();
60 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080061 }
Jeff Tinker9a33bb22017-02-14 21:04:31 +000062 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
63 return Void();
Jeff Tinkerb075caa2016-12-06 23:15:20 -080064 }
65
Jeff Tinker9a33bb22017-02-14 21:04:31 +000066 ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) {
67 return new CryptoFactory();
Jeff Tinkerb075caa2016-12-06 23:15:20 -080068 }
69
70} // namespace implementation
71} // namespace V1_0
Jeff Tinkerb075caa2016-12-06 23:15:20 -080072} // namespace drm
73} // namespace hardware
74} // namespace android