• 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_idm_callback_service.h"
17 
18 #include "iam_logger.h"
19 #include "iam_ptr.h"
20 
21 #define LOG_LABEL UserIam::Common::LABEL_USER_IDM_SDK
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
IdmCallbackService(const std::shared_ptr<UserIdmClientCallback> & impl)26 IdmCallbackService::IdmCallbackService(const std::shared_ptr<UserIdmClientCallback> &impl)
27     : idmClientCallback_(impl),
28     iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("IDM InnerKit"))
29 {
30 }
31 
OnResult(int32_t result,const Attributes & extraInfo)32 void IdmCallbackService::OnResult(int32_t result, const Attributes &extraInfo)
33 {
34     iamHitraceHelper_ = nullptr;
35     if (idmClientCallback_ == nullptr) {
36         IAM_LOGE("idm client callback is nullptr");
37         return;
38     }
39     idmClientCallback_->OnResult(result, extraInfo);
40 }
41 
OnAcquireInfo(int32_t module,int32_t acquireInfo,const Attributes & extraInfo)42 void IdmCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)
43 {
44     if (idmClientCallback_ == nullptr) {
45         IAM_LOGE("idm client callback is nullptr");
46         return;
47     }
48     idmClientCallback_->OnAcquireInfo(module, static_cast<uint32_t>(acquireInfo), extraInfo);
49 }
50 
IdmGetCredInfoCallbackService(const std::shared_ptr<GetCredentialInfoCallback> & impl)51 IdmGetCredInfoCallbackService::IdmGetCredInfoCallbackService(
52     const std::shared_ptr<GetCredentialInfoCallback> &impl) : getCredInfoCallback_(impl)
53 {
54 }
55 
OnCredentialInfos(const std::vector<std::shared_ptr<CredentialInfo>> infoList,const std::optional<PinSubType> pinSubType)56 void IdmGetCredInfoCallbackService::OnCredentialInfos(const std::vector<std::shared_ptr<CredentialInfo>> infoList,
57     const std::optional<PinSubType> pinSubType)
58 {
59     if (getCredInfoCallback_ == nullptr) {
60         IAM_LOGE("getCredInfoCallback is nullptr");
61         return;
62     }
63 
64     std::vector<UserAuth::CredentialInfo> credInfoList;
65     for (const auto &it : infoList) {
66         if (it == nullptr) {
67             continue;
68         }
69         UserAuth::CredentialInfo info = {};
70         info.credentialId = it->GetCredentialId();
71         info.templateId = it->GetTemplateId();
72         info.authType = it->GetAuthType();
73         if (info.authType == PIN && pinSubType.has_value()) {
74             info.pinType = pinSubType;
75         }
76         credInfoList.push_back(info);
77     }
78     getCredInfoCallback_->OnCredentialInfo(credInfoList);
79 }
80 
IdmGetSecureUserInfoCallbackService(const std::shared_ptr<GetSecUserInfoCallback> & impl)81 IdmGetSecureUserInfoCallbackService::IdmGetSecureUserInfoCallbackService(
82     const std::shared_ptr<GetSecUserInfoCallback> &impl) : getSecInfoCallback_(impl)
83 {
84 }
85 
OnSecureUserInfo(const std::shared_ptr<SecureUserInfo> info)86 void IdmGetSecureUserInfoCallbackService::OnSecureUserInfo(const std::shared_ptr<SecureUserInfo> info)
87 {
88     if (info == nullptr) {
89         IAM_LOGE("secure user info is nullptr");
90         return;
91     }
92     SecUserInfo secUserInfo = {};
93     secUserInfo.secureUid = info->GetSecUserId();
94     getSecInfoCallback_->OnSecUserInfo(secUserInfo);
95 }
96 } // namespace UserAuth
97 } // namespace UserIam
98 } // namespace OHOS