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 | |
| 18 | #include "DrmFactory.h" |
| 19 | #include "DrmPlugin.h" |
| 20 | #include "TypeConvert.h" |
| 21 | #include <utils/Log.h> |
| 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 | |
| 29 | DrmFactory::DrmFactory() : |
Jeff Tinker | d59d362 | 2016-12-16 01:34:52 -0800 | [diff] [blame] | 30 | loader("/vendor/lib/mediadrm", "createDrmFactory") { |
| 31 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 32 | |
Jeff Tinker | da002fe | 2017-01-19 14:41:11 -0800 | [diff] [blame] | 33 | // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow. |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 34 | Return<bool> DrmFactory::isCryptoSchemeSupported ( |
| 35 | const hidl_array<uint8_t, 16>& uuid) { |
| 36 | for (size_t i = 0; i < loader.factoryCount(); i++) { |
| 37 | if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { |
| 38 | return true; |
| 39 | } |
| 40 | } |
| 41 | return false; |
| 42 | } |
| 43 | |
Jeff Tinker | b3a1672 | 2016-12-30 19:03:17 -0800 | [diff] [blame] | 44 | Return<bool> DrmFactory::isContentTypeSupported ( |
| 45 | const hidl_string& mimeType) { |
| 46 | for (size_t i = 0; i < loader.factoryCount(); i++) { |
| 47 | if (loader.getFactory(i)->isContentTypeSupported(String8(mimeType.c_str()))) { |
| 48 | return true; |
| 49 | } |
| 50 | } |
| 51 | return false; |
| 52 | } |
| 53 | |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 54 | Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid, |
| 55 | createPlugin_cb _hidl_cb) { |
| 56 | |
| 57 | for (size_t i = 0; i < loader.factoryCount(); i++) { |
| 58 | if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { |
| 59 | android::DrmPlugin *legacyPlugin = NULL; |
| 60 | status_t status = loader.getFactory(i)->createDrmPlugin( |
| 61 | uuid.data(), &legacyPlugin); |
| 62 | DrmPlugin *newPlugin = NULL; |
| 63 | if (legacyPlugin == NULL) { |
| 64 | ALOGE("Drm legacy HAL: failed to create drm plugin"); |
| 65 | } else { |
| 66 | newPlugin = new DrmPlugin(legacyPlugin); |
| 67 | } |
| 68 | _hidl_cb(toStatus(status), newPlugin); |
| 69 | return Void(); |
| 70 | } |
| 71 | } |
| 72 | _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); |
| 73 | return Void(); |
| 74 | } |
| 75 | |
| 76 | IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) { |
| 77 | return new DrmFactory(); |
| 78 | } |
| 79 | |
| 80 | } // namespace implementation |
| 81 | } // namespace V1_0 |
| 82 | } // namespace drm |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 83 | } // namespace hardware |
| 84 | } // namespace android |