• 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 "useridm_getinfo_callback_stub.h"
17 #include <message_parcel.h>
18 #include "useridm_hilog_wrapper.h"
19 
20 namespace OHOS {
21 namespace UserIAM {
22 namespace UserIDM {
UserIDMGetInfoCallbackStub(const std::shared_ptr<GetInfoCallback> & impl)23 UserIDMGetInfoCallbackStub::UserIDMGetInfoCallbackStub(const std::shared_ptr<GetInfoCallback>& impl)
24 {
25     callback_ = impl;
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t UserIDMGetInfoCallbackStub::OnRemoteRequest(uint32_t code,
29     MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     USERIDM_HILOGI(MODULE_CLIENT, "UserIDMGetInfoCallbackStub::OnRemoteRequest, cmd = %{public}u, flags= %d",
32         code, option.GetFlags());
33 
34     if (UserIDMGetInfoCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
35         USERIDM_HILOGE(MODULE_CLIENT,
36             "UserIDMGetInfoCallbackStub::OnRemoteRequest failed, descriptor is not matched!");
37         return FAIL;
38     }
39 
40     switch (code) {
41         case static_cast<int32_t>(IGetInfoCallback::ON_GET_INFO):
42             return OnGetInfoStub(data, reply);
43         default:
44             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45     }
46 }
47 
OnGetInfoStub(MessageParcel & data,MessageParcel & reply)48 int32_t UserIDMGetInfoCallbackStub::OnGetInfoStub(MessageParcel& data, MessageParcel& reply)
49 {
50     USERIDM_HILOGI(MODULE_CLIENT, "UserIDMGetInfoCallbackStub OnGetInfoStub start");
51     uint32_t vectorSize = 0;
52     std::vector<CredentialInfo> credInfos;
53     if (!data.ReadUint32(vectorSize)) {
54         USERIDM_HILOGE(MODULE_CLIENT, "read size fail");
55         OnGetInfo(credInfos);
56         return FAIL;
57     }
58     for (uint32_t i = 0; i < vectorSize; i++) {
59         CredentialInfo info;
60         if (!data.ReadUint64(info.credentialId)) {
61             USERIDM_HILOGE(MODULE_CLIENT, "read credential id fail");
62             OnGetInfo(credInfos);
63             return FAIL;
64         }
65         uint32_t authType = 0;
66         if (!data.ReadUint32(authType)) {
67             USERIDM_HILOGE(MODULE_CLIENT, "read type fail");
68             OnGetInfo(credInfos);
69             return FAIL;
70         }
71         info.authType = static_cast<AuthType>(authType);
72         uint64_t authSubType = 0;
73         if (!data.ReadUint64(authSubType)) {
74             USERIDM_HILOGE(MODULE_CLIENT, "read subtype fail");
75             OnGetInfo(credInfos);
76             return FAIL;
77         }
78         info.authSubType = static_cast<AuthSubType>(authSubType);
79         if (!data.ReadUint64(info.templateId)) {
80             USERIDM_HILOGE(MODULE_CLIENT, "read template id fail");
81             OnGetInfo(credInfos);
82             return FAIL;
83         }
84         credInfos.push_back(info);
85     }
86     OnGetInfo(credInfos);
87     if (!reply.WriteInt32(SUCCESS)) {
88         USERIDM_HILOGE(MODULE_CLIENT, "write result fail");
89         return FAIL;
90     }
91     return SUCCESS;
92 }
93 
OnGetInfo(std::vector<CredentialInfo> & infos)94 void UserIDMGetInfoCallbackStub::OnGetInfo(std::vector<CredentialInfo>& infos)
95 {
96     USERIDM_HILOGI(MODULE_CLIENT, "UserIDMGetInfoCallbackStub OnGetInfo start");
97 
98     if (callback_ == nullptr) {
99         USERIDM_HILOGE(MODULE_CLIENT, "UserIDMGetInfoCallbackStub OnGetInfo callback_ is nullptr");
100         return;
101     }
102     if (infos.size() > 0) {
103         USERIDM_HILOGI(MODULE_CLIENT, "have data");
104     } else {
105         USERIDM_HILOGI(MODULE_CLIENT, "get no data");
106     }
107     // Call the NaPi interface and return the data to JS
108     callback_->OnGetInfo(infos);
109 }
110 }  // namespace UserIDM
111 }  // namespace UserIAM
112 }  // namespace OHOS
113