Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
Jeff Tinker | e3b6ae1 | 2017-05-16 18:21:39 +0000 | [diff] [blame] | 3 | ` * |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 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 | |
| 18 | #include "DrmFactory.h" |
Steven Moreland | 4e7a307 | 2017-04-06 12:15:23 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 20 | #include "DrmPlugin.h" |
John W. Bruce | fcde9ff | 2017-03-23 22:40:17 -0700 | [diff] [blame] | 21 | #include "LegacyPluginPath.h" |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 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 | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 30 | DrmFactory::DrmFactory() : |
John W. Bruce | fcde9ff | 2017-03-23 22:40:17 -0700 | [diff] [blame] | 31 | loader(getDrmPluginPath(), "createDrmFactory") { |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 32 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 33 | |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 34 | // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. |
| 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 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 44 | |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 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 | } |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [diff] [blame] | 54 | |
Jeff Tinker | 45548ea | 2017-01-25 11:46:52 -0800 | [diff] [blame] | 55 | Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid, |
Steven Moreland | 542f434 | 2017-03-08 08:16:47 -0800 | [diff] [blame] | 56 | const hidl_string& /* appPackageName */, createPlugin_cb _hidl_cb) { |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 57 | |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 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); |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 68 | } |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 69 | _hidl_cb(toStatus(status), newPlugin); |
| 70 | return Void(); |
| 71 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 72 | } |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 73 | _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); |
| 74 | return Void(); |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 77 | IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) { |
| 78 | return new DrmFactory(); |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } // namespace implementation |
| 82 | } // namespace V1_0 |
| 83 | } // namespace drm |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 84 | } // namespace hardware |
| 85 | } // namespace android |