1 /* 2 * Copyright (c) 2022 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 "face_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 "face_auth_defines.h" 29 #include "face_auth_executor_hdi.h" 30 #include "face_auth_hdi.h" 31 #include "face_auth_interface_adapter.h" 32 33 #define LOG_LABEL UserIam::Common::LABEL_FACE_AUTH_SA 34 35 namespace OHOS { 36 namespace UserIam { 37 namespace FaceAuth { 38 namespace UserAuth = OHOS::UserIam::UserAuth; 39 std::mutex FaceAuthDriverHdi::mutex_; 40 FaceAuthDriverHdi(const std::shared_ptr<FaceAuthInterfaceAdapter> faceAuthInterfaceAdapter)41FaceAuthDriverHdi::FaceAuthDriverHdi(const std::shared_ptr<FaceAuthInterfaceAdapter> faceAuthInterfaceAdapter) 42 : faceAuthInterfaceAdapter_(faceAuthInterfaceAdapter) 43 { 44 } 45 GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> & executorList)46void FaceAuthDriverHdi::GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> &executorList) 47 { 48 IF_FALSE_LOGE_AND_RETURN(faceAuthInterfaceAdapter_ != nullptr); 49 auto faceIf = faceAuthInterfaceAdapter_->Get(); 50 if (faceIf == nullptr) { 51 IAM_LOGE("IFaceAuthInterface is null"); 52 return; 53 } 54 55 std::vector<sptr<IExecutor>> iExecutorList; 56 auto ret = faceIf->GetExecutorListV1_1(iExecutorList); 57 if (ret != HDF_SUCCESS) { 58 IAM_LOGE("GetExecutorList fail"); 59 return; 60 } 61 62 std::lock_guard<std::mutex> guard(mutex_); 63 faceAuthExecutorList_.clear(); 64 for (const auto &iExecutor : iExecutorList) { 65 if (iExecutor == nullptr) { 66 IAM_LOGE("iExecutor is nullptr"); 67 continue; 68 } 69 auto executor = Common::MakeShared<FaceAuthExecutorHdi>(iExecutor); 70 if (executor == nullptr) { 71 IAM_LOGE("make share failed"); 72 continue; 73 } 74 executorList.push_back(executor); 75 faceAuthExecutorList_.push_back(executor); 76 } 77 } 78 OnHdiDisconnect()79void FaceAuthDriverHdi::OnHdiDisconnect() 80 { 81 IAM_LOGI("start"); 82 std::lock_guard<std::mutex> guard(mutex_); 83 for (const auto &iExecutor : faceAuthExecutorList_) { 84 if (iExecutor == nullptr) { 85 IAM_LOGE("iExecutor is nullptr"); 86 continue; 87 } 88 iExecutor->OnHdiDisconnect(); 89 } 90 faceAuthExecutorList_.clear(); 91 return; 92 } 93 SetBufferProducer(sptr<IBufferProducer> & producer)94int32_t FaceAuthDriverHdi::SetBufferProducer(sptr<IBufferProducer> &producer) 95 { 96 if (faceAuthExecutorList_.size() == 0) { 97 IAM_LOGE("no executor to set buffer producer"); 98 return FACE_AUTH_ERROR; 99 } 100 101 std::lock_guard<std::mutex> guard(mutex_); 102 for (auto executor : faceAuthExecutorList_) { 103 IF_FALSE_LOGE_AND_RETURN_VAL(executor != nullptr, FACE_AUTH_ERROR); 104 int32_t ret = executor->SetBufferProducer(producer); 105 if (ret != FACE_AUTH_SUCCESS) { 106 IAM_LOGE("executor SetBufferProducer fail %{public}d", ret); 107 return FACE_AUTH_ERROR; 108 } 109 } 110 return FACE_AUTH_SUCCESS; 111 } 112 } // namespace FaceAuth 113 } // namespace UserIam 114 } // namespace OHOS 115