1 /*
2 * Copyright (c) 2021-2023 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 #include "os_account_stub.h"
16 #include "account_log_wrapper.h"
17 #include "account_permission_manager.h"
18 #include "account_constants.h"
19 #include "idomain_account_callback.h"
20 #include "ipc_skeleton.h"
21 #include "memory_guard.h"
22 #ifdef HICOLLIE_ENABLE
23 #include "xcollie/xcollie.h"
24 #endif // HICOLLIE_ENABLE
25 namespace OHOS {
26 namespace AccountSA {
27 const std::map<uint32_t, OsAccountStub::OsAccountMessageProc> messageProcMap = {
28 {
29 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT),
30 {
31 .messageProcFunction = &OsAccountStub::ProcCreateOsAccount,
32 .isSyetemApi = true,
33 }
34 },
35 {
36 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN),
37 {
38 .messageProcFunction = &OsAccountStub::ProcCreateOsAccountForDomain,
39 .isSyetemApi = true,
40 }
41 },
42 {
43 static_cast<uint32_t>(OsAccountInterfaceCode::REMOVE_OS_ACCOUNT),
44 {
45 .messageProcFunction = &OsAccountStub::ProcRemoveOsAccount,
46 .isSyetemApi = true,
47 }
48 },
49 {
50 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_EXISTS),
51 {
52 .messageProcFunction = &OsAccountStub::ProcIsOsAccountExists,
53 }
54 },
55 {
56 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_ACTIVED),
57 {
58 .messageProcFunction = &OsAccountStub::ProcIsOsAccountActived,
59 }
60 },
61 {
62 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE),
63 {
64 .messageProcFunction = &OsAccountStub::ProcIsOsAccountConstraintEnable,
65 }
66 },
67 {
68 static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED),
69 {
70 .messageProcFunction = &OsAccountStub::ProcCheckOsAccountConstraintEnabled,
71 }
72 },
73 {
74 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_VERIFIED),
75 {
76 .messageProcFunction = &OsAccountStub::ProcIsOsAccountVerified,
77 }
78 },
79 {
80 static_cast<uint32_t>(OsAccountInterfaceCode::GET_CREATED_OS_ACCOUNT_COUNT),
81 {
82 .messageProcFunction = &OsAccountStub::ProcGetCreatedOsAccountsCount,
83 }
84 },
85 {
86 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FROM_PROCESS),
87 {
88 .messageProcFunction = &OsAccountStub::ProcGetOsAccountLocalIdFromProcess,
89 }
90 },
91 {
92 static_cast<uint32_t>(OsAccountInterfaceCode::IS_MAIN_OS_ACCOUNT),
93 {
94 .messageProcFunction = &OsAccountStub::ProcIsMainOsAccount,
95 .isSyetemApi = true,
96 }
97 },
98 {
99 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FROM_DOMAIN),
100 {
101 .messageProcFunction = &OsAccountStub::ProcGetOsAccountLocalIdFromDomain,
102 }
103 },
104 {
105 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_MAX_OS_ACCOUNT_NUMBER),
106 {
107 .messageProcFunction = &OsAccountStub::ProcQueryMaxOsAccountNumber,
108 .isSyetemApi = true,
109 }
110 },
111 {
112 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_ALL_CONSTRAINTS),
113 {
114 .messageProcFunction = &OsAccountStub::ProcGetOsAccountAllConstraints,
115 }
116 },
117 {
118 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_ALL_CREATED_OS_ACCOUNTS),
119 {
120 .messageProcFunction = &OsAccountStub::ProcQueryAllCreatedOsAccounts,
121 .isSyetemApi = true,
122 }
123 },
124 {
125 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_CURRENT_OS_ACCOUNT),
126 {
127 .messageProcFunction = &OsAccountStub::ProcQueryCurrentOsAccount,
128 }
129 },
130 {
131 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_OS_ACCOUNT_BY_ID),
132 {
133 .messageProcFunction = &OsAccountStub::ProcQueryOsAccountById,
134 .isSyetemApi = true,
135 }
136 },
137 {
138 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_TYPE_FROM_PROCESS),
139 {
140 .messageProcFunction = &OsAccountStub::ProcGetOsAccountTypeFromProcess,
141 }
142 },
143 {
144 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_PROFILE_PHOTO),
145 {
146 .messageProcFunction = &OsAccountStub::ProcGetOsAccountProfilePhoto,
147 .isSyetemApi = true,
148 }
149 },
150 {
151 static_cast<uint32_t>(OsAccountInterfaceCode::IS_MULTI_OS_ACCOUNT_ENABLE),
152 {
153 .messageProcFunction = &OsAccountStub::ProcIsMultiOsAccountEnable,
154 }
155 },
156 {
157 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_NAME),
158 {
159 .messageProcFunction = &OsAccountStub::ProcSetOsAccountName,
160 .isSyetemApi = true,
161 }
162 },
163 {
164 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_CONSTRAINTS),
165 {
166 .messageProcFunction = &OsAccountStub::ProcSetOsAccountConstraints,
167 .isSyetemApi = true,
168 }
169 },
170 {
171 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_PROFILE_PHOTO),
172 {
173 .messageProcFunction = &OsAccountStub::ProcSetOsAccountProfilePhoto,
174 .isSyetemApi = true,
175 }
176 },
177 {
178 static_cast<uint32_t>(OsAccountInterfaceCode::ACTIVATE_OS_ACCOUNT),
179 {
180 .messageProcFunction = &OsAccountStub::ProcActivateOsAccount,
181 .isSyetemApi = true,
182 }
183 },
184 {
185 static_cast<uint32_t>(OsAccountInterfaceCode::START_OS_ACCOUNT),
186 {
187 .messageProcFunction = &OsAccountStub::ProcStartOsAccount,
188 }
189 },
190 {
191 static_cast<uint32_t>(OsAccountInterfaceCode::STOP_OS_ACCOUNT),
192 {
193 .messageProcFunction = &OsAccountStub::ProcStopOsAccount,
194 }
195 },
196 {
197 static_cast<uint32_t>(OsAccountInterfaceCode::SUBSCRIBE_OS_ACCOUNT),
198 {
199 .messageProcFunction = &OsAccountStub::ProcSubscribeOsAccount,
200 .isSyetemApi = true,
201 }
202 },
203 {
204 static_cast<uint32_t>(OsAccountInterfaceCode::UNSUBSCRIBE_OS_ACCOUNT),
205 {
206 .messageProcFunction = &OsAccountStub::ProcUnsubscribeOsAccount,
207 .isSyetemApi = true,
208 }
209 },
210 {
211 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FOR_SERIAL_NUMBER),
212 {
213 .messageProcFunction = &OsAccountStub::ProcGetOsAccountLocalIdBySerialNumber,
214 }
215 },
216 {
217 static_cast<uint32_t>(OsAccountInterfaceCode::GET_SERIAL_NUMBER_FOR_OS_ACCOUNT),
218 {
219 .messageProcFunction = &OsAccountStub::ProcGetSerialNumberByOsAccountLocalId,
220 }
221 },
222 {
223 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_SWITCH_MOD),
224 {
225 .messageProcFunction = &OsAccountStub::ProcGetOsAccountSwitchMod,
226 }
227 },
228 {
229 static_cast<uint32_t>(OsAccountInterfaceCode::IS_CURRENT_OS_ACCOUNT_VERIFIED),
230 {
231 .messageProcFunction = &OsAccountStub::ProcIsCurrentOsAccountVerified,
232 }
233 },
234 {
235 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_COMPLETED),
236 {
237 .messageProcFunction = &OsAccountStub::ProcIsOsAccountCompleted,
238 }
239 },
240 {
241 static_cast<uint32_t>(OsAccountInterfaceCode::SET_CURRENT_OS_ACCOUNT_IS_VERIFIED),
242 {
243 .messageProcFunction = &OsAccountStub::ProcSetCurrentOsAccountIsVerified,
244 }
245 },
246 {
247 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_IS_VERIFIED),
248 {
249 .messageProcFunction = &OsAccountStub::ProcSetOsAccountIsVerified,
250 }
251 },
252 {
253 static_cast<uint32_t>(OsAccountInterfaceCode::DUMP_STATE),
254 {
255 .messageProcFunction = &OsAccountStub::ProcDumpState,
256 }
257 },
258 {
259 static_cast<uint32_t>(OsAccountInterfaceCode::GET_CREATED_OS_ACCOUNT_NUM_FROM_DATABASE),
260 {
261 .messageProcFunction = &OsAccountStub::ProcGetCreatedOsAccountNumFromDatabase,
262 }
263 },
264 {
265 static_cast<uint32_t>(OsAccountInterfaceCode::GET_SERIAL_NUM_FROM_DATABASE),
266 {
267 .messageProcFunction = &OsAccountStub::ProcGetSerialNumberFromDatabase,
268 }
269 },
270 {
271 static_cast<uint32_t>(OsAccountInterfaceCode::GET_MAX_ALLOW_CREATE_ID_FROM_DATABASE),
272 {
273 .messageProcFunction = &OsAccountStub::ProcGetMaxAllowCreateIdFromDatabase,
274 }
275 },
276 {
277 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_FROM_DATABASE),
278 {
279 .messageProcFunction = &OsAccountStub::ProcGetOsAccountFromDatabase,
280 }
281 },
282 {
283 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LIST_FROM_DATABASE),
284 {
285 .messageProcFunction = &OsAccountStub::ProcGetOsAccountListFromDatabase,
286 }
287 },
288 {
289 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_ACTIVE_OS_ACCOUNT_IDS),
290 {
291 .messageProcFunction = &OsAccountStub::ProcQueryActiveOsAccountIds,
292 }
293 },
294 {
295 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_OS_ACCOUNT_CONSTRAINT_SOURCE_TYPES),
296 {
297 .messageProcFunction = &OsAccountStub::ProcQueryOsAccountConstraintSourceTypes,
298 .isSyetemApi = true,
299 }
300 },
301 {
302 static_cast<uint32_t>(OsAccountInterfaceCode::SET_GLOBAL_OS_ACCOUNT_CONSTRAINTS),
303 {
304 .messageProcFunction = &OsAccountStub::ProcSetGlobalOsAccountConstraints,
305 }
306 },
307 {
308 static_cast<uint32_t>(OsAccountInterfaceCode::SET_SPECIFIC_OS_ACCOUNT_CONSTRAINTS),
309 {
310 .messageProcFunction = &OsAccountStub::ProcSetSpecificOsAccountConstraints,
311 }
312 },
313 {
314 static_cast<uint32_t>(OsAccountInterfaceCode::SET_DEFAULT_ACTIVATED_OS_ACCOUNT),
315 {
316 .messageProcFunction = &OsAccountStub::ProcSetDefaultActivatedOsAccount,
317 }
318 },
319 {
320 static_cast<uint32_t>(OsAccountInterfaceCode::GET_DEFAULT_ACTIVATED_OS_ACCOUNT),
321 {
322 .messageProcFunction = &OsAccountStub::ProcGetDefaultActivatedOsAccount,
323 }
324 },
325 };
326
OsAccountStub()327 OsAccountStub::OsAccountStub()
328 {
329 messageProcMap_ = messageProcMap;
330 }
331
~OsAccountStub()332 OsAccountStub::~OsAccountStub()
333 {}
334
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)335 int OsAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
336 {
337 ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingUid());
338 MemoryGuard cacheGuard;
339 if (data.ReadInterfaceToken() != GetDescriptor()) {
340 ACCOUNT_LOGE("check descriptor failed! code %{public}u.", code);
341 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
342 }
343
344 #ifdef HICOLLIE_ENABLE
345 int timerId =
346 HiviewDFX::XCollie::GetInstance().SetTimer(TIMER_NAME, TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG);
347 #endif // HICOLLIE_ENABLE
348
349 auto messageProc = messageProcMap_.find(code);
350 if (messageProc != messageProcMap_.end()) {
351 auto messageProcFunction = messageProc->second;
352 if (messageProcFunction.isSyetemApi) {
353 ErrCode result = AccountPermissionManager::CheckSystemApp();
354 if (result != ERR_OK) {
355 ACCOUNT_LOGE("is not system application, result = %{public}u.", result);
356 #ifdef HICOLLIE_ENABLE
357 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
358 #endif // HICOLLIE_ENABLE
359 return result;
360 }
361 }
362 int ret = (this->*messageProcFunction.messageProcFunction)(data, reply);
363 #ifdef HICOLLIE_ENABLE
364 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
365 #endif // HICOLLIE_ENABLE
366 return ret;
367 }
368 #ifdef HICOLLIE_ENABLE
369 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
370 #endif // HICOLLIE_ENABLE
371 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
372 }
373
374 template<typename T>
WriteParcelableVector(const std::vector<T> & parcelableVector,MessageParcel & data)375 bool OsAccountStub::WriteParcelableVector(const std::vector<T> &parcelableVector, MessageParcel &data)
376 {
377 if (!data.WriteUint32(parcelableVector.size())) {
378 ACCOUNT_LOGE("Account write ParcelableVector size failed");
379 return false;
380 }
381
382 for (auto parcelable : parcelableVector) {
383 if (!data.WriteParcelable(&parcelable)) {
384 ACCOUNT_LOGE("Account write ParcelableVector Parcelable failed");
385 return false;
386 }
387 }
388 return true;
389 }
390
391 template<typename T>
ReadParcelableVector(std::vector<T> & parcelableInfos,MessageParcel & data)392 bool OsAccountStub::ReadParcelableVector(std::vector<T> &parcelableInfos, MessageParcel &data)
393 {
394 uint32_t infoSize = 0;
395 if (!data.ReadUint32(infoSize)) {
396 ACCOUNT_LOGE("read Parcelable size failed.");
397 return false;
398 }
399
400 parcelableInfos.clear();
401 for (uint32_t index = 0; index < infoSize; index++) {
402 std::shared_ptr<T> info(data.ReadParcelable<T>());
403 if (info == nullptr) {
404 ACCOUNT_LOGE("read Parcelable infos failed.");
405 return false;
406 }
407 parcelableInfos.emplace_back(*info);
408 }
409
410 return true;
411 }
412
ProcCreateOsAccount(MessageParcel & data,MessageParcel & reply)413 ErrCode OsAccountStub::ProcCreateOsAccount(MessageParcel &data, MessageParcel &reply)
414 {
415 std::string name = data.ReadString();
416 if (name.size() == 0) {
417 ACCOUNT_LOGE("failed to read string for name");
418 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
419 return ERR_NONE;
420 }
421 OsAccountType type = static_cast<OsAccountType>(data.ReadInt32());
422 OsAccountInfo osAccountInfo;
423 ErrCode result = CreateOsAccount(name, type, osAccountInfo);
424 if (!reply.WriteInt32(result)) {
425 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
426 return IPC_STUB_WRITE_PARCEL_ERR;
427 }
428 if (!reply.WriteParcelable(&osAccountInfo)) {
429 ACCOUNT_LOGE("failed to write reply");
430 return IPC_STUB_WRITE_PARCEL_ERR;
431 }
432 return ERR_NONE;
433 }
434
ProcCreateOsAccountForDomain(MessageParcel & data,MessageParcel & reply)435 ErrCode OsAccountStub::ProcCreateOsAccountForDomain(MessageParcel &data, MessageParcel &reply)
436 {
437 OsAccountType type = static_cast<OsAccountType>(data.ReadInt32());
438 std::shared_ptr<DomainAccountInfo> info(data.ReadParcelable<DomainAccountInfo>());
439 if (info == nullptr) {
440 ACCOUNT_LOGE("failed to read domain account info");
441 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
442 }
443
444 if (info->domain_.empty() || info->domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
445 ACCOUNT_LOGE("read invalid domain length %{public}zu.", info->domain_.size());
446 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
447 return ERR_NONE;
448 }
449
450 if (info->accountName_.empty() || info->accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE) {
451 ACCOUNT_LOGE("read invalid domain account name length %{public}zu.", info->accountName_.size());
452 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
453 return ERR_NONE;
454 }
455
456 OsAccountInfo osAccountInfo;
457 auto callback = iface_cast<IDomainAccountCallback>(data.ReadRemoteObject());
458 if (callback == nullptr) {
459 ACCOUNT_LOGE("failed to read parcel");
460 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
461 }
462 ErrCode result = CreateOsAccountForDomain(type, *info, callback);
463 if (!reply.WriteInt32(result)) {
464 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
465 return IPC_STUB_WRITE_PARCEL_ERR;
466 }
467 if (!reply.WriteParcelable(&osAccountInfo)) {
468 ACCOUNT_LOGE("failed to write reply");
469 return IPC_STUB_WRITE_PARCEL_ERR;
470 }
471 return ERR_NONE;
472 }
473
ProcRemoveOsAccount(MessageParcel & data,MessageParcel & reply)474 ErrCode OsAccountStub::ProcRemoveOsAccount(MessageParcel &data, MessageParcel &reply)
475 {
476 int32_t localId;
477 if (!data.ReadInt32(localId)) {
478 ACCOUNT_LOGE("failed to read localId");
479 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
480 }
481
482 ErrCode result = RemoveOsAccount(localId);
483 if (!reply.WriteInt32(result)) {
484 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
485 return IPC_STUB_WRITE_PARCEL_ERR;
486 }
487 return ERR_NONE;
488 }
489
ProcSetOsAccountName(MessageParcel & data,MessageParcel & reply)490 ErrCode OsAccountStub::ProcSetOsAccountName(MessageParcel &data, MessageParcel &reply)
491 {
492 int32_t localId;
493 if (!data.ReadInt32(localId)) {
494 ACCOUNT_LOGE("failed to read localId");
495 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
496 }
497 std::string localName = data.ReadString();
498 ErrCode result = SetOsAccountName(localId, localName);
499 if (!reply.WriteInt32(result)) {
500 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
501 return IPC_STUB_WRITE_PARCEL_ERR;
502 }
503 return ERR_NONE;
504 }
505
ProcSetOsAccountConstraints(MessageParcel & data,MessageParcel & reply)506 ErrCode OsAccountStub::ProcSetOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
507 {
508 int32_t localId;
509 if (!data.ReadInt32(localId)) {
510 ACCOUNT_LOGE("failed to read localId");
511 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
512 }
513 std::vector<std::string> constraints;
514 bool stringVectorReadSuccess = data.ReadStringVector(&constraints);
515 if (!stringVectorReadSuccess) {
516 ACCOUNT_LOGE("failed to read StringVector for constraints");
517 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
518 }
519 bool enable = data.ReadBool();
520 ErrCode result = SetOsAccountConstraints(localId, constraints, enable);
521 if (!reply.WriteInt32(result)) {
522 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
523 return IPC_STUB_WRITE_PARCEL_ERR;
524 }
525 return ERR_NONE;
526 }
527
ProcSetOsAccountProfilePhoto(MessageParcel & data,MessageParcel & reply)528 ErrCode OsAccountStub::ProcSetOsAccountProfilePhoto(MessageParcel &data, MessageParcel &reply)
529 {
530 int32_t localId;
531 if (!data.ReadInt32(localId)) {
532 ACCOUNT_LOGE("failed to read localId");
533 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
534 }
535 std::string photo = data.ReadString();
536 ErrCode result = SetOsAccountProfilePhoto(localId, photo);
537 if (!reply.WriteInt32(result)) {
538 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
539 return IPC_STUB_WRITE_PARCEL_ERR;
540 }
541 return ERR_NONE;
542 }
543
ProcQueryOsAccountById(MessageParcel & data,MessageParcel & reply)544 ErrCode OsAccountStub::ProcQueryOsAccountById(MessageParcel &data, MessageParcel &reply)
545 {
546 int32_t localId;
547 if (!data.ReadInt32(localId)) {
548 ACCOUNT_LOGE("failed to read localId");
549 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
550 }
551 OsAccountInfo osAccountInfo = OsAccountInfo();
552 ErrCode result = QueryOsAccountById(localId, osAccountInfo);
553 if (!reply.WriteInt32(result)) {
554 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
555 return IPC_STUB_WRITE_PARCEL_ERR;
556 }
557 if (!reply.WriteParcelable(&osAccountInfo)) {
558 ACCOUNT_LOGE("failed to write reply");
559 return IPC_STUB_WRITE_PARCEL_ERR;
560 }
561 return ERR_NONE;
562 }
563
ProcQueryCurrentOsAccount(MessageParcel & data,MessageParcel & reply)564 ErrCode OsAccountStub::ProcQueryCurrentOsAccount(MessageParcel &data, MessageParcel &reply)
565 {
566 OsAccountInfo osAccountInfo = OsAccountInfo();
567 ErrCode result = QueryCurrentOsAccount(osAccountInfo);
568 if (!reply.WriteInt32(result)) {
569 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
570 return IPC_STUB_WRITE_PARCEL_ERR;
571 }
572 if (!reply.WriteParcelable(&osAccountInfo)) {
573 ACCOUNT_LOGE("failed to write reply");
574 return IPC_STUB_WRITE_PARCEL_ERR;
575 }
576 return ERR_NONE;
577 }
578
ProcQueryAllCreatedOsAccounts(MessageParcel & data,MessageParcel & reply)579 ErrCode OsAccountStub::ProcQueryAllCreatedOsAccounts(MessageParcel &data, MessageParcel &reply)
580 {
581 std::vector<OsAccountInfo> osAccountInfos;
582 osAccountInfos.clear();
583 ErrCode result = QueryAllCreatedOsAccounts(osAccountInfos);
584 if (!reply.WriteInt32(result)) {
585 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
586 return IPC_STUB_WRITE_PARCEL_ERR;
587 }
588 if (!WriteParcelableVector(osAccountInfos, reply)) {
589 ACCOUNT_LOGE("failed to write reply");
590 return IPC_STUB_WRITE_PARCEL_ERR;
591 }
592 return ERR_NONE;
593 }
594
ProcQueryMaxOsAccountNumber(MessageParcel & data,MessageParcel & reply)595 ErrCode OsAccountStub::ProcQueryMaxOsAccountNumber(MessageParcel &data, MessageParcel &reply)
596 {
597 int maxOsAccountNumber = 0;
598 ErrCode result = QueryMaxOsAccountNumber(maxOsAccountNumber);
599 if (!reply.WriteInt32(result)) {
600 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
601 return IPC_STUB_WRITE_PARCEL_ERR;
602 }
603 if (!reply.WriteInt32(maxOsAccountNumber)) {
604 ACCOUNT_LOGE("failed to write reply");
605 return IPC_STUB_WRITE_PARCEL_ERR;
606 }
607 return ERR_NONE;
608 }
609
ProcGetCreatedOsAccountsCount(MessageParcel & data,MessageParcel & reply)610 ErrCode OsAccountStub::ProcGetCreatedOsAccountsCount(MessageParcel &data, MessageParcel &reply)
611 {
612 unsigned int osAccountsCount = 0;
613 ErrCode result = GetCreatedOsAccountsCount(osAccountsCount);
614 if (!reply.WriteInt32(result)) {
615 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
616 return IPC_STUB_WRITE_PARCEL_ERR;
617 }
618 if (!reply.WriteUint32(osAccountsCount)) {
619 ACCOUNT_LOGE("failed to write reply");
620 return IPC_STUB_WRITE_PARCEL_ERR;
621 }
622 return ERR_NONE;
623 }
624
ProcGetOsAccountAllConstraints(MessageParcel & data,MessageParcel & reply)625 ErrCode OsAccountStub::ProcGetOsAccountAllConstraints(MessageParcel &data, MessageParcel &reply)
626 {
627 int32_t localId;
628 if (!data.ReadInt32(localId)) {
629 ACCOUNT_LOGE("failed to read localId");
630 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
631 }
632 std::vector<std::string> constraints;
633 ErrCode result = GetOsAccountAllConstraints(localId, constraints);
634 if (!reply.WriteInt32(result)) {
635 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
636 return IPC_STUB_WRITE_PARCEL_ERR;
637 }
638 if (!reply.WriteStringVector(constraints)) {
639 ACCOUNT_LOGE("failed to write reply");
640 return IPC_STUB_WRITE_PARCEL_ERR;
641 }
642 return ERR_NONE;
643 }
644
ProcGetOsAccountLocalIdFromProcess(MessageParcel & data,MessageParcel & reply)645 ErrCode OsAccountStub::ProcGetOsAccountLocalIdFromProcess(MessageParcel &data, MessageParcel &reply)
646 {
647 int localId = -1;
648 ErrCode result = GetOsAccountLocalIdFromProcess(localId);
649 if (!reply.WriteInt32(result)) {
650 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
651 return IPC_STUB_WRITE_PARCEL_ERR;
652 }
653 if (!reply.WriteInt32(localId)) {
654 ACCOUNT_LOGE("failed to write reply");
655 return IPC_STUB_WRITE_PARCEL_ERR;
656 }
657 return ERR_NONE;
658 }
659
ProcIsMainOsAccount(MessageParcel & data,MessageParcel & reply)660 ErrCode OsAccountStub::ProcIsMainOsAccount(MessageParcel &data, MessageParcel &reply)
661 {
662 bool isMainOsAccount = false;
663 ErrCode result = IsMainOsAccount(isMainOsAccount);
664 if (!reply.WriteInt32(result)) {
665 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
666 return IPC_STUB_WRITE_PARCEL_ERR;
667 }
668 if (!reply.WriteBool(isMainOsAccount)) {
669 ACCOUNT_LOGE("failed to write reply");
670 return IPC_STUB_WRITE_PARCEL_ERR;
671 }
672 return ERR_NONE;
673 }
674
ProcGetOsAccountProfilePhoto(MessageParcel & data,MessageParcel & reply)675 ErrCode OsAccountStub::ProcGetOsAccountProfilePhoto(MessageParcel &data, MessageParcel &reply)
676 {
677 int32_t localId;
678 if (!data.ReadInt32(localId)) {
679 ACCOUNT_LOGE("failed to read localId");
680 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
681 }
682 std::string photo;
683 ErrCode result = GetOsAccountProfilePhoto(localId, photo);
684 if (!reply.WriteInt32(result)) {
685 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
686 return IPC_STUB_WRITE_PARCEL_ERR;
687 }
688 if (!reply.WriteString(photo)) {
689 ACCOUNT_LOGE("failed to write reply");
690 return IPC_STUB_WRITE_PARCEL_ERR;
691 }
692 return ERR_NONE;
693 }
694
ProcGetOsAccountLocalIdFromDomain(MessageParcel & data,MessageParcel & reply)695 ErrCode OsAccountStub::ProcGetOsAccountLocalIdFromDomain(MessageParcel &data, MessageParcel &reply)
696 {
697 std::string domain = data.ReadString();
698 std::string domainAccountName = data.ReadString();
699 if (domain.empty() || domain.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
700 ACCOUNT_LOGE("failed to read string for domain name. length %{public}zu.", domain.size());
701 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
702 return ERR_NONE;
703 }
704
705 if (domainAccountName.empty() || domainAccountName.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE) {
706 ACCOUNT_LOGE("failed to read string for domainAccountName. length %{public}zu.", domainAccountName.size());
707 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
708 return ERR_NONE;
709 }
710
711 int localId = -1;
712 DomainAccountInfo domainInfo(domain, domainAccountName);
713 ErrCode result = GetOsAccountLocalIdFromDomain(domainInfo, localId);
714 if (!reply.WriteInt32(result)) {
715 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
716 return IPC_STUB_WRITE_PARCEL_ERR;
717 }
718 if (!reply.WriteInt32(localId)) {
719 ACCOUNT_LOGE("failed to write reply");
720 return IPC_STUB_WRITE_PARCEL_ERR;
721 }
722 return ERR_NONE;
723 }
724
ProcGetOsAccountTypeFromProcess(MessageParcel & data,MessageParcel & reply)725 ErrCode OsAccountStub::ProcGetOsAccountTypeFromProcess(MessageParcel &data, MessageParcel &reply)
726 {
727 OsAccountType type = OsAccountType::ADMIN;
728 ErrCode result = GetOsAccountTypeFromProcess(type);
729 if (!reply.WriteInt32(result)) {
730 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
731 return IPC_STUB_WRITE_PARCEL_ERR;
732 }
733 if (!reply.WriteInt32(type)) {
734 ACCOUNT_LOGE("failed to write reply");
735 return IPC_STUB_WRITE_PARCEL_ERR;
736 }
737 return ERR_NONE;
738 }
739
ProcGetApplicationConstraints(MessageParcel & data,MessageParcel & reply)740 ErrCode OsAccountStub::ProcGetApplicationConstraints(MessageParcel &data, MessageParcel &reply)
741 {
742 return ERR_NONE;
743 }
744
ProcGetApplicationConstraintsByNumber(MessageParcel & data,MessageParcel & reply)745 ErrCode OsAccountStub::ProcGetApplicationConstraintsByNumber(MessageParcel &data, MessageParcel &reply)
746 {
747 return ERR_NONE;
748 }
749
ProcGetOsAccountLocalIdBySerialNumber(MessageParcel & data,MessageParcel & reply)750 ErrCode OsAccountStub::ProcGetOsAccountLocalIdBySerialNumber(MessageParcel &data, MessageParcel &reply)
751 {
752 int64_t serialNumber = data.ReadInt64();
753 int id = 0;
754 ErrCode result = GetOsAccountLocalIdBySerialNumber(serialNumber, id);
755 if (!reply.WriteInt32(result)) {
756 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
757 return IPC_STUB_WRITE_PARCEL_ERR;
758 }
759 if (!reply.WriteInt32(id)) {
760 ACCOUNT_LOGE("failed to write reply");
761 return IPC_STUB_WRITE_PARCEL_ERR;
762 }
763 return ERR_NONE;
764 }
765
ProcGetSerialNumberByOsAccountLocalId(MessageParcel & data,MessageParcel & reply)766 ErrCode OsAccountStub::ProcGetSerialNumberByOsAccountLocalId(MessageParcel &data, MessageParcel &reply)
767 {
768 int id = data.ReadInt32();
769 int64_t serialNumber = 0;
770 ErrCode result = GetSerialNumberByOsAccountLocalId(id, serialNumber);
771 if (!reply.WriteInt32(result)) {
772 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
773 return IPC_STUB_WRITE_PARCEL_ERR;
774 }
775 if (!reply.WriteInt64(serialNumber)) {
776 ACCOUNT_LOGE("failed to write reply");
777 return IPC_STUB_WRITE_PARCEL_ERR;
778 }
779 return ERR_NONE;
780 }
781
ProcIsOsAccountActived(MessageParcel & data,MessageParcel & reply)782 ErrCode OsAccountStub::ProcIsOsAccountActived(MessageParcel &data, MessageParcel &reply)
783 {
784 int32_t localId;
785 if (!data.ReadInt32(localId)) {
786 ACCOUNT_LOGE("failed to read localId");
787 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
788 }
789 bool isOsAccountActived = false;
790 ErrCode result = IsOsAccountActived(localId, isOsAccountActived);
791 if (!reply.WriteInt32(result)) {
792 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
793 return IPC_STUB_WRITE_PARCEL_ERR;
794 }
795 if (!reply.WriteBool(isOsAccountActived)) {
796 ACCOUNT_LOGE("failed to write reply");
797 return IPC_STUB_WRITE_PARCEL_ERR;
798 }
799 return ERR_NONE;
800 }
801
ProcCheckOsAccountConstraintEnabled(uint32_t code,MessageParcel & data,MessageParcel & reply)802 ErrCode OsAccountStub::ProcCheckOsAccountConstraintEnabled(uint32_t code, MessageParcel &data, MessageParcel &reply)
803 {
804 int32_t localId;
805 if (!data.ReadInt32(localId)) {
806 ACCOUNT_LOGE("failed to read localId");
807 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
808 }
809 std::string constraint = data.ReadString();
810 if (constraint.empty() || constraint.size() > Constants::CONSTRAINT_MAX_SIZE) {
811 ACCOUNT_LOGE("failed to read string for constraint. length %{public}zu.", constraint.size());
812 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_CONSTRAINTS_ERROR);
813 return ERR_NONE;
814 }
815
816 bool isEnabled = false;
817 ErrCode result = ERR_OK;
818 if (code == static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE)) {
819 result = IsOsAccountConstraintEnable(localId, constraint, isEnabled);
820 } else if (code == static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED)) {
821 result = CheckOsAccountConstraintEnabled(localId, constraint, isEnabled);
822 } else {
823 ACCOUNT_LOGE("stub code is invalid");
824 return IPC_INVOKER_ERR;
825 }
826 if (!reply.WriteInt32(result)) {
827 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
828 return IPC_STUB_WRITE_PARCEL_ERR;
829 }
830 if (!reply.WriteBool(isEnabled)) {
831 ACCOUNT_LOGE("failed to write reply");
832 return IPC_STUB_WRITE_PARCEL_ERR;
833 }
834 return ERR_NONE;
835 }
836
ProcIsOsAccountConstraintEnable(MessageParcel & data,MessageParcel & reply)837 ErrCode OsAccountStub::ProcIsOsAccountConstraintEnable(MessageParcel &data, MessageParcel &reply)
838 {
839 return ProcCheckOsAccountConstraintEnabled(
840 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE), data, reply);
841 }
842
ProcCheckOsAccountConstraintEnabled(MessageParcel & data,MessageParcel & reply)843 ErrCode OsAccountStub::ProcCheckOsAccountConstraintEnabled(MessageParcel &data, MessageParcel &reply)
844 {
845 return ProcCheckOsAccountConstraintEnabled(
846 static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED), data, reply);
847 }
848
ProcIsMultiOsAccountEnable(MessageParcel & data,MessageParcel & reply)849 ErrCode OsAccountStub::ProcIsMultiOsAccountEnable(MessageParcel &data, MessageParcel &reply)
850 {
851 bool isMultiOsAccountEnable = false;
852 ErrCode result = IsMultiOsAccountEnable(isMultiOsAccountEnable);
853 if (!reply.WriteInt32(result)) {
854 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
855 return IPC_STUB_WRITE_PARCEL_ERR;
856 }
857 if (!reply.WriteBool(isMultiOsAccountEnable)) {
858 ACCOUNT_LOGE("failed to write reply");
859 return IPC_STUB_WRITE_PARCEL_ERR;
860 }
861 return ERR_NONE;
862 }
863
ProcIsOsAccountVerified(MessageParcel & data,MessageParcel & reply)864 ErrCode OsAccountStub::ProcIsOsAccountVerified(MessageParcel &data, MessageParcel &reply)
865 {
866 int32_t localId;
867 if (!data.ReadInt32(localId)) {
868 ACCOUNT_LOGE("failed to read localId");
869 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
870 }
871 bool isVerified = false;
872 ErrCode result = IsOsAccountVerified(localId, isVerified);
873 if (!reply.WriteInt32(result)) {
874 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
875 return IPC_STUB_WRITE_PARCEL_ERR;
876 }
877 if (!reply.WriteBool(isVerified)) {
878 ACCOUNT_LOGE("failed to write reply");
879 return IPC_STUB_WRITE_PARCEL_ERR;
880 }
881 return ERR_NONE;
882 }
883
ProcIsOsAccountExists(MessageParcel & data,MessageParcel & reply)884 ErrCode OsAccountStub::ProcIsOsAccountExists(MessageParcel &data, MessageParcel &reply)
885 {
886 int32_t localId;
887 if (!data.ReadInt32(localId)) {
888 ACCOUNT_LOGE("failed to read localId");
889 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
890 }
891 bool isOsAccountExists = false;
892 ErrCode result = IsOsAccountExists(localId, isOsAccountExists);
893 if (!reply.WriteInt32(result)) {
894 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
895 return IPC_STUB_WRITE_PARCEL_ERR;
896 }
897 if (!reply.WriteBool(isOsAccountExists)) {
898 ACCOUNT_LOGE("failed to write reply");
899 return IPC_STUB_WRITE_PARCEL_ERR;
900 }
901 return ERR_NONE;
902 }
903
ProcSubscribeOsAccount(MessageParcel & data,MessageParcel & reply)904 ErrCode OsAccountStub::ProcSubscribeOsAccount(MessageParcel &data, MessageParcel &reply)
905 {
906 std::unique_ptr<OsAccountSubscribeInfo> subscribeInfo(data.ReadParcelable<OsAccountSubscribeInfo>());
907 if (!subscribeInfo) {
908 ACCOUNT_LOGE("failed to read parcelable for subscribeInfo");
909 return IPC_STUB_INVALID_DATA_ERR;
910 }
911
912 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
913 if (eventListener == nullptr) {
914 ACCOUNT_LOGE("failed to read remote object for eventListener");
915 return IPC_STUB_INVALID_DATA_ERR;
916 }
917
918 ErrCode result = SubscribeOsAccount(*subscribeInfo, eventListener);
919 if (!reply.WriteInt32(result)) {
920 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
921 return IPC_STUB_WRITE_PARCEL_ERR;
922 }
923
924 return ERR_NONE;
925 }
926
ProcUnsubscribeOsAccount(MessageParcel & data,MessageParcel & reply)927 ErrCode OsAccountStub::ProcUnsubscribeOsAccount(MessageParcel &data, MessageParcel &reply)
928 {
929 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
930 if (eventListener == nullptr) {
931 ACCOUNT_LOGE("failed to read remote object for eventListener");
932 return IPC_STUB_INVALID_DATA_ERR;
933 }
934
935 ErrCode result = UnsubscribeOsAccount(eventListener);
936 if (!reply.WriteInt32(result)) {
937 ACCOUNT_LOGE("failed to write reply");
938 return IPC_STUB_WRITE_PARCEL_ERR;
939 }
940 return ERR_NONE;
941 }
942
ProcActivateOsAccount(MessageParcel & data,MessageParcel & reply)943 ErrCode OsAccountStub::ProcActivateOsAccount(MessageParcel &data, MessageParcel &reply)
944 {
945 int32_t localId;
946 if (!data.ReadInt32(localId)) {
947 ACCOUNT_LOGE("failed to read localId");
948 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
949 }
950 ErrCode result = ActivateOsAccount(localId);
951 if (!reply.WriteInt32(result)) {
952 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
953 return IPC_STUB_WRITE_PARCEL_ERR;
954 }
955 return ERR_NONE;
956 }
957
ProcStartOsAccount(MessageParcel & data,MessageParcel & reply)958 ErrCode OsAccountStub::ProcStartOsAccount(MessageParcel &data, MessageParcel &reply)
959 {
960 int32_t localId;
961 if (!data.ReadInt32(localId)) {
962 ACCOUNT_LOGE("failed to read localId");
963 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
964 }
965 ErrCode result = StartOsAccount(localId);
966 if (!reply.WriteInt32(result)) {
967 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
968 return IPC_STUB_WRITE_PARCEL_ERR;
969 }
970 return ERR_NONE;
971 }
972
ProcStopOsAccount(MessageParcel & data,MessageParcel & reply)973 ErrCode OsAccountStub::ProcStopOsAccount(MessageParcel &data, MessageParcel &reply)
974 {
975 int32_t localId;
976 if (!data.ReadInt32(localId)) {
977 ACCOUNT_LOGE("failed to read localId");
978 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
979 }
980 ErrCode result = StopOsAccount(localId);
981 if (!reply.WriteInt32(result)) {
982 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
983 return IPC_STUB_WRITE_PARCEL_ERR;
984 }
985 return ERR_NONE;
986 }
987
ProcGetOsAccountSwitchMod(MessageParcel & data,MessageParcel & reply)988 ErrCode OsAccountStub::ProcGetOsAccountSwitchMod(MessageParcel &data, MessageParcel &reply)
989 {
990 OS_ACCOUNT_SWITCH_MOD osAccountSwitchMod = GetOsAccountSwitchMod();
991 if (!reply.WriteInt32(osAccountSwitchMod)) {
992 ACCOUNT_LOGE("failed to write reply");
993 return IPC_STUB_WRITE_PARCEL_ERR;
994 }
995 return ERR_NONE;
996 }
997
ProcIsCurrentOsAccountVerified(MessageParcel & data,MessageParcel & reply)998 ErrCode OsAccountStub::ProcIsCurrentOsAccountVerified(MessageParcel &data, MessageParcel &reply)
999 {
1000 bool isVerified = false;
1001 ErrCode result = IsCurrentOsAccountVerified(isVerified);
1002 if (!reply.WriteInt32(result)) {
1003 ACCOUNT_LOGE("failed to write reply");
1004 return IPC_STUB_WRITE_PARCEL_ERR;
1005 }
1006 reply.WriteBool(isVerified);
1007 return ERR_NONE;
1008 }
1009
ProcIsOsAccountCompleted(MessageParcel & data,MessageParcel & reply)1010 ErrCode OsAccountStub::ProcIsOsAccountCompleted(MessageParcel &data, MessageParcel &reply)
1011 {
1012 int32_t localId;
1013 if (!data.ReadInt32(localId)) {
1014 ACCOUNT_LOGE("failed to read localId");
1015 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1016 }
1017 bool isOsAccountCompleted = false;
1018 ErrCode result = IsOsAccountCompleted(localId, isOsAccountCompleted);
1019 if (!reply.WriteInt32(result)) {
1020 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1021 return IPC_STUB_WRITE_PARCEL_ERR;
1022 }
1023 reply.WriteBool(isOsAccountCompleted);
1024 return ERR_NONE;
1025 }
1026
ProcSetCurrentOsAccountIsVerified(MessageParcel & data,MessageParcel & reply)1027 ErrCode OsAccountStub::ProcSetCurrentOsAccountIsVerified(MessageParcel &data, MessageParcel &reply)
1028 {
1029 bool isVerified = data.ReadBool();
1030 ErrCode result = SetCurrentOsAccountIsVerified(isVerified);
1031 if (!reply.WriteInt32(result)) {
1032 ACCOUNT_LOGE("failed to write reply");
1033 return IPC_STUB_WRITE_PARCEL_ERR;
1034 }
1035 return ERR_NONE;
1036 }
1037
ProcSetOsAccountIsVerified(MessageParcel & data,MessageParcel & reply)1038 ErrCode OsAccountStub::ProcSetOsAccountIsVerified(MessageParcel &data, MessageParcel &reply)
1039 {
1040 int32_t localId;
1041 if (!data.ReadInt32(localId)) {
1042 ACCOUNT_LOGE("failed to read localId");
1043 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1044 }
1045 bool isVerified = data.ReadBool();
1046 ErrCode result = SetOsAccountIsVerified(localId, isVerified);
1047 if (!reply.WriteInt32(result)) {
1048 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1049 return IPC_STUB_WRITE_PARCEL_ERR;
1050 }
1051 return ERR_NONE;
1052 }
1053
ProcDumpState(MessageParcel & data,MessageParcel & reply)1054 ErrCode OsAccountStub::ProcDumpState(MessageParcel &data, MessageParcel &reply)
1055 {
1056 int32_t id = data.ReadInt32();
1057 std::vector<std::string> state;
1058
1059 ErrCode result = DumpState(id, state);
1060 if (!reply.WriteInt32(result)) {
1061 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1062 return IPC_STUB_WRITE_PARCEL_ERR;
1063 }
1064
1065 if (!reply.WriteUint32(state.size())) {
1066 ACCOUNT_LOGE("failed to write reply");
1067 return IPC_STUB_WRITE_PARCEL_ERR;
1068 }
1069
1070 for (auto info : state) {
1071 if (!reply.WriteString(info)) {
1072 ACCOUNT_LOGE("failed to write reply");
1073 return IPC_STUB_WRITE_PARCEL_ERR;
1074 }
1075 }
1076
1077 return ERR_NONE;
1078 }
1079
ProcGetCreatedOsAccountNumFromDatabase(MessageParcel & data,MessageParcel & reply)1080 ErrCode OsAccountStub::ProcGetCreatedOsAccountNumFromDatabase(MessageParcel &data, MessageParcel &reply)
1081 {
1082 std::string storeID = data.ReadString();
1083 int createdOsAccountNum = -1;
1084 ErrCode result = GetCreatedOsAccountNumFromDatabase(storeID, createdOsAccountNum);
1085 if (!reply.WriteInt32(result)) {
1086 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1087 return IPC_STUB_WRITE_PARCEL_ERR;
1088 }
1089 if (!reply.WriteInt32(createdOsAccountNum)) {
1090 ACCOUNT_LOGE("failed to write reply");
1091 return IPC_STUB_WRITE_PARCEL_ERR;
1092 }
1093 return ERR_NONE;
1094 }
1095
ProcGetSerialNumberFromDatabase(MessageParcel & data,MessageParcel & reply)1096 ErrCode OsAccountStub::ProcGetSerialNumberFromDatabase(MessageParcel &data, MessageParcel &reply)
1097 {
1098 std::string storeID = data.ReadString();
1099 int64_t serialNumber = -1;
1100 ErrCode result = GetSerialNumberFromDatabase(storeID, serialNumber);
1101 if (!reply.WriteInt32(result)) {
1102 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1103 return IPC_STUB_WRITE_PARCEL_ERR;
1104 }
1105 if (!reply.WriteInt64(serialNumber)) {
1106 ACCOUNT_LOGE("failed to write reply");
1107 return IPC_STUB_WRITE_PARCEL_ERR;
1108 }
1109 return ERR_NONE;
1110 }
1111
ProcGetMaxAllowCreateIdFromDatabase(MessageParcel & data,MessageParcel & reply)1112 ErrCode OsAccountStub::ProcGetMaxAllowCreateIdFromDatabase(MessageParcel &data, MessageParcel &reply)
1113 {
1114 std::string storeID = data.ReadString();
1115 int id = -1;
1116 ErrCode result = GetMaxAllowCreateIdFromDatabase(storeID, id);
1117 if (!reply.WriteInt32(result)) {
1118 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1119 return IPC_STUB_WRITE_PARCEL_ERR;
1120 }
1121 if (!reply.WriteInt32(id)) {
1122 ACCOUNT_LOGE("failed to write reply");
1123 return IPC_STUB_WRITE_PARCEL_ERR;
1124 }
1125 return ERR_NONE;
1126 }
1127
ProcGetOsAccountFromDatabase(MessageParcel & data,MessageParcel & reply)1128 ErrCode OsAccountStub::ProcGetOsAccountFromDatabase(MessageParcel &data, MessageParcel &reply)
1129 {
1130 std::string storeID = data.ReadString();
1131 int id = data.ReadInt32();
1132 OsAccountInfo osAccountInfo;
1133 ErrCode result = GetOsAccountFromDatabase(storeID, id, osAccountInfo);
1134 if (!reply.WriteInt32(result)) {
1135 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1136 return IPC_STUB_WRITE_PARCEL_ERR;
1137 }
1138 if (!reply.WriteParcelable(&osAccountInfo)) {
1139 ACCOUNT_LOGE("failed to write reply");
1140 return IPC_STUB_WRITE_PARCEL_ERR;
1141 }
1142 return ERR_NONE;
1143 }
1144
ProcGetOsAccountListFromDatabase(MessageParcel & data,MessageParcel & reply)1145 ErrCode OsAccountStub::ProcGetOsAccountListFromDatabase(MessageParcel &data, MessageParcel &reply)
1146 {
1147 std::string storeID = data.ReadString();
1148 std::vector<OsAccountInfo> osAccountList;
1149 ErrCode result = GetOsAccountListFromDatabase(storeID, osAccountList);
1150 if (!reply.WriteInt32(result)) {
1151 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1152 return IPC_STUB_WRITE_PARCEL_ERR;
1153 }
1154 if (!WriteParcelableVector(osAccountList, reply)) {
1155 ACCOUNT_LOGE("ProcGetOsAccountListFromDatabase osAccountInfos failed stub");
1156 ACCOUNT_LOGE("failed to write reply");
1157 return IPC_STUB_WRITE_PARCEL_ERR;
1158 }
1159 return ERR_NONE;
1160 }
1161
ProcQueryActiveOsAccountIds(MessageParcel & data,MessageParcel & reply)1162 ErrCode OsAccountStub::ProcQueryActiveOsAccountIds(MessageParcel &data, MessageParcel &reply)
1163 {
1164 std::vector<int32_t> ids;
1165 ErrCode result = QueryActiveOsAccountIds(ids);
1166 if (!reply.WriteInt32(result)) {
1167 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1168 return IPC_STUB_WRITE_PARCEL_ERR;
1169 }
1170 if (!reply.WriteInt32Vector(ids)) {
1171 ACCOUNT_LOGE("failed to write active list");
1172 return IPC_STUB_WRITE_PARCEL_ERR;
1173 }
1174 return ERR_NONE;
1175 }
1176
ProcQueryOsAccountConstraintSourceTypes(MessageParcel & data,MessageParcel & reply)1177 ErrCode OsAccountStub::ProcQueryOsAccountConstraintSourceTypes(MessageParcel &data, MessageParcel &reply)
1178 {
1179 int32_t localId;
1180 if (!data.ReadInt32(localId)) {
1181 ACCOUNT_LOGE("failed to read localId");
1182 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1183 }
1184 std::string constraint;
1185 if (!data.ReadString(constraint)) {
1186 ACCOUNT_LOGE("failed to read constraint");
1187 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1188 }
1189
1190 std::vector<ConstraintSourceTypeInfo> constraintSourceTypeInfos;
1191 ErrCode result = QueryOsAccountConstraintSourceTypes(localId, constraint, constraintSourceTypeInfos);
1192 if (!reply.WriteInt32(result)|| (!reply.WriteUint32(constraintSourceTypeInfos.size()))) {
1193 ACCOUNT_LOGE("QueryOsAccountConstraintSourceTypes failed to write reply");
1194 return IPC_STUB_WRITE_PARCEL_ERR;
1195 }
1196 for (auto constraintInfo : constraintSourceTypeInfos) {
1197 if ((!reply.WriteInt32(constraintInfo.localId)) || (!reply.WriteInt32(constraintInfo.typeInfo))) {
1198 ACCOUNT_LOGE("failed to write reply");
1199 return IPC_STUB_WRITE_PARCEL_ERR;
1200 }
1201 }
1202
1203 return ERR_NONE;
1204 }
1205
ProcSetGlobalOsAccountConstraints(MessageParcel & data,MessageParcel & reply)1206 ErrCode OsAccountStub::ProcSetGlobalOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
1207 {
1208 std::vector<std::string> constraints;
1209 bool stringVectorReadSucess = data.ReadStringVector(&constraints);
1210 if (!stringVectorReadSucess) {
1211 ACCOUNT_LOGE("failed to read StringVector for constraints");
1212 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1213 }
1214 bool enable = data.ReadBool();
1215 int enforcerId = data.ReadInt32();
1216 if (enforcerId < 0) {
1217 ACCOUNT_LOGE("failed to read int for localId");
1218 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1219 return ERR_NONE;
1220 }
1221 bool isDeviceOwner = data.ReadBool();
1222 ErrCode result = SetGlobalOsAccountConstraints(constraints, enable, enforcerId, isDeviceOwner);
1223 if (!reply.WriteInt32(result)) {
1224 ACCOUNT_LOGE("failed to write reply");
1225 return IPC_STUB_WRITE_PARCEL_ERR;
1226 }
1227 return ERR_NONE;
1228 }
1229
ProcSetDefaultActivatedOsAccount(MessageParcel & data,MessageParcel & reply)1230 ErrCode OsAccountStub::ProcSetDefaultActivatedOsAccount(MessageParcel &data, MessageParcel &reply)
1231 {
1232 int32_t localId;
1233 if (!data.ReadInt32(localId)) {
1234 ACCOUNT_LOGE("failed to read localId");
1235 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1236 }
1237 ErrCode result = SetDefaultActivatedOsAccount(localId);
1238 if (!reply.WriteInt32(result)) {
1239 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1240 return IPC_STUB_WRITE_PARCEL_ERR;
1241 }
1242 return ERR_NONE;
1243 }
1244
ProcGetDefaultActivatedOsAccount(MessageParcel & data,MessageParcel & reply)1245 ErrCode OsAccountStub::ProcGetDefaultActivatedOsAccount(MessageParcel &data, MessageParcel &reply)
1246 {
1247 int32_t localId = 0;
1248 ErrCode result = GetDefaultActivatedOsAccount(localId);
1249 if (!reply.WriteInt32(result)) {
1250 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1251 return IPC_STUB_WRITE_PARCEL_ERR;
1252 }
1253 if (!reply.WriteInt32(localId)) {
1254 ACCOUNT_LOGE("failed to write reply");
1255 return IPC_STUB_WRITE_PARCEL_ERR;
1256 }
1257 return ERR_NONE;
1258 }
1259
ProcSetSpecificOsAccountConstraints(MessageParcel & data,MessageParcel & reply)1260 ErrCode OsAccountStub::ProcSetSpecificOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
1261 {
1262 std::vector<std::string> constraints;
1263 bool stringVectorReadSucess = data.ReadStringVector(&constraints);
1264 if (!stringVectorReadSucess) {
1265 ACCOUNT_LOGE("failed to read StringVector for constraints");
1266 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1267 }
1268 bool enable = data.ReadBool();
1269 int targetId = data.ReadInt32();
1270 if (targetId < 0) {
1271 ACCOUNT_LOGE("failed to read int for targetId");
1272 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1273 return ERR_NONE;
1274 }
1275 int enforcerId = data.ReadInt32();
1276 if (enforcerId < 0) {
1277 ACCOUNT_LOGE("failed to read int for enforcerId");
1278 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1279 return ERR_NONE;
1280 }
1281 bool isDeviceOwner = data.ReadBool();
1282 ErrCode result = SetSpecificOsAccountConstraints(constraints, enable, targetId, enforcerId, isDeviceOwner);
1283 if (!reply.WriteInt32(result)) {
1284 ACCOUNT_LOGE("failed to write reply");
1285 return IPC_STUB_WRITE_PARCEL_ERR;
1286 }
1287 return ERR_NONE;
1288 }
1289 } // namespace AccountSA
1290 } // namespace OHOS
1291