blob: 187d564b6705bb0f8978bae3abb9b4f28d533b15 [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 */
16
17#include "CryptoFactory.h"
18#include "CryptoPlugin.h"
19#include "TypeConvert.h"
20#include <utils/Log.h>
21
22namespace android {
23namespace hardware {
24namespace drm {
25namespace crypto {
26namespace V1_0 {
27namespace implementation {
28
29 CryptoFactory::CryptoFactory() :
Jeff Tinker65b7ef02016-12-28 18:53:33 -080030 loader("/vendor/lib/mediadrm", "createCryptoFactory") {}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080031
32 // Methods from ::android::hardware::drm::crypto::V1_0::ICryptoFactory follow.
33 Return<bool> CryptoFactory::isCryptoSchemeSupported(
34 const hidl_array<uint8_t, 16>& uuid) {
35 for (size_t i = 0; i < loader.factoryCount(); i++) {
36 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
37 return true;
38 }
39 }
40 return false;
41 }
42
43 Return<void> CryptoFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
44 const hidl_vec<uint8_t>& initData, createPlugin_cb _hidl_cb) {
45
46 for (size_t i = 0; i < loader.factoryCount(); i++) {
47 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
48 android::CryptoPlugin *legacyPlugin = NULL;
49 status_t status = loader.getFactory(i)->createPlugin(uuid.data(),
50 initData.data(), initData.size(), &legacyPlugin);
51 CryptoPlugin *newPlugin = NULL;
52 if (legacyPlugin == NULL) {
53 ALOGE("Crypto legacy HAL: failed to create crypto plugin");
54 } else {
55 newPlugin = new CryptoPlugin(legacyPlugin);
56 }
57 _hidl_cb(toStatus(status), newPlugin);
58 return Void();
59 }
60 }
61 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
62 return Void();
63 }
64
65 ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char /* *name */) {
66 return new CryptoFactory();
67 }
68
69} // namespace implementation
70} // namespace V1_0
71} // namespace crypto
72} // namespace drm
73} // namespace hardware
74} // namespace android