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 #define LOG_TAG "[email protected]" 17 18 #include "CryptoFactory.h" 19 #include <log/log.h> 20 #include "CryptoPlugin.h" 21 #include "LegacyPluginPath.h" 22 #include "TypeConvert.h" 23 24 namespace android { 25 namespace hardware { 26 namespace drm { 27 namespace V1_0 { 28 namespace implementation { 29 CryptoFactory()30 CryptoFactory::CryptoFactory() : 31 loader(getDrmPluginPath(), "createCryptoFactory") { 32 } 33 34 // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow. isCryptoSchemeSupported(const hidl_array<uint8_t,16> & uuid)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 createPlugin(const hidl_array<uint8_t,16> & uuid,const hidl_vec<uint8_t> & initData,createPlugin_cb _hidl_cb)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); 57 } 58 _hidl_cb(toStatus(status), newPlugin); 59 return Void(); 60 } 61 } 62 _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL); 63 return Void(); 64 } 65 HIDL_FETCH_ICryptoFactory(const char *)66 ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) { 67 return new CryptoFactory(); 68 } 69 70 } // namespace implementation 71 } // namespace V1_0 72 } // namespace drm 73 } // namespace hardware 74 } // namespace android 75