blob: c98c1daa0ac9e8ba8b390667d72c8aa0bbabd02f [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
Jeff Tinker45548ea2017-01-25 11:46:52 -080048 Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
49 const hidl_string& appPackageName, createPlugin_cb _hidl_cb) {
50 sp<IDrmPlugin> plugin = createTreblePlugin(uuid, appPackageName);
Jeff Tinkerfbf36502017-01-24 06:58:26 -080051 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 Tinker45548ea2017-01-25 11:46:52 -080058sp<IDrmPlugin> DrmFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid,
59 const hidl_string& appPackageName) {
Jeff Tinkerfbf36502017-01-24 06:58:26 -080060 sp<IDrmPlugin> plugin;
61 for (size_t i = 0; i < trebleLoader.factoryCount(); i++) {
62 Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid,
Jeff Tinker45548ea2017-01-25 11:46:52 -080063 appPackageName, [&](Status status, const sp<IDrmPlugin>& hPlugin) {
Jeff Tinkerfbf36502017-01-24 06:58:26 -080064 if (status == Status::OK) {
65 plugin = hPlugin;
66 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080067 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080068 );
69 if (plugin != nullptr) {
70 return plugin;
Jeff Tinkerb075caa2016-12-06 23:15:20 -080071 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080072 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080073 return nullptr;
74}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080075
Jeff Tinkerfbf36502017-01-24 06:58:26 -080076sp<IDrmPlugin> DrmFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid) {
77 android::DrmPlugin *legacyPlugin = nullptr;
78 for (size_t i = 0; i < legacyLoader.factoryCount(); i++) {
79 legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin);
80 if (legacyPlugin) {
81 return new DrmPlugin(legacyPlugin);
82 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080083 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080084 return nullptr;
85}
86
87IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
88 return new DrmFactory();
89}
Jeff Tinkerb075caa2016-12-06 23:15:20 -080090
91} // namespace implementation
92} // namespace V1_0
93} // namespace drm
Jeff Tinkerb075caa2016-12-06 23:15:20 -080094} // namespace hardware
95} // namespace android