2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #define LOG_TAG "android.hardware.drm@1.0-impl"
18 #include "DrmFactory.h"
20 #include "DrmPlugin.h"
21 #include "LegacyPluginPath.h"
22 #include "TypeConvert.h"
28 namespace implementation {
30 DrmFactory::DrmFactory() :
31 loader(getDrmPluginPath(), "createDrmFactory") {
34 // 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())) {
45 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()))) {
55 Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
56 const hidl_string& /* appPackageName */, createPlugin_cb _hidl_cb) {
58 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");
67 newPlugin = new DrmPlugin(legacyPlugin);
69 _hidl_cb(toStatus(status), newPlugin);
73 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
77 IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
78 return new DrmFactory();
81 } // namespace implementation
84 } // namespace hardware
85 } // namespace android