1 /*
2 * Copyright (C) 2018 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
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "hidl_ClearKeyDrmFactory"
19 #include <utils/Log.h>
20
21 #include <utils/Errors.h>
22
23 #include "DrmFactory.h"
24
25 #include "DrmPlugin.h"
26 #include "ClearKeyUUID.h"
27 #include "MimeType.h"
28 #include "SessionLibrary.h"
29
30 namespace android {
31 namespace hardware {
32 namespace drm {
33 namespace V1_1 {
34 namespace clearkey {
35
36 using ::android::hardware::drm::V1_0::Status;
37 using ::android::hardware::Void;
38
isCryptoSchemeSupported(const hidl_array<uint8_t,16> & uuid)39 Return<bool> DrmFactory::isCryptoSchemeSupported(
40 const hidl_array<uint8_t, 16>& uuid) {
41 return clearkeydrm::isClearKeyUUID(uuid.data());
42 }
43
isContentTypeSupported(const hidl_string & mimeType)44 Return<bool> DrmFactory::isContentTypeSupported(const hidl_string &mimeType) {
45 // This should match the mimeTypes handed by InitDataParser.
46 return mimeType == kIsoBmffVideoMimeType ||
47 mimeType == kIsoBmffAudioMimeType ||
48 mimeType == kCencInitDataFormat ||
49 mimeType == kWebmVideoMimeType ||
50 mimeType == kWebmAudioMimeType ||
51 mimeType == kWebmInitDataFormat;
52 }
53
createPlugin(const hidl_array<uint8_t,16> & uuid,const hidl_string & appPackageName,createPlugin_cb _hidl_cb)54 Return<void> DrmFactory::createPlugin(
55 const hidl_array<uint8_t, 16>& uuid,
56 const hidl_string& appPackageName,
57 createPlugin_cb _hidl_cb) {
58 UNUSED(appPackageName);
59
60 DrmPlugin *plugin = NULL;
61 if (!isCryptoSchemeSupported(uuid.data())) {
62 ALOGE("Clear key Drm HAL: failed to create drm plugin, " \
63 "invalid crypto scheme");
64 _hidl_cb(Status::BAD_VALUE, plugin);
65 return Void();
66 }
67
68 plugin = new DrmPlugin(SessionLibrary::get());
69 _hidl_cb(Status::OK, plugin);
70 return Void();
71 }
72
73 } // namespace clearkey
74 } // namespace V1_1
75 } // namespace drm
76 } // namespace hardware
77 } // namespace android
78