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 "CryptoFactory.h" |
| 19 | #include "CryptoPlugin.h" |
John W. Bruce | fcde9ff | 2017-03-23 22:40:17 -0700 | [diff] [blame^] | 20 | #include "LegacyPluginPath.h" |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 21 | #include "TypeConvert.h" |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 22 | #include <utils/Log.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 | CryptoFactory::CryptoFactory() : |
John W. Bruce | fcde9ff | 2017-03-23 22:40:17 -0700 | [diff] [blame^] | 31 | loader(getDrmPluginPath(), "createCryptoFactory") { |
Jeff Tinker | fbf3650 | 2017-01-24 06:58:26 -0800 | [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::ICryptoFactory follow. |
| 35 | Return<bool> CryptoFactory::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 | } |
| 44 | |
| 45 | Return<void> CryptoFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid, |
| 46 | const hidl_vec<uint8_t>& initData, createPlugin_cb _hidl_cb) { |
| 47 | for (size_t i = 0; i < loader.factoryCount(); i++) { |
| 48 | if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) { |
| 49 | android::CryptoPlugin *legacyPlugin = NULL; |
| 50 | status_t status = loader.getFactory(i)->createPlugin(uuid.data(), |
| 51 | initData.data(), initData.size(), &legacyPlugin); |
| 52 | CryptoPlugin *newPlugin = NULL; |
| 53 | if (legacyPlugin == NULL) { |
| 54 | ALOGE("Crypto legacy HAL: failed to create crypto plugin"); |
| 55 | } else { |
| 56 | newPlugin = new CryptoPlugin(legacyPlugin); |
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 | _hidl_cb(toStatus(status), newPlugin); |
| 59 | return Void(); |
| 60 | } |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 61 | } |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 62 | _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); |
| 63 | return Void(); |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Jeff Tinker | 9a33bb2 | 2017-02-14 21:04:31 +0000 | [diff] [blame] | 66 | ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) { |
| 67 | return new CryptoFactory(); |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace implementation |
| 71 | } // namespace V1_0 |
Jeff Tinker | b075caa | 2016-12-06 23:15:20 -0800 | [diff] [blame] | 72 | } // namespace drm |
| 73 | } // namespace hardware |
| 74 | } // namespace android |