• 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 "user_auth_callback_service.h"
17 
18 #include "iam_logger.h"
19 #include "iam_ptr.h"
20 
21 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SDK
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
UserAuthCallbackService(const std::shared_ptr<AuthenticationCallback> & impl)26 UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr<AuthenticationCallback> &impl)
27     : authCallback_(impl),
28     iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
29 {
30 }
31 
UserAuthCallbackService(const std::shared_ptr<IdentificationCallback> & impl)32 UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr<IdentificationCallback> &impl)
33     : identifyCallback_(impl),
34     iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuth InnerKit"))
35 {
36 }
37 
OnResult(int32_t result,const Attributes & extraInfo)38 void UserAuthCallbackService::OnResult(int32_t result, const Attributes &extraInfo)
39 {
40     if (authCallback_ != nullptr) {
41         authCallback_->OnResult(result, extraInfo);
42     } else if (identifyCallback_ != nullptr) {
43         identifyCallback_->OnResult(result, extraInfo);
44     } else {
45         IAM_LOGE("both auth and identify callback is nullptr");
46         return;
47     }
48     iamHitraceHelper_= nullptr;
49 }
50 
OnAcquireInfo(int32_t module,int32_t acquireInfo,const Attributes & extraInfo)51 void UserAuthCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)
52 {
53     if (authCallback_ != nullptr) {
54         authCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
55     } else if (identifyCallback_ != nullptr) {
56         identifyCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
57     } else {
58         IAM_LOGE("both auth and identify callback is nullptr");
59         return;
60     }
61 }
62 
GetExecutorPropertyCallbackService(const std::shared_ptr<GetPropCallback> & impl)63 GetExecutorPropertyCallbackService::GetExecutorPropertyCallbackService(const std::shared_ptr<GetPropCallback> &impl)
64     : getPropCallback_(impl)
65 {
66 }
67 
OnGetExecutorPropertyResult(int32_t result,const Attributes & attributes)68 void GetExecutorPropertyCallbackService::OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes)
69 {
70     if (getPropCallback_ == nullptr) {
71         IAM_LOGE("get prop callback is nullptr");
72         return;
73     }
74     getPropCallback_->OnResult(result, attributes);
75 }
76 
SetExecutorPropertyCallbackService(const std::shared_ptr<SetPropCallback> & impl)77 SetExecutorPropertyCallbackService::SetExecutorPropertyCallbackService(const std::shared_ptr<SetPropCallback> &impl)
78     : setPropCallback_(impl)
79 {
80 }
81 
OnSetExecutorPropertyResult(int32_t result)82 void SetExecutorPropertyCallbackService::OnSetExecutorPropertyResult(int32_t result)
83 {
84     if (setPropCallback_ == nullptr) {
85         IAM_LOGE("set prop callback is nullptr");
86         return;
87     }
88     Attributes attr;
89     setPropCallback_->OnResult(result, attr);
90 }
91 } // namespace UserAuth
92 } // namespace UserIam
93 } // namespace OHOS