blob: d7a7c6dcccc941fdc58aaca673649edd29970b6e [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
Jeff Tinkerfbf36502017-01-24 06:58:26 -080018#include <utils/Log.h>
19
Jeff Tinkerb075caa2016-12-06 23:15:20 -080020#include "DrmFactory.h"
21#include "DrmPlugin.h"
22#include "TypeConvert.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 Tinkerfbf36502017-01-24 06:58:26 -080030DrmFactory::DrmFactory() :
31 trebleLoader("/vendor/lib/hw", "createDrmFactory"),
32 legacyLoader("/vendor/lib/mediadrm", "createDrmFactory") {
33}
34
35// Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
36Return<bool> DrmFactory::isCryptoSchemeSupported(
37 const hidl_array<uint8_t, 16>& uuid) {
38 return isCryptoSchemeSupported(trebleLoader, uuid) ||
39 isCryptoSchemeSupported(legacyLoader, uuid);
40}
41
42Return<bool> DrmFactory::isContentTypeSupported (
43 const hidl_string& mimeType) {
44 return isContentTypeSupported<PluginLoader, hidl_string>(trebleLoader, mimeType) ||
45 isContentTypeSupported<LegacyLoader, String8>(legacyLoader, mimeType);
46}
47
48Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
49 createPlugin_cb _hidl_cb) {
50 sp<IDrmPlugin> plugin = createTreblePlugin(uuid);
51 if (plugin == nullptr) {
52 plugin = createLegacyPlugin(uuid);
Jeff Tinkerd59d3622016-12-16 01:34:52 -080053 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080054 _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin);
55 return Void();
56}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080057
Jeff Tinkerfbf36502017-01-24 06:58:26 -080058sp<IDrmPlugin> DrmFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid) {
59 sp<IDrmPlugin> plugin;
60 for (size_t i = 0; i < trebleLoader.factoryCount(); i++) {
61 Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid,
62 [&](Status status, const sp<IDrmPlugin>& hPlugin) {
63 if (status == Status::OK) {
64 plugin = hPlugin;
65 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080066 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080067 );
68 if (plugin != nullptr) {
69 return plugin;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080070 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080071 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080072 return nullptr;
73}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080074
Jeff Tinkerfbf36502017-01-24 06:58:26 -080075sp<IDrmPlugin> DrmFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid) {
76 android::DrmPlugin *legacyPlugin = nullptr;
77 for (size_t i = 0; i < legacyLoader.factoryCount(); i++) {
78 legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin);
79 if (legacyPlugin) {
80 return new DrmPlugin(legacyPlugin);
81 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080082 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080083 return nullptr;
84}
85
86IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
87 return new DrmFactory();
88}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080089
90} // namespace implementation
91} // namespace V1_0
92} // namespace drm
Jeff Tinkerb075caa2016-12-06 23:15:20 -080093} // namespace hardware
94} // namespace android