Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 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 | */ |
Jeff Tinker | 972a3e3 | 2017-01-23 14:02:50 -0800 | [diff] [blame] | 16 | #define LOG_TAG "android.hardware.drm@1.0-impl" |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 17 | |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 18 | #include <utils/Log.h> |
| 19 | |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 20 | #include "DrmFactory.h" |
| 21 | #include "DrmPlugin.h" |
| 22 | #include "TypeConvert.h" |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace drm { |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 27 | namespace V1_0 { |
| 28 | namespace implementation { |
| 29 | |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 30 | DrmFactory::DrmFactory() : |
| 31 | trebleLoader("/vendor/lib/hw", "createDrmFactory"), |
| 32 | legacyLoader("/vendor/lib/mediadrm", "createDrmFactory") { |
| 33 | } |
| 34 | |
| 35 | // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. |
| 36 | Return<bool> DrmFactory::isCryptoSchemeSupported( |
| 37 | const hidl_array<uint8_t, 16>& uuid) { |
| 38 | return isCryptoSchemeSupported(trebleLoader, uuid) || |
| 39 | isCryptoSchemeSupported(legacyLoader, uuid); |
| 40 | } |
| 41 | |
| 42 | Return<bool> DrmFactory::isContentTypeSupported ( |
| 43 | const hidl_string& mimeType) { |
| 44 | return isContentTypeSupported<PluginLoader, hidl_string>(trebleLoader, mimeType) || |
| 45 | isContentTypeSupported<LegacyLoader, String8>(legacyLoader, mimeType); |
| 46 | } |
| 47 | |
Jeff Tinker | 45548ea | 2017-01-25 11:46:52 -0800 | [diff] [blame^] | 48 | Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid, |
| 49 | const hidl_string& appPackageName, createPlugin_cb _hidl_cb) { |
| 50 | sp<IDrmPlugin> plugin = createTreblePlugin(uuid, appPackageName); |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 51 | if (plugin == nullptr) { |
| 52 | plugin = createLegacyPlugin(uuid); |
Jeff Tinker | d59d362 | 2016-12-16 01:34:52 -0800 | [diff] [blame] | 53 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 54 | _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin); |
| 55 | return Void(); |
| 56 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 57 | |
Jeff Tinker | 45548ea | 2017-01-25 11:46:52 -0800 | [diff] [blame^] | 58 | sp<IDrmPlugin> DrmFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid, |
| 59 | const hidl_string& appPackageName) { |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 60 | sp<IDrmPlugin> plugin; |
| 61 | for (size_t i = 0; i < trebleLoader.factoryCount(); i++) { |
| 62 | Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid, |
Jeff Tinker | 45548ea | 2017-01-25 11:46:52 -0800 | [diff] [blame^] | 63 | appPackageName, [&](Status status, const sp<IDrmPlugin>& hPlugin) { |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 64 | if (status == Status::OK) { |
| 65 | plugin = hPlugin; |
| 66 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 67 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 68 | ); |
| 69 | if (plugin != nullptr) { |
| 70 | return plugin; |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 71 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 72 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 73 | return nullptr; |
| 74 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 75 | |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 76 | sp<IDrmPlugin> DrmFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid) { |
| 77 | android::DrmPlugin *legacyPlugin = nullptr; |
| 78 | for (size_t i = 0; i < legacyLoader.factoryCount(); i++) { |
| 79 | legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin); |
| 80 | if (legacyPlugin) { |
| 81 | return new DrmPlugin(legacyPlugin); |
| 82 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 83 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 84 | return nullptr; |
| 85 | } |
| 86 | |
| 87 | IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) { |
| 88 | return new DrmFactory(); |
| 89 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 90 | |
| 91 | } // namespace implementation |
| 92 | } // namespace V1_0 |
| 93 | } // namespace drm |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 94 | } // namespace hardware |
| 95 | } // namespace android |