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_all_in_one_executor_hdi.h" 29 #include "face_auth_defines.h" 30 #include "face_auth_hdi.h" 31 #include "face_auth_interface_adapter.h" 32 33 #define LOG_TAG "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<IAllInOneExecutor>> iExecutorList; 56 auto ret = faceIf->GetExecutorList(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<FaceAuthAllInOneExecutorHdi>(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 OHOS::sptr<BufferProducerSequenceable> producerSequenceable(nullptr); 97 if (producer != nullptr) { 98 producerSequenceable = 99 sptr<BufferProducerSequenceable>(new (std::nothrow) BufferProducerSequenceable(producer)); 100 IF_FALSE_LOGE_AND_RETURN_VAL(producerSequenceable != nullptr, FACE_AUTH_ERROR); 101 } 102 103 IF_FALSE_LOGE_AND_RETURN_VAL(faceAuthInterfaceAdapter_ != nullptr, FACE_AUTH_ERROR); 104 auto faceIf = faceAuthInterfaceAdapter_->Get(); 105 if (faceIf == nullptr) { 106 IAM_LOGE("IFaceAuthInterface is null"); 107 return FACE_AUTH_ERROR; 108 } 109 110 auto ret = faceIf->SetBufferProducer(producerSequenceable); 111 if (ret != HDF_SUCCESS) { 112 IAM_LOGE("GetExecutorList fail"); 113 return FACE_AUTH_ERROR; 114 } 115 116 return FACE_AUTH_SUCCESS; 117 } 118 } // namespace FaceAuth 119 } // namespace UserIam 120 } // namespace OHOS 121