• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
16 #include "app_account_stub.h"
17 
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20 #include "app_account_constants.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 #define RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(str)                        \
25     if (CheckSpecialCharacters(str) != ERR_OK) {                           \
26         ACCOUNT_LOGE("fail to check special characters");                  \
27         if (!reply.WriteInt32(ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER)) { \
28             ACCOUNT_LOGE("failed to write reply");                         \
29             return IPC_STUB_WRITE_PARCEL_ERR;                              \
30         }                                                                  \
31         return ERR_NONE;                                                   \
32     }                                                                      \
33 
34 #define RETURN_IF_STRING_IS_OVERSIZE(str, maxSize, msg)                                                         \
35     if ((str).size() > (maxSize)) {                                                                             \
36         ACCOUNT_LOGE("%{public}s, input size: %{public}zu, max size: %{public}zu", msg, (str).size(), maxSize); \
37         if (!reply.WriteInt32(ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER)) {                                      \
38             ACCOUNT_LOGE("failed to write reply");                                                              \
39             return IPC_STUB_WRITE_PARCEL_ERR;                                                                   \
40         }                                                                                                       \
41         return ERR_NONE;                                                                                        \
42     }                                                                                                           \
43 
44 #define RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(str, maxSize, msg)                                                \
45     if ((str).empty() || ((str).size() > (maxSize))) {                                                          \
46         ACCOUNT_LOGE("%{public}s, input size: %{public}zu, max size: %{public}zu", msg, (str).size(), maxSize); \
47         if (!reply.WriteInt32(ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER)) {                                      \
48             ACCOUNT_LOGE("failed to write reply");                                                              \
49             return IPC_STUB_WRITE_PARCEL_ERR;                                                                   \
50         }                                                                                                       \
51         return ERR_NONE;                                                                                        \
52     }                                                                                                           \
53 
54 const std::map<uint32_t, AppAccountStub::MessageProcFunction> AppAccountStub::messageProcMap_ = {
55     {
56         static_cast<uint32_t>(IAppAccount::Message::ADD_ACCOUNT),
57         &AppAccountStub::ProcAddAccount,
58     },
59     {
60         static_cast<uint32_t>(IAppAccount::Message::ADD_ACCOUNT_IMPLICITLY),
61         &AppAccountStub::ProcAddAccountImplicitly,
62     },
63     {
64         static_cast<uint32_t>(IAppAccount::Message::CREATE_ACCOUNT),
65         &AppAccountStub::ProcCreateAccount,
66     },
67     {
68         static_cast<uint32_t>(IAppAccount::Message::CREATE_ACCOUNT_IMPLICITLY),
69         &AppAccountStub::ProcCreateAccountImplicitly,
70     },
71     {
72         static_cast<uint32_t>(IAppAccount::Message::DELETE_ACCOUNT),
73         &AppAccountStub::ProcDeleteAccount,
74     },
75     {
76         static_cast<uint32_t>(IAppAccount::Message::GET_ACCOUNT_EXTRA_INFO),
77         &AppAccountStub::ProcGetAccountExtraInfo,
78     },
79     {
80         static_cast<uint32_t>(IAppAccount::Message::SET_ACCOUNT_EXTRA_INFO),
81         &AppAccountStub::ProcSetAccountExtraInfo,
82     },
83     {
84         static_cast<uint32_t>(IAppAccount::Message::ENABLE_APP_ACCESS),
85         &AppAccountStub::ProcSetAppAccess,
86     },
87     {
88         static_cast<uint32_t>(IAppAccount::Message::DISABLE_APP_ACCESS),
89         &AppAccountStub::ProcSetAppAccess,
90     },
91     {
92         static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCESS),
93         &AppAccountStub::ProcSetAppAccess,
94     },
95     {
96         static_cast<uint32_t>(IAppAccount::Message::CHECK_APP_ACCESS),
97         &AppAccountStub::ProcCheckAppAccess,
98     },
99     {
100         static_cast<uint32_t>(IAppAccount::Message::CHECK_APP_ACCOUNT_SYNC_ENABLE),
101         &AppAccountStub::ProcCheckAppAccountSyncEnable,
102     },
103     {
104         static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCOUNT_SYNC_ENABLE),
105         &AppAccountStub::ProcSetAppAccountSyncEnable,
106     },
107     {
108         static_cast<uint32_t>(IAppAccount::Message::GET_ASSOCIATED_DATA),
109         &AppAccountStub::ProcGetAssociatedData,
110     },
111     {
112         static_cast<uint32_t>(IAppAccount::Message::SET_ASSOCIATED_DATA),
113         &AppAccountStub::ProcSetAssociatedData,
114     },
115     {
116         static_cast<uint32_t>(IAppAccount::Message::GET_ACCOUNT_CREDENTIAL),
117         &AppAccountStub::ProcGetAccountCredential,
118     },
119     {
120         static_cast<uint32_t>(IAppAccount::Message::SET_ACCOUNT_CREDENTIAL),
121         &AppAccountStub::ProcSetAccountCredential,
122     },
123     {
124         static_cast<uint32_t>(IAppAccount::Message::DELETE_ACCOUNT_CREDENTIAL),
125         &AppAccountStub::ProcDeleteAccountCredential,
126     },
127     {
128         static_cast<uint32_t>(IAppAccount::Message::AUTHENTICATE),
129         &AppAccountStub::ProcAuthenticate,
130     },
131     {
132         static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_TOKEN),
133         &AppAccountStub::ProcGetAuthToken,
134     },
135     {
136         static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_TOKEN),
137         &AppAccountStub::ProcGetAuthToken,
138     },
139     {
140         static_cast<uint32_t>(IAppAccount::Message::SET_OAUTH_TOKEN),
141         &AppAccountStub::ProcSetOAuthToken,
142     },
143     {
144         static_cast<uint32_t>(IAppAccount::Message::DELETE_OAUTH_TOKEN),
145         &AppAccountStub::ProcDeleteAuthToken,
146     },
147     {
148         static_cast<uint32_t>(IAppAccount::Message::DELETE_AUTH_TOKEN),
149         &AppAccountStub::ProcDeleteAuthToken,
150     },
151     {
152         static_cast<uint32_t>(IAppAccount::Message::SET_OAUTH_TOKEN_VISIBILITY),
153         &AppAccountStub::ProcSetAuthTokenVisibility,
154     },
155     {
156         static_cast<uint32_t>(IAppAccount::Message::SET_AUTH_TOKEN_VISIBILITY),
157         &AppAccountStub::ProcSetAuthTokenVisibility,
158     },
159     {
160         static_cast<uint32_t>(IAppAccount::Message::CHECK_OAUTH_TOKEN_VISIBILITY),
161         &AppAccountStub::ProcCheckAuthTokenVisibility,
162     },
163     {
164         static_cast<uint32_t>(IAppAccount::Message::CHECK_AUTH_TOKEN_VISIBILITY),
165         &AppAccountStub::ProcCheckAuthTokenVisibility,
166     },
167     {
168         static_cast<uint32_t>(IAppAccount::Message::GET_AUTHENTICATOR_CALLBACK),
169         &AppAccountStub::ProcGetAuthenticatorCallback,
170     },
171     {
172         static_cast<uint32_t>(IAppAccount::Message::GET_AUTHENTICATOR_INFO),
173         &AppAccountStub::ProcGetAuthenticatorInfo,
174     },
175     {
176         static_cast<uint32_t>(IAppAccount::Message::GET_ALL_OAUTH_TOKENS),
177         &AppAccountStub::ProcGetAllOAuthTokens,
178     },
179     {
180         static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_LIST),
181         &AppAccountStub::ProcGetAuthList,
182     },
183     {
184         static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_LIST),
185         &AppAccountStub::ProcGetAuthList,
186     },
187     {
188         static_cast<uint32_t>(IAppAccount::Message::GET_ALL_ACCOUNTS),
189         &AppAccountStub::ProcGetAllAccounts,
190     },
191     {
192         static_cast<uint32_t>(IAppAccount::Message::GET_ALL_ACCESSIBLE_ACCOUNTS),
193         &AppAccountStub::ProcGetAllAccessibleAccounts,
194     },
195     {
196         static_cast<uint32_t>(IAppAccount::Message::QUERY_ALL_ACCESSIBLE_ACCOUNTS),
197         &AppAccountStub::ProcGetAllAccessibleAccounts,
198     },
199     {
200         static_cast<uint32_t>(IAppAccount::Message::SELECT_ACCOUNTS_BY_OPTIONS),
201         &AppAccountStub::ProcSelectAccountsByOptions,
202     },
203     {
204         static_cast<uint32_t>(IAppAccount::Message::VERIFY_CREDENTIAL),
205         &AppAccountStub::ProcVerifyCredential,
206     },
207     {
208         static_cast<uint32_t>(IAppAccount::Message::CHECK_ACCOUNT_LABELS),
209         &AppAccountStub::ProcCheckAccountLabels,
210     },
211     {
212         static_cast<uint32_t>(IAppAccount::Message::SET_AUTHENTICATOR_PROPERTIES),
213         &AppAccountStub::ProcSetAuthenticatorProperties,
214     },
215     {
216         static_cast<uint32_t>(IAppAccount::Message::SUBSCRIBE_ACCOUNT),
217         &AppAccountStub::ProcSubscribeAccount,
218     },
219     {
220         static_cast<uint32_t>(IAppAccount::Message::UNSUBSCRIBE_ACCOUNT),
221         &AppAccountStub::ProcUnsubscribeAccount,
222     },
223 };
224 
AppAccountStub()225 AppAccountStub::AppAccountStub()
226 {}
227 
~AppAccountStub()228 AppAccountStub::~AppAccountStub()
229 {}
230 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)231 int AppAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
232 {
233     if (data.ReadInterfaceToken() != GetDescriptor()) {
234         ACCOUNT_LOGE("failed to check descriptor! code %{public}u.", code);
235         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
236     }
237 
238     auto messageProc = messageProcMap_.find(code);
239     if (messageProc != messageProcMap_.end()) {
240         auto messageProcFunction = messageProc->second;
241         if (messageProcFunction != nullptr) {
242             int ret = (this->*messageProcFunction)(code, data, reply);
243             return ret;
244         }
245     }
246 
247     ACCOUNT_LOGD("end, code = %{public}u, flags = %{public}u", code, option.GetFlags());
248 
249     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
250 }
251 
252 template<typename T>
WriteParcelableVector(const std::vector<T> & parcelableVector,MessageParcel & data)253 bool AppAccountStub::WriteParcelableVector(const std::vector<T> &parcelableVector, MessageParcel &data)
254 {
255     if (!data.WriteUint32(parcelableVector.size())) {
256         ACCOUNT_LOGE("failed to WriteInt32 for parcelableVector.size()");
257         return false;
258     }
259 
260     for (const auto &parcelable : parcelableVector) {
261         if (!data.WriteParcelable(&parcelable)) {
262             ACCOUNT_LOGE("failed to WriteParcelable for parcelable");
263             return false;
264         }
265     }
266 
267     return true;
268 }
269 
270 template<typename T>
ReadParcelableVector(std::vector<T> & parcelableVector,MessageParcel & data)271 bool AppAccountStub::ReadParcelableVector(std::vector<T> &parcelableVector, MessageParcel &data)
272 {
273     uint32_t size = 0;
274     if (!data.ReadUint32(size)) {
275         ACCOUNT_LOGE("read Parcelable size failed.");
276         return false;
277     }
278 
279     parcelableVector.clear();
280     for (uint32_t index = 0; index < size; index++) {
281         std::shared_ptr<T> info(data.ReadParcelable<T>());
282         if (info == nullptr) {
283             ACCOUNT_LOGE("read Parcelable infos failed.");
284             return false;
285         }
286         parcelableVector.emplace_back(*info);
287     }
288 
289     return true;
290 }
291 
CheckSpecialCharacters(const std::string & str)292 static ErrCode CheckSpecialCharacters(const std::string &str)
293 {
294     for (auto specialCharacter : Constants::SPECIAL_CHARACTERS) {
295         std::size_t found = str.find(specialCharacter);
296         if (found != std::string::npos) {
297             ACCOUNT_LOGE("found a special character, specialCharacter = %{public}c", specialCharacter);
298             return ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
299         }
300     }
301     return ERR_OK;
302 }
303 
ProcAddAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)304 ErrCode AppAccountStub::ProcAddAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
305 {
306     std::string name = data.ReadString();
307     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
308     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
309     std::string extraInfo = data.ReadString();
310     RETURN_IF_STRING_IS_OVERSIZE(extraInfo, Constants::EXTRA_INFO_MAX_SIZE, "extraInfo is oversize");
311     ErrCode result = AddAccount(name, extraInfo);
312     if (!reply.WriteInt32(result)) {
313         ACCOUNT_LOGE("failed to write reply");
314         return IPC_STUB_WRITE_PARCEL_ERR;
315     }
316     return ERR_NONE;
317 }
318 
ProcAddAccountImplicitly(uint32_t code,MessageParcel & data,MessageParcel & reply)319 ErrCode AppAccountStub::ProcAddAccountImplicitly(uint32_t code, MessageParcel &data, MessageParcel &reply)
320 {
321     std::string owner = data.ReadString();
322     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
323     std::string authType = data.ReadString();
324     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
325     std::shared_ptr<AAFwk::Want> options(data.ReadParcelable<AAFwk::Want>());
326     ErrCode result = ERR_OK;
327     if (options == nullptr) {
328         ACCOUNT_LOGE("invalid options");
329         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
330     } else {
331         RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(options->GetStringParam(Constants::KEY_CALLER_ABILITY_NAME),
332             Constants::ABILITY_NAME_MAX_SIZE, "abilityName is empty or oversize");
333         sptr<IRemoteObject> callback = data.ReadRemoteObject();
334         result = AddAccountImplicitly(owner, authType, *options, callback);
335     }
336     if (!reply.WriteInt32(result)) {
337         ACCOUNT_LOGE("failed to write reply");
338         return IPC_STUB_WRITE_PARCEL_ERR;
339     }
340     return ERR_NONE;
341 }
342 
ProcCreateAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)343 ErrCode AppAccountStub::ProcCreateAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
344 {
345     std::string name = data.ReadString();
346     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
347     sptr<CreateAccountOptions> options = data.ReadParcelable<CreateAccountOptions>();
348     ErrCode result = ERR_OK;
349     if (options == nullptr) {
350         ACCOUNT_LOGE("invalid options");
351         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
352     } else {
353         RETURN_IF_STRING_IS_OVERSIZE(options->customData, Constants::MAX_CUSTOM_DATA_SIZE, "customData is oversize");
354         for (const auto &it : options->customData) {
355             RETURN_IF_STRING_IS_OVERSIZE(it.first, Constants::ASSOCIATED_KEY_MAX_SIZE, "customData key is oversize");
356             RETURN_IF_STRING_IS_OVERSIZE(
357                 it.second, Constants::ASSOCIATED_VALUE_MAX_SIZE, "customData value is oversize");
358         }
359         result = CreateAccount(name, *options);
360     }
361     if (!reply.WriteInt32(result)) {
362         ACCOUNT_LOGE("failed to write reply");
363         return IPC_STUB_WRITE_PARCEL_ERR;
364     }
365     return ERR_NONE;
366 }
367 
ProcCreateAccountImplicitly(uint32_t code,MessageParcel & data,MessageParcel & reply)368 ErrCode AppAccountStub::ProcCreateAccountImplicitly(uint32_t code, MessageParcel &data, MessageParcel &reply)
369 {
370     std::string owner = data.ReadString();
371     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
372     sptr<CreateAccountImplicitlyOptions> options = data.ReadParcelable<CreateAccountImplicitlyOptions>();
373     ErrCode result = ERR_OK;
374     if (options == nullptr) {
375         ACCOUNT_LOGE("invalid options");
376         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
377     } else {
378         RETURN_IF_STRING_IS_OVERSIZE(options->authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is empty or oversize");
379         RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(options->parameters.GetStringParam(Constants::KEY_CALLER_ABILITY_NAME),
380             Constants::ABILITY_NAME_MAX_SIZE, "abilityName is empty or oversize");
381         RETURN_IF_STRING_IS_OVERSIZE(
382             options->requiredLabels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "requiredLabels array is oversize");
383         sptr<IRemoteObject> callback = data.ReadRemoteObject();
384         result = CreateAccountImplicitly(owner, *options, callback);
385     }
386     if (!reply.WriteInt32(result)) {
387         ACCOUNT_LOGE("failed to write reply");
388         return IPC_STUB_WRITE_PARCEL_ERR;
389     }
390     return ERR_NONE;
391 }
392 
ProcDeleteAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)393 ErrCode AppAccountStub::ProcDeleteAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
394 {
395     std::string name = data.ReadString();
396     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
397     ErrCode result = DeleteAccount(name);
398     if (!reply.WriteInt32(result)) {
399         ACCOUNT_LOGE("failed to write reply");
400         return IPC_STUB_WRITE_PARCEL_ERR;
401     }
402 
403     return ERR_NONE;
404 }
405 
ProcGetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)406 ErrCode AppAccountStub::ProcGetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
407 {
408     std::string name = data.ReadString();
409     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
410     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
411     std::string extraInfo;
412     ErrCode result = GetAccountExtraInfo(name, extraInfo);
413     if (!reply.WriteInt32(result)) {
414         ACCOUNT_LOGE("failed to write reply");
415         return IPC_STUB_WRITE_PARCEL_ERR;
416     }
417     if (!reply.WriteString(extraInfo)) {
418         ACCOUNT_LOGE("failed to write string for extra info");
419         return IPC_STUB_WRITE_PARCEL_ERR;
420     }
421     return ERR_NONE;
422 }
423 
ProcSetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)424 ErrCode AppAccountStub::ProcSetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
425 {
426     std::string name = data.ReadString();
427     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
428     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
429     std::string extraInfo = data.ReadString();
430     RETURN_IF_STRING_IS_OVERSIZE(extraInfo, Constants::EXTRA_INFO_MAX_SIZE, "extraInfo is oversize");
431     ErrCode result = SetAccountExtraInfo(name, extraInfo);
432     if (!reply.WriteInt32(result)) {
433         ACCOUNT_LOGE("failed to write reply");
434         return IPC_STUB_WRITE_PARCEL_ERR;
435     }
436     return ERR_NONE;
437 }
438 
ProcSetAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)439 ErrCode AppAccountStub::ProcSetAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
440 {
441     std::string name = data.ReadString();
442     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
443     if (code != static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCESS)) {
444         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
445     }
446 
447     std::string authorizedApp = data.ReadString();
448     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(authorizedApp, Constants::BUNDLE_NAME_MAX_SIZE,
449         "bundleName is empty or oversize");
450 
451     ErrCode result = ERR_OK;
452     if (code == static_cast<uint32_t>(IAppAccount::Message::ENABLE_APP_ACCESS)) {
453         result = EnableAppAccess(name, authorizedApp);
454     } else if (code == static_cast<uint32_t>(IAppAccount::Message::DISABLE_APP_ACCESS)) {
455         result = DisableAppAccess(name, authorizedApp);
456     } else if (code == static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCESS)) {
457         bool isAccessible = data.ReadBool();
458         result = SetAppAccess(name, authorizedApp, isAccessible);
459     } else {
460         ACCOUNT_LOGE("stub code is invalid");
461         return IPC_INVOKER_ERR;
462     }
463 
464     if (!reply.WriteInt32(result)) {
465         ACCOUNT_LOGE("failed to write reply");
466         return IPC_STUB_WRITE_PARCEL_ERR;
467     }
468     return ERR_NONE;
469 }
470 
ProcCheckAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)471 ErrCode AppAccountStub::ProcCheckAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
472 {
473     std::string name = data.ReadString();
474     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
475     bool syncEnable = false;
476     ErrCode result = CheckAppAccountSyncEnable(name, syncEnable);
477     if (!reply.WriteInt32(result)) {
478         ACCOUNT_LOGE("failed to write reply");
479         return IPC_STUB_WRITE_PARCEL_ERR;
480     }
481     if (!reply.WriteBool(syncEnable)) {
482         ACCOUNT_LOGE("failed to write bool for syncEnable");
483         return IPC_STUB_WRITE_PARCEL_ERR;
484     }
485     return ERR_NONE;
486 }
487 
ProcSetAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)488 ErrCode AppAccountStub::ProcSetAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
489 {
490     std::string name = data.ReadString();
491     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
492     bool syncEnable = data.ReadBool();
493     ErrCode result = SetAppAccountSyncEnable(name, syncEnable);
494     if (!reply.WriteInt32(result)) {
495         ACCOUNT_LOGE("failed to write reply");
496         return IPC_STUB_WRITE_PARCEL_ERR;
497     }
498     return ERR_NONE;
499 }
500 
ProcGetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)501 ErrCode AppAccountStub::ProcGetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
502 {
503     std::string name = data.ReadString();
504     std::string key = data.ReadString();
505     std::string value;
506     ErrCode result = GetAssociatedData(name, key, value);
507     if (!reply.WriteInt32(result)) {
508         ACCOUNT_LOGE("failed to write reply");
509         return IPC_STUB_WRITE_PARCEL_ERR;
510     }
511     if (!reply.WriteString(value)) {
512         ACCOUNT_LOGE("failed to write string for value");
513         return IPC_STUB_WRITE_PARCEL_ERR;
514     }
515     return ERR_NONE;
516 }
517 
ProcSetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)518 ErrCode AppAccountStub::ProcSetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
519 {
520     std::string name = data.ReadString();
521     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
522     std::string key = data.ReadString();
523     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(key, Constants::ASSOCIATED_KEY_MAX_SIZE, "key is empty or oversize");
524     std::string value = data.ReadString();
525     RETURN_IF_STRING_IS_OVERSIZE(value, Constants::ASSOCIATED_VALUE_MAX_SIZE, "value is oversize");
526     ErrCode result = SetAssociatedData(name, key, value);
527     if (!reply.WriteInt32(result)) {
528         ACCOUNT_LOGE("failed to write reply");
529         return IPC_STUB_WRITE_PARCEL_ERR;
530     }
531     return ERR_NONE;
532 }
533 
ProcGetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)534 ErrCode AppAccountStub::ProcGetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
535 {
536     std::string name = data.ReadString();
537     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
538     std::string credentialType = data.ReadString();
539     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
540         "credentialType is empty or oversize");
541     std::string credential;
542     ErrCode result = GetAccountCredential(name, credentialType, credential);
543     if (!reply.WriteInt32(result)) {
544         ACCOUNT_LOGE("failed to write reply");
545         return IPC_STUB_WRITE_PARCEL_ERR;
546     }
547     if (!reply.WriteString(credential)) {
548         ACCOUNT_LOGE("failed to write string for credential");
549         return IPC_STUB_WRITE_PARCEL_ERR;
550     }
551     return ERR_NONE;
552 }
553 
ProcSetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)554 ErrCode AppAccountStub::ProcSetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
555 {
556     std::string name = data.ReadString();
557     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
558     std::string credentialType = data.ReadString();
559     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
560         "credentialType is empty or oversize");
561     std::string credential = data.ReadString();
562     RETURN_IF_STRING_IS_OVERSIZE(credential, Constants::CREDENTIAL_MAX_SIZE, "credential is oversize");
563     ErrCode result = SetAccountCredential(name, credentialType, credential);
564     if (!reply.WriteInt32(result)) {
565         ACCOUNT_LOGE("failed to write reply");
566         return IPC_STUB_WRITE_PARCEL_ERR;
567     }
568     return ERR_NONE;
569 }
570 
ProcAuthenticate(uint32_t code,MessageParcel & data,MessageParcel & reply)571 ErrCode AppAccountStub::ProcAuthenticate(uint32_t code, MessageParcel &data, MessageParcel &reply)
572 {
573     std::string name = data.ReadString();
574     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
575     std::string owner = data.ReadString();
576     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
577     std::string authType = data.ReadString();
578     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
579     std::shared_ptr<AAFwk::Want> options(data.ReadParcelable<AAFwk::Want>());
580     ErrCode result = ERR_OK;
581     if (options == nullptr) {
582         ACCOUNT_LOGE("invalid options");
583         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
584     } else {
585         RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(options->GetStringParam(Constants::KEY_CALLER_ABILITY_NAME),
586             Constants::ABILITY_NAME_MAX_SIZE, "abilityName is empty or oversize");
587         sptr<IRemoteObject> callback = data.ReadRemoteObject();
588         result = Authenticate(name, owner, authType, *options, callback);
589     }
590     if (!reply.WriteInt32(result)) {
591         ACCOUNT_LOGE("failed to write reply");
592         return IPC_STUB_WRITE_PARCEL_ERR;
593     }
594     return ERR_NONE;
595 }
596 
ProcGetAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)597 ErrCode AppAccountStub::ProcGetAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
598 {
599     std::string name = data.ReadString();
600     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
601     std::string owner = data.ReadString();
602     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
603     std::string authType = data.ReadString();
604     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
605     std::string token;
606     ErrCode result = ERR_OK;
607     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_TOKEN)) {
608         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
609         result = GetOAuthToken(name, owner, authType, token);
610     } else if (code == static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_TOKEN)) {
611         result = GetAuthToken(name, owner, authType, token);
612     } else {
613         ACCOUNT_LOGE("stub code is invalid");
614         return IPC_INVOKER_ERR;
615     }
616     if ((!reply.WriteInt32(result)) || (!reply.WriteString(token))) {
617         ACCOUNT_LOGE("failed to write reply");
618         return IPC_STUB_WRITE_PARCEL_ERR;
619     }
620     return ERR_NONE;
621 }
622 
ProcSetOAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)623 ErrCode AppAccountStub::ProcSetOAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
624 {
625     std::string name = data.ReadString();
626     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
627     std::string authType = data.ReadString();
628     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
629     std::string token = data.ReadString();
630     RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize");
631     ErrCode result = SetOAuthToken(name, authType, token);
632     if (!reply.WriteInt32(result)) {
633         ACCOUNT_LOGE("failed to write reply");
634         return IPC_STUB_WRITE_PARCEL_ERR;
635     }
636     return ERR_NONE;
637 }
638 
ProcDeleteAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)639 ErrCode AppAccountStub::ProcDeleteAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
640 {
641     std::string name = data.ReadString();
642     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
643     std::string owner = data.ReadString();
644     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
645     std::string authType = data.ReadString();
646     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
647     std::string token = data.ReadString();
648     RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize");
649 
650     ErrCode result = ERR_OK;
651     if (code == static_cast<uint32_t>(IAppAccount::Message::DELETE_OAUTH_TOKEN)) {
652         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
653         result = DeleteOAuthToken(name, owner, authType, token);
654     } else if (code == static_cast<uint32_t>(IAppAccount::Message::DELETE_AUTH_TOKEN)) {
655         result = DeleteAuthToken(name, owner, authType, token);
656     } else {
657         ACCOUNT_LOGE("stub code is invalid");
658         return IPC_INVOKER_ERR;
659     }
660 
661     if (!reply.WriteInt32(result)) {
662         ACCOUNT_LOGE("failed to write reply");
663         return IPC_STUB_WRITE_PARCEL_ERR;
664     }
665     return ERR_NONE;
666 }
667 
ProcSetAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)668 ErrCode AppAccountStub::ProcSetAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
669 {
670     std::string name = data.ReadString();
671     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
672     std::string authType = data.ReadString();
673     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
674     std::string bundleName = data.ReadString();
675     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
676         "bundleName is empty or oversize");
677     bool isVisible = data.ReadBool();
678     ErrCode result = ERR_OK;
679     if (code == static_cast<uint32_t>(IAppAccount::Message::SET_OAUTH_TOKEN_VISIBILITY)) {
680         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
681         result = SetOAuthTokenVisibility(name, authType, bundleName, isVisible);
682     } else if (code == static_cast<uint32_t>(IAppAccount::Message::SET_AUTH_TOKEN_VISIBILITY)) {
683         result = SetAuthTokenVisibility(name, authType, bundleName, isVisible);
684     } else {
685         ACCOUNT_LOGE("stub code is invalid");
686         return IPC_INVOKER_ERR;
687     }
688 
689     if (!reply.WriteInt32(result)) {
690         ACCOUNT_LOGE("failed to write reply");
691         return IPC_STUB_WRITE_PARCEL_ERR;
692     }
693     return ERR_NONE;
694 }
695 
ProcCheckAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)696 ErrCode AppAccountStub::ProcCheckAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
697 {
698     std::string name = data.ReadString();
699     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
700     std::string authType = data.ReadString();
701     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
702     std::string bundleName = data.ReadString();
703     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
704         "bundleName is empty or oversize");
705     bool isVisible = false;
706     ErrCode result = ERR_OK;
707     if (code == static_cast<uint32_t>(IAppAccount::Message::CHECK_OAUTH_TOKEN_VISIBILITY)) {
708         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
709         result = CheckOAuthTokenVisibility(name, authType, bundleName, isVisible);
710     } else if (code == static_cast<uint32_t>(IAppAccount::Message::CHECK_AUTH_TOKEN_VISIBILITY)) {
711         result = CheckAuthTokenVisibility(name, authType, bundleName, isVisible);
712     } else {
713         ACCOUNT_LOGE("stub code is invalid");
714         return IPC_INVOKER_ERR;
715     }
716 
717     if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isVisible))) {
718         ACCOUNT_LOGE("failed to write reply");
719         return IPC_STUB_WRITE_PARCEL_ERR;
720     }
721     return ERR_NONE;
722 }
723 
ProcGetAuthenticatorInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)724 ErrCode AppAccountStub::ProcGetAuthenticatorInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
725 {
726     std::string owner = data.ReadString();
727     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
728     AuthenticatorInfo info;
729     ErrCode result = GetAuthenticatorInfo(owner, info);
730     if ((!reply.WriteInt32(result)) || (!reply.WriteString(info.owner)) ||
731         (!reply.WriteInt32(info.iconId)) || (!reply.WriteInt32(info.labelId))) {
732         ACCOUNT_LOGE("failed to write reply");
733         return IPC_STUB_WRITE_PARCEL_ERR;
734     }
735     return ERR_NONE;
736 }
737 
ProcGetAllOAuthTokens(uint32_t code,MessageParcel & data,MessageParcel & reply)738 ErrCode AppAccountStub::ProcGetAllOAuthTokens(uint32_t code, MessageParcel &data, MessageParcel &reply)
739 {
740     std::string name = data.ReadString();
741     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
742     std::string owner = data.ReadString();
743     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
744     std::vector<OAuthTokenInfo> tokenInfos;
745     ErrCode result = GetAllOAuthTokens(name, owner, tokenInfos);
746     if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(tokenInfos.size()))) {
747         ACCOUNT_LOGE("failed to write reply");
748         return IPC_STUB_WRITE_PARCEL_ERR;
749     }
750     for (auto tokenInfo : tokenInfos) {
751         if ((!reply.WriteString(tokenInfo.token)) || (!reply.WriteString(tokenInfo.authType))) {
752             ACCOUNT_LOGE("failed to write reply");
753             return IPC_STUB_WRITE_PARCEL_ERR;
754         }
755     }
756     return ERR_NONE;
757 }
758 
ProcGetAuthList(uint32_t code,MessageParcel & data,MessageParcel & reply)759 ErrCode AppAccountStub::ProcGetAuthList(uint32_t code, MessageParcel &data, MessageParcel &reply)
760 {
761     std::string name = data.ReadString();
762     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
763     std::string authType = data.ReadString();
764     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::OWNER_MAX_SIZE, "authType is oversize");
765     std::set<std::string> oauthList;
766     ErrCode result = ERR_OK;
767     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_LIST)) {
768         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
769         result = GetOAuthList(name, authType, oauthList);
770     } else if (code == static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_LIST)) {
771         result = GetAuthList(name, authType, oauthList);
772     } else {
773         ACCOUNT_LOGE("stub code is invalid");
774         return IPC_INVOKER_ERR;
775     }
776     if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(oauthList.size()))) {
777         ACCOUNT_LOGE("failed to write reply");
778         return IPC_STUB_WRITE_PARCEL_ERR;
779     }
780     for (auto bundleName : oauthList) {
781         if (!reply.WriteString(bundleName)) {
782             ACCOUNT_LOGE("failed to WriteString for bundleName");
783             return IPC_STUB_WRITE_PARCEL_ERR;
784         }
785     }
786     return ERR_NONE;
787 }
788 
ProcGetAuthenticatorCallback(uint32_t code,MessageParcel & data,MessageParcel & reply)789 ErrCode AppAccountStub::ProcGetAuthenticatorCallback(uint32_t code, MessageParcel &data, MessageParcel &reply)
790 {
791     std::string sessionId = data.ReadString();
792     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(sessionId, Constants::SESSION_ID_MAX_SIZE,
793         "sessionId is empty or oversize");
794     sptr<IRemoteObject> callback;
795     ErrCode result = GetAuthenticatorCallback(sessionId, callback);
796     if ((!reply.WriteInt32(result)) || (!reply.WriteRemoteObject(callback))) {
797         ACCOUNT_LOGE("failed to write reply");
798         return IPC_STUB_WRITE_PARCEL_ERR;
799     }
800     return ERR_NONE;
801 }
802 
ProcGetAllAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)803 ErrCode AppAccountStub::ProcGetAllAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
804 {
805     std::string owner = data.ReadString();
806     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
807     std::vector<AppAccountInfo> appAccounts;
808     ErrCode result = GetAllAccounts(owner, appAccounts);
809     if (!reply.WriteInt32(result)) {
810         ACCOUNT_LOGE("failed to write reply");
811         return IPC_STUB_WRITE_PARCEL_ERR;
812     }
813     if (!WriteParcelableVector(appAccounts, reply)) {
814         ACCOUNT_LOGE("failed to write vector<AppAccount> for appAccounts");
815         return IPC_STUB_WRITE_PARCEL_ERR;
816     }
817     return ERR_NONE;
818 }
819 
ProcGetAllAccessibleAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)820 ErrCode AppAccountStub::ProcGetAllAccessibleAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
821 {
822     std::vector<AppAccountInfo> appAccounts;
823     ErrCode result = ERR_OK;
824     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_ALL_ACCESSIBLE_ACCOUNTS)) {
825         result = GetAllAccessibleAccounts(appAccounts);
826     } else if (code == static_cast<uint32_t>(IAppAccount::Message::QUERY_ALL_ACCESSIBLE_ACCOUNTS)) {
827         std::string owner = data.ReadString();
828         RETURN_IF_STRING_IS_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is or oversize");
829         result = QueryAllAccessibleAccounts(owner, appAccounts);
830     } else {
831         ACCOUNT_LOGE("stub code is invalid");
832         return IPC_INVOKER_ERR;
833     }
834     if (!reply.WriteInt32(result)) {
835         ACCOUNT_LOGE("failed to write reply");
836         return IPC_STUB_WRITE_PARCEL_ERR;
837     }
838     if (!WriteParcelableVector(appAccounts, reply)) {
839         ACCOUNT_LOGE("failed to write vector<AppAccount> for appAccounts");
840         return IPC_STUB_WRITE_PARCEL_ERR;
841     }
842     return ERR_NONE;
843 }
844 
ProcCheckAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)845 ErrCode AppAccountStub::ProcCheckAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
846 {
847     std::string name = data.ReadString();
848     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
849     std::string bundleName = data.ReadString();
850     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
851         "bundleName is empty or oversize");
852     bool isAccessible = false;
853     ErrCode result = CheckAppAccess(name, bundleName, isAccessible);
854     if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isAccessible))) {
855         ACCOUNT_LOGE("failed to write reply");
856         return IPC_STUB_WRITE_PARCEL_ERR;
857     }
858     return ERR_NONE;
859 }
860 
ProcDeleteAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)861 ErrCode AppAccountStub::ProcDeleteAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
862 {
863     std::string name = data.ReadString();
864     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
865     std::string credentialType = data.ReadString();
866     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
867         "credentialType is empty or oversize");
868     ErrCode result = DeleteAccountCredential(name, credentialType);
869     if (!reply.WriteInt32(result)) {
870         ACCOUNT_LOGE("failed to write reply");
871         return IPC_STUB_WRITE_PARCEL_ERR;
872     }
873     return ERR_NONE;
874 }
875 
ProcSelectAccountsByOptions(uint32_t code,MessageParcel & data,MessageParcel & reply)876 ErrCode AppAccountStub::ProcSelectAccountsByOptions(uint32_t code, MessageParcel &data, MessageParcel &reply)
877 {
878     std::shared_ptr<SelectAccountsOptions> options(data.ReadParcelable<SelectAccountsOptions>());
879     sptr<IRemoteObject> callback = data.ReadRemoteObject();
880     ErrCode result = ERR_OK;
881     if ((options == nullptr) || (callback == nullptr)) {
882         ACCOUNT_LOGE("invalid parameters");
883         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
884     } else {
885         RETURN_IF_STRING_IS_OVERSIZE(
886             options->allowedAccounts, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedAccounts array is oversize");
887         RETURN_IF_STRING_IS_OVERSIZE(
888             options->allowedOwners, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedOwners array is oversize");
889         RETURN_IF_STRING_IS_OVERSIZE(
890             options->requiredLabels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "requiredLabels array is oversize");
891         result = SelectAccountsByOptions(*options, callback);
892     }
893     if (!reply.WriteInt32(result)) {
894         ACCOUNT_LOGE("failed to write reply");
895         return IPC_STUB_WRITE_PARCEL_ERR;
896     }
897     return ERR_NONE;
898 }
899 
ProcVerifyCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)900 ErrCode AppAccountStub::ProcVerifyCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
901 {
902     std::string name = data.ReadString();
903     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
904     std::string owner = data.ReadString();
905     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
906     std::shared_ptr<VerifyCredentialOptions> options(data.ReadParcelable<VerifyCredentialOptions>());
907     sptr<IRemoteObject> callback = data.ReadRemoteObject();
908     ErrCode result = ERR_OK;
909     if ((options == nullptr) || (callback == nullptr)) {
910         ACCOUNT_LOGE("invalid parameters");
911         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
912     } else {
913         RETURN_IF_STRING_IS_OVERSIZE(
914             options->credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE, "the credential type is oversize");
915         RETURN_IF_STRING_IS_OVERSIZE(
916             options->credential, Constants::CREDENTIAL_MAX_SIZE, "the credential is oversize");
917         result = VerifyCredential(name, owner, *options, callback);
918     }
919     if (!reply.WriteInt32(result)) {
920         ACCOUNT_LOGE("failed to write reply");
921         return IPC_STUB_WRITE_PARCEL_ERR;
922     }
923     return ERR_NONE;
924 }
925 
ProcCheckAccountLabels(uint32_t code,MessageParcel & data,MessageParcel & reply)926 ErrCode AppAccountStub::ProcCheckAccountLabels(uint32_t code, MessageParcel &data, MessageParcel &reply)
927 {
928     std::string name = data.ReadString();
929     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
930     std::string owner = data.ReadString();
931     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
932     std::vector<std::string> labels;
933     data.ReadStringVector(&labels);
934     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(
935         labels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "labels array is empty or oversize");
936     sptr<IRemoteObject> callback = data.ReadRemoteObject();
937     ErrCode result = ERR_OK;
938     if (callback == nullptr) {
939         ACCOUNT_LOGE("invalid options");
940         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
941     } else {
942         result = CheckAccountLabels(name, owner, labels, callback);
943     }
944     if (!reply.WriteInt32(result)) {
945         ACCOUNT_LOGE("failed to write reply");
946         return IPC_STUB_WRITE_PARCEL_ERR;
947     }
948     return ERR_NONE;
949 }
950 
ProcSetAuthenticatorProperties(uint32_t code,MessageParcel & data,MessageParcel & reply)951 ErrCode AppAccountStub::ProcSetAuthenticatorProperties(uint32_t code, MessageParcel &data, MessageParcel &reply)
952 {
953     std::string owner = data.ReadString();
954     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE,  "owner is empty or oversize");
955     std::shared_ptr<SetPropertiesOptions> options(data.ReadParcelable<SetPropertiesOptions>());
956     sptr<IRemoteObject> callback = data.ReadRemoteObject();
957     ErrCode result = ERR_OK;
958     if ((options == nullptr) || (callback == nullptr)) {
959         ACCOUNT_LOGE("invalid parameters");
960         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
961     } else {
962         result = SetAuthenticatorProperties(owner, *options, callback);
963     }
964     if (!reply.WriteInt32(result)) {
965         ACCOUNT_LOGE("failed to write reply");
966         return IPC_STUB_WRITE_PARCEL_ERR;
967     }
968     return ERR_NONE;
969 }
970 
ProcSubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)971 ErrCode AppAccountStub::ProcSubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
972 {
973     std::unique_ptr<AppAccountSubscribeInfo> subscribeInfo(data.ReadParcelable<AppAccountSubscribeInfo>());
974     if (!subscribeInfo) {
975         ACCOUNT_LOGE("failed to read parcelable for subscribeInfo");
976         return IPC_STUB_INVALID_DATA_ERR;
977     }
978     sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
979     if (eventListener == nullptr) {
980         ACCOUNT_LOGE("failed to read remote object for eventListener");
981         return IPC_STUB_INVALID_DATA_ERR;
982     }
983     ErrCode result = SubscribeAppAccount(*subscribeInfo, eventListener);
984     if (!reply.WriteInt32(result)) {
985         ACCOUNT_LOGE("failed to write reply");
986         return IPC_STUB_WRITE_PARCEL_ERR;
987     }
988     return ERR_NONE;
989 }
990 
ProcUnsubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)991 ErrCode AppAccountStub::ProcUnsubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
992 {
993     sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
994     if (eventListener == nullptr) {
995         ACCOUNT_LOGE("failed to read remote object for eventListener");
996         return IPC_STUB_INVALID_DATA_ERR;
997     }
998     ErrCode result = UnsubscribeAppAccount(eventListener);
999     if (!reply.WriteInt32(result)) {
1000         ACCOUNT_LOGE("failed to write reply");
1001         return IPC_STUB_WRITE_PARCEL_ERR;
1002     }
1003     return ERR_NONE;
1004 }
1005 }  // namespace AccountSA
1006 }  // namespace OHOS
1007