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 "executor_impl.h"
17
18 #include <hdf_base.h>
19
20 #include "face_auth_defines.h"
21 #include "iam_logger.h"
22 #include "iam_para2str.h"
23
24 #define LOG_LABEL OHOS::UserIam::Common::LABEL_FACE_AUTH_IMPL
25
26 namespace OHOS {
27 namespace HDI {
28 namespace FaceAuth {
29 namespace V1_0 {
30 namespace {
31 constexpr uint16_t SENSOR_ID = 123;
32 constexpr uint32_t EXECUTOR_TYPE = 123;
33 constexpr size_t PUBLIC_KEY_LEN = 32;
34 } // namespace
35
ExecutorImpl()36 ExecutorImpl::ExecutorImpl()
37 {
38 executorInfo_ = {
39 .sensorId = SENSOR_ID,
40 .executorType = EXECUTOR_TYPE,
41 .executorRole = ExecutorRole::ALL_IN_ONE,
42 .authType = AuthType::FACE,
43 .esl = ExecutorSecureLevel::ESL0,
44 .publicKey = std::vector<uint8_t>(PUBLIC_KEY_LEN, 0),
45 .extraInfo = {},
46 };
47 }
48
GetExecutorInfo(ExecutorInfo & executorInfo)49 int32_t ExecutorImpl::GetExecutorInfo(ExecutorInfo &executorInfo)
50 {
51 IAM_LOGI("interface mock start");
52 executorInfo = executorInfo_;
53 IAM_LOGI("get executor information success");
54 return HDF_SUCCESS;
55 }
56
GetTemplateInfo(uint64_t templateId,TemplateInfo & templateInfo)57 int32_t ExecutorImpl::GetTemplateInfo(uint64_t templateId, TemplateInfo &templateInfo)
58 {
59 IAM_LOGI("interface mock start");
60 static_cast<void>(templateId);
61 templateInfo = {0};
62 IAM_LOGI("get template information success");
63 return HDF_SUCCESS;
64 }
65
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)66 int32_t ExecutorImpl::OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
67 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo)
68 {
69 IAM_LOGI("interface mock start");
70 static_cast<void>(templateIdList);
71 static_cast<void>(extraInfo);
72 static_cast<void>(frameworkPublicKey);
73 IAM_LOGI("register finish");
74 return HDF_SUCCESS;
75 }
76
Enroll(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)77 int32_t ExecutorImpl::Enroll(
78 uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
79 {
80 IAM_LOGI("interface mock start");
81 static_cast<void>(scheduleId);
82 static_cast<void>(extraInfo);
83 if (callbackObj == nullptr) {
84 IAM_LOGE("callbackObj is nullptr");
85 return HDF_ERR_INVALID_PARAM;
86 }
87 IAM_LOGI("enroll, result is %{public}d", ResultCode::OPERATION_NOT_SUPPORT);
88 int32_t ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
89 if (ret != HDF_SUCCESS) {
90 IAM_LOGE("callback result is %{public}d", ret);
91 return HDF_FAILURE;
92 }
93 return HDF_SUCCESS;
94 }
95
Authenticate(uint64_t scheduleId,const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)96 int32_t ExecutorImpl::Authenticate(uint64_t scheduleId, const std::vector<uint64_t> &templateIdList,
97 const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
98 {
99 IAM_LOGI("interface mock start");
100 static_cast<void>(scheduleId);
101 static_cast<void>(templateIdList);
102 static_cast<void>(extraInfo);
103 if (callbackObj == nullptr) {
104 IAM_LOGE("callbackObj is nullptr");
105 return HDF_ERR_INVALID_PARAM;
106 }
107 IAM_LOGI("authenticate, result is %{public}d", ResultCode::NOT_ENROLLED);
108 int32_t ret = callbackObj->OnResult(ResultCode::NOT_ENROLLED, {});
109 if (ret != HDF_SUCCESS) {
110 IAM_LOGE("callback result is %{public}d", ret);
111 return HDF_FAILURE;
112 }
113 return HDF_SUCCESS;
114 }
115
Identify(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)116 int32_t ExecutorImpl::Identify(
117 uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
118 {
119 IAM_LOGI("interface mock start");
120 static_cast<void>(scheduleId);
121 static_cast<void>(extraInfo);
122 if (callbackObj == nullptr) {
123 IAM_LOGE("callbackObj is nullptr");
124 return HDF_ERR_INVALID_PARAM;
125 }
126 IAM_LOGI("identify, result is %{public}d", ResultCode::OPERATION_NOT_SUPPORT);
127 int32_t ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
128 if (ret != HDF_SUCCESS) {
129 IAM_LOGE("callback result is %{public}d", ret);
130 return HDF_FAILURE;
131 }
132 return HDF_SUCCESS;
133 }
134
Delete(const std::vector<uint64_t> & templateIdList)135 int32_t ExecutorImpl::Delete(const std::vector<uint64_t> &templateIdList)
136 {
137 IAM_LOGI("interface mock start");
138 static_cast<void>(templateIdList);
139 IAM_LOGI("delete success");
140 return HDF_SUCCESS;
141 }
142
Cancel(uint64_t scheduleId)143 int32_t ExecutorImpl::Cancel(uint64_t scheduleId)
144 {
145 IAM_LOGI("interface mock start");
146 static_cast<void>(scheduleId);
147 IAM_LOGI("cancel success");
148 return HDF_SUCCESS;
149 }
150
SendCommand(int32_t commandId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)151 int32_t ExecutorImpl::SendCommand(
152 int32_t commandId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
153 {
154 IAM_LOGI("interface mock start");
155 static_cast<void>(extraInfo);
156 if (callbackObj == nullptr) {
157 IAM_LOGE("callbackObj is nullptr");
158 return HDF_ERR_INVALID_PARAM;
159 }
160 int32_t ret;
161 switch (commandId) {
162 case LOCK_TEMPLATE:
163 IAM_LOGI("lock template, result is %{public}d", ResultCode::SUCCESS);
164 ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
165 if (ret != HDF_SUCCESS) {
166 IAM_LOGE("callback result is %{public}d", ret);
167 return HDF_FAILURE;
168 }
169 break;
170 case UNLOCK_TEMPLATE:
171 IAM_LOGI("unlock template, result is %{public}d", ResultCode::SUCCESS);
172 ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
173 if (ret != HDF_SUCCESS) {
174 IAM_LOGE("callback result is %{public}d", ret);
175 return HDF_FAILURE;
176 }
177 break;
178 default:
179 IAM_LOGD("not support CommandId : %{public}d", commandId);
180 ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
181 if (ret != HDF_SUCCESS) {
182 IAM_LOGE("callback result is %{public}d", ret);
183 return HDF_FAILURE;
184 }
185 }
186 return HDF_SUCCESS;
187 }
188
SetBufferProducer(const sptr<BufferProducerSequenceable> & bufferProducer)189 int32_t ExecutorImpl::SetBufferProducer(const sptr<BufferProducerSequenceable> &bufferProducer)
190 {
191 IAM_LOGI("interface mock start set buffer producer %{public}s",
192 UserIam::Common::GetPointerNullStateString(bufferProducer.GetRefPtr()).c_str());
193 return HDF_SUCCESS;
194 }
195 } // namespace V1_0
196 } // namespace FaceAuth
197 } // namespace HDI
198 } // namespace OHOS
199