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