blob: a72c9cca46a54268c8cb9d37e30deeec1d6ab219 [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
Jeff Tinkerfbf36502017-01-24 06:58:26 -080017#include <utils/Log.h>
18
Jeff Tinkerb075caa2016-12-06 23:15:20 -080019#include "DrmFactory.h"
20#include "DrmPlugin.h"
21#include "TypeConvert.h"
Jeff Tinkerb075caa2016-12-06 23:15:20 -080022
23namespace android {
24namespace hardware {
25namespace drm {
Jeff Tinkerb075caa2016-12-06 23:15:20 -080026namespace V1_0 {
27namespace implementation {
28
Jeff Tinkerfbf36502017-01-24 06:58:26 -080029DrmFactory::DrmFactory() :
30 trebleLoader("/vendor/lib/hw", "createDrmFactory"),
31 legacyLoader("/vendor/lib/mediadrm", "createDrmFactory") {
32}
33
34// Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
35Return<bool> DrmFactory::isCryptoSchemeSupported(
36 const hidl_array<uint8_t, 16>& uuid) {
37 return isCryptoSchemeSupported(trebleLoader, uuid) ||
38 isCryptoSchemeSupported(legacyLoader, uuid);
39}
40
41Return<bool> DrmFactory::isContentTypeSupported (
42 const hidl_string& mimeType) {
43 return isContentTypeSupported<PluginLoader, hidl_string>(trebleLoader, mimeType) ||
44 isContentTypeSupported<LegacyLoader, String8>(legacyLoader, mimeType);
45}
46
47Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
48 createPlugin_cb _hidl_cb) {
49 sp<IDrmPlugin> plugin = createTreblePlugin(uuid);
50 if (plugin == nullptr) {
51 plugin = createLegacyPlugin(uuid);
Jeff Tinkerd59d3622016-12-16 01:34:52 -080052 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080053 _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin);
54 return Void();
55}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080056
Jeff Tinkerfbf36502017-01-24 06:58:26 -080057sp<IDrmPlugin> DrmFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid) {
58 sp<IDrmPlugin> plugin;
59 for (size_t i = 0; i < trebleLoader.factoryCount(); i++) {
60 Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid,
61 [&](Status status, const sp<IDrmPlugin>& hPlugin) {
62 if (status == Status::OK) {
63 plugin = hPlugin;
64 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080065 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080066 );
67 if (plugin != nullptr) {
68 return plugin;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080069 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080070 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080071 return nullptr;
72}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080073
Jeff Tinkerfbf36502017-01-24 06:58:26 -080074sp<IDrmPlugin> DrmFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid) {
75 android::DrmPlugin *legacyPlugin = nullptr;
76 for (size_t i = 0; i < legacyLoader.factoryCount(); i++) {
77 legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin);
78 if (legacyPlugin) {
79 return new DrmPlugin(legacyPlugin);
80 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080081 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080082 return nullptr;
83}
84
85IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
86 return new DrmFactory();
87}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080088
89} // namespace implementation
90} // namespace V1_0
91} // namespace drm
Jeff Tinkerb075caa2016-12-06 23:15:20 -080092} // namespace hardware
93} // namespace android