• 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     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
398     ErrCode result = DeleteAccount(name);
399     if (!reply.WriteInt32(result)) {
400         ACCOUNT_LOGE("failed to write reply");
401         return IPC_STUB_WRITE_PARCEL_ERR;
402     }
403 
404     return ERR_NONE;
405 }
406 
ProcGetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)407 ErrCode AppAccountStub::ProcGetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
408 {
409     std::string name = data.ReadString();
410     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
411     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
412     std::string extraInfo;
413     ErrCode result = GetAccountExtraInfo(name, extraInfo);
414     if (!reply.WriteInt32(result)) {
415         ACCOUNT_LOGE("failed to write reply");
416         return IPC_STUB_WRITE_PARCEL_ERR;
417     }
418     if (!reply.WriteString(extraInfo)) {
419         ACCOUNT_LOGE("failed to write string for extra info");
420         return IPC_STUB_WRITE_PARCEL_ERR;
421     }
422     return ERR_NONE;
423 }
424 
ProcSetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)425 ErrCode AppAccountStub::ProcSetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
426 {
427     std::string name = data.ReadString();
428     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
429     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
430     std::string extraInfo = data.ReadString();
431     RETURN_IF_STRING_IS_OVERSIZE(extraInfo, Constants::EXTRA_INFO_MAX_SIZE, "extraInfo is oversize");
432     ErrCode result = SetAccountExtraInfo(name, extraInfo);
433     if (!reply.WriteInt32(result)) {
434         ACCOUNT_LOGE("failed to write reply");
435         return IPC_STUB_WRITE_PARCEL_ERR;
436     }
437     return ERR_NONE;
438 }
439 
ProcSetAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)440 ErrCode AppAccountStub::ProcSetAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
441 {
442     std::string name = data.ReadString();
443     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
444     if (code != static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCESS)) {
445         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
446     }
447 
448     std::string authorizedApp = data.ReadString();
449     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(authorizedApp, Constants::BUNDLE_NAME_MAX_SIZE,
450         "bundleName is empty or oversize");
451 
452     ErrCode result = ERR_OK;
453     if (code == static_cast<uint32_t>(IAppAccount::Message::ENABLE_APP_ACCESS)) {
454         result = EnableAppAccess(name, authorizedApp);
455     } else if (code == static_cast<uint32_t>(IAppAccount::Message::DISABLE_APP_ACCESS)) {
456         result = DisableAppAccess(name, authorizedApp);
457     } else if (code == static_cast<uint32_t>(IAppAccount::Message::SET_APP_ACCESS)) {
458         bool isAccessible = data.ReadBool();
459         result = SetAppAccess(name, authorizedApp, isAccessible);
460     } else {
461         ACCOUNT_LOGE("stub code is invalid");
462         return IPC_INVOKER_ERR;
463     }
464 
465     if (!reply.WriteInt32(result)) {
466         ACCOUNT_LOGE("failed to write reply");
467         return IPC_STUB_WRITE_PARCEL_ERR;
468     }
469     return ERR_NONE;
470 }
471 
ProcCheckAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)472 ErrCode AppAccountStub::ProcCheckAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
473 {
474     std::string name = data.ReadString();
475     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
476     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
477     bool syncEnable = false;
478     ErrCode result = CheckAppAccountSyncEnable(name, syncEnable);
479     if (!reply.WriteInt32(result)) {
480         ACCOUNT_LOGE("failed to write reply");
481         return IPC_STUB_WRITE_PARCEL_ERR;
482     }
483     if (!reply.WriteBool(syncEnable)) {
484         ACCOUNT_LOGE("failed to write bool for syncEnable");
485         return IPC_STUB_WRITE_PARCEL_ERR;
486     }
487     return ERR_NONE;
488 }
489 
ProcSetAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)490 ErrCode AppAccountStub::ProcSetAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
491 {
492     std::string name = data.ReadString();
493     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
494     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
495     bool syncEnable = data.ReadBool();
496     ErrCode result = SetAppAccountSyncEnable(name, syncEnable);
497     if (!reply.WriteInt32(result)) {
498         ACCOUNT_LOGE("failed to write reply");
499         return IPC_STUB_WRITE_PARCEL_ERR;
500     }
501     return ERR_NONE;
502 }
503 
ProcGetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)504 ErrCode AppAccountStub::ProcGetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
505 {
506     std::string name = data.ReadString();
507     std::string key = data.ReadString();
508     std::string value;
509     ErrCode result = GetAssociatedData(name, key, value);
510     if (!reply.WriteInt32(result)) {
511         ACCOUNT_LOGE("failed to write reply");
512         return IPC_STUB_WRITE_PARCEL_ERR;
513     }
514     if (!reply.WriteString(value)) {
515         ACCOUNT_LOGE("failed to write string for value");
516         return IPC_STUB_WRITE_PARCEL_ERR;
517     }
518     return ERR_NONE;
519 }
520 
ProcSetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)521 ErrCode AppAccountStub::ProcSetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
522 {
523     std::string name = data.ReadString();
524     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
525     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
526     std::string key = data.ReadString();
527     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(key, Constants::ASSOCIATED_KEY_MAX_SIZE, "key is empty or oversize");
528     std::string value = data.ReadString();
529     RETURN_IF_STRING_IS_OVERSIZE(value, Constants::ASSOCIATED_VALUE_MAX_SIZE, "value is oversize");
530     ErrCode result = SetAssociatedData(name, key, value);
531     if (!reply.WriteInt32(result)) {
532         ACCOUNT_LOGE("failed to write reply");
533         return IPC_STUB_WRITE_PARCEL_ERR;
534     }
535     return ERR_NONE;
536 }
537 
ProcGetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)538 ErrCode AppAccountStub::ProcGetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
539 {
540     std::string name = data.ReadString();
541     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
542     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
543     std::string credentialType = data.ReadString();
544     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
545         "credentialType is empty or oversize");
546     std::string credential;
547     ErrCode result = GetAccountCredential(name, credentialType, credential);
548     if (!reply.WriteInt32(result)) {
549         ACCOUNT_LOGE("failed to write reply");
550         return IPC_STUB_WRITE_PARCEL_ERR;
551     }
552     if (!reply.WriteString(credential)) {
553         ACCOUNT_LOGE("failed to write string for credential");
554         return IPC_STUB_WRITE_PARCEL_ERR;
555     }
556     return ERR_NONE;
557 }
558 
ProcSetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)559 ErrCode AppAccountStub::ProcSetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
560 {
561     std::string name = data.ReadString();
562     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
563     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
564     std::string credentialType = data.ReadString();
565     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
566         "credentialType is empty or oversize");
567     std::string credential = data.ReadString();
568     RETURN_IF_STRING_IS_OVERSIZE(credential, Constants::CREDENTIAL_MAX_SIZE, "credential is oversize");
569     ErrCode result = SetAccountCredential(name, credentialType, credential);
570     if (!reply.WriteInt32(result)) {
571         ACCOUNT_LOGE("failed to write reply");
572         return IPC_STUB_WRITE_PARCEL_ERR;
573     }
574     return ERR_NONE;
575 }
576 
ProcAuthenticate(uint32_t code,MessageParcel & data,MessageParcel & reply)577 ErrCode AppAccountStub::ProcAuthenticate(uint32_t code, MessageParcel &data, MessageParcel &reply)
578 {
579     std::string name = data.ReadString();
580     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
581     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
582     std::string owner = data.ReadString();
583     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
584     std::string authType = data.ReadString();
585     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
586     std::shared_ptr<AAFwk::Want> options(data.ReadParcelable<AAFwk::Want>());
587     ErrCode result = ERR_OK;
588     if (options == nullptr) {
589         ACCOUNT_LOGE("invalid options");
590         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
591     } else {
592         RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(options->GetStringParam(Constants::KEY_CALLER_ABILITY_NAME),
593             Constants::ABILITY_NAME_MAX_SIZE, "abilityName is empty or oversize");
594         sptr<IRemoteObject> callback = data.ReadRemoteObject();
595         result = Authenticate(name, owner, authType, *options, callback);
596     }
597     if (!reply.WriteInt32(result)) {
598         ACCOUNT_LOGE("failed to write reply");
599         return IPC_STUB_WRITE_PARCEL_ERR;
600     }
601     return ERR_NONE;
602 }
603 
ProcGetAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)604 ErrCode AppAccountStub::ProcGetAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
605 {
606     std::string name = data.ReadString();
607     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
608     std::string owner = data.ReadString();
609     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
610     std::string authType = data.ReadString();
611     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
612     std::string token;
613     ErrCode result = ERR_OK;
614     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_TOKEN)) {
615         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
616         result = GetOAuthToken(name, owner, authType, token);
617     } else if (code == static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_TOKEN)) {
618         result = GetAuthToken(name, owner, authType, token);
619     } else {
620         ACCOUNT_LOGE("stub code is invalid");
621         return IPC_INVOKER_ERR;
622     }
623     if ((!reply.WriteInt32(result)) || (!reply.WriteString(token))) {
624         ACCOUNT_LOGE("failed to write reply");
625         return IPC_STUB_WRITE_PARCEL_ERR;
626     }
627     return ERR_NONE;
628 }
629 
ProcSetOAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)630 ErrCode AppAccountStub::ProcSetOAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
631 {
632     std::string name = data.ReadString();
633     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
634     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
635     std::string authType = data.ReadString();
636     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
637     std::string token = data.ReadString();
638     RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize");
639     ErrCode result = SetOAuthToken(name, authType, token);
640     if (!reply.WriteInt32(result)) {
641         ACCOUNT_LOGE("failed to write reply");
642         return IPC_STUB_WRITE_PARCEL_ERR;
643     }
644     return ERR_NONE;
645 }
646 
ProcDeleteAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)647 ErrCode AppAccountStub::ProcDeleteAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
648 {
649     std::string name = data.ReadString();
650     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
651     std::string owner = data.ReadString();
652     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
653     std::string authType = data.ReadString();
654     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
655     std::string token = data.ReadString();
656     RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize");
657 
658     ErrCode result = ERR_OK;
659     if (code == static_cast<uint32_t>(IAppAccount::Message::DELETE_OAUTH_TOKEN)) {
660         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
661         result = DeleteOAuthToken(name, owner, authType, token);
662     } else if (code == static_cast<uint32_t>(IAppAccount::Message::DELETE_AUTH_TOKEN)) {
663         result = DeleteAuthToken(name, owner, authType, token);
664     } else {
665         ACCOUNT_LOGE("stub code is invalid");
666         return IPC_INVOKER_ERR;
667     }
668 
669     if (!reply.WriteInt32(result)) {
670         ACCOUNT_LOGE("failed to write reply");
671         return IPC_STUB_WRITE_PARCEL_ERR;
672     }
673     return ERR_NONE;
674 }
675 
ProcSetAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)676 ErrCode AppAccountStub::ProcSetAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
677 {
678     std::string name = data.ReadString();
679     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
680     std::string authType = data.ReadString();
681     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
682     std::string bundleName = data.ReadString();
683     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
684         "bundleName is empty or oversize");
685     bool isVisible = data.ReadBool();
686     ErrCode result = ERR_OK;
687     if (code == static_cast<uint32_t>(IAppAccount::Message::SET_OAUTH_TOKEN_VISIBILITY)) {
688         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
689         result = SetOAuthTokenVisibility(name, authType, bundleName, isVisible);
690     } else if (code == static_cast<uint32_t>(IAppAccount::Message::SET_AUTH_TOKEN_VISIBILITY)) {
691         result = SetAuthTokenVisibility(name, authType, bundleName, isVisible);
692     } else {
693         ACCOUNT_LOGE("stub code is invalid");
694         return IPC_INVOKER_ERR;
695     }
696 
697     if (!reply.WriteInt32(result)) {
698         ACCOUNT_LOGE("failed to write reply");
699         return IPC_STUB_WRITE_PARCEL_ERR;
700     }
701     return ERR_NONE;
702 }
703 
ProcCheckAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)704 ErrCode AppAccountStub::ProcCheckAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
705 {
706     std::string name = data.ReadString();
707     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
708     std::string authType = data.ReadString();
709     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize");
710     std::string bundleName = data.ReadString();
711     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
712         "bundleName is empty or oversize");
713     bool isVisible = false;
714     ErrCode result = ERR_OK;
715     if (code == static_cast<uint32_t>(IAppAccount::Message::CHECK_OAUTH_TOKEN_VISIBILITY)) {
716         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
717         result = CheckOAuthTokenVisibility(name, authType, bundleName, isVisible);
718     } else if (code == static_cast<uint32_t>(IAppAccount::Message::CHECK_AUTH_TOKEN_VISIBILITY)) {
719         result = CheckAuthTokenVisibility(name, authType, bundleName, isVisible);
720     } else {
721         ACCOUNT_LOGE("stub code is invalid");
722         return IPC_INVOKER_ERR;
723     }
724 
725     if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isVisible))) {
726         ACCOUNT_LOGE("failed to write reply");
727         return IPC_STUB_WRITE_PARCEL_ERR;
728     }
729     return ERR_NONE;
730 }
731 
ProcGetAuthenticatorInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)732 ErrCode AppAccountStub::ProcGetAuthenticatorInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
733 {
734     std::string owner = data.ReadString();
735     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
736     AuthenticatorInfo info;
737     ErrCode result = GetAuthenticatorInfo(owner, info);
738     if ((!reply.WriteInt32(result)) || (!reply.WriteString(info.owner)) ||
739         (!reply.WriteInt32(info.iconId)) || (!reply.WriteInt32(info.labelId))) {
740         ACCOUNT_LOGE("failed to write reply");
741         return IPC_STUB_WRITE_PARCEL_ERR;
742     }
743     return ERR_NONE;
744 }
745 
ProcGetAllOAuthTokens(uint32_t code,MessageParcel & data,MessageParcel & reply)746 ErrCode AppAccountStub::ProcGetAllOAuthTokens(uint32_t code, MessageParcel &data, MessageParcel &reply)
747 {
748     std::string name = data.ReadString();
749     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
750     RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
751     std::string owner = data.ReadString();
752     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
753     std::vector<OAuthTokenInfo> tokenInfos;
754     ErrCode result = GetAllOAuthTokens(name, owner, tokenInfos);
755     if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(tokenInfos.size()))) {
756         ACCOUNT_LOGE("failed to write reply");
757         return IPC_STUB_WRITE_PARCEL_ERR;
758     }
759     for (auto tokenInfo : tokenInfos) {
760         if ((!reply.WriteString(tokenInfo.token)) || (!reply.WriteString(tokenInfo.authType))) {
761             ACCOUNT_LOGE("failed to write reply");
762             return IPC_STUB_WRITE_PARCEL_ERR;
763         }
764     }
765     return ERR_NONE;
766 }
767 
ProcGetAuthList(uint32_t code,MessageParcel & data,MessageParcel & reply)768 ErrCode AppAccountStub::ProcGetAuthList(uint32_t code, MessageParcel &data, MessageParcel &reply)
769 {
770     std::string name = data.ReadString();
771     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
772     std::string authType = data.ReadString();
773     RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::OWNER_MAX_SIZE, "authType is oversize");
774     std::set<std::string> oauthList;
775     ErrCode result = ERR_OK;
776     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_OAUTH_LIST)) {
777         RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name);
778         result = GetOAuthList(name, authType, oauthList);
779     } else if (code == static_cast<uint32_t>(IAppAccount::Message::GET_AUTH_LIST)) {
780         result = GetAuthList(name, authType, oauthList);
781     } else {
782         ACCOUNT_LOGE("stub code is invalid");
783         return IPC_INVOKER_ERR;
784     }
785     if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(oauthList.size()))) {
786         ACCOUNT_LOGE("failed to write reply");
787         return IPC_STUB_WRITE_PARCEL_ERR;
788     }
789     for (auto bundleName : oauthList) {
790         if (!reply.WriteString(bundleName)) {
791             ACCOUNT_LOGE("failed to WriteString for bundleName");
792             return IPC_STUB_WRITE_PARCEL_ERR;
793         }
794     }
795     return ERR_NONE;
796 }
797 
ProcGetAuthenticatorCallback(uint32_t code,MessageParcel & data,MessageParcel & reply)798 ErrCode AppAccountStub::ProcGetAuthenticatorCallback(uint32_t code, MessageParcel &data, MessageParcel &reply)
799 {
800     std::string sessionId = data.ReadString();
801     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(sessionId, Constants::SESSION_ID_MAX_SIZE,
802         "sessionId is empty or oversize");
803     sptr<IRemoteObject> callback;
804     ErrCode result = GetAuthenticatorCallback(sessionId, callback);
805     if ((!reply.WriteInt32(result)) || (!reply.WriteRemoteObject(callback))) {
806         ACCOUNT_LOGE("failed to write reply");
807         return IPC_STUB_WRITE_PARCEL_ERR;
808     }
809     return ERR_NONE;
810 }
811 
ProcGetAllAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)812 ErrCode AppAccountStub::ProcGetAllAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
813 {
814     std::string owner = data.ReadString();
815     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
816     std::vector<AppAccountInfo> appAccounts;
817     ErrCode result = GetAllAccounts(owner, appAccounts);
818     if (!reply.WriteInt32(result)) {
819         ACCOUNT_LOGE("failed to write reply");
820         return IPC_STUB_WRITE_PARCEL_ERR;
821     }
822     if (!WriteParcelableVector(appAccounts, reply)) {
823         ACCOUNT_LOGE("failed to write vector<AppAccount> for appAccounts");
824         return IPC_STUB_WRITE_PARCEL_ERR;
825     }
826     return ERR_NONE;
827 }
828 
ProcGetAllAccessibleAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)829 ErrCode AppAccountStub::ProcGetAllAccessibleAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
830 {
831     std::vector<AppAccountInfo> appAccounts;
832     ErrCode result = ERR_OK;
833     if (code == static_cast<uint32_t>(IAppAccount::Message::GET_ALL_ACCESSIBLE_ACCOUNTS)) {
834         result = GetAllAccessibleAccounts(appAccounts);
835     } else if (code == static_cast<uint32_t>(IAppAccount::Message::QUERY_ALL_ACCESSIBLE_ACCOUNTS)) {
836         std::string owner = data.ReadString();
837         RETURN_IF_STRING_IS_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is or oversize");
838         result = QueryAllAccessibleAccounts(owner, appAccounts);
839     } else {
840         ACCOUNT_LOGE("stub code is invalid");
841         return IPC_INVOKER_ERR;
842     }
843     if (!reply.WriteInt32(result)) {
844         ACCOUNT_LOGE("failed to write reply");
845         return IPC_STUB_WRITE_PARCEL_ERR;
846     }
847     if (!WriteParcelableVector(appAccounts, reply)) {
848         ACCOUNT_LOGE("failed to write vector<AppAccount> for appAccounts");
849         return IPC_STUB_WRITE_PARCEL_ERR;
850     }
851     return ERR_NONE;
852 }
853 
ProcCheckAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)854 ErrCode AppAccountStub::ProcCheckAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
855 {
856     std::string name = data.ReadString();
857     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
858     std::string bundleName = data.ReadString();
859     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
860         "bundleName is empty or oversize");
861     bool isAccessible = false;
862     ErrCode result = CheckAppAccess(name, bundleName, isAccessible);
863     if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isAccessible))) {
864         ACCOUNT_LOGE("failed to write reply");
865         return IPC_STUB_WRITE_PARCEL_ERR;
866     }
867     return ERR_NONE;
868 }
869 
ProcDeleteAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)870 ErrCode AppAccountStub::ProcDeleteAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
871 {
872     std::string name = data.ReadString();
873     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
874     std::string credentialType = data.ReadString();
875     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
876         "credentialType is empty or oversize");
877     ErrCode result = DeleteAccountCredential(name, credentialType);
878     if (!reply.WriteInt32(result)) {
879         ACCOUNT_LOGE("failed to write reply");
880         return IPC_STUB_WRITE_PARCEL_ERR;
881     }
882     return ERR_NONE;
883 }
884 
ProcSelectAccountsByOptions(uint32_t code,MessageParcel & data,MessageParcel & reply)885 ErrCode AppAccountStub::ProcSelectAccountsByOptions(uint32_t code, MessageParcel &data, MessageParcel &reply)
886 {
887     std::shared_ptr<SelectAccountsOptions> options(data.ReadParcelable<SelectAccountsOptions>());
888     sptr<IRemoteObject> callback = data.ReadRemoteObject();
889     ErrCode result = ERR_OK;
890     if ((options == nullptr) || (callback == nullptr)) {
891         ACCOUNT_LOGE("invalid parameters");
892         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
893     } else {
894         RETURN_IF_STRING_IS_OVERSIZE(
895             options->allowedAccounts, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedAccounts array is oversize");
896         RETURN_IF_STRING_IS_OVERSIZE(
897             options->allowedOwners, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedOwners array is oversize");
898         RETURN_IF_STRING_IS_OVERSIZE(
899             options->requiredLabels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "requiredLabels array is oversize");
900         result = SelectAccountsByOptions(*options, callback);
901     }
902     if (!reply.WriteInt32(result)) {
903         ACCOUNT_LOGE("failed to write reply");
904         return IPC_STUB_WRITE_PARCEL_ERR;
905     }
906     return ERR_NONE;
907 }
908 
ProcVerifyCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)909 ErrCode AppAccountStub::ProcVerifyCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
910 {
911     std::string name = data.ReadString();
912     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
913     std::string owner = data.ReadString();
914     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
915     std::shared_ptr<VerifyCredentialOptions> options(data.ReadParcelable<VerifyCredentialOptions>());
916     sptr<IRemoteObject> callback = data.ReadRemoteObject();
917     ErrCode result = ERR_OK;
918     if ((options == nullptr) || (callback == nullptr)) {
919         ACCOUNT_LOGE("invalid parameters");
920         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
921     } else {
922         RETURN_IF_STRING_IS_OVERSIZE(
923             options->credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE, "the credential type is oversize");
924         RETURN_IF_STRING_IS_OVERSIZE(
925             options->credential, Constants::CREDENTIAL_MAX_SIZE, "the credential is oversize");
926         result = VerifyCredential(name, owner, *options, callback);
927     }
928     if (!reply.WriteInt32(result)) {
929         ACCOUNT_LOGE("failed to write reply");
930         return IPC_STUB_WRITE_PARCEL_ERR;
931     }
932     return ERR_NONE;
933 }
934 
ProcCheckAccountLabels(uint32_t code,MessageParcel & data,MessageParcel & reply)935 ErrCode AppAccountStub::ProcCheckAccountLabels(uint32_t code, MessageParcel &data, MessageParcel &reply)
936 {
937     std::string name = data.ReadString();
938     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize");
939     std::string owner = data.ReadString();
940     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize");
941     std::vector<std::string> labels;
942     data.ReadStringVector(&labels);
943     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(
944         labels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "labels array is empty or oversize");
945     sptr<IRemoteObject> callback = data.ReadRemoteObject();
946     ErrCode result = ERR_OK;
947     if (callback == nullptr) {
948         ACCOUNT_LOGE("invalid options");
949         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
950     } else {
951         result = CheckAccountLabels(name, owner, labels, callback);
952     }
953     if (!reply.WriteInt32(result)) {
954         ACCOUNT_LOGE("failed to write reply");
955         return IPC_STUB_WRITE_PARCEL_ERR;
956     }
957     return ERR_NONE;
958 }
959 
ProcSetAuthenticatorProperties(uint32_t code,MessageParcel & data,MessageParcel & reply)960 ErrCode AppAccountStub::ProcSetAuthenticatorProperties(uint32_t code, MessageParcel &data, MessageParcel &reply)
961 {
962     std::string owner = data.ReadString();
963     RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE,  "owner is empty or oversize");
964     std::shared_ptr<SetPropertiesOptions> options(data.ReadParcelable<SetPropertiesOptions>());
965     sptr<IRemoteObject> callback = data.ReadRemoteObject();
966     ErrCode result = ERR_OK;
967     if ((options == nullptr) || (callback == nullptr)) {
968         ACCOUNT_LOGE("invalid parameters");
969         result = ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER;
970     } else {
971         result = SetAuthenticatorProperties(owner, *options, callback);
972     }
973     if (!reply.WriteInt32(result)) {
974         ACCOUNT_LOGE("failed to write reply");
975         return IPC_STUB_WRITE_PARCEL_ERR;
976     }
977     return ERR_NONE;
978 }
979 
ProcSubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)980 ErrCode AppAccountStub::ProcSubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
981 {
982     std::unique_ptr<AppAccountSubscribeInfo> subscribeInfo(data.ReadParcelable<AppAccountSubscribeInfo>());
983     if (!subscribeInfo) {
984         ACCOUNT_LOGE("failed to read parcelable for subscribeInfo");
985         return IPC_STUB_INVALID_DATA_ERR;
986     }
987     sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
988     if (eventListener == nullptr) {
989         ACCOUNT_LOGE("failed to read remote object for eventListener");
990         return IPC_STUB_INVALID_DATA_ERR;
991     }
992     ErrCode result = SubscribeAppAccount(*subscribeInfo, eventListener);
993     if (!reply.WriteInt32(result)) {
994         ACCOUNT_LOGE("failed to write reply");
995         return IPC_STUB_WRITE_PARCEL_ERR;
996     }
997     return ERR_NONE;
998 }
999 
ProcUnsubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)1000 ErrCode AppAccountStub::ProcUnsubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
1001 {
1002     sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
1003     if (eventListener == nullptr) {
1004         ACCOUNT_LOGE("failed to read remote object for eventListener");
1005         return IPC_STUB_INVALID_DATA_ERR;
1006     }
1007     ErrCode result = UnsubscribeAppAccount(eventListener);
1008     if (!reply.WriteInt32(result)) {
1009         ACCOUNT_LOGE("failed to write reply");
1010         return IPC_STUB_WRITE_PARCEL_ERR;
1011     }
1012     return ERR_NONE;
1013 }
1014 }  // namespace AccountSA
1015 }  // namespace OHOS
1016