blob: 7e5d998e4f483d371849868d374e73a0bd0b5ec3 [file] [log] [blame]
Jeff Tinkerb075caa2016-12-06 23:15:20 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
John W. Brucefcde9ff2017-03-23 22:40:17 -07003` *
Jeff Tinkerb075caa2016-12-06 23:15:20 -08004 * 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 "DrmFactory.h"
Steven Moreland4e7a3072017-04-06 12:15:23 -070019#include <log/log.h>
Jeff Tinkerb075caa2016-12-06 23:15:20 -080020#include "DrmPlugin.h"
John W. Brucefcde9ff2017-03-23 22:40:17 -070021#include "LegacyPluginPath.h"
Jeff Tinkerb075caa2016-12-06 23:15:20 -080022#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 Tinker9a33bb22017-02-14 21:04:31 +000030 DrmFactory::DrmFactory() :
John W. Brucefcde9ff2017-03-23 22:40:17 -070031 loader(getDrmPluginPath(), "createDrmFactory") {
Jeff Tinker9a33bb22017-02-14 21:04:31 +000032 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080033
Jeff Tinker9a33bb22017-02-14 21:04:31 +000034 // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
35 Return<bool> DrmFactory::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 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080044
Jeff Tinker9a33bb22017-02-14 21:04:31 +000045 Return<bool> DrmFactory::isContentTypeSupported (
46 const hidl_string& mimeType) {
47 for (size_t i = 0; i < loader.factoryCount(); i++) {
48 if (loader.getFactory(i)->isContentTypeSupported(String8(mimeType.c_str()))) {
49 return true;
50 }
51 }
52 return false;
53 }
Jeff Tinkerfbf36502017-01-24 06:58:26 -080054
Jeff Tinker45548ea2017-01-25 11:46:52 -080055 Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
Steven Moreland542f4342017-03-08 08:16:47 -080056 const hidl_string& /* appPackageName */, createPlugin_cb _hidl_cb) {
Jeff Tinkerb075caa2016-12-06 23:15:20 -080057
Jeff Tinker9a33bb22017-02-14 21:04:31 +000058 for (size_t i = 0; i < loader.factoryCount(); i++) {
59 if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
60 android::DrmPlugin *legacyPlugin = NULL;
61 status_t status = loader.getFactory(i)->createDrmPlugin(
62 uuid.data(), &legacyPlugin);
63 DrmPlugin *newPlugin = NULL;
64 if (legacyPlugin == NULL) {
65 ALOGE("Drm legacy HAL: failed to create drm plugin");
66 } else {
67 newPlugin = new DrmPlugin(legacyPlugin);
Jeff Tinkerb075caa2016-12-06 23:15:20 -080068 }
Jeff Tinker9a33bb22017-02-14 21:04:31 +000069 _hidl_cb(toStatus(status), newPlugin);
70 return Void();
71 }
Jeff Tinkerb075caa2016-12-06 23:15:20 -080072 }
Jeff Tinker9a33bb22017-02-14 21:04:31 +000073 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
74 return Void();
Jeff Tinkerb075caa2016-12-06 23:15:20 -080075 }
76
Jeff Tinker9a33bb22017-02-14 21:04:31 +000077 IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
78 return new DrmFactory();
Jeff Tinkerb075caa2016-12-06 23:15:20 -080079 }
80
81} // namespace implementation
82} // namespace V1_0
83} // namespace drm
Jeff Tinkerb075caa2016-12-06 23:15:20 -080084} // namespace hardware
85} // namespace android