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