1 /*
2 * Copyright (c) 2021-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 #include "os_account_stub.h"
16 #include "account_log_wrapper.h"
17 #include "account_permission_manager.h"
18 #include "account_constants.h"
19 #include "hitrace_adapter.h"
20 #include "idomain_account_callback.h"
21 #include "ipc_skeleton.h"
22 #include "memory_guard.h"
23 #include "os_account_constants.h"
24 #ifdef HICOLLIE_ENABLE
25 #include "account_timer.h"
26 #include "xcollie/xcollie.h"
27 #endif // HICOLLIE_ENABLE
28 namespace OHOS {
29 namespace AccountSA {
30 #ifdef HICOLLIE_ENABLE
31 constexpr std::int32_t RECOVERY_TIMEOUT = 6; // timeout 6s
32 const std::set<uint32_t> WATCH_DOG_WHITE_LIST = {
33 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT),
34 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_SHORT_NAME),
35 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_FULL_INFO),
36 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN),
37 };
38 #endif // HICOLLIE_ENABLE
39 const std::map<uint32_t, OsAccountStub::OsAccountMessageProc> messageProcMap = {
40 {
41 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT),
42 {
__anon2db93fd20102() 43 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
44 return ptr->ProcCreateOsAccount(data, reply); },
45 .isSyetemApi = true,
46 }
47 },
48 {
49 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_SHORT_NAME),
50 {
__anon2db93fd20202() 51 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
52 return ptr->ProcCreateOsAccountWithShortName(data, reply); },
53 .isSyetemApi = true,
54 }
55 },
56 {
57 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_WITH_FULL_INFO),
58 {
__anon2db93fd20302() 59 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
60 return ptr->ProcCreateOsAccountWithFullInfo(data, reply); },
61 .isSyetemApi = true,
62 }
63 },
64 {
65 static_cast<uint32_t>(OsAccountInterfaceCode::UPDATE_OS_ACCOUNT_WITH_FULL_INFO),
66 {
__anon2db93fd20402() 67 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
68 return ptr->ProcUpdateOsAccountWithFullInfo(data, reply); },
69 .isSyetemApi = true,
70 }
71 },
72 {
73 static_cast<uint32_t>(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN),
74 {
__anon2db93fd20502() 75 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
76 return ptr->ProcCreateOsAccountForDomain(data, reply); },
77 .isSyetemApi = true,
78 }
79 },
80 {
81 static_cast<uint32_t>(OsAccountInterfaceCode::REMOVE_OS_ACCOUNT),
82 {
__anon2db93fd20602() 83 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
84 return ptr->ProcRemoveOsAccount(data, reply); },
85 .isSyetemApi = true,
86 }
87 },
88 {
89 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_EXISTS),
90 {
__anon2db93fd20702() 91 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
92 return ptr->ProcIsOsAccountExists(data, reply); },
93 }
94 },
95 {
96 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_ACTIVED),
97 {
__anon2db93fd20802() 98 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
99 return ptr->ProcIsOsAccountActived(data, reply); },
100 }
101 },
102 {
103 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE),
104 {
__anon2db93fd20902() 105 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
106 return ptr->ProcIsOsAccountConstraintEnable(data, reply); },
107 }
108 },
109 {
110 static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED),
111 {
__anon2db93fd20a02() 112 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
113 return ptr->ProcCheckOsAccountConstraintEnabled(data, reply); },
114 }
115 },
116 {
117 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_VERIFIED),
118 {
__anon2db93fd20b02() 119 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
120 return ptr->ProcIsOsAccountVerified(data, reply); },
121 }
122 },
123 {
124 static_cast<uint32_t>(OsAccountInterfaceCode::GET_CREATED_OS_ACCOUNT_COUNT),
125 {
__anon2db93fd20c02() 126 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
127 return ptr->ProcGetCreatedOsAccountsCount(data, reply); },
128 }
129 },
130 {
131 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FROM_PROCESS),
132 {
__anon2db93fd20d02() 133 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
134 return ptr->ProcGetOsAccountLocalIdFromProcess(data, reply); },
135 }
136 },
137 {
138 static_cast<uint32_t>(OsAccountInterfaceCode::IS_MAIN_OS_ACCOUNT),
139 {
__anon2db93fd20e02() 140 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
141 return ptr->ProcIsMainOsAccount(data, reply); },
142 .isSyetemApi = true,
143 }
144 },
145 {
146 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FROM_DOMAIN),
147 {
__anon2db93fd20f02() 148 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
149 return ptr->ProcGetOsAccountLocalIdFromDomain(data, reply); },
150 }
151 },
152 {
153 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_MAX_OS_ACCOUNT_NUMBER),
154 {
__anon2db93fd21002() 155 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
156 return ptr->ProcQueryMaxOsAccountNumber(data, reply); },
157 .isSyetemApi = true,
158 }
159 },
160 {
161 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_MAX_LOGGED_IN_OS_ACCOUNT_NUMBER),
162 {
__anon2db93fd21102() 163 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
164 return ptr->ProcQueryMaxLoggedInOsAccountNumber(data, reply); },
165 .isSyetemApi = true,
166 }
167 },
168 {
169 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_ALL_CONSTRAINTS),
170 {
__anon2db93fd21202() 171 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
172 return ptr->ProcGetOsAccountAllConstraints(data, reply); },
173 }
174 },
175 {
176 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_ALL_CREATED_OS_ACCOUNTS),
177 {
__anon2db93fd21302() 178 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
179 return ptr->ProcQueryAllCreatedOsAccounts(data, reply); },
180 .isSyetemApi = true,
181 }
182 },
183 {
184 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_CURRENT_OS_ACCOUNT),
185 {
__anon2db93fd21402() 186 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
187 return ptr->ProcQueryCurrentOsAccount(data, reply); },
188 }
189 },
190 {
191 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_OS_ACCOUNT_BY_ID),
192 {
__anon2db93fd21502() 193 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
194 return ptr->ProcQueryOsAccountById(data, reply); },
195 .isSyetemApi = true,
196 }
197 },
198 {
199 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_TYPE_FROM_PROCESS),
200 {
__anon2db93fd21602() 201 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
202 return ptr->ProcGetOsAccountTypeFromProcess(data, reply); },
203 }
204 },
205 {
206 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_TYPE),
207 {
__anon2db93fd21702() 208 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
209 return ptr->ProcGetOsAccountType(data, reply); },
210 .isSyetemApi = true,
211 }
212 },
213 {
214 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_PROFILE_PHOTO),
215 {
__anon2db93fd21802() 216 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
217 return ptr->ProcGetOsAccountProfilePhoto(data, reply); },
218 .isSyetemApi = true,
219 }
220 },
221 {
222 static_cast<uint32_t>(OsAccountInterfaceCode::IS_MULTI_OS_ACCOUNT_ENABLE),
223 {
__anon2db93fd21902() 224 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
225 return ptr->ProcIsMultiOsAccountEnable(data, reply); },
226 }
227 },
228 {
229 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_NAME),
230 {
__anon2db93fd21a02() 231 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
232 return ptr->ProcSetOsAccountName(data, reply); },
233 .isSyetemApi = true,
234 }
235 },
236 {
237 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_CONSTRAINTS),
238 {
__anon2db93fd21b02() 239 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
240 return ptr->ProcSetOsAccountConstraints(data, reply); },
241 .isSyetemApi = true,
242 }
243 },
244 {
245 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_PROFILE_PHOTO),
246 {
__anon2db93fd21c02() 247 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
248 return ptr->ProcSetOsAccountProfilePhoto(data, reply); },
249 .isSyetemApi = true,
250 }
251 },
252 {
253 static_cast<uint32_t>(OsAccountInterfaceCode::ACTIVATE_OS_ACCOUNT),
254 {
__anon2db93fd21d02() 255 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
256 return ptr->ProcActivateOsAccount(data, reply); },
257 .isSyetemApi = true,
258 }
259 },
260 {
261 static_cast<uint32_t>(OsAccountInterfaceCode::DEACTIVATE_OS_ACCOUNT),
262 {
__anon2db93fd21e02() 263 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
264 return ptr->ProcDeactivateOsAccount(data, reply); },
265 .isSyetemApi = true,
266 }
267 },
268 {
269 static_cast<uint32_t>(OsAccountInterfaceCode::DEACTIVATE_ALL_OS_ACCOUNTS),
270 {
__anon2db93fd21f02() 271 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
272 return ptr->ProcDeactivateAllOsAccounts(data, reply); },
273 .isSyetemApi = true,
274 }
275 },
276 {
277 static_cast<uint32_t>(OsAccountInterfaceCode::START_OS_ACCOUNT),
278 {
__anon2db93fd22002() 279 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
280 return ptr->ProcStartOsAccount(data, reply); },
281 }
282 },
283 {
284 static_cast<uint32_t>(OsAccountInterfaceCode::SUBSCRIBE_OS_ACCOUNT),
285 {
__anon2db93fd22102() 286 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
287 return ptr->ProcSubscribeOsAccount(data, reply); },
288 .isSyetemApi = true,
289 }
290 },
291 {
292 static_cast<uint32_t>(OsAccountInterfaceCode::UNSUBSCRIBE_OS_ACCOUNT),
293 {
__anon2db93fd22202() 294 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
295 return ptr->ProcUnsubscribeOsAccount(data, reply); },
296 .isSyetemApi = true,
297 }
298 },
299 {
300 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LOCAL_ID_FOR_SERIAL_NUMBER),
301 {
__anon2db93fd22302() 302 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
303 return ptr->ProcGetOsAccountLocalIdBySerialNumber(data, reply); },
304 }
305 },
306 {
307 static_cast<uint32_t>(OsAccountInterfaceCode::GET_SERIAL_NUMBER_FOR_OS_ACCOUNT),
308 {
__anon2db93fd22402() 309 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
310 return ptr->ProcGetSerialNumberByOsAccountLocalId(data, reply); },
311 }
312 },
313 {
314 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_SWITCH_MOD),
315 {
__anon2db93fd22502() 316 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
317 return ptr->ProcGetOsAccountSwitchMod(data, reply); },
318 }
319 },
320 {
321 static_cast<uint32_t>(OsAccountInterfaceCode::IS_CURRENT_OS_ACCOUNT_VERIFIED),
322 {
__anon2db93fd22602() 323 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
324 return ptr->ProcIsCurrentOsAccountVerified(data, reply); },
325 }
326 },
327 {
328 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_COMPLETED),
329 {
__anon2db93fd22702() 330 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
331 return ptr->ProcIsOsAccountCompleted(data, reply); },
332 }
333 },
334 {
335 static_cast<uint32_t>(OsAccountInterfaceCode::SET_CURRENT_OS_ACCOUNT_IS_VERIFIED),
336 {
__anon2db93fd22802() 337 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
338 return ptr->ProcSetCurrentOsAccountIsVerified(data, reply); },
339 }
340 },
341 {
342 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_IS_VERIFIED),
343 {
__anon2db93fd22902() 344 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
345 return ptr->ProcSetOsAccountIsVerified(data, reply); },
346 }
347 },
348 {
349 static_cast<uint32_t>(OsAccountInterfaceCode::DUMP_STATE),
350 {
__anon2db93fd22a02() 351 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
352 return ptr->ProcDumpState(data, reply); },
353 }
354 },
355 {
356 static_cast<uint32_t>(OsAccountInterfaceCode::GET_CREATED_OS_ACCOUNT_NUM_FROM_DATABASE),
357 {
__anon2db93fd22b02() 358 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
359 return ptr->ProcGetCreatedOsAccountNumFromDatabase(data, reply); },
360 }
361 },
362 {
363 static_cast<uint32_t>(OsAccountInterfaceCode::GET_SERIAL_NUM_FROM_DATABASE),
364 {
__anon2db93fd22c02() 365 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
366 return ptr->ProcGetSerialNumberFromDatabase(data, reply); },
367 }
368 },
369 {
370 static_cast<uint32_t>(OsAccountInterfaceCode::GET_MAX_ALLOW_CREATE_ID_FROM_DATABASE),
371 {
__anon2db93fd22d02() 372 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
373 return ptr->ProcGetMaxAllowCreateIdFromDatabase(data, reply); },
374 }
375 },
376 {
377 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_FROM_DATABASE),
378 {
__anon2db93fd22e02() 379 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
380 return ptr->ProcGetOsAccountFromDatabase(data, reply); },
381 }
382 },
383 {
384 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_LIST_FROM_DATABASE),
385 {
__anon2db93fd22f02() 386 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
387 return ptr->ProcGetOsAccountListFromDatabase(data, reply); },
388 }
389 },
390 {
391 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_ACTIVE_OS_ACCOUNT_IDS),
392 {
__anon2db93fd23002() 393 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
394 return ptr->ProcQueryActiveOsAccountIds(data, reply); },
395 }
396 },
397 {
398 static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_OS_ACCOUNT_CONSTRAINT_SOURCE_TYPES),
399 {
__anon2db93fd23102() 400 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
401 return ptr->ProcQueryOsAccountConstraintSourceTypes(data, reply); },
402 .isSyetemApi = true,
403 }
404 },
405 {
406 static_cast<uint32_t>(OsAccountInterfaceCode::SET_GLOBAL_OS_ACCOUNT_CONSTRAINTS),
407 {
__anon2db93fd23202() 408 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
409 return ptr->ProcSetGlobalOsAccountConstraints(data, reply); },
410 }
411 },
412 {
413 static_cast<uint32_t>(OsAccountInterfaceCode::SET_SPECIFIC_OS_ACCOUNT_CONSTRAINTS),
414 {
__anon2db93fd23302() 415 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
416 return ptr->ProcSetSpecificOsAccountConstraints(data, reply); },
417 }
418 },
419 {
420 static_cast<uint32_t>(OsAccountInterfaceCode::SET_DEFAULT_ACTIVATED_OS_ACCOUNT),
421 {
__anon2db93fd23402() 422 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
423 return ptr->ProcSetDefaultActivatedOsAccount(data, reply); },
424 }
425 },
426 {
427 static_cast<uint32_t>(OsAccountInterfaceCode::GET_DEFAULT_ACTIVATED_OS_ACCOUNT),
428 {
__anon2db93fd23502() 429 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
430 return ptr->ProcGetDefaultActivatedOsAccount(data, reply); },
431 }
432 },
433 {
434 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_SHORT_NAME),
435 {
__anon2db93fd23602() 436 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
437 return ptr->ProcGetOsAccountShortName(data, reply); },
438 .isSyetemApi = true,
439 }
440 },
441 {
442 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_NAME),
443 {
__anon2db93fd23702() 444 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
445 return ptr->ProcGetOsAccountName(data, reply); },
446 .isSyetemApi = false,
447 }
448 },
449 {
450 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_FOREGROUND),
451 {
__anon2db93fd23802() 452 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
453 return ptr->ProcIsOsAccountForeground(data, reply); },
454 .isSyetemApi = true,
455 }
456 },
457 {
458 static_cast<uint32_t>(OsAccountInterfaceCode::GET_FOREGROUND_OS_ACCOUNT_LOCAL_ID),
459 {
__anon2db93fd23902() 460 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
461 return ptr->ProcGetForegroundOsAccountLocalId(data, reply); },
462 .isSyetemApi = true,
463 }
464 },
465 {
466 static_cast<uint32_t>(OsAccountInterfaceCode::GET_FOREGROUND_OS_ACCOUNTS),
467 {
__anon2db93fd23a02() 468 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
469 return ptr->ProcGetForegroundOsAccounts(data, reply); },
470 .isSyetemApi = true,
471 }
472 },
473 {
474 static_cast<uint32_t>(OsAccountInterfaceCode::GET_BACKGROUND_OS_ACCOUNT_LOCAL_IDS),
475 {
__anon2db93fd23b02() 476 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
477 return ptr->ProcGetBackgroundOsAccountLocalIds(data, reply); },
478 }
479 },
480 {
481 static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_SHORT_NAME_BY_ID),
482 {
__anon2db93fd23c02() 483 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
484 return ptr->ProcGetOsAccountShortNameById(data, reply); },
485 .isSyetemApi = true,
486 }
487 },
488 {
489 static_cast<uint32_t>(OsAccountInterfaceCode::SET_OS_ACCOUNT_TO_BE_REMOVED),
490 {
__anon2db93fd23d02() 491 .messageProcFunction = [] (OsAccountStub *ptr, MessageParcel &data, MessageParcel &reply) {
492 return ptr->ProcSetOsAccountToBeRemoved(data, reply); },
493 .isSyetemApi = true,
494 }
495 },
496 };
497
OsAccountStub()498 OsAccountStub::OsAccountStub()
499 {
500 messageProcMap_ = messageProcMap;
501 }
502
~OsAccountStub()503 OsAccountStub::~OsAccountStub()
504 {}
505
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)506 int OsAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
507 {
508 ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingUid());
509 MemoryGuard cacheGuard;
510 if (data.ReadInterfaceToken() != GetDescriptor()) {
511 ACCOUNT_LOGE("check descriptor failed! code %{public}u.", code);
512 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
513 }
514
515 #ifdef HICOLLIE_ENABLE
516 AccountTimer timer(false);
517 if (WATCH_DOG_WHITE_LIST.find(code) == WATCH_DOG_WHITE_LIST.end()) {
518 timer.Init();
519 }
520 #endif // HICOLLIE_ENABLE
521
522 auto messageProc = messageProcMap_.find(code);
523 if (messageProc != messageProcMap_.end()) {
524 auto messageProcFunction = messageProc->second;
525 if (messageProcFunction.isSyetemApi) {
526 ErrCode result = AccountPermissionManager::CheckSystemApp();
527 if (result != ERR_OK) {
528 ACCOUNT_LOGE("is not system application, result = %{public}u.", result);
529 return result;
530 }
531 }
532 int ret = (messageProcFunction.messageProcFunction)(this, data, reply);
533 return ret;
534 }
535 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
536 }
537
WriteOsAccountInfoList(const std::vector<OsAccountInfo> & accounts,MessageParcel & data)538 bool OsAccountStub::WriteOsAccountInfoList(const std::vector<OsAccountInfo> &accounts, MessageParcel &data)
539 {
540 nlohmann::json accountJsonArray;
541 for (uint32_t i = 0; i < accounts.size(); i++) {
542 accountJsonArray.emplace_back(accounts[i].ToJson());
543 }
544 std::string accountJsonArrayStr = accountJsonArray.dump();
545 if (accountJsonArrayStr.size() >= Constants::IPC_WRITE_RAW_DATA_MAX_SIZE) {
546 ACCOUNT_LOGE("accountJsonArrayStr is too long");
547 return false;
548 }
549 if (!data.WriteUint32(accountJsonArrayStr.size() + 1)) {
550 ACCOUNT_LOGE("Failed to write accountJsonArrayStr size");
551 return false;
552 }
553 if (!data.WriteRawData(accountJsonArrayStr.c_str(), accountJsonArrayStr.size() + 1)) {
554 ACCOUNT_LOGE("Failed to write string for accountJsonArrayStr");
555 return false;
556 }
557 return true;
558 }
559
WriteResultWithOsAccountInfo(MessageParcel & reply,int32_t result,const OsAccountInfo & info)560 static ErrCode WriteResultWithOsAccountInfo(MessageParcel &reply, int32_t result, const OsAccountInfo &info)
561 {
562 if (!reply.WriteInt32(result)) {
563 ACCOUNT_LOGE("failed to write result");
564 return IPC_STUB_WRITE_PARCEL_ERR;
565 }
566 std::string accountStr = info.ToString();
567 if (!reply.WriteInt32(accountStr.size() + 1)) {
568 ACCOUNT_LOGE("Failed to write accountStr size");
569 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
570 }
571 if (!reply.WriteRawData(accountStr.c_str(), accountStr.size() + 1)) {
572 ACCOUNT_LOGE("Failed to write string for account");
573 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
574 }
575 return ERR_NONE;
576 }
577
ProcCreateOsAccount(MessageParcel & data,MessageParcel & reply)578 ErrCode OsAccountStub::ProcCreateOsAccount(MessageParcel &data, MessageParcel &reply)
579 {
580 std::string name;
581 if (!data.ReadString(name)) {
582 ACCOUNT_LOGE("failed to read string for name");
583 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
584 return ERR_NONE;
585 }
586 OsAccountType type = static_cast<OsAccountType>(data.ReadInt32());
587 OsAccountInfo osAccountInfo;
588 ErrCode result = CreateOsAccount(name, type, osAccountInfo);
589 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
590 }
591
ProcCreateOsAccountWithShortName(MessageParcel & data,MessageParcel & reply)592 ErrCode OsAccountStub::ProcCreateOsAccountWithShortName(MessageParcel &data, MessageParcel &reply)
593 {
594 std::string localName;
595 if (!data.ReadString(localName)) {
596 ACCOUNT_LOGE("failed to read string for local name");
597 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
598 return ERR_NONE;
599 }
600 bool hasShortName;
601 if (!data.ReadBool(hasShortName)) {
602 ACCOUNT_LOGE("failed to read bool for hasShortName");
603 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
604 return ERR_NONE;
605 }
606 std::string shortName;
607 if (hasShortName && !data.ReadString(shortName)) {
608 ACCOUNT_LOGE("failed to read string for short name");
609 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
610 return ERR_NONE;
611 }
612 int32_t type = 0;
613 if (!data.ReadInt32(type)) {
614 ACCOUNT_LOGE("failed to read int for account type");
615 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_LOCALNAME_ERROR);
616 return ERR_NONE;
617 }
618 OsAccountType osAccountType = static_cast<OsAccountType>(type);
619 sptr<CreateOsAccountOptions> options = data.ReadParcelable<CreateOsAccountOptions>();
620 if (options == nullptr) {
621 ACCOUNT_LOGE("read options failed");
622 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
623 }
624 OsAccountInfo osAccountInfo;
625 ErrCode result = CreateOsAccount(localName, shortName, osAccountType, osAccountInfo, *options);
626 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
627 }
628
629
ProcCreateOsAccountWithFullInfo(MessageParcel & data,MessageParcel & reply)630 ErrCode OsAccountStub::ProcCreateOsAccountWithFullInfo(MessageParcel &data, MessageParcel &reply)
631 {
632 std::shared_ptr<OsAccountInfo> info(data.ReadParcelable<OsAccountInfo>());
633 if (info == nullptr) {
634 ACCOUNT_LOGE("failed to read OsAccountInfo");
635 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
636 }
637
638 ErrCode code = info->ParamCheck();
639 if (code != ERR_OK) {
640 ACCOUNT_LOGE("OsAccountInfo required field is invalidate");
641 return code;
642 }
643
644 sptr<CreateOsAccountOptions> options = data.ReadParcelable<CreateOsAccountOptions>();
645 if (options == nullptr) {
646 ACCOUNT_LOGE("read options failed");
647 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
648 }
649
650 ErrCode result = CreateOsAccountWithFullInfo(*info, *options);
651 if (!reply.WriteInt32(result)) {
652 ACCOUNT_LOGE("failed to write result");
653 return IPC_STUB_WRITE_PARCEL_ERR;
654 }
655 return ERR_NONE;
656 }
657
ProcUpdateOsAccountWithFullInfo(MessageParcel & data,MessageParcel & reply)658 ErrCode OsAccountStub::ProcUpdateOsAccountWithFullInfo(MessageParcel &data, MessageParcel &reply)
659 {
660 std::shared_ptr<OsAccountInfo> info(data.ReadParcelable<OsAccountInfo>());
661 if (info == nullptr) {
662 ACCOUNT_LOGE("failed to read OsAccountInfo");
663 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
664 }
665
666 ErrCode code = info->ParamCheck();
667 if (code != ERR_OK) {
668 ACCOUNT_LOGE("OsAccountInfo required field is invalidate");
669 return code;
670 }
671
672 ErrCode result = UpdateOsAccountWithFullInfo(*info);
673 if (!reply.WriteInt32(result)) {
674 ACCOUNT_LOGE("failed to write result");
675 return IPC_STUB_WRITE_PARCEL_ERR;
676 }
677 return ERR_NONE;
678 }
679
ProcCreateOsAccountForDomain(MessageParcel & data,MessageParcel & reply)680 ErrCode OsAccountStub::ProcCreateOsAccountForDomain(MessageParcel &data, MessageParcel &reply)
681 {
682 OsAccountType type = static_cast<OsAccountType>(data.ReadInt32());
683 std::shared_ptr<DomainAccountInfo> info(data.ReadParcelable<DomainAccountInfo>());
684 if (info == nullptr) {
685 ACCOUNT_LOGE("failed to read domain account info");
686 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
687 }
688
689 if (info->domain_.empty() || info->domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
690 ACCOUNT_LOGE("read invalid domain length %{public}zu.", info->domain_.size());
691 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
692 return ERR_NONE;
693 }
694
695 if (info->accountName_.empty() || info->accountName_.size() > Constants::LOCAL_NAME_MAX_SIZE) {
696 ACCOUNT_LOGE("read invalid domain account name length %{public}zu.", info->accountName_.size());
697 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
698 return ERR_NONE;
699 }
700
701 OsAccountInfo osAccountInfo;
702 auto callback = iface_cast<IDomainAccountCallback>(data.ReadRemoteObject());
703 if (callback == nullptr) {
704 ACCOUNT_LOGE("failed to read parcel");
705 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
706 }
707
708 sptr<CreateOsAccountForDomainOptions> options = data.ReadParcelable<CreateOsAccountForDomainOptions>();
709 if (options == nullptr) {
710 ACCOUNT_LOGE("Read options failed");
711 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
712 }
713 ErrCode result = CreateOsAccountForDomain(type, *info, callback, *options);
714 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
715 }
716
ProcRemoveOsAccount(MessageParcel & data,MessageParcel & reply)717 ErrCode OsAccountStub::ProcRemoveOsAccount(MessageParcel &data, MessageParcel &reply)
718 {
719 int32_t localId;
720 if (!data.ReadInt32(localId)) {
721 ACCOUNT_LOGE("failed to read localId");
722 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
723 }
724
725 ErrCode result = RemoveOsAccount(localId);
726 if (!reply.WriteInt32(result)) {
727 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
728 return IPC_STUB_WRITE_PARCEL_ERR;
729 }
730 return ERR_NONE;
731 }
732
ProcSetOsAccountName(MessageParcel & data,MessageParcel & reply)733 ErrCode OsAccountStub::ProcSetOsAccountName(MessageParcel &data, MessageParcel &reply)
734 {
735 int32_t localId;
736 if (!data.ReadInt32(localId)) {
737 ACCOUNT_LOGE("failed to read localId");
738 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
739 }
740 std::string localName = data.ReadString();
741 ErrCode result = SetOsAccountName(localId, localName);
742 if (!reply.WriteInt32(result)) {
743 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
744 return IPC_STUB_WRITE_PARCEL_ERR;
745 }
746 return ERR_NONE;
747 }
748
ProcSetOsAccountConstraints(MessageParcel & data,MessageParcel & reply)749 ErrCode OsAccountStub::ProcSetOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
750 {
751 int32_t localId;
752 if (!data.ReadInt32(localId)) {
753 ACCOUNT_LOGE("failed to read localId");
754 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
755 }
756 std::vector<std::string> constraints;
757 bool stringVectorReadSuccess = data.ReadStringVector(&constraints);
758 if (!stringVectorReadSuccess) {
759 ACCOUNT_LOGE("failed to read StringVector for constraints");
760 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
761 }
762 bool enable = data.ReadBool();
763 ErrCode result = SetOsAccountConstraints(localId, constraints, enable);
764 if (!reply.WriteInt32(result)) {
765 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
766 return IPC_STUB_WRITE_PARCEL_ERR;
767 }
768 return ERR_NONE;
769 }
770
ProcSetOsAccountProfilePhoto(MessageParcel & data,MessageParcel & reply)771 ErrCode OsAccountStub::ProcSetOsAccountProfilePhoto(MessageParcel &data, MessageParcel &reply)
772 {
773 int32_t localId;
774 if (!data.ReadInt32(localId)) {
775 ACCOUNT_LOGE("Failed to read localId");
776 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
777 }
778
779 int32_t photoSize;
780 if (!data.ReadInt32(photoSize)) {
781 ACCOUNT_LOGE("Failed to read photoSize");
782 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
783 }
784
785 if (photoSize - 1 > static_cast<int32_t>(Constants::LOCAL_PHOTO_MAX_SIZE) || photoSize < 1) {
786 ACCOUNT_LOGE("PhotoSize is invalid, photosize = %{public}d", photoSize);
787 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
788 }
789 auto readRawData = data.ReadRawData(photoSize);
790 if (readRawData == nullptr) {
791 ACCOUNT_LOGE("Failed to read photoData");
792 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
793 }
794 const char *photoData = reinterpret_cast<const char *>(readRawData);
795 std::string photo = std::string(photoData, photoSize - 1);
796 ErrCode result = SetOsAccountProfilePhoto(localId, photo);
797 if (!reply.WriteInt32(result)) {
798 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
799 return IPC_STUB_WRITE_PARCEL_ERR;
800 }
801 return ERR_NONE;
802 }
803
ProcQueryOsAccountById(MessageParcel & data,MessageParcel & reply)804 ErrCode OsAccountStub::ProcQueryOsAccountById(MessageParcel &data, MessageParcel &reply)
805 {
806 int32_t localId;
807 if (!data.ReadInt32(localId)) {
808 ACCOUNT_LOGE("failed to read localId");
809 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
810 }
811 OsAccountInfo osAccountInfo = OsAccountInfo();
812 ErrCode result = QueryOsAccountById(localId, osAccountInfo);
813 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
814 }
815
ProcQueryCurrentOsAccount(MessageParcel & data,MessageParcel & reply)816 ErrCode OsAccountStub::ProcQueryCurrentOsAccount(MessageParcel &data, MessageParcel &reply)
817 {
818 OsAccountInfo osAccountInfo = OsAccountInfo();
819 ErrCode result = QueryCurrentOsAccount(osAccountInfo);
820 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
821 }
822
ProcQueryAllCreatedOsAccounts(MessageParcel & data,MessageParcel & reply)823 ErrCode OsAccountStub::ProcQueryAllCreatedOsAccounts(MessageParcel &data, MessageParcel &reply)
824 {
825 std::vector<OsAccountInfo> osAccountInfos;
826 osAccountInfos.clear();
827 ErrCode result = QueryAllCreatedOsAccounts(osAccountInfos);
828 if (!reply.WriteInt32(result)) {
829 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
830 return IPC_STUB_WRITE_PARCEL_ERR;
831 }
832 if (!WriteOsAccountInfoList(osAccountInfos, reply)) {
833 ACCOUNT_LOGE("failed to write reply");
834 return IPC_STUB_WRITE_PARCEL_ERR;
835 }
836 return ERR_NONE;
837 }
838
ProcQueryMaxOsAccountNumber(MessageParcel & data,MessageParcel & reply)839 ErrCode OsAccountStub::ProcQueryMaxOsAccountNumber(MessageParcel &data, MessageParcel &reply)
840 {
841 uint32_t maxOsAccountNumber = 0;
842 ErrCode result = QueryMaxOsAccountNumber(maxOsAccountNumber);
843 if (!reply.WriteInt32(result)) {
844 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
845 return IPC_STUB_WRITE_PARCEL_ERR;
846 }
847 if (!reply.WriteUint32(maxOsAccountNumber)) {
848 ACCOUNT_LOGE("failed to write reply");
849 return IPC_STUB_WRITE_PARCEL_ERR;
850 }
851 return ERR_NONE;
852 }
853
ProcQueryMaxLoggedInOsAccountNumber(MessageParcel & data,MessageParcel & reply)854 ErrCode OsAccountStub::ProcQueryMaxLoggedInOsAccountNumber(MessageParcel &data, MessageParcel &reply)
855 {
856 uint32_t maxNum = 0;
857 ErrCode result = QueryMaxLoggedInOsAccountNumber(maxNum);
858 if (!reply.WriteInt32(result)) {
859 ACCOUNT_LOGE("Failed to write reply, result %{public}d.", result);
860 return IPC_STUB_WRITE_PARCEL_ERR;
861 }
862 if (!reply.WriteUint32(maxNum)) {
863 ACCOUNT_LOGE("Failed to write reply");
864 return IPC_STUB_WRITE_PARCEL_ERR;
865 }
866 return ERR_NONE;
867 }
868
ProcGetCreatedOsAccountsCount(MessageParcel & data,MessageParcel & reply)869 ErrCode OsAccountStub::ProcGetCreatedOsAccountsCount(MessageParcel &data, MessageParcel &reply)
870 {
871 unsigned int osAccountsCount = 0;
872 ErrCode result = GetCreatedOsAccountsCount(osAccountsCount);
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.WriteUint32(osAccountsCount)) {
878 ACCOUNT_LOGE("failed to write reply");
879 return IPC_STUB_WRITE_PARCEL_ERR;
880 }
881 return ERR_NONE;
882 }
883
ProcGetOsAccountAllConstraints(MessageParcel & data,MessageParcel & reply)884 ErrCode OsAccountStub::ProcGetOsAccountAllConstraints(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 std::vector<std::string> constraints;
892 ErrCode result = GetOsAccountAllConstraints(localId, constraints);
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.WriteStringVector(constraints)) {
898 ACCOUNT_LOGE("failed to write reply");
899 return IPC_STUB_WRITE_PARCEL_ERR;
900 }
901 return ERR_NONE;
902 }
903
ProcGetOsAccountLocalIdFromProcess(MessageParcel & data,MessageParcel & reply)904 ErrCode OsAccountStub::ProcGetOsAccountLocalIdFromProcess(MessageParcel &data, MessageParcel &reply)
905 {
906 int localId = -1;
907 #ifdef HICOLLIE_ENABLE
908 int timerId = HiviewDFX::XCollie::GetInstance().SetTimer(
909 TIMER_NAME, RECOVERY_TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_RECOVERY);
910 #endif // HICOLLIE_ENABLE
911 ErrCode result = GetOsAccountLocalIdFromProcess(localId);
912 if (!reply.WriteInt32(result)) {
913 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
914 #ifdef HICOLLIE_ENABLE
915 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
916 #endif // HICOLLIE_ENABLE
917 return IPC_STUB_WRITE_PARCEL_ERR;
918 }
919 if (!reply.WriteInt32(localId)) {
920 ACCOUNT_LOGE("failed to write reply");
921 #ifdef HICOLLIE_ENABLE
922 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
923 #endif // HICOLLIE_ENABLE
924 return IPC_STUB_WRITE_PARCEL_ERR;
925 }
926 #ifdef HICOLLIE_ENABLE
927 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
928 #endif // HICOLLIE_ENABLE
929 return ERR_NONE;
930 }
931
ProcIsMainOsAccount(MessageParcel & data,MessageParcel & reply)932 ErrCode OsAccountStub::ProcIsMainOsAccount(MessageParcel &data, MessageParcel &reply)
933 {
934 bool isMainOsAccount = false;
935 ErrCode result = IsMainOsAccount(isMainOsAccount);
936 if (!reply.WriteInt32(result)) {
937 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
938 return IPC_STUB_WRITE_PARCEL_ERR;
939 }
940 if (!reply.WriteBool(isMainOsAccount)) {
941 ACCOUNT_LOGE("failed to write reply");
942 return IPC_STUB_WRITE_PARCEL_ERR;
943 }
944 return ERR_NONE;
945 }
946
ProcGetOsAccountProfilePhoto(MessageParcel & data,MessageParcel & reply)947 ErrCode OsAccountStub::ProcGetOsAccountProfilePhoto(MessageParcel &data, MessageParcel &reply)
948 {
949 int32_t localId;
950 if (!data.ReadInt32(localId)) {
951 ACCOUNT_LOGE("failed to read localId");
952 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
953 }
954 std::string photo;
955 ErrCode result = GetOsAccountProfilePhoto(localId, photo);
956 if (!reply.WriteInt32(result)) {
957 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
958 return IPC_STUB_WRITE_PARCEL_ERR;
959 }
960 if (!reply.WriteInt32(photo.size() + 1)) {
961 ACCOUNT_LOGE("Failed to write photo");
962 return IPC_STUB_WRITE_PARCEL_ERR;
963 }
964 if (!reply.WriteRawData(photo.c_str(), photo.size() + 1)) {
965 ACCOUNT_LOGE("Failed to write photo");
966 return IPC_STUB_WRITE_PARCEL_ERR;
967 }
968 return ERR_NONE;
969 }
970
ProcGetOsAccountLocalIdFromDomain(MessageParcel & data,MessageParcel & reply)971 ErrCode OsAccountStub::ProcGetOsAccountLocalIdFromDomain(MessageParcel &data, MessageParcel &reply)
972 {
973 std::string domain = data.ReadString();
974 std::string domainAccountName = data.ReadString();
975 if (domain.empty() || domain.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
976 ACCOUNT_LOGE("failed to read string for domain name. length %{public}zu.", domain.size());
977 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
978 return ERR_NONE;
979 }
980
981 if (domainAccountName.empty() || domainAccountName.size() > Constants::LOCAL_NAME_MAX_SIZE) {
982 ACCOUNT_LOGE("failed to read string for domainAccountName. length %{public}zu.", domainAccountName.size());
983 reply.WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
984 return ERR_NONE;
985 }
986
987 int localId = -1;
988 DomainAccountInfo domainInfo(domain, domainAccountName);
989 ErrCode result = GetOsAccountLocalIdFromDomain(domainInfo, localId);
990 if (!reply.WriteInt32(result)) {
991 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
992 return IPC_STUB_WRITE_PARCEL_ERR;
993 }
994 if (!reply.WriteInt32(localId)) {
995 ACCOUNT_LOGE("failed to write reply");
996 return IPC_STUB_WRITE_PARCEL_ERR;
997 }
998 return ERR_NONE;
999 }
1000
ProcGetOsAccountTypeFromProcess(MessageParcel & data,MessageParcel & reply)1001 ErrCode OsAccountStub::ProcGetOsAccountTypeFromProcess(MessageParcel &data, MessageParcel &reply)
1002 {
1003 OsAccountType type = OsAccountType::ADMIN;
1004 ErrCode result = GetOsAccountTypeFromProcess(type);
1005 if (!reply.WriteInt32(result)) {
1006 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1007 return IPC_STUB_WRITE_PARCEL_ERR;
1008 }
1009 if (!reply.WriteInt32(static_cast<int32_t>(type))) {
1010 ACCOUNT_LOGE("failed to write reply");
1011 return IPC_STUB_WRITE_PARCEL_ERR;
1012 }
1013 return ERR_NONE;
1014 }
1015
ProcGetOsAccountType(MessageParcel & data,MessageParcel & reply)1016 ErrCode OsAccountStub::ProcGetOsAccountType(MessageParcel &data, MessageParcel &reply)
1017 {
1018 OsAccountType type = OsAccountType::ADMIN;
1019 int32_t localId;
1020 if (!data.ReadInt32(localId)) {
1021 ACCOUNT_LOGE("Read localId failed.");
1022 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1023 }
1024 ErrCode result = GetOsAccountType(localId, type);
1025 if (!reply.WriteInt32(result)) {
1026 ACCOUNT_LOGE("Write reply failed.");
1027 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1028 }
1029 if (result != ERR_OK) {
1030 return ERR_NONE;
1031 }
1032 if (!reply.WriteInt32(static_cast<int32_t>(type))) {
1033 ACCOUNT_LOGE("Write reply failed.");
1034 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1035 }
1036 return ERR_NONE;
1037 }
1038
ProcGetApplicationConstraints(MessageParcel & data,MessageParcel & reply)1039 ErrCode OsAccountStub::ProcGetApplicationConstraints(MessageParcel &data, MessageParcel &reply)
1040 {
1041 return ERR_NONE;
1042 }
1043
ProcGetApplicationConstraintsByNumber(MessageParcel & data,MessageParcel & reply)1044 ErrCode OsAccountStub::ProcGetApplicationConstraintsByNumber(MessageParcel &data, MessageParcel &reply)
1045 {
1046 return ERR_NONE;
1047 }
1048
ProcGetOsAccountLocalIdBySerialNumber(MessageParcel & data,MessageParcel & reply)1049 ErrCode OsAccountStub::ProcGetOsAccountLocalIdBySerialNumber(MessageParcel &data, MessageParcel &reply)
1050 {
1051 int64_t serialNumber = data.ReadInt64();
1052 int id = 0;
1053 ErrCode result = GetOsAccountLocalIdBySerialNumber(serialNumber, id);
1054 if (!reply.WriteInt32(result)) {
1055 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1056 return IPC_STUB_WRITE_PARCEL_ERR;
1057 }
1058 if (!reply.WriteInt32(id)) {
1059 ACCOUNT_LOGE("failed to write reply");
1060 return IPC_STUB_WRITE_PARCEL_ERR;
1061 }
1062 return ERR_NONE;
1063 }
1064
ProcGetSerialNumberByOsAccountLocalId(MessageParcel & data,MessageParcel & reply)1065 ErrCode OsAccountStub::ProcGetSerialNumberByOsAccountLocalId(MessageParcel &data, MessageParcel &reply)
1066 {
1067 int id = data.ReadInt32();
1068 int64_t serialNumber = 0;
1069 ErrCode result = GetSerialNumberByOsAccountLocalId(id, serialNumber);
1070 if (!reply.WriteInt32(result)) {
1071 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1072 return IPC_STUB_WRITE_PARCEL_ERR;
1073 }
1074 if (!reply.WriteInt64(serialNumber)) {
1075 ACCOUNT_LOGE("failed to write reply");
1076 return IPC_STUB_WRITE_PARCEL_ERR;
1077 }
1078 return ERR_NONE;
1079 }
1080
ProcIsOsAccountActived(MessageParcel & data,MessageParcel & reply)1081 ErrCode OsAccountStub::ProcIsOsAccountActived(MessageParcel &data, MessageParcel &reply)
1082 {
1083 int32_t localId;
1084 if (!data.ReadInt32(localId)) {
1085 ACCOUNT_LOGE("failed to read localId");
1086 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1087 }
1088 bool isOsAccountActived = false;
1089 ErrCode result = IsOsAccountActived(localId, isOsAccountActived);
1090 if (!reply.WriteInt32(result)) {
1091 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1092 return IPC_STUB_WRITE_PARCEL_ERR;
1093 }
1094 if (!reply.WriteBool(isOsAccountActived)) {
1095 ACCOUNT_LOGE("failed to write reply");
1096 return IPC_STUB_WRITE_PARCEL_ERR;
1097 }
1098 return ERR_NONE;
1099 }
1100
ProcCheckOsAccountConstraintEnabled(uint32_t code,MessageParcel & data,MessageParcel & reply)1101 ErrCode OsAccountStub::ProcCheckOsAccountConstraintEnabled(uint32_t code, MessageParcel &data, MessageParcel &reply)
1102 {
1103 int32_t localId;
1104 if (!data.ReadInt32(localId)) {
1105 ACCOUNT_LOGE("failed to read localId");
1106 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1107 }
1108 std::string constraint = data.ReadString();
1109 if (constraint.empty() || constraint.size() > Constants::CONSTRAINT_MAX_SIZE) {
1110 ACCOUNT_LOGE("failed to read string for constraint. length %{public}zu.", constraint.size());
1111 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_CONSTRAINTS_ERROR);
1112 return ERR_NONE;
1113 }
1114
1115 bool isEnabled = false;
1116 ErrCode result = ERR_OK;
1117 if (code == static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE)) {
1118 result = IsOsAccountConstraintEnable(localId, constraint, isEnabled);
1119 } else if (code == static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED)) {
1120 result = CheckOsAccountConstraintEnabled(localId, constraint, isEnabled);
1121 } else {
1122 ACCOUNT_LOGE("stub code is invalid");
1123 return IPC_INVOKER_ERR;
1124 }
1125 if (!reply.WriteInt32(result)) {
1126 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1127 return IPC_STUB_WRITE_PARCEL_ERR;
1128 }
1129 if (!reply.WriteBool(isEnabled)) {
1130 ACCOUNT_LOGE("failed to write reply");
1131 return IPC_STUB_WRITE_PARCEL_ERR;
1132 }
1133 return ERR_NONE;
1134 }
1135
ProcIsOsAccountConstraintEnable(MessageParcel & data,MessageParcel & reply)1136 ErrCode OsAccountStub::ProcIsOsAccountConstraintEnable(MessageParcel &data, MessageParcel &reply)
1137 {
1138 return ProcCheckOsAccountConstraintEnabled(
1139 static_cast<uint32_t>(OsAccountInterfaceCode::IS_OS_ACCOUNT_CONSTRAINT_ENABLE), data, reply);
1140 }
1141
ProcCheckOsAccountConstraintEnabled(MessageParcel & data,MessageParcel & reply)1142 ErrCode OsAccountStub::ProcCheckOsAccountConstraintEnabled(MessageParcel &data, MessageParcel &reply)
1143 {
1144 return ProcCheckOsAccountConstraintEnabled(
1145 static_cast<uint32_t>(OsAccountInterfaceCode::CHECK_OS_ACCOUNT_CONSTRAINT_ENABLED), data, reply);
1146 }
1147
ProcIsMultiOsAccountEnable(MessageParcel & data,MessageParcel & reply)1148 ErrCode OsAccountStub::ProcIsMultiOsAccountEnable(MessageParcel &data, MessageParcel &reply)
1149 {
1150 bool isMultiOsAccountEnable = false;
1151 ErrCode result = IsMultiOsAccountEnable(isMultiOsAccountEnable);
1152 if (!reply.WriteInt32(result)) {
1153 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1154 return IPC_STUB_WRITE_PARCEL_ERR;
1155 }
1156 if (!reply.WriteBool(isMultiOsAccountEnable)) {
1157 ACCOUNT_LOGE("failed to write reply");
1158 return IPC_STUB_WRITE_PARCEL_ERR;
1159 }
1160 return ERR_NONE;
1161 }
1162
ProcIsOsAccountVerified(MessageParcel & data,MessageParcel & reply)1163 ErrCode OsAccountStub::ProcIsOsAccountVerified(MessageParcel &data, MessageParcel &reply)
1164 {
1165 int32_t localId;
1166 if (!data.ReadInt32(localId)) {
1167 ACCOUNT_LOGE("failed to read localId");
1168 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1169 }
1170 bool isVerified = false;
1171 ErrCode result = IsOsAccountVerified(localId, isVerified);
1172 if (!reply.WriteInt32(result)) {
1173 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1174 return IPC_STUB_WRITE_PARCEL_ERR;
1175 }
1176 if (!reply.WriteBool(isVerified)) {
1177 ACCOUNT_LOGE("failed to write reply");
1178 return IPC_STUB_WRITE_PARCEL_ERR;
1179 }
1180 return ERR_NONE;
1181 }
1182
ProcIsOsAccountExists(MessageParcel & data,MessageParcel & reply)1183 ErrCode OsAccountStub::ProcIsOsAccountExists(MessageParcel &data, MessageParcel &reply)
1184 {
1185 int32_t localId;
1186 if (!data.ReadInt32(localId)) {
1187 ACCOUNT_LOGE("failed to read localId");
1188 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1189 }
1190 bool isOsAccountExists = false;
1191 ErrCode result = IsOsAccountExists(localId, isOsAccountExists);
1192 if (!reply.WriteInt32(result)) {
1193 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1194 return IPC_STUB_WRITE_PARCEL_ERR;
1195 }
1196 if (!reply.WriteBool(isOsAccountExists)) {
1197 ACCOUNT_LOGE("failed to write reply");
1198 return IPC_STUB_WRITE_PARCEL_ERR;
1199 }
1200 return ERR_NONE;
1201 }
1202
ProcSubscribeOsAccount(MessageParcel & data,MessageParcel & reply)1203 ErrCode OsAccountStub::ProcSubscribeOsAccount(MessageParcel &data, MessageParcel &reply)
1204 {
1205 #ifdef HICOLLIE_ENABLE
1206 int timerId = HiviewDFX::XCollie::GetInstance().SetTimer(
1207 TIMER_NAME, RECOVERY_TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_RECOVERY);
1208 #endif // HICOLLIE_ENABLE
1209 std::unique_ptr<OsAccountSubscribeInfo> subscribeInfo(data.ReadParcelable<OsAccountSubscribeInfo>());
1210 if (!subscribeInfo) {
1211 ACCOUNT_LOGE("failed to read parcelable for subscribeInfo");
1212 #ifdef HICOLLIE_ENABLE
1213 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1214 #endif // HICOLLIE_ENABLE
1215 return IPC_STUB_INVALID_DATA_ERR;
1216 }
1217
1218 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
1219 if (eventListener == nullptr) {
1220 ACCOUNT_LOGE("failed to read remote object for eventListener");
1221 #ifdef HICOLLIE_ENABLE
1222 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1223 #endif // HICOLLIE_ENABLE
1224 return IPC_STUB_INVALID_DATA_ERR;
1225 }
1226
1227 ErrCode result = SubscribeOsAccount(*subscribeInfo, eventListener);
1228 if (!reply.WriteInt32(result)) {
1229 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1230 #ifdef HICOLLIE_ENABLE
1231 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1232 #endif // HICOLLIE_ENABLE
1233 return IPC_STUB_WRITE_PARCEL_ERR;
1234 }
1235 #ifdef HICOLLIE_ENABLE
1236 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1237 #endif // HICOLLIE_ENABLE
1238 return ERR_NONE;
1239 }
1240
ProcUnsubscribeOsAccount(MessageParcel & data,MessageParcel & reply)1241 ErrCode OsAccountStub::ProcUnsubscribeOsAccount(MessageParcel &data, MessageParcel &reply)
1242 {
1243 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
1244 if (eventListener == nullptr) {
1245 ACCOUNT_LOGE("failed to read remote object for eventListener");
1246 return IPC_STUB_INVALID_DATA_ERR;
1247 }
1248
1249 ErrCode result = UnsubscribeOsAccount(eventListener);
1250 if (!reply.WriteInt32(result)) {
1251 ACCOUNT_LOGE("failed to write reply");
1252 return IPC_STUB_WRITE_PARCEL_ERR;
1253 }
1254 return ERR_NONE;
1255 }
1256
ProcActivateOsAccount(MessageParcel & data,MessageParcel & reply)1257 ErrCode OsAccountStub::ProcActivateOsAccount(MessageParcel &data, MessageParcel &reply)
1258 {
1259 int32_t localId;
1260 if (!data.ReadInt32(localId)) {
1261 ACCOUNT_LOGE("failed to read localId");
1262 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1263 }
1264 StartTraceAdapter("AccountManager ActivateAccount");
1265 ErrCode result = ActivateOsAccount(localId);
1266 if (!reply.WriteInt32(result)) {
1267 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1268 FinishTraceAdapter();
1269 return IPC_STUB_WRITE_PARCEL_ERR;
1270 }
1271 FinishTraceAdapter();
1272 return ERR_NONE;
1273 }
1274
ProcDeactivateOsAccount(MessageParcel & data,MessageParcel & reply)1275 ErrCode OsAccountStub::ProcDeactivateOsAccount(MessageParcel &data, MessageParcel &reply)
1276 {
1277 int32_t localId;
1278 if (!data.ReadInt32(localId)) {
1279 ACCOUNT_LOGE("failed to read localId");
1280 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1281 }
1282 ErrCode result = DeactivateOsAccount(localId);
1283 if (!reply.WriteInt32(result)) {
1284 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1285 return IPC_STUB_WRITE_PARCEL_ERR;
1286 }
1287 return ERR_NONE;
1288 }
1289
ProcDeactivateAllOsAccounts(MessageParcel & data,MessageParcel & reply)1290 ErrCode OsAccountStub::ProcDeactivateAllOsAccounts(MessageParcel &data, MessageParcel &reply)
1291 {
1292 ErrCode result = DeactivateAllOsAccounts();
1293 if (!reply.WriteInt32(result)) {
1294 ACCOUNT_LOGE("Write reply failed, result=%{public}d.", result);
1295 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1296 }
1297 return ERR_NONE;
1298 }
1299
ProcStartOsAccount(MessageParcel & data,MessageParcel & reply)1300 ErrCode OsAccountStub::ProcStartOsAccount(MessageParcel &data, MessageParcel &reply)
1301 {
1302 int32_t localId;
1303 if (!data.ReadInt32(localId)) {
1304 ACCOUNT_LOGE("failed to read localId");
1305 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1306 }
1307 ErrCode result = StartOsAccount(localId);
1308 if (!reply.WriteInt32(result)) {
1309 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1310 return IPC_STUB_WRITE_PARCEL_ERR;
1311 }
1312 return ERR_NONE;
1313 }
1314
ProcGetOsAccountSwitchMod(MessageParcel & data,MessageParcel & reply)1315 ErrCode OsAccountStub::ProcGetOsAccountSwitchMod(MessageParcel &data, MessageParcel &reply)
1316 {
1317 OS_ACCOUNT_SWITCH_MOD osAccountSwitchMod = GetOsAccountSwitchMod();
1318 if (!reply.WriteInt32(osAccountSwitchMod)) {
1319 ACCOUNT_LOGE("failed to write reply");
1320 return IPC_STUB_WRITE_PARCEL_ERR;
1321 }
1322 return ERR_NONE;
1323 }
1324
ProcIsCurrentOsAccountVerified(MessageParcel & data,MessageParcel & reply)1325 ErrCode OsAccountStub::ProcIsCurrentOsAccountVerified(MessageParcel &data, MessageParcel &reply)
1326 {
1327 bool isVerified = false;
1328 ErrCode result = IsCurrentOsAccountVerified(isVerified);
1329 if (!reply.WriteInt32(result)) {
1330 ACCOUNT_LOGE("failed to write reply");
1331 return IPC_STUB_WRITE_PARCEL_ERR;
1332 }
1333 reply.WriteBool(isVerified);
1334 return ERR_NONE;
1335 }
1336
ProcIsOsAccountCompleted(MessageParcel & data,MessageParcel & reply)1337 ErrCode OsAccountStub::ProcIsOsAccountCompleted(MessageParcel &data, MessageParcel &reply)
1338 {
1339 int32_t localId;
1340 if (!data.ReadInt32(localId)) {
1341 ACCOUNT_LOGE("failed to read localId");
1342 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1343 }
1344 bool isOsAccountCompleted = false;
1345 ErrCode result = IsOsAccountCompleted(localId, isOsAccountCompleted);
1346 if (!reply.WriteInt32(result)) {
1347 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1348 return IPC_STUB_WRITE_PARCEL_ERR;
1349 }
1350 reply.WriteBool(isOsAccountCompleted);
1351 return ERR_NONE;
1352 }
1353
ProcSetCurrentOsAccountIsVerified(MessageParcel & data,MessageParcel & reply)1354 ErrCode OsAccountStub::ProcSetCurrentOsAccountIsVerified(MessageParcel &data, MessageParcel &reply)
1355 {
1356 bool isVerified = data.ReadBool();
1357 ErrCode result = SetCurrentOsAccountIsVerified(isVerified);
1358 if (!reply.WriteInt32(result)) {
1359 ACCOUNT_LOGE("failed to write reply");
1360 return IPC_STUB_WRITE_PARCEL_ERR;
1361 }
1362 return ERR_NONE;
1363 }
1364
ProcSetOsAccountIsVerified(MessageParcel & data,MessageParcel & reply)1365 ErrCode OsAccountStub::ProcSetOsAccountIsVerified(MessageParcel &data, MessageParcel &reply)
1366 {
1367 int32_t localId;
1368 if (!data.ReadInt32(localId)) {
1369 ACCOUNT_LOGE("failed to read localId");
1370 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1371 }
1372 bool isVerified = data.ReadBool();
1373 ErrCode result = SetOsAccountIsVerified(localId, isVerified);
1374 if (!reply.WriteInt32(result)) {
1375 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1376 return IPC_STUB_WRITE_PARCEL_ERR;
1377 }
1378 return ERR_NONE;
1379 }
1380
ProcDumpState(MessageParcel & data,MessageParcel & reply)1381 ErrCode OsAccountStub::ProcDumpState(MessageParcel &data, MessageParcel &reply)
1382 {
1383 int32_t id = data.ReadInt32();
1384 std::vector<std::string> state;
1385
1386 ErrCode result = DumpState(id, state);
1387 if (!reply.WriteInt32(result)) {
1388 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1389 return IPC_STUB_WRITE_PARCEL_ERR;
1390 }
1391
1392 if (!reply.WriteUint32(state.size())) {
1393 ACCOUNT_LOGE("failed to write reply");
1394 return IPC_STUB_WRITE_PARCEL_ERR;
1395 }
1396
1397 for (auto info : state) {
1398 if (!reply.WriteString(info)) {
1399 ACCOUNT_LOGE("failed to write reply");
1400 return IPC_STUB_WRITE_PARCEL_ERR;
1401 }
1402 }
1403
1404 return ERR_NONE;
1405 }
1406
ProcGetCreatedOsAccountNumFromDatabase(MessageParcel & data,MessageParcel & reply)1407 ErrCode OsAccountStub::ProcGetCreatedOsAccountNumFromDatabase(MessageParcel &data, MessageParcel &reply)
1408 {
1409 std::string storeID = data.ReadString();
1410 int createdOsAccountNum = -1;
1411 ErrCode result = GetCreatedOsAccountNumFromDatabase(storeID, createdOsAccountNum);
1412 if (!reply.WriteInt32(result)) {
1413 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1414 return IPC_STUB_WRITE_PARCEL_ERR;
1415 }
1416 if (!reply.WriteInt32(createdOsAccountNum)) {
1417 ACCOUNT_LOGE("failed to write reply");
1418 return IPC_STUB_WRITE_PARCEL_ERR;
1419 }
1420 return ERR_NONE;
1421 }
1422
ProcGetSerialNumberFromDatabase(MessageParcel & data,MessageParcel & reply)1423 ErrCode OsAccountStub::ProcGetSerialNumberFromDatabase(MessageParcel &data, MessageParcel &reply)
1424 {
1425 std::string storeID = data.ReadString();
1426 int64_t serialNumber = -1;
1427 ErrCode result = GetSerialNumberFromDatabase(storeID, serialNumber);
1428 if (!reply.WriteInt32(result)) {
1429 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1430 return IPC_STUB_WRITE_PARCEL_ERR;
1431 }
1432 if (!reply.WriteInt64(serialNumber)) {
1433 ACCOUNT_LOGE("failed to write reply");
1434 return IPC_STUB_WRITE_PARCEL_ERR;
1435 }
1436 return ERR_NONE;
1437 }
1438
ProcGetMaxAllowCreateIdFromDatabase(MessageParcel & data,MessageParcel & reply)1439 ErrCode OsAccountStub::ProcGetMaxAllowCreateIdFromDatabase(MessageParcel &data, MessageParcel &reply)
1440 {
1441 std::string storeID = data.ReadString();
1442 int id = -1;
1443 ErrCode result = GetMaxAllowCreateIdFromDatabase(storeID, id);
1444 if (!reply.WriteInt32(result)) {
1445 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1446 return IPC_STUB_WRITE_PARCEL_ERR;
1447 }
1448 if (!reply.WriteInt32(id)) {
1449 ACCOUNT_LOGE("failed to write reply");
1450 return IPC_STUB_WRITE_PARCEL_ERR;
1451 }
1452 return ERR_NONE;
1453 }
1454
ProcGetOsAccountFromDatabase(MessageParcel & data,MessageParcel & reply)1455 ErrCode OsAccountStub::ProcGetOsAccountFromDatabase(MessageParcel &data, MessageParcel &reply)
1456 {
1457 std::string storeID = data.ReadString();
1458 int id = data.ReadInt32();
1459 OsAccountInfo osAccountInfo;
1460 ErrCode result = GetOsAccountFromDatabase(storeID, id, osAccountInfo);
1461 return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
1462 }
1463
ProcGetOsAccountListFromDatabase(MessageParcel & data,MessageParcel & reply)1464 ErrCode OsAccountStub::ProcGetOsAccountListFromDatabase(MessageParcel &data, MessageParcel &reply)
1465 {
1466 std::string storeID = data.ReadString();
1467 std::vector<OsAccountInfo> osAccountList;
1468 ErrCode result = GetOsAccountListFromDatabase(storeID, osAccountList);
1469 if (!reply.WriteInt32(result)) {
1470 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1471 return IPC_STUB_WRITE_PARCEL_ERR;
1472 }
1473 if (!WriteOsAccountInfoList(osAccountList, reply)) {
1474 ACCOUNT_LOGE("ProcGetOsAccountListFromDatabase osAccountInfos failed stub");
1475 ACCOUNT_LOGE("failed to write reply");
1476 return IPC_STUB_WRITE_PARCEL_ERR;
1477 }
1478 return ERR_NONE;
1479 }
1480
ProcQueryActiveOsAccountIds(MessageParcel & data,MessageParcel & reply)1481 ErrCode OsAccountStub::ProcQueryActiveOsAccountIds(MessageParcel &data, MessageParcel &reply)
1482 {
1483 std::vector<int32_t> ids;
1484 #ifdef HICOLLIE_ENABLE
1485 int timerId = HiviewDFX::XCollie::GetInstance().SetTimer(
1486 TIMER_NAME, RECOVERY_TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_RECOVERY);
1487 #endif // HICOLLIE_ENABLE
1488 ErrCode result = QueryActiveOsAccountIds(ids);
1489 if (!reply.WriteInt32(result)) {
1490 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1491 #ifdef HICOLLIE_ENABLE
1492 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1493 #endif // HICOLLIE_ENABLE
1494 return IPC_STUB_WRITE_PARCEL_ERR;
1495 }
1496 if (!reply.WriteInt32Vector(ids)) {
1497 ACCOUNT_LOGE("failed to write active list");
1498 #ifdef HICOLLIE_ENABLE
1499 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1500 #endif // HICOLLIE_ENABLE
1501 return IPC_STUB_WRITE_PARCEL_ERR;
1502 }
1503 #ifdef HICOLLIE_ENABLE
1504 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
1505 #endif // HICOLLIE_ENABLE
1506 return ERR_NONE;
1507 }
1508
ProcQueryOsAccountConstraintSourceTypes(MessageParcel & data,MessageParcel & reply)1509 ErrCode OsAccountStub::ProcQueryOsAccountConstraintSourceTypes(MessageParcel &data, MessageParcel &reply)
1510 {
1511 int32_t localId;
1512 if (!data.ReadInt32(localId)) {
1513 ACCOUNT_LOGE("failed to read localId");
1514 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1515 }
1516 std::string constraint;
1517 if (!data.ReadString(constraint)) {
1518 ACCOUNT_LOGE("failed to read constraint");
1519 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1520 }
1521
1522 std::vector<ConstraintSourceTypeInfo> constraintSourceTypeInfos;
1523 ErrCode result = QueryOsAccountConstraintSourceTypes(localId, constraint, constraintSourceTypeInfos);
1524 if (!reply.WriteInt32(result)|| (!reply.WriteUint32(constraintSourceTypeInfos.size()))) {
1525 ACCOUNT_LOGE("QueryOsAccountConstraintSourceTypes failed to write reply");
1526 return IPC_STUB_WRITE_PARCEL_ERR;
1527 }
1528 for (auto constraintInfo : constraintSourceTypeInfos) {
1529 if ((!reply.WriteInt32(constraintInfo.localId)) || (!reply.WriteInt32(constraintInfo.typeInfo))) {
1530 ACCOUNT_LOGE("failed to write reply");
1531 return IPC_STUB_WRITE_PARCEL_ERR;
1532 }
1533 }
1534
1535 return ERR_NONE;
1536 }
1537
ProcSetGlobalOsAccountConstraints(MessageParcel & data,MessageParcel & reply)1538 ErrCode OsAccountStub::ProcSetGlobalOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
1539 {
1540 std::vector<std::string> constraints;
1541 bool stringVectorReadSucess = data.ReadStringVector(&constraints);
1542 if (!stringVectorReadSucess) {
1543 ACCOUNT_LOGE("failed to read StringVector for constraints");
1544 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1545 }
1546 bool enable = data.ReadBool();
1547 int enforcerId = data.ReadInt32();
1548 if (enforcerId < 0) {
1549 ACCOUNT_LOGE("failed to read int for localId");
1550 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1551 return ERR_NONE;
1552 }
1553 bool isDeviceOwner = data.ReadBool();
1554 ErrCode result = SetGlobalOsAccountConstraints(constraints, enable, enforcerId, isDeviceOwner);
1555 if (!reply.WriteInt32(result)) {
1556 ACCOUNT_LOGE("failed to write reply");
1557 return IPC_STUB_WRITE_PARCEL_ERR;
1558 }
1559 return ERR_NONE;
1560 }
1561
ProcSetDefaultActivatedOsAccount(MessageParcel & data,MessageParcel & reply)1562 ErrCode OsAccountStub::ProcSetDefaultActivatedOsAccount(MessageParcel &data, MessageParcel &reply)
1563 {
1564 int32_t localId;
1565 if (!data.ReadInt32(localId)) {
1566 ACCOUNT_LOGE("failed to read localId");
1567 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1568 }
1569 ErrCode result = SetDefaultActivatedOsAccount(localId);
1570 if (!reply.WriteInt32(result)) {
1571 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1572 return IPC_STUB_WRITE_PARCEL_ERR;
1573 }
1574 return ERR_NONE;
1575 }
1576
ProcGetDefaultActivatedOsAccount(MessageParcel & data,MessageParcel & reply)1577 ErrCode OsAccountStub::ProcGetDefaultActivatedOsAccount(MessageParcel &data, MessageParcel &reply)
1578 {
1579 int32_t localId = 0;
1580 ErrCode result = GetDefaultActivatedOsAccount(localId);
1581 if (!reply.WriteInt32(result)) {
1582 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1583 return IPC_STUB_WRITE_PARCEL_ERR;
1584 }
1585 if (!reply.WriteInt32(localId)) {
1586 ACCOUNT_LOGE("failed to write reply");
1587 return IPC_STUB_WRITE_PARCEL_ERR;
1588 }
1589 return ERR_NONE;
1590 }
1591
ProcGetOsAccountShortName(MessageParcel & data,MessageParcel & reply)1592 ErrCode OsAccountStub::ProcGetOsAccountShortName(MessageParcel &data, MessageParcel &reply)
1593 {
1594 std::string shortName;
1595 ErrCode result = GetOsAccountShortName(shortName);
1596 if (!reply.WriteInt32(result)) {
1597 ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
1598 return IPC_STUB_WRITE_PARCEL_ERR;
1599 }
1600 if (!reply.WriteString(shortName)) {
1601 ACCOUNT_LOGE("failed to write reply");
1602 return IPC_STUB_WRITE_PARCEL_ERR;
1603 }
1604 return ERR_NONE;
1605 }
1606
ProcGetOsAccountName(MessageParcel & data,MessageParcel & reply)1607 ErrCode OsAccountStub::ProcGetOsAccountName(MessageParcel &data, MessageParcel &reply)
1608 {
1609 std::string name;
1610 ErrCode result = GetOsAccountName(name);
1611 if (!reply.WriteInt32(result)) {
1612 ACCOUNT_LOGE("Failed to write result, result=%{public}d.", result);
1613 return IPC_STUB_WRITE_PARCEL_ERR;
1614 }
1615 if (!reply.WriteString(name)) {
1616 ACCOUNT_LOGE("Failed to write name");
1617 return IPC_STUB_WRITE_PARCEL_ERR;
1618 }
1619 return ERR_NONE;
1620 }
1621
ProcGetOsAccountShortNameById(MessageParcel & data,MessageParcel & reply)1622 ErrCode OsAccountStub::ProcGetOsAccountShortNameById(MessageParcel &data, MessageParcel &reply)
1623 {
1624 int32_t id;
1625 if (!data.ReadInt32(id)) {
1626 ACCOUNT_LOGE("Read id failed.");
1627 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1628 }
1629 std::string shortName;
1630 ErrCode result = GetOsAccountShortNameById(id, shortName);
1631 if (!reply.WriteInt32(result)) {
1632 ACCOUNT_LOGE("Write result failed.");
1633 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1634 }
1635 if (result != ERR_OK) {
1636 return ERR_NONE;
1637 }
1638 if (!reply.WriteString(shortName)) {
1639 ACCOUNT_LOGE("Write short name failed.");
1640 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1641 }
1642 return ERR_NONE;
1643 }
1644
ProcSetSpecificOsAccountConstraints(MessageParcel & data,MessageParcel & reply)1645 ErrCode OsAccountStub::ProcSetSpecificOsAccountConstraints(MessageParcel &data, MessageParcel &reply)
1646 {
1647 std::vector<std::string> constraints;
1648 bool stringVectorReadSucess = data.ReadStringVector(&constraints);
1649 if (!stringVectorReadSucess) {
1650 ACCOUNT_LOGE("failed to read StringVector for constraints");
1651 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1652 }
1653 bool enable = data.ReadBool();
1654 int targetId = data.ReadInt32();
1655 if (targetId < 0) {
1656 ACCOUNT_LOGE("failed to read int for targetId");
1657 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1658 return ERR_NONE;
1659 }
1660 int enforcerId = data.ReadInt32();
1661 if (enforcerId < 0) {
1662 ACCOUNT_LOGE("failed to read int for enforcerId");
1663 reply.WriteInt32(ERR_OSACCOUNT_KIT_READ_IN_LOCAL_ID_ERROR);
1664 return ERR_NONE;
1665 }
1666 bool isDeviceOwner = data.ReadBool();
1667 ErrCode result = SetSpecificOsAccountConstraints(constraints, enable, targetId, enforcerId, isDeviceOwner);
1668 if (!reply.WriteInt32(result)) {
1669 ACCOUNT_LOGE("failed to write reply");
1670 return IPC_STUB_WRITE_PARCEL_ERR;
1671 }
1672 return ERR_NONE;
1673 }
1674
ProcIsOsAccountForeground(MessageParcel & data,MessageParcel & reply)1675 ErrCode OsAccountStub::ProcIsOsAccountForeground(MessageParcel &data, MessageParcel &reply)
1676 {
1677 int32_t localId;
1678 if (!data.ReadInt32(localId)) {
1679 ACCOUNT_LOGE("Read localId failed.");
1680 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1681 }
1682 uint64_t displayId;
1683 if (!data.ReadUint64(displayId)) {
1684 ACCOUNT_LOGE("Read displayId failed.");
1685 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1686 }
1687 bool isForeground = false;
1688 ErrCode result = IsOsAccountForeground(localId, displayId, isForeground);
1689 if (!reply.WriteInt32(result)) {
1690 ACCOUNT_LOGE("Write result failed.");
1691 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1692 }
1693 if (result != ERR_OK) {
1694 return result;
1695 }
1696 if (!reply.WriteBool(isForeground)) {
1697 ACCOUNT_LOGE("Write isForeground failed.");
1698 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1699 }
1700 return ERR_NONE;
1701 }
1702
ProcGetForegroundOsAccountLocalId(MessageParcel & data,MessageParcel & reply)1703 ErrCode OsAccountStub::ProcGetForegroundOsAccountLocalId(MessageParcel &data, MessageParcel &reply)
1704 {
1705 uint64_t displayId;
1706 if (!data.ReadUint64(displayId)) {
1707 ACCOUNT_LOGE("Read displayId failed.");
1708 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1709 }
1710 int32_t localId;
1711 ErrCode result = GetForegroundOsAccountLocalId(displayId, localId);
1712 if (!reply.WriteInt32(result)) {
1713 ACCOUNT_LOGE("Write result failed.");
1714 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1715 }
1716 if (result != ERR_OK) {
1717 return result;
1718 }
1719 if (!reply.WriteInt32(localId)) {
1720 ACCOUNT_LOGE("Write localId failed.");
1721 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1722 }
1723 return ERR_NONE;
1724 }
1725
ProcGetForegroundOsAccounts(MessageParcel & data,MessageParcel & reply)1726 ErrCode OsAccountStub::ProcGetForegroundOsAccounts(MessageParcel &data, MessageParcel &reply)
1727 {
1728 std::vector<ForegroundOsAccount> foregroundAccounts;
1729 ErrCode result = GetForegroundOsAccounts(foregroundAccounts);
1730 if (!reply.WriteInt32(result)) {
1731 ACCOUNT_LOGE("Write result failed.");
1732 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1733 }
1734 if (result != ERR_OK) {
1735 return result;
1736 }
1737 if (!reply.WriteUint32(foregroundAccounts.size())) {
1738 ACCOUNT_LOGE("Write foregroundAccounts size failed.");
1739 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1740 }
1741 for (const auto &iter : foregroundAccounts) {
1742 if ((!reply.WriteInt32(iter.localId)) || (!reply.WriteUint64(iter.displayId))) {
1743 ACCOUNT_LOGE("Write ForegroundOsAccount failed.");
1744 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1745 }
1746 }
1747 return ERR_NONE;
1748 }
1749
ProcGetBackgroundOsAccountLocalIds(MessageParcel & data,MessageParcel & reply)1750 ErrCode OsAccountStub::ProcGetBackgroundOsAccountLocalIds(MessageParcel &data, MessageParcel &reply)
1751 {
1752 std::vector<int32_t> localIds;
1753 ErrCode result = GetBackgroundOsAccountLocalIds(localIds);
1754 if (!reply.WriteInt32(result)) {
1755 ACCOUNT_LOGE("Write result failed.");
1756 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1757 }
1758 if (result != ERR_OK) {
1759 return result;
1760 }
1761 if (!reply.WriteInt32Vector(localIds)) {
1762 ACCOUNT_LOGE("Write localIds failed.");
1763 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1764 }
1765 return ERR_NONE;
1766 }
1767
ProcSetOsAccountToBeRemoved(MessageParcel & data,MessageParcel & reply)1768 ErrCode OsAccountStub::ProcSetOsAccountToBeRemoved(MessageParcel &data, MessageParcel &reply)
1769 {
1770 int32_t localId;
1771 if (!data.ReadInt32(localId)) {
1772 ACCOUNT_LOGE("Read localId failed.");
1773 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1774 }
1775 bool toBeRemoved = false;
1776 if (!data.ReadBool(toBeRemoved)) {
1777 ACCOUNT_LOGE("Read toBeRemoved failed.");
1778 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
1779 }
1780 ErrCode result = SetOsAccountToBeRemoved(localId, toBeRemoved);
1781 if (!reply.WriteInt32(result)) {
1782 ACCOUNT_LOGE("Write result failed.");
1783 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
1784 }
1785 return ERR_NONE;
1786 }
1787 } // namespace AccountSA
1788 } // namespace OHOS
1789