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