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