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_2 { 34 namespace clearkey { 35 36 using ::android::hardware::drm::V1_0::Status; 37 using ::android::hardware::drm::V1_1::SecurityLevel; 38 using ::android::hardware::Void; 39 40 Return<bool> DrmFactory::isCryptoSchemeSupported( 41 const hidl_array<uint8_t, 16>& uuid) { 42 return clearkeydrm::isClearKeyUUID(uuid.data()); 43 } 44 45 Return<bool> DrmFactory::isCryptoSchemeSupported_1_2(const hidl_array<uint8_t, 16>& uuid, 46 const hidl_string &mimeType, 47 SecurityLevel level) { 48 return isCryptoSchemeSupported(uuid) && isContentTypeSupported(mimeType) && 49 level == SecurityLevel::SW_SECURE_CRYPTO; 50 } 51 52 Return<bool> DrmFactory::isContentTypeSupported(const hidl_string &mimeType) { 53 // This should match the mimeTypes handed by InitDataParser. 54 return mimeType == kIsoBmffVideoMimeType || 55 mimeType == kIsoBmffAudioMimeType || 56 mimeType == kCencInitDataFormat || 57 mimeType == kWebmVideoMimeType || 58 mimeType == kWebmAudioMimeType || 59 mimeType == kWebmInitDataFormat; 60 } 61 62 Return<void> DrmFactory::createPlugin( 63 const hidl_array<uint8_t, 16>& uuid, 64 const hidl_string& appPackageName, 65 createPlugin_cb _hidl_cb) { 66 UNUSED(appPackageName); 67 68 DrmPlugin *plugin = NULL; 69 if (!isCryptoSchemeSupported(uuid.data())) { 70 ALOGE("Clear key Drm HAL: failed to create drm plugin, " \ 71 "invalid crypto scheme"); 72 _hidl_cb(Status::BAD_VALUE, plugin); 73 return Void(); 74 } 75 76 plugin = new DrmPlugin(SessionLibrary::get()); 77 _hidl_cb(Status::OK, plugin); 78 return Void(); 79 } 80 81 } // namespace clearkey 82 } // namespace V1_2 83 } // namespace drm 84 } // namespace hardware 85 } // namespace android 86