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_mgr_proxy.h"
17
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20
21 namespace OHOS {
22 namespace AccountSA {
AccountIAMMgrProxy(const sptr<IRemoteObject> & object)23 AccountIAMMgrProxy::AccountIAMMgrProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IAccountIAM>(object)
24 {}
25
~AccountIAMMgrProxy()26 AccountIAMMgrProxy::~AccountIAMMgrProxy()
27 {}
28
SendRequest(AccountIAMInterfaceCode code,MessageParcel & data,MessageParcel & reply)29 ErrCode AccountIAMMgrProxy::SendRequest(AccountIAMInterfaceCode code, MessageParcel &data, MessageParcel &reply)
30 {
31 ACCOUNT_LOGI("send request enter, code = %{public}d", code);
32 sptr<IRemoteObject> remote = Remote();
33 if (remote == nullptr) {
34 ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
35 return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
36 }
37 MessageOption option(MessageOption::TF_SYNC);
38 int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
39 if (result != ERR_OK) {
40 ACCOUNT_LOGE("failed to send account iam request, code = %{public}d, result = %{public}d", code, result);
41 }
42 return result;
43 }
44
WriteCommonData(MessageParcel & data,int32_t userId)45 bool AccountIAMMgrProxy::WriteCommonData(MessageParcel &data, int32_t userId)
46 {
47 if (!data.WriteInterfaceToken(GetDescriptor())) {
48 ACCOUNT_LOGE("failed to write descriptor!");
49 return false;
50 }
51 if (!data.WriteInt32(userId)) {
52 ACCOUNT_LOGE("failed to write userId!");
53 return false;
54 }
55 return true;
56 }
57
OpenSession(int32_t userId,std::vector<uint8_t> & challenge)58 int32_t AccountIAMMgrProxy::OpenSession(int32_t userId, std::vector<uint8_t> &challenge)
59 {
60 challenge.clear();
61 MessageParcel data;
62 if (!WriteCommonData(data, userId)) {
63 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
64 }
65 MessageParcel reply;
66 int32_t result = SendRequest(AccountIAMInterfaceCode::OPEN_SESSION, data, reply);
67 if (result != ERR_OK) {
68 return result;
69 }
70 if (!reply.ReadInt32(result)) {
71 ACCOUNT_LOGE("failed to read result");
72 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
73 }
74 if (result != ERR_OK) {
75 ACCOUNT_LOGE("failed to open session, result: %{public}d", result);
76 return result;
77 }
78 if (!reply.ReadUInt8Vector(&challenge)) {
79 ACCOUNT_LOGE("failed to read challenge!");
80 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
81 }
82 return ERR_OK;
83 }
84
CloseSession(int32_t userId)85 int32_t AccountIAMMgrProxy::CloseSession(int32_t userId)
86 {
87 MessageParcel data;
88 if (!WriteCommonData(data, userId)) {
89 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
90 }
91 MessageParcel reply;
92 int32_t result = SendRequest(AccountIAMInterfaceCode::CLOSE_SESSION, data, reply);
93 if (result != ERR_OK) {
94 return result;
95 }
96 if (!reply.ReadInt32(result)) {
97 ACCOUNT_LOGE("failed to read result");
98 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
99 }
100 return result;
101 }
102
AddOrUpdateCredential(int32_t userId,const CredentialParameters & credInfo,const sptr<IIDMCallback> & callback,bool isAdd)103 void AccountIAMMgrProxy::AddOrUpdateCredential(
104 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback, bool isAdd)
105 {
106 if (callback == nullptr) {
107 ACCOUNT_LOGE("callback is nullptr");
108 return;
109 }
110 Attributes emptyResult;
111 MessageParcel data;
112 if (!WriteCommonData(data, userId)) {
113 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
114 return;
115 }
116 if (!data.WriteInt32(credInfo.authType)) {
117 ACCOUNT_LOGE("failed to write authType");
118 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
119 return;
120 }
121 PinSubType pinType = credInfo.pinType.value_or(PinSubType::PIN_MAX);
122 if (!data.WriteInt32(pinType)) {
123 ACCOUNT_LOGE("failed to write pinType");
124 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
125 return;
126 }
127 if (!data.WriteUInt8Vector(credInfo.token)) {
128 ACCOUNT_LOGE("failed to write token");
129 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
130 return;
131 }
132 if (!data.WriteRemoteObject(callback->AsObject())) {
133 ACCOUNT_LOGE("failed to write callback");
134 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
135 return;
136 }
137 MessageParcel reply;
138 int32_t result;
139 if (isAdd) {
140 result = SendRequest(AccountIAMInterfaceCode::ADD_CREDENTIAL, data, reply);
141 } else {
142 result = SendRequest(AccountIAMInterfaceCode::UPDATE_CREDENTIAL, data, reply);
143 }
144 if (result != ERR_OK) {
145 callback->OnResult(result, emptyResult);
146 }
147 }
148
AddCredential(int32_t userId,const CredentialParameters & credInfo,const sptr<IIDMCallback> & callback)149 void AccountIAMMgrProxy::AddCredential(
150 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback)
151 {
152 AddOrUpdateCredential(userId, credInfo, callback, true);
153 }
154
UpdateCredential(int32_t userId,const CredentialParameters & credInfo,const sptr<IIDMCallback> & callback)155 void AccountIAMMgrProxy::UpdateCredential(
156 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback)
157 {
158 AddOrUpdateCredential(userId, credInfo, callback, false);
159 }
160
Cancel(int32_t userId)161 int32_t AccountIAMMgrProxy::Cancel(int32_t userId)
162 {
163 MessageParcel data;
164 if (!WriteCommonData(data, userId)) {
165 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
166 }
167 MessageParcel reply;
168 int32_t result = SendRequest(AccountIAMInterfaceCode::CANCEL, data, reply);
169 if (result != ERR_OK) {
170 return result;
171 }
172 if (!reply.ReadInt32(result)) {
173 ACCOUNT_LOGE("failed to read result");
174 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
175 }
176 return result;
177 }
178
DelCred(int32_t userId,uint64_t credentialId,const std::vector<uint8_t> & authToken,const sptr<IIDMCallback> & callback)179 void AccountIAMMgrProxy::DelCred(
180 int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, const sptr<IIDMCallback> &callback)
181 {
182 if (callback == nullptr) {
183 ACCOUNT_LOGE("callback is nullptr");
184 return;
185 }
186 Attributes emptyResult;
187 MessageParcel data;
188 if (!WriteCommonData(data, userId)) {
189 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
190 return;
191 }
192 if (!data.WriteUint64(credentialId)) {
193 ACCOUNT_LOGE("failed to write userId");
194 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
195 return;
196 }
197 if (!data.WriteUInt8Vector(authToken)) {
198 ACCOUNT_LOGE("failed to write token for DelCred");
199 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
200 return;
201 }
202 if (!data.WriteRemoteObject(callback->AsObject())) {
203 ACCOUNT_LOGE("failed to write callback for DelCred");
204 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
205 return;
206 }
207 MessageParcel reply;
208 int32_t result = SendRequest(AccountIAMInterfaceCode::DEL_CRED, data, reply);
209 if (result != ERR_OK) {
210 callback->OnResult(result, emptyResult);
211 }
212 }
213
DelUser(int32_t userId,const std::vector<uint8_t> & authToken,const sptr<IIDMCallback> & callback)214 void AccountIAMMgrProxy::DelUser(
215 int32_t userId, const std::vector<uint8_t> &authToken, const sptr<IIDMCallback> &callback)
216 {
217 if (callback == nullptr) {
218 ACCOUNT_LOGE("callback is nullptr");
219 return;
220 }
221 Attributes emptyResult;
222 MessageParcel data;
223 if (!WriteCommonData(data, userId)) {
224 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
225 return;
226 }
227 if (!data.WriteUInt8Vector(authToken)) {
228 ACCOUNT_LOGE("failed to write token for DelUser");
229 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
230 return;
231 }
232 if (!data.WriteRemoteObject(callback->AsObject())) {
233 ACCOUNT_LOGE("failed to write callback for DelUser");
234 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
235 return;
236 }
237 MessageParcel reply;
238 int32_t result = SendRequest(AccountIAMInterfaceCode::DEL_USER, data, reply);
239 if (result != ERR_OK) {
240 callback->OnResult(result, emptyResult);
241 }
242 }
243
GetCredentialInfo(int32_t userId,AuthType authType,const sptr<IGetCredInfoCallback> & callback)244 int32_t AccountIAMMgrProxy::GetCredentialInfo(
245 int32_t userId, AuthType authType, const sptr<IGetCredInfoCallback> &callback)
246 {
247 if (callback == nullptr) {
248 ACCOUNT_LOGE("callback is nullptr");
249 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
250 }
251 MessageParcel data;
252 if (!WriteCommonData(data, userId)) {
253 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
254 }
255 if (!data.WriteInt32(authType)) {
256 ACCOUNT_LOGE("failed to write authType");
257 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
258 }
259 if (!data.WriteRemoteObject(callback->AsObject())) {
260 ACCOUNT_LOGE("failed to write callback");
261 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
262 }
263 MessageParcel reply;
264 int32_t result = SendRequest(AccountIAMInterfaceCode::GET_CREDENTIAL_INFO, data, reply);
265 if (result != ERR_OK) {
266 return result;
267 }
268 if (!reply.ReadInt32(result)) {
269 ACCOUNT_LOGE("failed to read result");
270 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
271 }
272 return result;
273 }
274
PrepareRemoteAuth(const std::string & remoteNetworkId,const sptr<IPreRemoteAuthCallback> & callback)275 int32_t AccountIAMMgrProxy::PrepareRemoteAuth(
276 const std::string &remoteNetworkId, const sptr<IPreRemoteAuthCallback> &callback)
277 {
278 if (callback == nullptr) {
279 ACCOUNT_LOGE("Prepare remote auth callback is nullptr.");
280 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
281 }
282 MessageParcel data;
283 if (!data.WriteInterfaceToken(GetDescriptor())) {
284 ACCOUNT_LOGE("Write descriptor failed.");
285 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR);
286 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
287 }
288 if (!data.WriteString(remoteNetworkId)) {
289 ACCOUNT_LOGE("Write remoteNetworkId failed.");
290 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR);
291 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
292 }
293 if (!data.WriteRemoteObject(callback->AsObject())) {
294 ACCOUNT_LOGE("Write callback failed.");
295 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR);
296 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
297 }
298 MessageParcel reply;
299 int32_t result = SendRequest(AccountIAMInterfaceCode::PREPARE_REMOTE_AUTH, data, reply);
300 if (result != ERR_OK) {
301 callback->OnResult(result);
302 return result;
303 }
304
305 if (!reply.ReadInt32(result)) {
306 ACCOUNT_LOGE("Read result failed.");
307 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
308 }
309 return result;
310 }
311
WriteAuthParam(MessageParcel & data,const AuthParam & authParam)312 bool AccountIAMMgrProxy::WriteAuthParam(MessageParcel &data, const AuthParam &authParam)
313 {
314 if (!WriteCommonData(data, authParam.userId)) {
315 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
316 }
317 if (!data.WriteUInt8Vector(authParam.challenge)) {
318 ACCOUNT_LOGE("failed to write challenge");
319 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
320 }
321 if (!data.WriteInt32(authParam.authType)) {
322 ACCOUNT_LOGE("failed to write authType");
323 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
324 }
325 if (!data.WriteUint32(authParam.authTrustLevel)) {
326 ACCOUNT_LOGE("failed to write authTrustLevel");
327 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
328 }
329 if (!data.WriteInt32(static_cast<int32_t>(authParam.authIntent))) {
330 ACCOUNT_LOGE("failed to write authTrustLevel");
331 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
332 }
333 return true;
334 }
335
WriteRemoteAuthParam(MessageParcel & data,const std::optional<RemoteAuthParam> & remoteAuthParam)336 bool AccountIAMMgrProxy::WriteRemoteAuthParam(MessageParcel &data,
337 const std::optional<RemoteAuthParam> &remoteAuthParam)
338 {
339 bool res = (remoteAuthParam != std::nullopt);
340 if (!data.WriteBool(res)) {
341 ACCOUNT_LOGE("Write RemoteAuthParam exist failed.");
342 return false;
343 }
344 if (!res) {
345 return true;
346 }
347 res = (remoteAuthParam.value().verifierNetworkId != std::nullopt);
348 if (!data.WriteBool(res)) {
349 ACCOUNT_LOGE("Write verifierNetworkId exist failed.");
350 return false;
351 }
352 if (res) {
353 if (!data.WriteString(remoteAuthParam.value().verifierNetworkId.value())) {
354 ACCOUNT_LOGE("Write verifierNetworkId failed.");
355 return false;
356 }
357 }
358 res = (remoteAuthParam.value().collectorNetworkId != std::nullopt);
359 if (!data.WriteBool(res)) {
360 ACCOUNT_LOGE("Write collectorNetworkId exist failed.");
361 return false;
362 }
363 if (res) {
364 if (!data.WriteString(remoteAuthParam.value().collectorNetworkId.value())) {
365 ACCOUNT_LOGE("Write collectorNetworkId failed.");
366 return false;
367 }
368 }
369 res = (remoteAuthParam.value().collectorTokenId != std::nullopt);
370 if (!data.WriteBool(res)) {
371 ACCOUNT_LOGE("Write collectorTokenId exist failed.");
372 return false;
373 }
374 if (res) {
375 if (!data.WriteUint32(remoteAuthParam.value().collectorTokenId.value())) {
376 ACCOUNT_LOGE("Write collectorTokenId failed.");
377 return false;
378 }
379 }
380 return true;
381 }
382
AuthUser(AuthParam & authParam,const sptr<IIDMCallback> & callback,uint64_t & contextId)383 ErrCode AccountIAMMgrProxy::AuthUser(
384 AuthParam &authParam, const sptr<IIDMCallback> &callback, uint64_t &contextId)
385 {
386 if (callback == nullptr) {
387 ACCOUNT_LOGE("callback is nullptr");
388 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
389 }
390 MessageParcel data;
391 if (!WriteAuthParam(data, authParam)) {
392 ACCOUNT_LOGE("failed to write authParam");
393 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
394 }
395 if (!data.WriteRemoteObject(callback->AsObject())) {
396 ACCOUNT_LOGE("failed to write callback");
397 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
398 }
399 if (!WriteRemoteAuthParam(data, authParam.remoteAuthParam)) {
400 ACCOUNT_LOGE("failed to write RemoteAuthParam");
401 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
402 }
403 MessageParcel reply;
404 ErrCode result = SendRequest(AccountIAMInterfaceCode::AUTH_USER, data, reply);
405 if (result != ERR_OK) {
406 ACCOUNT_LOGE("failed to send request, result: %{public}d", result);
407 return result;
408 }
409 if (!reply.ReadInt32(result)) {
410 ACCOUNT_LOGE("failed to read result");
411 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
412 }
413 if (!reply.ReadUint64(contextId)) {
414 ACCOUNT_LOGE("failed to read contextId");
415 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
416 }
417 return result;
418 }
419
CancelAuth(uint64_t contextId)420 int32_t AccountIAMMgrProxy::CancelAuth(uint64_t contextId)
421 {
422 MessageParcel data;
423 if (!data.WriteInterfaceToken(GetDescriptor())) {
424 ACCOUNT_LOGE("failed to write descriptor");
425 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
426 }
427 if (!data.WriteUint64(contextId)) {
428 ACCOUNT_LOGE("failed to write contextId");
429 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
430 }
431 MessageParcel reply;
432 int32_t result = SendRequest(AccountIAMInterfaceCode::CANCEL_AUTH, data, reply);
433 if (result != ERR_OK) {
434 return result;
435 }
436 if (!reply.ReadInt32(result)) {
437 ACCOUNT_LOGE("failed to read result");
438 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
439 }
440 return result;
441 }
442
GetAvailableStatus(const AuthType authType,const AuthTrustLevel authTrustLevel,int32_t & status)443 int32_t AccountIAMMgrProxy::GetAvailableStatus(const AuthType authType, const AuthTrustLevel authTrustLevel,
444 int32_t &status)
445 {
446 MessageParcel data;
447 if (!data.WriteInterfaceToken(GetDescriptor())) {
448 ACCOUNT_LOGE("failed to write descriptor");
449 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
450 }
451 if (!data.WriteInt32(authType)) {
452 ACCOUNT_LOGE("failed to write authType");
453 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
454 }
455 if (!data.WriteUint32(authTrustLevel)) {
456 ACCOUNT_LOGE("failed to write authTrustLevel");
457 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
458 }
459 MessageParcel reply;
460 int32_t res = SendRequest(AccountIAMInterfaceCode::GET_AVAILABLE_STATUS, data, reply);
461 if (res != ERR_OK) {
462 return res;
463 }
464 if (!reply.ReadInt32(res)) {
465 ACCOUNT_LOGE("failed to read result");
466 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
467 }
468 if (res != ERR_OK) {
469 ACCOUNT_LOGE("failed to get available status, result: %{public}d", res);
470 return res;
471 }
472 if (!reply.ReadInt32(status)) {
473 ACCOUNT_LOGE("failed to read status");
474 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
475 }
476 return ERR_OK;
477 }
478
GetProperty(int32_t userId,const GetPropertyRequest & request,const sptr<IGetSetPropCallback> & callback)479 void AccountIAMMgrProxy::GetProperty(
480 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback)
481 {
482 if (callback == nullptr) {
483 ACCOUNT_LOGE("get property callback is nullptr");
484 return;
485 }
486 Attributes emptyResult;
487 MessageParcel data;
488 if (!WriteCommonData(data, userId)) {
489 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
490 return;
491 }
492 if (!data.WriteInt32(request.authType)) {
493 ACCOUNT_LOGE("failed to write authType for GetProperty");
494 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
495 return;
496 }
497 std::vector<uint32_t> attrKeys;
498 std::transform(request.keys.begin(), request.keys.end(), std::back_inserter(attrKeys),
499 [](const auto &key) { return static_cast<uint32_t>(key); });
500
501 if (!data.WriteUInt32Vector(attrKeys)) {
502 ACCOUNT_LOGE("failed to write keys");
503 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
504 return;
505 }
506 if (!data.WriteRemoteObject(callback->AsObject())) {
507 ACCOUNT_LOGE("failed to write callback");
508 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
509 return;
510 }
511 MessageParcel reply;
512 int32_t result = SendRequest(AccountIAMInterfaceCode::GET_PROPERTY, data, reply);
513 if (result != ERR_OK) {
514 callback->OnResult(result, emptyResult);
515 }
516 }
517
SetProperty(int32_t userId,const SetPropertyRequest & request,const sptr<IGetSetPropCallback> & callback)518 void AccountIAMMgrProxy::SetProperty(
519 int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback)
520 {
521 if (callback == nullptr) {
522 ACCOUNT_LOGE("set property callback is nullptr");
523 return;
524 }
525 Attributes emptyResult;
526 MessageParcel data;
527 if (!WriteCommonData(data, userId)) {
528 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
529 return;
530 }
531 if (!data.WriteInt32(request.authType)) {
532 ACCOUNT_LOGE("failed to write authType for SetProperty");
533 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
534 return;
535 }
536 auto buffer = request.attrs.Serialize();
537 if (!data.WriteUInt8Vector(buffer)) {
538 ACCOUNT_LOGE("failed to write attributes");
539 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
540 return;
541 }
542 if (!data.WriteRemoteObject(callback->AsObject())) {
543 ACCOUNT_LOGE("failed to write callback");
544 callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
545 return;
546 }
547 MessageParcel reply;
548 int32_t result = SendRequest(AccountIAMInterfaceCode::SET_PROPERTY, data, reply);
549 if (result != ERR_OK) {
550 callback->OnResult(result, emptyResult);
551 }
552 }
553
GetEnrolledId(int32_t accountId,AuthType authType,const sptr<IGetEnrolledIdCallback> & callback)554 void AccountIAMMgrProxy::GetEnrolledId(
555 int32_t accountId, AuthType authType, const sptr<IGetEnrolledIdCallback> &callback)
556 {
557 if (callback == nullptr) {
558 ACCOUNT_LOGE("Callback is nullptr");
559 return;
560 }
561 uint64_t emptyResult = 0;
562 MessageParcel data;
563 if (!WriteCommonData(data, accountId)) {
564 callback->OnEnrolledId(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
565 return;
566 }
567 if (!data.WriteInt32(authType)) {
568 ACCOUNT_LOGE("Failed to write authType");
569 callback->OnEnrolledId(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
570 return;
571 }
572 if (!data.WriteRemoteObject(callback->AsObject())) {
573 ACCOUNT_LOGE("Failed to write callback");
574 callback->OnEnrolledId(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyResult);
575 return;
576 }
577 MessageParcel reply;
578 int32_t result = SendRequest(AccountIAMInterfaceCode::GET_ENROLLED_ID, data, reply);
579 if (result != ERR_OK) {
580 callback->OnEnrolledId(result, emptyResult);
581 }
582 }
583
GetAccountState(int32_t userId)584 IAMState AccountIAMMgrProxy::GetAccountState(int32_t userId)
585 {
586 IAMState defaultState = IDLE;
587 MessageParcel data;
588 if (!WriteCommonData(data, userId)) {
589 return defaultState;
590 }
591 MessageParcel reply;
592 SendRequest(AccountIAMInterfaceCode::GET_ACCOUNT_STATE, data, reply);
593 int32_t state = defaultState;
594 if (!reply.ReadInt32(state)) {
595 ACCOUNT_LOGE("failed to read state");
596 }
597 return static_cast<IAMState>(state);
598 }
599 } // namespace AccountSA
600 } // namespace OHOS
601