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 "account_iam_client_callback_proxy.h"
17
18 #include "account_log_wrapper.h"
19
20 namespace OHOS {
21 namespace AccountSA {
SendRequestFunc(const sptr<IRemoteObject> & remote,uint32_t code,MessageParcel & data,MessageParcel & reply)22 static ErrCode SendRequestFunc(
23 const sptr<IRemoteObject> &remote, uint32_t code, MessageParcel &data, MessageParcel &reply)
24 {
25 ACCOUNT_LOGI("send request, code = %{public}d", code);
26 if (remote == nullptr) {
27 ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
28 return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
29 }
30 MessageOption option(MessageOption::TF_SYNC);
31 int32_t result = remote->SendRequest(code, data, reply, option);
32 if (result != ERR_OK) {
33 ACCOUNT_LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
34 return result;
35 }
36 return ERR_OK;
37 }
38
OnResultFunc(const sptr<IRemoteObject> & remote,uint32_t code,std::u16string descriptor,int32_t result,const Attributes & extraInfo)39 static void OnResultFunc(const sptr<IRemoteObject> &remote, uint32_t code, std::u16string descriptor,
40 int32_t result, const Attributes &extraInfo)
41 {
42 MessageParcel data;
43 MessageParcel reply;
44 if (!data.WriteInterfaceToken(descriptor)) {
45 ACCOUNT_LOGE("write descriptor fail");
46 return;
47 }
48 if (!data.WriteInt32(result)) {
49 ACCOUNT_LOGE("write result fail");
50 return;
51 }
52 auto buffer = extraInfo.Serialize();
53 if (!data.WriteUInt8Vector(buffer)) {
54 ACCOUNT_LOGE("write buffer fail");
55 return;
56 }
57 SendRequestFunc(remote, code, data, reply);
58 }
59
IDMCallbackProxy(const sptr<IRemoteObject> & object)60 IDMCallbackProxy::IDMCallbackProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IIDMCallback>(object)
61 {}
62
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)63 void IDMCallbackProxy::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
64 {
65 MessageParcel data;
66 MessageParcel reply;
67 if (!data.WriteInterfaceToken(GetDescriptor())) {
68 ACCOUNT_LOGE("write descriptor fail");
69 return;
70 }
71 if (!data.WriteInt32(module)) {
72 ACCOUNT_LOGE("write module fail");
73 return;
74 }
75 if (!data.WriteUint32(acquireInfo)) {
76 ACCOUNT_LOGE("write acquireInfo fail");
77 return;
78 }
79 auto buffer = extraInfo.Serialize();
80 if (!data.WriteUInt8Vector(buffer)) {
81 ACCOUNT_LOGE("write buffer fail");
82 return;
83 }
84 uint32_t code = static_cast<uint32_t>(IDMCallbackInterfaceCode::ON_ACQUIRE_INFO);
85 SendRequestFunc(Remote(), code, data, reply);
86 }
87
OnResult(int32_t result,const Attributes & extraInfo)88 void IDMCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo)
89 {
90 uint32_t code = static_cast<uint32_t>(IDMCallbackInterfaceCode::ON_RESULT);
91 OnResultFunc(Remote(), code, GetDescriptor(), result, extraInfo);
92 }
93
GetCredInfoCallbackProxy(const sptr<IRemoteObject> & object)94 GetCredInfoCallbackProxy::GetCredInfoCallbackProxy(const sptr<IRemoteObject> &object)
95 : IRemoteProxy<IGetCredInfoCallback>(object)
96 {}
97
OnCredentialInfo(const std::vector<CredentialInfo> & infoList)98 void GetCredInfoCallbackProxy::OnCredentialInfo(const std::vector<CredentialInfo> &infoList)
99 {
100 MessageParcel data;
101 MessageParcel reply;
102 if (!data.WriteInterfaceToken(GetDescriptor())) {
103 ACCOUNT_LOGE("write descriptor fail");
104 return;
105 }
106 if (!data.WriteUint32(infoList.size())) {
107 ACCOUNT_LOGE("write info size fail");
108 return;
109 }
110 for (const auto &info : infoList) {
111 if (!data.WriteUint64(info.credentialId)) {
112 ACCOUNT_LOGE("write credentialId fail");
113 return;
114 }
115 if (!data.WriteInt32(info.authType)) {
116 ACCOUNT_LOGE("write authType fail");
117 return;
118 }
119 PinSubType pinType = info.pinType.value_or(PinSubType::PIN_MAX);
120 if (!data.WriteInt32(pinType)) {
121 ACCOUNT_LOGE("write authSubType fail");
122 return;
123 }
124 if (!data.WriteUint64(info.templateId)) {
125 ACCOUNT_LOGE("write templateId fail");
126 return;
127 }
128 }
129 uint32_t code = static_cast<uint32_t>(GetCredInfoCallbackInterfaceCode::ON_CREDENTIAL_INFO);
130 SendRequestFunc(Remote(), code, data, reply);
131 }
132
GetSetPropCallbackProxy(const sptr<IRemoteObject> & object)133 GetSetPropCallbackProxy::GetSetPropCallbackProxy(const sptr<IRemoteObject> &object)
134 : IRemoteProxy<IGetSetPropCallback>(object)
135 {}
136
OnResult(int32_t result,const Attributes & extraInfo)137 void GetSetPropCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo)
138 {
139 uint32_t code = static_cast<uint32_t>(GetSetPropCallbackInterfaceCode::ON_RESULT);
140 OnResultFunc(Remote(), code, GetDescriptor(), result, extraInfo);
141 }
142
GetEnrolledIdCallbackProxy(const sptr<IRemoteObject> & object)143 GetEnrolledIdCallbackProxy::GetEnrolledIdCallbackProxy(const sptr<IRemoteObject> &object)
144 : IRemoteProxy<IGetEnrolledIdCallback>(object)
145 {}
146
OnEnrolledId(int32_t result,uint64_t enrolledId)147 void GetEnrolledIdCallbackProxy::OnEnrolledId(int32_t result, uint64_t enrolledId)
148 {
149 MessageParcel data;
150 MessageParcel reply;
151 if (!data.WriteInterfaceToken(GetDescriptor())) {
152 ACCOUNT_LOGE("Write descriptor fail");
153 return;
154 }
155 if (!data.WriteInt32(result)) {
156 ACCOUNT_LOGE("Write result fail");
157 return;
158 }
159 if (!data.WriteUint64(enrolledId)) {
160 ACCOUNT_LOGE("Write enrolledId fail");
161 return;
162 }
163 uint32_t code = static_cast<uint32_t>(GetEnrolledIdCallbackInterfaceCode::ON_ENROLLED_ID);
164 SendRequestFunc(Remote(), code, data, reply);
165 }
166
PreRemoteAuthCallbackProxy(const sptr<IRemoteObject> & object)167 PreRemoteAuthCallbackProxy::PreRemoteAuthCallbackProxy(const sptr<IRemoteObject> &object)
168 : IRemoteProxy<IPreRemoteAuthCallback>(object)
169 {}
170
OnResult(int32_t result)171 void PreRemoteAuthCallbackProxy::OnResult(int32_t result)
172 {
173 uint32_t code = static_cast<uint32_t>(PreRemoteAuthCallbackInterfaceCode::ON_RESULT);
174 MessageParcel data;
175 MessageParcel reply;
176 if (!data.WriteInterfaceToken(GetDescriptor())) {
177 ACCOUNT_LOGE("Write descriptor failed.");
178 return;
179 }
180 if (!data.WriteInt32(result)) {
181 ACCOUNT_LOGE("Write result failed.");
182 return;
183 }
184 SendRequestFunc(Remote(), code, data, reply);
185 }
186 } // namespace AccountSA
187 } // namespace OHOS
188