• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_executor_callback_hdi.h"
17 
18 #include <cstdint>
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "hdf_base.h"
26 
27 #include "iam_check.h"
28 #include "iam_executor_iexecute_callback.h"
29 #include "iam_logger.h"
30 
31 #include "face_auth_defines.h"
32 #include "sa_command_manager.h"
33 
34 #define LOG_LABEL UserIam::Common::LABEL_FACE_AUTH_SA
35 
36 namespace OHOS {
37 namespace UserIam {
38 namespace FaceAuth {
FaceAuthExecutorCallbackHdi(std::shared_ptr<UserAuth::IExecuteCallback> frameworkCallback)39 FaceAuthExecutorCallbackHdi::FaceAuthExecutorCallbackHdi(std::shared_ptr<UserAuth::IExecuteCallback> frameworkCallback)
40     : frameworkCallback_(frameworkCallback)
41 {
42 }
43 
OnResult(int32_t result,const std::vector<uint8_t> & extraInfo)44 int32_t FaceAuthExecutorCallbackHdi::OnResult(int32_t result, const std::vector<uint8_t> &extraInfo)
45 {
46     IAM_LOGI("OnResult %{public}d", result);
47     UserAuth::ResultCode retCode = ConvertResultCode(result);
48     IF_FALSE_LOGE_AND_RETURN_VAL(frameworkCallback_ != nullptr, HDF_FAILURE);
49     frameworkCallback_->OnResult(retCode, extraInfo);
50     return HDF_SUCCESS;
51 }
52 
OnTip(int32_t tip,const std::vector<uint8_t> & extraInfo)53 int32_t FaceAuthExecutorCallbackHdi::OnTip(int32_t tip, const std::vector<uint8_t> &extraInfo)
54 {
55     IAM_LOGI("OnTip %{public}d", tip);
56     IF_FALSE_LOGE_AND_RETURN_VAL(frameworkCallback_ != nullptr, HDF_FAILURE);
57     frameworkCallback_->OnAcquireInfo(tip, extraInfo);
58     return HDF_SUCCESS;
59 }
60 
ConvertResultCode(const int32_t in)61 UserAuth::ResultCode FaceAuthExecutorCallbackHdi::ConvertResultCode(const int32_t in)
62 {
63     ResultCode hdiIn = static_cast<ResultCode>(in);
64     if (hdiIn > ResultCode::VENDOR_RESULT_CODE_BEGIN) {
65         IAM_LOGI("vendor hdi result code %{public}d, no covert", hdiIn);
66         return static_cast<UserAuth::ResultCode>(in);
67     }
68 
69     static const std::map<ResultCode, UserAuth::ResultCode> data = {
70         { ResultCode::SUCCESS, UserAuth::ResultCode::SUCCESS },
71         { ResultCode::FAIL, UserAuth::ResultCode::FAIL },
72         { ResultCode::GENERAL_ERROR, UserAuth::ResultCode::GENERAL_ERROR },
73         { ResultCode::CANCELED, UserAuth::ResultCode::CANCELED },
74         { ResultCode::TIMEOUT, UserAuth::ResultCode::TIMEOUT },
75         { ResultCode::BUSY, UserAuth::ResultCode::BUSY },
76         { ResultCode::INVALID_PARAMETERS, UserAuth::ResultCode::INVALID_PARAMETERS },
77         { ResultCode::LOCKED, UserAuth::ResultCode::LOCKED },
78         { ResultCode::NOT_ENROLLED, UserAuth::ResultCode::NOT_ENROLLED },
79         // should be UserAuth::ResultCode::OPERATION_NOT_SUPPORT
80         { ResultCode::OPERATION_NOT_SUPPORT, UserAuth::ResultCode::FAIL },
81     };
82 
83     UserAuth::ResultCode out;
84     auto iter = data.find(hdiIn);
85     if (iter == data.end()) {
86         out = UserAuth::ResultCode::GENERAL_ERROR;
87         IAM_LOGE("convert hdi undefined result code %{public}d to framework result code %{public}d", in, out);
88         return out;
89     }
90     out = iter->second;
91     IAM_LOGI("covert hdi result code %{public}d to framework result code %{public}d", hdiIn, out);
92     return out;
93 }
94 } // namespace FaceAuth
95 } // namespace UserIam
96 } // namespace OHOS
97