1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "fingerprint_auth_driver_hdi.h" 17 18 #include <memory> 19 #include <vector> 20 21 #include "hdf_base.h" 22 #include "refbase.h" 23 24 #include "iam_check.h" 25 #include "iam_logger.h" 26 #include "iam_ptr.h" 27 28 #include "fingerprint_auth_all_in_one_executor_hdi.h" 29 #include "fingerprint_auth_defines.h" 30 #include "fingerprint_auth_hdi.h" 31 #include "fingerprint_auth_interface_adapter.h" 32 33 #define LOG_TAG "FINGERPRINT_AUTH_SA" 34 35 namespace OHOS { 36 namespace UserIam { 37 namespace FingerprintAuth { 38 namespace UserAuth = OHOS::UserIam::UserAuth; 39 std::mutex FingerprintAuthDriverHdi::mutex_; 40 FingerprintAuthDriverHdi(const std::shared_ptr<FingerprintAuthInterfaceAdapter> fingerprintAuthInterfaceAdapter)41FingerprintAuthDriverHdi::FingerprintAuthDriverHdi( 42 const std::shared_ptr<FingerprintAuthInterfaceAdapter> fingerprintAuthInterfaceAdapter) 43 : fingerprintAuthInterfaceAdapter_(fingerprintAuthInterfaceAdapter) 44 { 45 } 46 GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> & executorList)47void FingerprintAuthDriverHdi::GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> &executorList) 48 { 49 IF_FALSE_LOGE_AND_RETURN(fingerprintAuthInterfaceAdapter_ != nullptr); 50 auto fingerprintIf = fingerprintAuthInterfaceAdapter_->Get(); 51 if (fingerprintIf == nullptr) { 52 IAM_LOGE("IFingerprintAuthInterface is null"); 53 return; 54 } 55 56 std::vector<sptr<IAllInOneExecutor>> iExecutorList; 57 auto ret = fingerprintIf->GetExecutorList(iExecutorList); 58 if (ret != HDF_SUCCESS) { 59 IAM_LOGE("GetExecutorList fail"); 60 return; 61 } 62 63 std::lock_guard<std::mutex> guard(mutex_); 64 fingerprintAuthExecutorList_.clear(); 65 for (const auto &iExecutor : iExecutorList) { 66 if (iExecutor == nullptr) { 67 IAM_LOGE("iExecutor is nullptr"); 68 continue; 69 } 70 auto executor = Common::MakeShared<FingerprintAllInOneExecutorHdi>(iExecutor); 71 if (executor == nullptr) { 72 IAM_LOGE("make share failed"); 73 continue; 74 } 75 executorList.push_back(executor); 76 fingerprintAuthExecutorList_.push_back(executor); 77 } 78 } 79 OnHdiDisconnect()80void FingerprintAuthDriverHdi::OnHdiDisconnect() 81 { 82 IAM_LOGI("start"); 83 std::lock_guard<std::mutex> guard(mutex_); 84 for (const auto &iExecutor : fingerprintAuthExecutorList_) { 85 if (iExecutor == nullptr) { 86 IAM_LOGE("iExecutor is nullptr"); 87 continue; 88 } 89 iExecutor->OnHdiDisconnect(); 90 } 91 fingerprintAuthExecutorList_.clear(); 92 return; 93 } 94 } // namespace FingerprintAuth 95 } // namespace UserIam 96 } // namespace OHOS 97