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