• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetPropertyInner(int32_t userId,const SetPropertyRequest & request,const std::shared_ptr<SetPropCallback> & callback)146 ResultCode UserAuthClientImpl::SetPropertyInner(int32_t userId, const SetPropertyRequest &request,
147     const std::shared_ptr<SetPropCallback> &callback)
148 {
149     auto proxy = GetProxy();
150     if (!proxy) {
151         IAM_LOGE("proxy is nullptr");
152         return GENERAL_ERROR;
153     }
154 
155     auto keys = request.attrs.GetKeys();
156     IF_FALSE_LOGE_AND_RETURN_VAL(keys.size() == 1, GENERAL_ERROR);
157 
158     Attributes::AttributeKey key = keys[0];
159     Attributes attr;
160 
161     std::vector<uint8_t> extraInfo;
162     bool getArrayRet = request.attrs.GetUint8ArrayValue(static_cast<Attributes::AttributeKey>(key), extraInfo);
163     IF_FALSE_LOGE_AND_RETURN_VAL(getArrayRet, GENERAL_ERROR);
164 
165     bool setModeRet = attr.SetUint32Value(Attributes::ATTR_PROPERTY_MODE, static_cast<uint32_t>(key));
166     IF_FALSE_LOGE_AND_RETURN_VAL(setModeRet, GENERAL_ERROR);
167 
168     bool setArrayRet = attr.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo);
169     IF_FALSE_LOGE_AND_RETURN_VAL(setArrayRet, GENERAL_ERROR);
170 
171     sptr<SetExecutorPropertyCallbackInterface> wrapper(
172         new (std::nothrow) SetExecutorPropertyCallbackService(callback));
173     IF_FALSE_LOGE_AND_RETURN_VAL(wrapper != nullptr, GENERAL_ERROR);
174     proxy->SetProperty(userId, request.authType, attr, wrapper);
175     return SUCCESS;
176 }
177 
SetProperty(int32_t userId,const SetPropertyRequest & request,const std::shared_ptr<SetPropCallback> & callback)178 void UserAuthClientImpl::SetProperty(int32_t userId, const SetPropertyRequest &request,
179     const std::shared_ptr<SetPropCallback> &callback)
180 {
181     IAM_LOGI("start, userId:%{public}d authType:%{public}d", userId, request.authType);
182     if (!callback) {
183         IAM_LOGE("set prop callback is nullptr");
184         return;
185     }
186 
187     ResultCode result = SetPropertyInner(userId, request, callback);
188     if (result != SUCCESS) {
189         IAM_LOGE("result is not success");
190         Attributes retExtraInfo;
191         callback->OnResult(GENERAL_ERROR, retExtraInfo);
192         return;
193     }
194 }
195 
BeginAuthentication(const AuthParam & authParam,const std::shared_ptr<AuthenticationCallback> & callback)196 uint64_t UserAuthClientImpl::BeginAuthentication(const AuthParam &authParam,
197     const std::shared_ptr<AuthenticationCallback> &callback)
198 {
199     IAM_LOGI("start, userId:%{public}d authType:%{public}d atl:%{public}u remoteAuthParamHasValue:%{public}s",
200         authParam.userId, authParam.authType, authParam.authTrustLevel,
201         Common::GetBoolStr(authParam.remoteAuthParam.has_value()));
202     if (authParam.remoteAuthParam.has_value()) {
203         IAM_LOGI("verifierNetworkIdHasValue:%{public}s collectorNetworkIdHasValue:%{public}s "
204             "collectorTokenIdHasValue:%{public}s",
205             Common::GetBoolStr(authParam.remoteAuthParam->verifierNetworkId.has_value()),
206             Common::GetBoolStr(authParam.remoteAuthParam->collectorNetworkId.has_value()),
207             Common::GetBoolStr(authParam.remoteAuthParam->collectorTokenId.has_value()));
208     }
209 
210     if (!callback) {
211         IAM_LOGE("auth callback is nullptr");
212         return BAD_CONTEXT_ID;
213     }
214 
215     auto proxy = GetProxy();
216     if (!proxy) {
217         IAM_LOGE("proxy is nullptr");
218         Attributes extraInfo;
219         callback->OnResult(GENERAL_ERROR, extraInfo);
220         return BAD_CONTEXT_ID;
221     }
222 
223     sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
224     if (wrapper == nullptr) {
225         IAM_LOGE("failed to create wrapper");
226         Attributes extraInfo;
227         callback->OnResult(GENERAL_ERROR, extraInfo);
228         return BAD_CONTEXT_ID;
229     }
230     AuthParamInner authParamInner = {
231         .userId = authParam.userId,
232         .challenge = authParam.challenge,
233         .authType = authParam.authType,
234         .authTrustLevel = authParam.authTrustLevel,
235         .authIntent = authParam.authIntent
236     };
237     std::optional<RemoteAuthParam> remoteAuthParam = authParam.remoteAuthParam;
238     return proxy->AuthUser(authParamInner, remoteAuthParam, wrapper);
239 }
240 
BeginNorthAuthentication(int32_t apiVersion,const std::vector<uint8_t> & challenge,AuthType authType,AuthTrustLevel atl,const std::shared_ptr<AuthenticationCallback> & callback)241 uint64_t UserAuthClientImpl::BeginNorthAuthentication(int32_t apiVersion, const std::vector<uint8_t> &challenge,
242     AuthType authType, AuthTrustLevel atl, const std::shared_ptr<AuthenticationCallback> &callback)
243 {
244     IAM_LOGI("start, apiVersion:%{public}d authType:%{public}d atl:%{public}u", apiVersion, authType, atl);
245     if (!callback) {
246         IAM_LOGE("auth callback is nullptr");
247         return BAD_CONTEXT_ID;
248     }
249 
250     auto northCallback = Common::MakeShared<NorthAuthenticationCallback>(callback);
251     if (!northCallback) {
252         IAM_LOGE("auth callback is nullptr");
253         Attributes extraInfo;
254         callback->OnResult(GENERAL_ERROR, extraInfo);
255         return BAD_CONTEXT_ID;
256     }
257 
258     auto proxy = GetProxy();
259     if (!proxy) {
260         IAM_LOGE("proxy is nullptr");
261         Attributes extraInfo;
262         callback->OnResult(GENERAL_ERROR, extraInfo);
263         return BAD_CONTEXT_ID;
264     }
265 
266     sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(northCallback));
267     if (wrapper == nullptr) {
268         IAM_LOGE("failed to create wrapper");
269         Attributes extraInfo;
270         callback->OnResult(GENERAL_ERROR, extraInfo);
271         return BAD_CONTEXT_ID;
272     }
273     return proxy->Auth(apiVersion, challenge, authType, atl, wrapper);
274 }
275 
CancelAuthentication(uint64_t contextId)276 int32_t UserAuthClientImpl::CancelAuthentication(uint64_t contextId)
277 {
278     IAM_LOGI("start");
279     auto proxy = GetProxy();
280     if (!proxy) {
281         IAM_LOGE("proxy is nullptr");
282         return GENERAL_ERROR;
283     }
284 
285     return proxy->CancelAuthOrIdentify(contextId);
286 }
287 
BeginIdentification(const std::vector<uint8_t> & challenge,AuthType authType,const std::shared_ptr<IdentificationCallback> & callback)288 uint64_t UserAuthClientImpl::BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType,
289     const std::shared_ptr<IdentificationCallback> &callback)
290 {
291     IAM_LOGI("start, authType:%{public}d", authType);
292     if (!callback) {
293         IAM_LOGE("identify callback is nullptr");
294         return BAD_CONTEXT_ID;
295     }
296 
297     auto proxy = GetProxy();
298     if (!proxy) {
299         IAM_LOGE("proxy is nullptr");
300         Attributes extraInfo;
301         callback->OnResult(GENERAL_ERROR, extraInfo);
302         return BAD_CONTEXT_ID;
303     }
304 
305     sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
306     if (wrapper == nullptr) {
307         IAM_LOGE("failed to create wrapper");
308         Attributes extraInfo;
309         callback->OnResult(GENERAL_ERROR, extraInfo);
310         return BAD_CONTEXT_ID;
311     }
312     return proxy->Identify(challenge, authType, wrapper);
313 }
314 
CancelIdentification(uint64_t contextId)315 int32_t UserAuthClientImpl::CancelIdentification(uint64_t contextId)
316 {
317     IAM_LOGI("start");
318     auto proxy = GetProxy();
319     if (!proxy) {
320         IAM_LOGE("proxy is nullptr");
321         return GENERAL_ERROR;
322     }
323 
324     return proxy->CancelAuthOrIdentify(contextId);
325 }
326 
GetVersion(int32_t & version)327 int32_t UserAuthClientImpl::GetVersion(int32_t &version)
328 {
329     IAM_LOGI("start");
330     auto proxy = GetProxy();
331     if (!proxy) {
332         IAM_LOGE("proxy is nullptr");
333         return GENERAL_ERROR;
334     }
335 
336     return proxy->GetVersion(version);
337 }
338 
SetGlobalConfigParam(const GlobalConfigParam & param)339 int32_t UserAuthClientImpl::SetGlobalConfigParam(const GlobalConfigParam &param)
340 {
341     IAM_LOGI("start");
342     auto proxy = GetProxy();
343     if (!proxy) {
344         IAM_LOGE("proxy is nullptr");
345         return GENERAL_ERROR;
346     }
347 
348     return proxy->SetGlobalConfigParam(param);
349 }
350 
GetProxy()351 sptr<UserAuthInterface> UserAuthClientImpl::GetProxy()
352 {
353     std::lock_guard<std::mutex> lock(mutex_);
354     if (proxy_ != nullptr) {
355         return proxy_;
356     }
357     sptr<IRemoteObject> obj = IpcClientUtils::GetRemoteObject(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH);
358     if (obj == nullptr) {
359         IAM_LOGE("remote object is null");
360         return proxy_;
361     }
362     sptr<IRemoteObject::DeathRecipient> dr(new (std::nothrow) UserAuthImplDeathRecipient());
363     if ((dr == nullptr) || (obj->IsProxyObject() && !obj->AddDeathRecipient(dr))) {
364         IAM_LOGE("add death recipient fail");
365         return proxy_;
366     }
367 
368     proxy_ = iface_cast<UserAuthInterface>(obj);
369     deathRecipient_ = dr;
370     return proxy_;
371 }
372 
ResetProxy(const wptr<IRemoteObject> & remote)373 void UserAuthClientImpl::ResetProxy(const wptr<IRemoteObject> &remote)
374 {
375     IAM_LOGI("start");
376     std::lock_guard<std::mutex> lock(mutex_);
377     if (proxy_ == nullptr) {
378         IAM_LOGE("proxy_ is null");
379         return;
380     }
381     auto serviceRemote = proxy_->AsObject();
382     if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
383         IAM_LOGI("need reset");
384         serviceRemote->RemoveDeathRecipient(deathRecipient_);
385         proxy_ = nullptr;
386         deathRecipient_ = nullptr;
387     }
388     IAM_LOGI("end reset proxy");
389 }
390 
OnRemoteDied(const wptr<IRemoteObject> & remote)391 void UserAuthClientImpl::UserAuthImplDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
392 {
393     IAM_LOGI("start");
394     if (remote == nullptr) {
395         IAM_LOGE("remote is nullptr");
396         return;
397     }
398     CallbackManager::GetInstance().OnServiceDeath();
399     UserAuthClientImpl::Instance().ResetProxy(remote);
400 }
401 
Instance()402 UserAuthClientImpl &UserAuthClientImpl::Instance()
403 {
404     static UserAuthClientImpl impl;
405     return impl;
406 }
407 
GetInstance()408 UserAuthClient &UserAuthClient::GetInstance()
409 {
410     return UserAuthClientImpl::Instance();
411 }
412 
BeginWidgetAuth(const WidgetAuthParam & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)413 uint64_t UserAuthClientImpl::BeginWidgetAuth(const WidgetAuthParam &authParam, const WidgetParam &widgetParam,
414     const std::shared_ptr<AuthenticationCallback> &callback)
415 {
416     IAM_LOGI("start, authTypeSize:%{public}zu authTrustLevel:%{public}u", authParam.authTypes.size(),
417         authParam.authTrustLevel);
418     AuthParamInner authParamInner = {
419         .userId = authParam.userId,
420         .isUserIdSpecified = true,
421         .challenge = authParam.challenge,
422         .authTypes = authParam.authTypes,
423         .authTrustLevel = authParam.authTrustLevel,
424         .reuseUnlockResult = authParam.reuseUnlockResult,
425     };
426     return BeginWidgetAuthInner(INNER_API_VERSION_20000, authParamInner, widgetParam, callback);
427 }
428 
BeginWidgetAuth(int32_t apiVersion,const WidgetAuthParam & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)429 uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const WidgetAuthParam &authParam,
430     const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
431 {
432     IAM_LOGI("start, apiVersion:%{public}d authTypeSize:%{public}zu authTrustLevel:%{public}u",
433         apiVersion, authParam.authTypes.size(), authParam.authTrustLevel);
434 
435     AuthParamInner authParamInner = {
436         .isUserIdSpecified = false,
437         .challenge = authParam.challenge,
438         .authTypes = authParam.authTypes,
439         .authTrustLevel = authParam.authTrustLevel,
440         .reuseUnlockResult = authParam.reuseUnlockResult,
441     };
442     return BeginWidgetAuthInner(apiVersion, authParamInner, widgetParam, callback);
443 }
444 
BeginWidgetAuthInner(int32_t apiVersion,const AuthParamInner & authParam,const WidgetParam & widgetParam,const std::shared_ptr<AuthenticationCallback> & callback)445 uint64_t UserAuthClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
446     const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback)
447 {
448     if (!callback) {
449         IAM_LOGE("auth callback is nullptr");
450         return BAD_CONTEXT_ID;
451     }
452     auto proxy = GetProxy();
453     if (!proxy) {
454         IAM_LOGE("proxy is nullptr");
455         Attributes extraInfo;
456         callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
457         return BAD_CONTEXT_ID;
458     }
459 
460     sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
461     if (wrapper == nullptr) {
462         IAM_LOGE("failed to create wrapper");
463         Attributes extraInfo;
464         callback->OnResult(static_cast<int32_t>(ResultCode::GENERAL_ERROR), extraInfo);
465         return BAD_CONTEXT_ID;
466     }
467     return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper);
468 }
469 
SetWidgetCallback(int32_t version,const std::shared_ptr<IUserAuthWidgetCallback> & callback)470 int32_t UserAuthClientImpl::SetWidgetCallback(int32_t version, const std::shared_ptr<IUserAuthWidgetCallback> &callback)
471 {
472     IAM_LOGI("start, version:%{public}d", version);
473     if (!callback) {
474         IAM_LOGE("widget callback is nullptr");
475         return GENERAL_ERROR;
476     }
477     auto proxy = GetProxy();
478     if (!proxy) {
479         IAM_LOGE("proxy is nullptr");
480         return GENERAL_ERROR;
481     }
482 
483     sptr<WidgetCallbackInterface> wrapper(new (std::nothrow) WidgetCallbackService(callback));
484     if (wrapper == nullptr) {
485         IAM_LOGE("failed to create wrapper");
486         return GENERAL_ERROR;
487     }
488     return proxy->RegisterWidgetCallback(version, wrapper);
489 }
490 
Notice(NoticeType noticeType,const std::string & eventData)491 int32_t UserAuthClientImpl::Notice(NoticeType noticeType, const std::string &eventData)
492 {
493     IAM_LOGI("start, noticeType:%{public}d", noticeType);
494     auto proxy = GetProxy();
495     if (!proxy) {
496         IAM_LOGE("proxy is nullptr");
497         return GENERAL_ERROR;
498     }
499     IAM_LOGI("UserAuthClientImpl::Notice noticeType:%{public}d, eventDat:%{public}s",
500         static_cast<int32_t>(noticeType), eventData.c_str());
501     return proxy->Notice(noticeType, eventData);
502 }
503 
GetEnrolledState(int32_t apiVersion,AuthType authType,EnrolledState & enrolledState)504 int32_t UserAuthClientImpl::GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState)
505 {
506     IAM_LOGI("start, apiVersion:%{public}d authType:%{public}d ", apiVersion, authType);
507     auto proxy = GetProxy();
508     if (!proxy) {
509         IAM_LOGE("proxy is nullptr");
510         return GENERAL_ERROR;
511     }
512     int32_t ret = proxy->GetEnrolledState(apiVersion, authType, enrolledState);
513     if (ret != SUCCESS) {
514         IAM_LOGE("proxy GetEnrolledState failed");
515         return ret;
516     }
517     return ret;
518 }
519 
RegistUserAuthSuccessEventListener(const std::vector<AuthType> & authType,const sptr<AuthEventListenerInterface> & listener)520 int32_t UserAuthClientImpl::RegistUserAuthSuccessEventListener(const std::vector<AuthType> &authType,
521     const sptr<AuthEventListenerInterface> &listener)
522 {
523     IAM_LOGI("start");
524     if (!listener) {
525         IAM_LOGE("listener is nullptr");
526         return GENERAL_ERROR;
527     }
528 
529     auto proxy = GetProxy();
530     if (!proxy) {
531         IAM_LOGE("proxy is nullptr");
532         return GENERAL_ERROR;
533     }
534 
535     int32_t ret = proxy->RegistUserAuthSuccessEventListener(authType, listener);
536     if (ret != SUCCESS) {
537         IAM_LOGE("Regist userAuth success event listener failed");
538         return ret;
539     }
540 
541     return SUCCESS;
542 }
543 
UnRegistUserAuthSuccessEventListener(const sptr<AuthEventListenerInterface> & listener)544 int32_t UserAuthClientImpl::UnRegistUserAuthSuccessEventListener(const sptr<AuthEventListenerInterface> &listener)
545 {
546     IAM_LOGI("start");
547     if (!listener) {
548         IAM_LOGE("listener is nullptr");
549         return GENERAL_ERROR;
550     }
551 
552     auto proxy = GetProxy();
553     if (!proxy) {
554         IAM_LOGE("proxy is nullptr");
555         return GENERAL_ERROR;
556     }
557 
558     int32_t ret = proxy->UnRegistUserAuthSuccessEventListener(listener);
559     if (ret != SUCCESS) {
560         IAM_LOGE("unRegist userAuth success event listener failed");
561         return ret;
562     }
563 
564     return SUCCESS;
565 }
566 
PrepareRemoteAuth(const std::string & networkId,const std::shared_ptr<PrepareRemoteAuthCallback> & callback)567 int32_t UserAuthClientImpl::PrepareRemoteAuth(const std::string &networkId,
568     const std::shared_ptr<PrepareRemoteAuthCallback> &callback)
569 {
570     IAM_LOGI("start");
571     if (!callback) {
572         IAM_LOGE("prepare remote auth callback is nullptr");
573         return GENERAL_ERROR;
574     }
575 
576     auto proxy = GetProxy();
577     if (!proxy) {
578         IAM_LOGE("proxy is nullptr");
579         callback->OnResult(GENERAL_ERROR);
580         return GENERAL_ERROR;
581     }
582 
583     sptr<UserAuthCallbackInterface> wrapper(new (std::nothrow) UserAuthCallbackService(callback));
584     if (wrapper == nullptr) {
585         IAM_LOGE("failed to create wrapper");
586         callback->OnResult(GENERAL_ERROR);
587         return GENERAL_ERROR;
588     }
589 
590     return proxy->PrepareRemoteAuth(networkId, wrapper);
591 }
592 } // namespace UserAuth
593 } // namespace UserIam
594 } // namespace OHOS
595