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