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