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