• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_defines.h"
29 #include "fingerprint_auth_executor_hdi.h"
30 #include "fingerprint_auth_hdi.h"
31 #include "fingerprint_auth_interface_adapter.h"
32 
33 #define LOG_LABEL UserIam::Common::LABEL_FINGERPRINT_AUTH_SA
34 using namespace OHOS::HDI::FingerprintAuth::V1_0;
35 
36 namespace OHOS {
37 namespace UserIam {
38 namespace FingerprintAuth {
39 namespace UserAuth = OHOS::UserIam::UserAuth;
40 using namespace OHOS::UserIam;
41 
42 std::mutex FingerprintAuthDriverHdi::mutex_;
43 
FingerprintAuthDriverHdi(const std::shared_ptr<FingerprintAuthInterfaceAdapter> fingerprintAuthInterfaceAdapter)44 FingerprintAuthDriverHdi::FingerprintAuthDriverHdi(
45     const std::shared_ptr<FingerprintAuthInterfaceAdapter> fingerprintAuthInterfaceAdapter)
46     : fingerprintAuthInterfaceAdapter_(fingerprintAuthInterfaceAdapter)
47 {
48 }
49 
GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> & executorList)50 void FingerprintAuthDriverHdi::GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> &executorList)
51 {
52     IF_FALSE_LOGE_AND_RETURN(fingerprintAuthInterfaceAdapter_ != nullptr);
53     auto fingerprintIf = fingerprintAuthInterfaceAdapter_->Get();
54     if (fingerprintIf == nullptr) {
55         IAM_LOGE("IFingerprintAuthInterface is null");
56         return;
57     }
58 
59     std::vector<sptr<IExecutor>> iExecutorList;
60     auto ret = fingerprintIf->GetExecutorListV1_1(iExecutorList);
61     if (ret != HDF_SUCCESS) {
62         IAM_LOGE("GetExecutorList fail");
63         return;
64     }
65 
66     std::lock_guard<std::mutex> guard(mutex_);
67     fingerprintAuthExecutorList_.clear();
68     for (const auto &iExecutor : iExecutorList) {
69         if (iExecutor == nullptr) {
70             IAM_LOGE("iExecutor is nullptr");
71             continue;
72         }
73         auto executor = Common::MakeShared<FingerprintAuthExecutorHdi>(iExecutor);
74         if (executor == nullptr) {
75             IAM_LOGE("make share failed");
76             continue;
77         }
78         executorList.push_back(executor);
79         fingerprintAuthExecutorList_.push_back(executor);
80     }
81 }
82 
OnHdiDisconnect()83 void FingerprintAuthDriverHdi::OnHdiDisconnect()
84 {
85     IAM_LOGI("start");
86     std::lock_guard<std::mutex> guard(mutex_);
87     for (const auto &iExecutor : fingerprintAuthExecutorList_) {
88         if (iExecutor == nullptr) {
89             IAM_LOGE("iExecutor is nullptr");
90             continue;
91         }
92         iExecutor->OnHdiDisconnect();
93     }
94     fingerprintAuthExecutorList_.clear();
95     return;
96 }
97 } // namespace FingerprintAuth
98 } // namespace UserIam
99 } // namespace OHOS
100