• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #define LOG_TAG "android.hardware.drm@1.0-impl"
17 
18 #include "DrmFactory.h"
19 #include <log/log.h>
20 #include "DrmPlugin.h"
21 #include "LegacyPluginPath.h"
22 #include "TypeConvert.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace drm {
27 namespace V1_0 {
28 namespace implementation {
29 
DrmFactory()30     DrmFactory::DrmFactory() :
31         loader(getDrmPluginPath(), "createDrmFactory") {
32     }
33 
34     // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
isCryptoSchemeSupported(const hidl_array<uint8_t,16> & uuid)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     }
44 
isContentTypeSupported(const hidl_string & mimeType)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()))) {
49                 return true;
50             }
51         }
52         return false;
53     }
54 
createPlugin(const hidl_array<uint8_t,16> & uuid,const hidl_string &,createPlugin_cb _hidl_cb)55     Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
56             const hidl_string& /* appPackageName */, createPlugin_cb _hidl_cb) {
57 
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");
66                 } else {
67                     newPlugin = new DrmPlugin(legacyPlugin);
68                 }
69                 _hidl_cb(toStatus(status), newPlugin);
70                 return Void();
71             }
72         }
73         _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
74         return Void();
75     }
76 
HIDL_FETCH_IDrmFactory(const char *)77     IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
78         return new DrmFactory();
79     }
80 
81 }  // namespace implementation
82 }  // namespace V1_0
83 }  // namespace drm
84 }  // namespace hardware
85 }  // namespace android
86