1 /*
2 * Copyright (c) 2022-2024 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 "user_auth_client_impl.h"
17
18 #include "system_ability_definition.h"
19
20 #include "auth_common.h"
21 #include "callback_manager.h"
22 #include "iam_check.h"
23 #include "iam_defines.h"
24 #include "iam_logger.h"
25 #include "iam_para2str.h"
26 #include "iam_ptr.h"
27 #include "ipc_client_utils.h"
28 #include "user_auth_callback_service.h"
29 #include "widget_callback_service.h"
30
31 #define LOG_TAG "USER_AUTH_SDK"
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 namespace {
36 class NorthAuthenticationCallback : public AuthenticationCallback, public NoCopyable {
37 public:
38 explicit NorthAuthenticationCallback(std::shared_ptr<AuthenticationCallback> innerCallback);
39 void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
40 void OnResult(int32_t result, const Attributes &extraInfo) override;
41
42 private:
43 std::shared_ptr<AuthenticationCallback> innerCallback_ = nullptr;
44 };
45
NorthAuthenticationCallback(std::shared_ptr<AuthenticationCallback> innerCallback)46 NorthAuthenticationCallback::NorthAuthenticationCallback(std::shared_ptr<AuthenticationCallback> innerCallback)
47 : innerCallback_(innerCallback) {};
48
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)49 void NorthAuthenticationCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
50 {
51 if (innerCallback_ == nullptr) {
52 IAM_LOGE("callback is nullptr");
53 return;
54 }
55
56 if (module == AuthType::FACE) {
57 if (acquireInfo == 0 || acquireInfo > FACE_AUTH_TIP_MAX) {
58 IAM_LOGI("skip undefined face auth tip %{public}u", acquireInfo);
59 return;
60 }
61 } else if (module == AuthType::FINGERPRINT) {
62 if (acquireInfo > FINGERPRINT_AUTH_TIP_MAX) {
63 IAM_LOGI("skip undefined fingerprint auth tip %{public}u", acquireInfo);
64 return;
65 }
66 }
67
68 innerCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
69 }
70
OnResult(int32_t result,const Attributes & extraInfo)71 void NorthAuthenticationCallback::OnResult(int32_t result, const Attributes &extraInfo)
72 {
73 if (innerCallback_ == nullptr) {
74 IAM_LOGE("callback is nullptr");
75 return;
76 }
77
78 innerCallback_->OnResult(result, extraInfo);
79 }
80 } // namespace
81
GetAvailableStatus(AuthType authType,AuthTrustLevel authTrustLevel)82 int32_t UserAuthClientImpl::GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel)
83 {
84 IAM_LOGI("start, authType:%{public}d authTrustLevel:%{public}u", authType, authTrustLevel);
85 auto proxy = GetProxy();
86 if (!proxy) {
87 IAM_LOGE("proxy is nullptr");
88 return GENERAL_ERROR;
89 }
90 return proxy->GetAvailableStatus(INNER_API_VERSION_10000, authType, authTrustLevel);
91 }
92
GetNorthAvailableStatus(int32_t apiVersion,AuthType authType,AuthTrustLevel authTrustLevel)93 int32_t UserAuthClientImpl::GetNorthAvailableStatus(int32_t apiVersion, AuthType authType,
94 AuthTrustLevel authTrustLevel)
95 {
96 IAM_LOGI("start, apiVersion:%{public}d authType:%{public}d authTrustLevel:%{public}u",
97 apiVersion, authType, authTrustLevel);
98 auto proxy = GetProxy();
99 if (!proxy) {
100 IAM_LOGE("proxy is nullptr");
101 return GENERAL_ERROR;
102 }
103 return proxy->GetAvailableStatus(apiVersion, authType, authTrustLevel);
104 }
105
GetAvailableStatus(int32_t userId,AuthType authType,AuthTrustLevel authTrustLevel)106 int32_t UserAuthClientImpl::GetAvailableStatus(int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel)
107 {
108 IAM_LOGI("start, userId:%{public}d authType:%{public}d authTrustLevel:%{public}u",
109 userId, authType, authTrustLevel);
110 auto proxy = GetProxy();
111 if (!proxy) {
112 IAM_LOGE("proxy is nullptr");
113 return GENERAL_ERROR;
114 }
115 return proxy->GetAvailableStatus(INNER_API_VERSION_10000, userId, authType, authTrustLevel);
116 }
117
GetProperty(int32_t userId,const GetPropertyRequest & request,const std::shared_ptr<GetPropCallback> & callback)118 void UserAuthClientImpl::GetProperty(int32_t userId, const GetPropertyRequest &request,
119 const std::shared_ptr<GetPropCallback> &callback)
120 {
121 IAM_LOGI("start, userId:%{public}d authType:%{public}d", userId, request.authType);
122 if (!callback) {
123 IAM_LOGE("get prop callback is nullptr");
124 return;
125 }
126
127 auto proxy = GetProxy();
128 if (!proxy) {
129 IAM_LOGE("proxy is nullptr");
130 Attributes extraInfo;
131 callback->OnResult(GENERAL_ERROR, extraInfo);
132 return;
133 }
134
135 sptr<GetExecutorPropertyCallbackInterface> wrapper(
136 new (std::nothrow) GetExecutorPropertyCallbackService(callback));
137 if (wrapper == nullptr) {
138 IAM_LOGE("failed to create wrapper");
139 Attributes extraInfo;
140 callback->OnResult(GENERAL_ERROR, extraInfo);
141 return;
142 }
143 proxy->GetProperty(userId, request.authType, request.keys, wrapper);
144 }
145
GetPropertyById(uint64_t credentialId,const std::vector<Attributes::AttributeKey> & keys,const std::shared_ptr<GetPropCallback> & callback)146 void UserAuthClientImpl::GetPropertyById(uint64_t credentialId, const std::vector<Attributes::AttributeKey> &keys,
147 const std::shared_ptr<GetPropCallback> &callback)
148 {
149 IAM_LOGI("start");
150 if (!callback) {
151 IAM_LOGE("get prop callback is nullptr");
152 return;
153 }
154
155 auto proxy = GetProxy();
156 if (!proxy) {
157 IAM_LOGE("proxy is nullptr");
158 Attributes extraInfo;
159 callback->OnResult(GENERAL_ERROR, extraInfo);
160 return;
161 }
162
163 sptr<GetExecutorPropertyCallbackInterface> wrapper(
164 new (std::nothrow) GetExecutorPropertyCallbackService(callback));
165 if (wrapper == nullptr) {
166 IAM_LOGE("failed to create wrapper");
167 Attributes extraInfo;
168 callback->OnResult(GENERAL_ERROR, extraInfo);
169 return;
170 }
171 proxy->GetPropertyById(credentialId, keys, wrapper);
172 }
173
SetPropertyInner(int32_t userId,const SetPropertyRequest & request,const std::shared_ptr<SetPropCallback> & callback)174 ResultCode UserAuthClientImpl::SetPropertyInner(int32_t userId, const SetPropertyRequest &request,
175 const std::shared_ptr<SetPropCallback> &callback)
176 {
177 auto proxy = GetProxy();
178 if (!proxy) {
179 IAM_LOGE("proxy is nullptr");
180 return GENERAL_ERROR;
181 }
182
183 auto keys = request.attrs.GetKeys();
184 IF_FALSE_LOGE_AND_RETURN_VAL(keys.size() == 1, GENERAL_ERROR);
185
186 Attributes::AttributeKey key = keys[0];
187 Attributes attr;
188
189 std::vector<uint8_t> extraInfo;
190 bool getArrayRet = request.attrs.GetUint8ArrayValue(static_cast<Attributes::AttributeKey>(key), extraInfo);
191 IF_FALSE_LOGE_AND_RETURN_VAL(getArrayRet, GENERAL_ERROR);
192
193 bool setModeRet = attr.SetUint32Value(Attributes::ATTR_PROPERTY_MODE, static_cast<uint32_t>(key));
194 IF_FALSE_LOGE_AND_RETURN_VAL(setModeRet, GENERAL_ERROR);
195
196 bool setArrayRet = attr.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo);
197 IF_FALSE_LOGE_AND_RETURN_VAL(setArrayRet, GENERAL_ERROR);
198
199 sptr<SetExecutorPropertyCallbackInterface> wrapper(
200 new (std::nothrow) SetExecutorPropertyCallbackService(callback));
201 IF_FALSE_LOGE_AND_RETURN_VAL(wrapper != nullptr, GENERAL_ERROR);
202 proxy->SetProperty(userId, request.authType, attr, wrapper);
203 return SUCCESS;
204 }
205
SetProperty(int32_t userId,const SetPropertyRequest & request,const std::shared_ptr<SetPropCallback> & callback)206 void UserAuthClientImpl::SetProperty(int32_t userId, const SetPropertyRequest &request,
207 const std::shared_ptr<SetPropCallback> &callback)
208 {
209 IAM_LOGI("start, userId:%{public}d authType:%{public}d", userId, request.authType);
210 if (!callback) {
211 IAM_LOGE("set prop callback is nullptr");
212 return;
213 }
214
215 ResultCode result = SetPropertyInner(userId, request, callback);
216 if (result != SUCCESS) {
217 IAM_LOGE("result is not success");
218 Attributes retExtraInfo;
219 callback->OnResult(GENERAL_ERROR, retExtraInfo);
220 return;
221 }
222 }
223
BeginAuthentication(const AuthParam & authParam,const std::shared_ptr<AuthenticationCallback> & callback)224 uint64_t UserAuthClientImpl::BeginAuthentication(const AuthParam &authParam,
225 const std::shared_ptr<AuthenticationCallback> &callback)
226 {
227 IAM_LOGI("start, userId:%{public}d, authType:%{public}d, atl:%{public}u, authIntent:%{public}u,"
228 "remoteAuthParamHasValue:%{public}s", authParam.userId, authParam.authType, authParam.authTrustLevel,
229 authParam.authIntent, Common::GetBoolStr(authParam.remoteAuthParam.has_value()));
230 if (authParam.remoteAuthParam.has_value()) {
231 IAM_LOGI("verifierNetworkIdHasValue:%{public}s collectorNetworkIdHasValue:%{public}s "
232 "collectorTokenIdHasValue:%{public}s",
233 Common::GetBoolStr(authParam.remoteAuthParam->verifierNetworkId.has_value()),
234 Common::GetBoolStr(authParam.remoteAuthParam->collectorNetworkId.has_value()),
235 Common::GetBoolStr(authParam.remoteAuthParam->collectorTokenId.has_value()));
236 }
237
238 if (!callback) {
239 IAM_LOGE("auth callback is nullptr");
240 return BAD_CONTEXT_ID;
241 }
242
243 auto proxy = GetProxy();
244 if (!proxy) {
245 IAM_LOGE("proxy is nullptr");
246 Attributes extraInfo;
247 callback->OnResult(GENERAL_ERROR, extraInfo);
248 return BAD_CONTEXT_ID;
249 }
250
251 sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
252 if (wrapper == nullptr) {
253 IAM_LOGE("failed to create wrapper");
254 Attributes extraInfo;
255 callback->OnResult(GENERAL_ERROR, extraInfo);
256 return BAD_CONTEXT_ID;
257 }
258 AuthParamInner authParamInner = {
259 .userId = authParam.userId,
260 .challenge = authParam.challenge,
261 .authType = authParam.authType,
262 .authTrustLevel = authParam.authTrustLevel,
263 .authIntent = authParam.authIntent
264 };
265 std::optional<RemoteAuthParam> remoteAuthParam = authParam.remoteAuthParam;
266 return proxy->AuthUser(authParamInner, remoteAuthParam, wrapper);
267 }
268
BeginNorthAuthentication(int32_t apiVersion,const std::vector<uint8_t> & challenge,AuthType authType,AuthTrustLevel atl,const std::shared_ptr<AuthenticationCallback> & callback)269 uint64_t UserAuthClientImpl::BeginNorthAuthentication(int32_t apiVersion, const std::vector<uint8_t> &challenge,
270 AuthType authType, AuthTrustLevel atl, const std::shared_ptr<AuthenticationCallback> &callback)
271 {
272 IAM_LOGI("start, apiVersion:%{public}d authType:%{public}d atl:%{public}u", apiVersion, authType, atl);
273 if (!callback) {
274 IAM_LOGE("auth callback is nullptr");
275 return BAD_CONTEXT_ID;
276 }
277
278 auto northCallback = Common::MakeShared<NorthAuthenticationCallback>(callback);
279 if (!northCallback) {
280 IAM_LOGE("auth callback is nullptr");
281 Attributes extraInfo;
282 callback->OnResult(GENERAL_ERROR, extraInfo);
283 return BAD_CONTEXT_ID;
284 }
285
286 auto proxy = GetProxy();
287 if (!proxy) {
288 IAM_LOGE("proxy is nullptr");
289 Attributes extraInfo;
290 callback->OnResult(GENERAL_ERROR, extraInfo);
291 return BAD_CONTEXT_ID;
292 }
293
294 sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(northCallback));
295 if (wrapper == nullptr) {
296 IAM_LOGE("failed to create wrapper");
297 Attributes extraInfo;
298 callback->OnResult(GENERAL_ERROR, extraInfo);
299 return BAD_CONTEXT_ID;
300 }
301 return proxy->Auth(apiVersion, challenge, authType, atl, wrapper);
302 }
303
CancelAuthentication(uint64_t contextId)304 int32_t UserAuthClientImpl::CancelAuthentication(uint64_t contextId)
305 {
306 IAM_LOGI("start");
307 auto proxy = GetProxy();
308 if (!proxy) {
309 IAM_LOGE("proxy is nullptr");
310 return GENERAL_ERROR;
311 }
312
313 return proxy->CancelAuthOrIdentify(contextId);
314 }
315
BeginIdentification(const std::vector<uint8_t> & challenge,AuthType authType,const std::shared_ptr<IdentificationCallback> & callback)316 uint64_t UserAuthClientImpl::BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType,
317 const std::shared_ptr<IdentificationCallback> &callback)
318 {
319 IAM_LOGI("start, authType:%{public}d", authType);
320 if (!callback) {
321 IAM_LOGE("identify callback is nullptr");
322 return BAD_CONTEXT_ID;
323 }
324
325 auto proxy = GetProxy();
326 if (!proxy) {
327 IAM_LOGE("proxy is nullptr");
328 Attributes extraInfo;
329 callback->OnResult(GENERAL_ERROR, extraInfo);
330 return BAD_CONTEXT_ID;
331 }
332
333 sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
334 if (wrapper == nullptr) {
335 IAM_LOGE("failed to create wrapper");
336 Attributes extraInfo;
337 callback->OnResult(GENERAL_ERROR, extraInfo);
338 return BAD_CONTEXT_ID;
339 }
340 return proxy->Identify(challenge, authType, wrapper);
341 }
342
CancelIdentification(uint64_t contextId)343 int32_t UserAuthClientImpl::CancelIdentification(uint64_t contextId)
344 {
345 IAM_LOGI("start");
346 auto proxy = GetProxy();
347 if (!proxy) {
348 IAM_LOGE("proxy is nullptr");
349 return GENERAL_ERROR;
350 }
351
352 return proxy->CancelAuthOrIdentify(contextId);
353 }
354
GetVersion(int32_t & version)355 int32_t UserAuthClientImpl::GetVersion(int32_t &version)
356 {
357 IAM_LOGI("start");
358 auto proxy = GetProxy();
359 if (!proxy) {
360 IAM_LOGE("proxy is nullptr");
361 return GENERAL_ERROR;
362 }
363
364 return proxy->GetVersion(version);
365 }
366
SetGlobalConfigParam(const GlobalConfigParam & param)367 int32_t UserAuthClientImpl::SetGlobalConfigParam(const GlobalConfigParam ¶m)
368 {
369 IAM_LOGI("start");
370 auto proxy = GetProxy();
371 if (!proxy) {
372 IAM_LOGE("proxy is nullptr");
373 return GENERAL_ERROR;
374 }
375
376 return proxy->SetGlobalConfigParam(param);
377 }
378
GetProxy()379 sptr<UserAuthInterface> UserAuthClientImpl::GetProxy()
380 {
381 std::lock_guard<std::mutex> lock(mutex_);
382 if (proxy_ != nullptr) {
383 return proxy_;
384 }
385 sptr<IRemoteObject> obj = IpcClientUtils::GetRemoteObject(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH);
386 if (obj == nullptr) {
387 IAM_LOGE("remote object is null");
388 return proxy_;
389 }
390 sptr<IRemoteObject::DeathRecipient> dr(new (std::nothrow) UserAuthImplDeathRecipient());
391 if ((dr == nullptr) || (obj->IsProxyObject() && !obj->AddDeathRecipient(dr))) {
392 IAM_LOGE("add death recipient fail");
393 return proxy_;
394 }
395
396 proxy_ = iface_cast<UserAuthInterface>(obj);
397 deathRecipient_ = dr;
398 return proxy_;
399 }
400
ResetProxy(const wptr<IRemoteObject> & remote)401 void UserAuthClientImpl::ResetProxy(const wptr<IRemoteObject> &remote)
402 {
403 IAM_LOGI("start");
404 std::lock_guard<std::mutex> lock(mutex_);
405 if (proxy_ == nullptr) {
406 IAM_LOGE("proxy_ is null");
407 return;
408 }
409 auto serviceRemote = proxy_->AsObject();
410 if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
411 IAM_LOGI("need reset");
412 serviceRemote->RemoveDeathRecipient(deathRecipient_);
413 proxy_ = nullptr;
414 deathRecipient_ = nullptr;
415 }
416 IAM_LOGI("end reset proxy");
417 }
418
OnRemoteDied(const wptr<IRemoteObject> & remote)419 void UserAuthClientImpl::UserAuthImplDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
420 {
421 IAM_LOGI("start");
422 if (remote == nullptr) {
423 IAM_LOGE("remote is nullptr");
424 return;
425 }
426 CallbackManager::GetInstance().OnServiceDeath();
427 UserAuthClientImpl::Instance().ResetProxy(remote);
428 }
429
Instance()430 UserAuthClientImpl &UserAuthClientImpl::Instance()
431 {
432 static UserAuthClientImpl impl;
433 return impl;
434 }
435
GetInstance()436 UserAuthClient &UserAuthClient::GetInstance()
437 {
438 return UserAuthClientImpl::Instance();
439 }
440
BeginWidgetAuth(const WidgetAuthParam & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)441 uint64_t UserAuthClientImpl::BeginWidgetAuth(const WidgetAuthParam &authParam, const WidgetParam &widgetParam,
442 const std::shared_ptr<AuthenticationCallback> &callback)
443 {
444 IAM_LOGI("start, authTypeSize:%{public}zu authTrustLevel:%{public}u", authParam.authTypes.size(),
445 authParam.authTrustLevel);
446 AuthParamInner authParamInner = {
447 .userId = authParam.userId,
448 .isUserIdSpecified = true,
449 .challenge = authParam.challenge,
450 .authTypes = authParam.authTypes,
451 .authTrustLevel = authParam.authTrustLevel,
452 .reuseUnlockResult = authParam.reuseUnlockResult,
453 };
454 return BeginWidgetAuthInner(INNER_API_VERSION_20000, authParamInner, widgetParam, callback);
455 }
456
BeginWidgetAuth(int32_t apiVersion,const WidgetAuthParam & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)457 uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const WidgetAuthParam &authParam,
458 const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
459 {
460 IAM_LOGI("start, apiVersion:%{public}d authTypeSize:%{public}zu authTrustLevel:%{public}u",
461 apiVersion, authParam.authTypes.size(), authParam.authTrustLevel);
462
463 AuthParamInner authParamInner = {
464 .isUserIdSpecified = false,
465 .challenge = authParam.challenge,
466 .authTypes = authParam.authTypes,
467 .authTrustLevel = authParam.authTrustLevel,
468 .reuseUnlockResult = authParam.reuseUnlockResult,
469 };
470 return BeginWidgetAuthInner(apiVersion, authParamInner, widgetParam, callback);
471 }
472
BeginWidgetAuthInner(int32_t apiVersion,const AuthParamInner & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)473 uint64_t UserAuthClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
474 const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
475 {
476 if (!callback) {
477 IAM_LOGE("auth callback is nullptr");
478 return BAD_CONTEXT_ID;
479 }
480 auto proxy = GetProxy();
481 if (!proxy) {
482 IAM_LOGE("proxy is nullptr");
483 Attributes extraInfo;
484 callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
485 return BAD_CONTEXT_ID;
486 }
487
488 sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
489 if (wrapper == nullptr) {
490 IAM_LOGE("failed to create wrapper");
491 Attributes extraInfo;
492 callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
493 return BAD_CONTEXT_ID;
494 }
495 return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper);
496 }
497
SetWidgetCallback(int32_t version,const std::shared_ptr<IUserAuthWidgetCallback> & callback)498 int32_t UserAuthClientImpl::SetWidgetCallback(int32_t version, const std::shared_ptr<IUserAuthWidgetCallback> &callback)
499 {
500 IAM_LOGI("start, version:%{public}d", version);
501 if (!callback) {
502 IAM_LOGE("widget callback is nullptr");
503 return GENERAL_ERROR;
504 }
505 auto proxy = GetProxy();
506 if (!proxy) {
507 IAM_LOGE("proxy is nullptr");
508 return GENERAL_ERROR;
509 }
510
511 sptr<WidgetCallbackInterface> wrapper(new (std::nothrow) WidgetCallbackService(callback));
512 if (wrapper == nullptr) {
513 IAM_LOGE("failed to create wrapper");
514 return GENERAL_ERROR;
515 }
516 return proxy->RegisterWidgetCallback(version, wrapper);
517 }
518
Notice(NoticeType noticeType,const std::string & eventData)519 int32_t UserAuthClientImpl::Notice(NoticeType noticeType, const std::string &eventData)
520 {
521 IAM_LOGI("start, noticeType:%{public}d", noticeType);
522 auto proxy = GetProxy();
523 if (!proxy) {
524 IAM_LOGE("proxy is nullptr");
525 return GENERAL_ERROR;
526 }
527 IAM_LOGI("UserAuthClientImpl::Notice noticeType:%{public}d, eventDat:%{public}s",
528 static_cast<int32_t>(noticeType), eventData.c_str());
529 return proxy->Notice(noticeType, eventData);
530 }
531
GetEnrolledState(int32_t apiVersion,AuthType authType,EnrolledState & enrolledState)532 int32_t UserAuthClientImpl::GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState)
533 {
534 IAM_LOGI("start, apiVersion:%{public}d authType:%{public}d ", apiVersion, authType);
535 auto proxy = GetProxy();
536 if (!proxy) {
537 IAM_LOGE("proxy is nullptr");
538 return GENERAL_ERROR;
539 }
540 int32_t ret = proxy->GetEnrolledState(apiVersion, authType, enrolledState);
541 if (ret != SUCCESS) {
542 IAM_LOGE("proxy GetEnrolledState failed");
543 return ret;
544 }
545 return ret;
546 }
547
RegistUserAuthSuccessEventListener(const std::vector<AuthType> & authType,const sptr<AuthEventListenerInterface> & listener)548 int32_t UserAuthClientImpl::RegistUserAuthSuccessEventListener(const std::vector<AuthType> &authType,
549 const sptr<AuthEventListenerInterface> &listener)
550 {
551 IAM_LOGI("start");
552 if (!listener) {
553 IAM_LOGE("listener is nullptr");
554 return GENERAL_ERROR;
555 }
556
557 auto proxy = GetProxy();
558 if (!proxy) {
559 IAM_LOGE("proxy is nullptr");
560 return GENERAL_ERROR;
561 }
562
563 int32_t ret = proxy->RegistUserAuthSuccessEventListener(authType, listener);
564 if (ret != SUCCESS) {
565 IAM_LOGE("Regist userAuth success event listener failed");
566 return ret;
567 }
568
569 return SUCCESS;
570 }
571
UnRegistUserAuthSuccessEventListener(const sptr<AuthEventListenerInterface> & listener)572 int32_t UserAuthClientImpl::UnRegistUserAuthSuccessEventListener(const sptr<AuthEventListenerInterface> &listener)
573 {
574 IAM_LOGI("start");
575 if (!listener) {
576 IAM_LOGE("listener is nullptr");
577 return GENERAL_ERROR;
578 }
579
580 auto proxy = GetProxy();
581 if (!proxy) {
582 IAM_LOGE("proxy is nullptr");
583 return GENERAL_ERROR;
584 }
585
586 int32_t ret = proxy->UnRegistUserAuthSuccessEventListener(listener);
587 if (ret != SUCCESS) {
588 IAM_LOGE("unRegist userAuth success event listener failed");
589 return ret;
590 }
591
592 return SUCCESS;
593 }
594
PrepareRemoteAuth(const std::string & networkId,const std::shared_ptr<PrepareRemoteAuthCallback> & callback)595 int32_t UserAuthClientImpl::PrepareRemoteAuth(const std::string &networkId,
596 const std::shared_ptr<PrepareRemoteAuthCallback> &callback)
597 {
598 IAM_LOGI("start");
599 if (!callback) {
600 IAM_LOGE("prepare remote auth callback is nullptr");
601 return GENERAL_ERROR;
602 }
603
604 auto proxy = GetProxy();
605 if (!proxy) {
606 IAM_LOGE("proxy is nullptr");
607 callback->OnResult(GENERAL_ERROR);
608 return GENERAL_ERROR;
609 }
610
611 sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
612 if (wrapper == nullptr) {
613 IAM_LOGE("failed to create wrapper");
614 callback->OnResult(GENERAL_ERROR);
615 return GENERAL_ERROR;
616 }
617
618 return proxy->PrepareRemoteAuth(networkId, wrapper);
619 }
620 } // namespace UserAuth
621 } // namespace UserIam
622 } // namespace OHOS
623