1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "inner_app_account_manager.h"
17
18 #include "account_info.h"
19 #include "account_log_wrapper.h"
20 #include "app_account_authenticator_session.h"
21 #include "app_account_control_manager.h"
22 #include "app_account_subscribe_manager.h"
23
24 namespace OHOS {
25 namespace AccountSA {
InnerAppAccountManager()26 InnerAppAccountManager::InnerAppAccountManager()
27 : controlManagerPtr_(AppAccountControlManager::GetInstance()),
28 subscribeManagerPtr_(AppAccountSubscribeManager::GetInstance()),
29 sessionManagerPtr_(AppAccountAuthenticatorSessionManager::GetInstance()),
30 authenticatorManagerPtr_(AppAccountAuthenticatorManager::GetInstance())
31 {}
32
~InnerAppAccountManager()33 InnerAppAccountManager::~InnerAppAccountManager()
34 {}
35
AddAccount(const std::string & name,const std::string & extraInfo,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)36 ErrCode InnerAppAccountManager::AddAccount(const std::string &name, const std::string &extraInfo,
37 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
38 {
39 if (!controlManagerPtr_) {
40 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
41 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
42 }
43
44 AppAccountInfo appAccountInfo(name, bundleName);
45 appAccountInfo.SetAppIndex(appIndex);
46 ErrCode result = controlManagerPtr_->AddAccount(name, extraInfo, uid, bundleName, appAccountInfo);
47
48 return result;
49 }
50
AddAccountImplicitly(const AuthenticatorSessionRequest & request)51 ErrCode InnerAppAccountManager::AddAccountImplicitly(const AuthenticatorSessionRequest &request)
52 {
53 if (!sessionManagerPtr_) {
54 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
55 return ERR_APPACCOUNT_SERVICE_SESSION_MANAGER_PTR_IS_NULLPTR;
56 }
57 return sessionManagerPtr_->AddAccountImplicitly(request);
58 }
59
CreateAccount(const std::string & name,const CreateAccountOptions & options,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)60 ErrCode InnerAppAccountManager::CreateAccount(const std::string &name, const CreateAccountOptions &options,
61 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
62 {
63 if (!controlManagerPtr_) {
64 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
65 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
66 }
67
68 AppAccountInfo appAccountInfo(name, bundleName);
69 appAccountInfo.SetAppIndex(appIndex);
70 ErrCode result = controlManagerPtr_->CreateAccount(name, options, uid, bundleName, appAccountInfo);
71
72 return result;
73 }
74
CreateAccountImplicitly(const AuthenticatorSessionRequest & request)75 ErrCode InnerAppAccountManager::CreateAccountImplicitly(const AuthenticatorSessionRequest &request)
76 {
77 if (!sessionManagerPtr_) {
78 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
79 return ERR_APPACCOUNT_SERVICE_SESSION_MANAGER_PTR_IS_NULLPTR;
80 }
81 return sessionManagerPtr_->CreateAccountImplicitly(request);
82 }
83
DeleteAccount(const std::string & name,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)84 ErrCode InnerAppAccountManager::DeleteAccount(
85 const std::string &name, const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
86 {
87 if (!controlManagerPtr_) {
88 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
89 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
90 }
91
92 AppAccountInfo appAccountInfo(name, bundleName);
93 appAccountInfo.SetAppIndex(appIndex);
94 ErrCode result = controlManagerPtr_->DeleteAccount(name, uid, bundleName, appAccountInfo);
95
96 if (!subscribeManagerPtr_) {
97 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
98 } else if (subscribeManagerPtr_->PublishAccount(appAccountInfo, uid, bundleName) != true) {
99 ACCOUNT_LOGE("failed to publish account");
100 }
101
102 return result;
103 }
104
GetAccountExtraInfo(const std::string & name,std::string & extraInfo,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)105 ErrCode InnerAppAccountManager::GetAccountExtraInfo(const std::string &name, std::string &extraInfo,
106 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
107 {
108 if (!controlManagerPtr_) {
109 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
110 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
111 }
112
113 ErrCode result = controlManagerPtr_->GetAccountExtraInfo(name, extraInfo, uid, bundleName, appIndex);
114
115 return result;
116 }
117
SetAccountExtraInfo(const std::string & name,const std::string & extraInfo,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)118 ErrCode InnerAppAccountManager::SetAccountExtraInfo(const std::string &name, const std::string &extraInfo,
119 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
120 {
121 if (!controlManagerPtr_) {
122 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
123 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
124 }
125
126 AppAccountInfo appAccountInfo(name, bundleName);
127 appAccountInfo.SetAppIndex(appIndex);
128 ErrCode result = controlManagerPtr_->SetAccountExtraInfo(name, extraInfo, uid, bundleName, appAccountInfo);
129
130 if (!subscribeManagerPtr_) {
131 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
132 } else if (subscribeManagerPtr_->PublishAccount(appAccountInfo, uid, bundleName) != true) {
133 ACCOUNT_LOGE("failed to publish account");
134 }
135
136 return result;
137 }
138
EnableAppAccess(const std::string & name,const std::string & authorizedApp,AppAccountCallingInfo & appAccountCallingInfo,const uint32_t apiVersion)139 ErrCode InnerAppAccountManager::EnableAppAccess(const std::string &name, const std::string &authorizedApp,
140 AppAccountCallingInfo &appAccountCallingInfo, const uint32_t apiVersion)
141 {
142 if (!controlManagerPtr_) {
143 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
144 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
145 }
146
147 AppAccountInfo appAccountInfo(name, appAccountCallingInfo.bundleName);
148 appAccountInfo.SetAppIndex(appAccountCallingInfo.appIndex);
149 ErrCode result = controlManagerPtr_->EnableAppAccess(
150 name, authorizedApp, appAccountCallingInfo, appAccountInfo, apiVersion);
151
152 if (!subscribeManagerPtr_) {
153 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
154 } else if (subscribeManagerPtr_->PublishAccount(
155 appAccountInfo, appAccountCallingInfo.callingUid, appAccountCallingInfo.bundleName) != true) {
156 ACCOUNT_LOGE("failed to publish account");
157 }
158
159 return result;
160 }
161
DisableAppAccess(const std::string & name,const std::string & authorizedApp,AppAccountCallingInfo & appAccountCallingInfo,const uint32_t apiVersion)162 ErrCode InnerAppAccountManager::DisableAppAccess(const std::string &name, const std::string &authorizedApp,
163 AppAccountCallingInfo &appAccountCallingInfo, const uint32_t apiVersion)
164 {
165 if (!controlManagerPtr_) {
166 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
167 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
168 }
169
170 AppAccountInfo appAccountInfo(name, appAccountCallingInfo.bundleName);
171 appAccountInfo.SetAppIndex(appAccountCallingInfo.appIndex);
172 ErrCode result = controlManagerPtr_->DisableAppAccess(
173 name, authorizedApp, appAccountCallingInfo, appAccountInfo, apiVersion);
174
175 if (!subscribeManagerPtr_) {
176 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
177 } else if (!subscribeManagerPtr_->PublishAccount(
178 appAccountInfo, appAccountCallingInfo.callingUid, appAccountCallingInfo.bundleName)) {
179 ACCOUNT_LOGE("failed to publish account");
180 }
181
182 return result;
183 }
184
CheckAppAccess(const std::string & name,const std::string & authorizedApp,bool & isAccessible,const AppAccountCallingInfo & appAccountCallingInfo)185 ErrCode InnerAppAccountManager::CheckAppAccess(const std::string &name, const std::string &authorizedApp,
186 bool &isAccessible, const AppAccountCallingInfo &appAccountCallingInfo)
187 {
188 if (!controlManagerPtr_) {
189 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
190 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
191 }
192 return controlManagerPtr_->CheckAppAccess(name, authorizedApp, isAccessible, appAccountCallingInfo);
193 }
194
CheckAppAccountSyncEnable(const std::string & name,bool & syncEnable,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)195 ErrCode InnerAppAccountManager::CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable,
196 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
197 {
198 if (!controlManagerPtr_) {
199 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
200 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
201 }
202
203 ErrCode result = controlManagerPtr_->CheckAppAccountSyncEnable(name, syncEnable, uid, bundleName, appIndex);
204
205 return result;
206 }
207
SetAppAccountSyncEnable(const std::string & name,const bool & syncEnable,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)208 ErrCode InnerAppAccountManager::SetAppAccountSyncEnable(const std::string &name, const bool &syncEnable,
209 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
210 {
211 if (!controlManagerPtr_) {
212 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
213 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
214 }
215
216 AppAccountInfo appAccountInfo(name, bundleName);
217 appAccountInfo.SetAppIndex(appIndex);
218 ErrCode result = controlManagerPtr_->SetAppAccountSyncEnable(name, syncEnable, uid, bundleName, appAccountInfo);
219
220 return result;
221 }
222
GetAssociatedData(const std::string & name,const std::string & key,std::string & value,const uid_t & uid)223 ErrCode InnerAppAccountManager::GetAssociatedData(const std::string &name, const std::string &key,
224 std::string &value, const uid_t &uid)
225 {
226 if (!controlManagerPtr_) {
227 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
228 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
229 }
230
231 ErrCode result = controlManagerPtr_->GetAssociatedData(name, key, value, uid);
232
233 return result;
234 }
235
SetAssociatedData(const std::string & name,const std::string & key,const std::string & value,const AppAccountCallingInfo & appAccountCallingInfo)236 ErrCode InnerAppAccountManager::SetAssociatedData(const std::string &name, const std::string &key,
237 const std::string &value, const AppAccountCallingInfo &appAccountCallingInfo)
238 {
239 if (!controlManagerPtr_) {
240 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
241 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
242 }
243
244 ErrCode result = controlManagerPtr_->SetAssociatedData(name, key, value, appAccountCallingInfo);
245
246 if (!subscribeManagerPtr_) {
247 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
248 return result;
249 }
250 AppAccountInfo appAccountInfo(name, appAccountCallingInfo.bundleName);
251 appAccountInfo.SetAppIndex(appAccountCallingInfo.appIndex);
252 if (!subscribeManagerPtr_->PublishAccount(appAccountInfo,
253 appAccountCallingInfo.callingUid, appAccountCallingInfo.bundleName)) {
254 ACCOUNT_LOGE("failed to publish account");
255 }
256 return result;
257 }
258
GetAccountCredential(const std::string & name,const std::string & credentialType,std::string & credential,const AppAccountCallingInfo & appAccountCallingInfo)259 ErrCode InnerAppAccountManager::GetAccountCredential(const std::string &name, const std::string &credentialType,
260 std::string &credential, const AppAccountCallingInfo &appAccountCallingInfo)
261 {
262 if (!controlManagerPtr_) {
263 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
264 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
265 }
266
267 ErrCode result = controlManagerPtr_->GetAccountCredential(name, credentialType, credential, appAccountCallingInfo);
268
269 return result;
270 }
271
SetAccountCredential(const std::string & name,const std::string & credentialType,const std::string & credential,const AppAccountCallingInfo & appAccountCallingInfo)272 ErrCode InnerAppAccountManager::SetAccountCredential(const std::string &name, const std::string &credentialType,
273 const std::string &credential, const AppAccountCallingInfo &appAccountCallingInfo)
274 {
275 if (!controlManagerPtr_) {
276 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
277 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
278 }
279
280 ErrCode result =
281 controlManagerPtr_->SetAccountCredential(name, credentialType, credential, appAccountCallingInfo);
282
283 if (!subscribeManagerPtr_) {
284 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
285 return result;
286 }
287 AppAccountInfo appAccountInfo(name, appAccountCallingInfo.bundleName);
288 appAccountInfo.SetAppIndex(appAccountCallingInfo.appIndex);
289 if (subscribeManagerPtr_->PublishAccount(appAccountInfo,
290 appAccountCallingInfo.callingUid, appAccountCallingInfo.bundleName) != true) {
291 ACCOUNT_LOGE("failed to publish account");
292 }
293 return result;
294 }
295
DeleteAccountCredential(const std::string & name,const std::string & credentialType,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)296 ErrCode InnerAppAccountManager::DeleteAccountCredential(const std::string &name, const std::string &credentialType,
297 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
298 {
299 if (!controlManagerPtr_) {
300 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
301 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
302 }
303 AppAccountCallingInfo appAccountCallingInfo;
304 appAccountCallingInfo.callingUid = uid;
305 appAccountCallingInfo.bundleName = bundleName;
306 appAccountCallingInfo.appIndex = appIndex;
307 ErrCode result = controlManagerPtr_->SetAccountCredential(name, credentialType, "", appAccountCallingInfo, true);
308 if (!subscribeManagerPtr_) {
309 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
310 return result;
311 }
312 AppAccountInfo appAccountInfo(name, bundleName);
313 appAccountInfo.SetAppIndex(appIndex);
314 if (subscribeManagerPtr_->PublishAccount(appAccountInfo, uid, bundleName) != true) {
315 ACCOUNT_LOGE("failed to publish account");
316 }
317 return result;
318 }
319
Authenticate(const AuthenticatorSessionRequest & request)320 ErrCode InnerAppAccountManager::Authenticate(const AuthenticatorSessionRequest &request)
321 {
322 if (!controlManagerPtr_) {
323 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
324 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
325 }
326 std::string token;
327 ErrCode ret = ERR_OK;
328 bool isApi9 = request.options.GetBoolParam(Constants::API_V9, false);
329 if (isApi9) {
330 ret = controlManagerPtr_->GetOAuthToken(request, token, Constants::API_VERSION9);
331 } else {
332 ret = controlManagerPtr_->GetOAuthToken(request, token);
333 }
334 if (ret == ERR_OK) {
335 if ((request.callback != nullptr) && (request.callback->AsObject() != nullptr)) {
336 AAFwk::Want result;
337 result.SetParam(Constants::KEY_NAME, request.name);
338 result.SetParam(Constants::KEY_AUTH_TYPE, request.authType);
339 result.SetParam(Constants::KEY_TOKEN, token);
340 request.callback->OnResult(ERR_OK, result);
341 }
342 return ERR_OK;
343 }
344 if (!sessionManagerPtr_) {
345 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
346 return ERR_APPACCOUNT_SERVICE_SESSION_MANAGER_PTR_IS_NULLPTR;
347 }
348
349 if (isApi9) {
350 return sessionManagerPtr_->Auth(request);
351 }
352 return sessionManagerPtr_->Authenticate(request);
353 }
354
GetOAuthToken(const AuthenticatorSessionRequest & request,std::string & token,const uint32_t apiVersion)355 ErrCode InnerAppAccountManager::GetOAuthToken(
356 const AuthenticatorSessionRequest &request, std::string &token, const uint32_t apiVersion)
357 {
358 if (!controlManagerPtr_) {
359 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
360 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
361 }
362 return controlManagerPtr_->GetOAuthToken(request, token, apiVersion);
363 }
364
SetOAuthToken(const AuthenticatorSessionRequest & request)365 ErrCode InnerAppAccountManager::SetOAuthToken(const AuthenticatorSessionRequest &request)
366 {
367 if (!controlManagerPtr_) {
368 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
369 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
370 }
371 ErrCode result = controlManagerPtr_->SetOAuthToken(request);
372 if (result != ERR_OK) {
373 return result;
374 }
375 AppAccountInfo appAccountInfo(request.name, request.callerBundleName);
376 appAccountInfo.SetAppIndex(request.appIndex);
377 if (!subscribeManagerPtr_) {
378 ACCOUNT_LOGI("subscribeManagerPtr_ is nullptr");
379 return ERR_OK;
380 }
381 if (!subscribeManagerPtr_->PublishAccount(appAccountInfo, request.callerUid, request.callerBundleName)) {
382 ACCOUNT_LOGE("failed to publish account");
383 }
384 return ERR_OK;
385 }
386
DeleteOAuthToken(const AuthenticatorSessionRequest & request,const uint32_t apiVersion)387 ErrCode InnerAppAccountManager::DeleteOAuthToken(const AuthenticatorSessionRequest &request, const uint32_t apiVersion)
388 {
389 if (!controlManagerPtr_) {
390 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
391 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
392 }
393 return controlManagerPtr_->DeleteOAuthToken(request, apiVersion);
394 }
395
SetOAuthTokenVisibility(const AuthenticatorSessionRequest & request,const uint32_t apiVersion)396 ErrCode InnerAppAccountManager::SetOAuthTokenVisibility(
397 const AuthenticatorSessionRequest &request, const uint32_t apiVersion)
398 {
399 if (!controlManagerPtr_) {
400 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
401 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
402 }
403 return controlManagerPtr_->SetOAuthTokenVisibility(request, apiVersion);
404 }
405
CheckOAuthTokenVisibility(const AuthenticatorSessionRequest & request,bool & isVisible,const uint32_t apiVersion)406 ErrCode InnerAppAccountManager::CheckOAuthTokenVisibility(
407 const AuthenticatorSessionRequest &request, bool &isVisible, const uint32_t apiVersion)
408 {
409 if (!controlManagerPtr_) {
410 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
411 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
412 }
413 return controlManagerPtr_->CheckOAuthTokenVisibility(request, isVisible, apiVersion);
414 }
415
GetAuthenticatorInfo(const AuthenticatorSessionRequest & request,AuthenticatorInfo & info)416 ErrCode InnerAppAccountManager::GetAuthenticatorInfo(
417 const AuthenticatorSessionRequest &request, AuthenticatorInfo &info)
418 {
419 if (!authenticatorManagerPtr_) {
420 ACCOUNT_LOGE("authenticatorManagerPtr_ is nullptr");
421 return ERR_APPACCOUNT_SERVICE_AUTHENTICATOR_MANAGER_PTR_IS_NULLPTR;
422 }
423 int32_t userId = request.callerUid / UID_TRANSFORM_DIVISOR;
424 return authenticatorManagerPtr_->GetAuthenticatorInfo(request.owner, userId, info);
425 }
426
GetAllOAuthTokens(const AuthenticatorSessionRequest & request,std::vector<OAuthTokenInfo> & tokenInfos)427 ErrCode InnerAppAccountManager::GetAllOAuthTokens(
428 const AuthenticatorSessionRequest &request, std::vector<OAuthTokenInfo> &tokenInfos)
429 {
430 if (!controlManagerPtr_) {
431 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
432 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
433 }
434 return controlManagerPtr_->GetAllOAuthTokens(request, tokenInfos);
435 }
436
GetOAuthList(const AuthenticatorSessionRequest & request,std::set<std::string> & oauthList,const uint32_t apiVersion)437 ErrCode InnerAppAccountManager::GetOAuthList(
438 const AuthenticatorSessionRequest &request, std::set<std::string> &oauthList, const uint32_t apiVersion)
439 {
440 if (!controlManagerPtr_) {
441 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
442 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
443 }
444 return controlManagerPtr_->GetOAuthList(request, oauthList, apiVersion);
445 }
446
GetAuthenticatorCallback(const AuthenticatorSessionRequest & request,sptr<IRemoteObject> & callback)447 ErrCode InnerAppAccountManager::GetAuthenticatorCallback(
448 const AuthenticatorSessionRequest &request, sptr<IRemoteObject> &callback)
449 {
450 callback = nullptr;
451 if (!sessionManagerPtr_) {
452 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
453 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
454 }
455 ErrCode result = sessionManagerPtr_->GetAuthenticatorCallback(request, callback);
456
457 return result;
458 }
459
GetAllAccounts(const std::string & owner,std::vector<AppAccountInfo> & appAccounts,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)460 ErrCode InnerAppAccountManager::GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts,
461 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
462 {
463 if (!controlManagerPtr_) {
464 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
465 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
466 }
467
468 ErrCode result = controlManagerPtr_->GetAllAccounts(owner, appAccounts, uid, bundleName, appIndex);
469
470 return result;
471 }
472
GetAllAccessibleAccounts(std::vector<AppAccountInfo> & appAccounts,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)473 ErrCode InnerAppAccountManager::GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts,
474 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
475 {
476 if (!controlManagerPtr_) {
477 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
478 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
479 }
480
481 ErrCode result = controlManagerPtr_->GetAllAccessibleAccounts(appAccounts, uid, bundleName, appIndex);
482
483 return result;
484 }
485
SelectAccountsByOptions(const SelectAccountsOptions & options,const sptr<IAppAccountAuthenticatorCallback> & callback,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)486 ErrCode InnerAppAccountManager::SelectAccountsByOptions(
487 const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback,
488 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
489 {
490 if (!controlManagerPtr_) {
491 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
492 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
493 }
494 AuthenticatorSessionRequest request;
495 ErrCode result = controlManagerPtr_->SelectAccountsByOptions(options, callback, uid, bundleName, appIndex);
496 return result;
497 }
498
VerifyCredential(const AuthenticatorSessionRequest & request)499 ErrCode InnerAppAccountManager::VerifyCredential(const AuthenticatorSessionRequest &request)
500 {
501 if (!sessionManagerPtr_) {
502 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
503 return ERR_APPACCOUNT_SERVICE_SESSION_MANAGER_PTR_IS_NULLPTR;
504 }
505 return sessionManagerPtr_->VerifyCredential(request);
506 }
507
CheckAccountLabels(const AuthenticatorSessionRequest & request)508 ErrCode InnerAppAccountManager::CheckAccountLabels(const AuthenticatorSessionRequest &request)
509 {
510 if (!sessionManagerPtr_) {
511 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
512 return ERR_APPACCOUNT_SERVICE_SESSION_MANAGER_PTR_IS_NULLPTR;
513 }
514 return sessionManagerPtr_->CheckAccountLabels(request);
515 }
516
SetAuthenticatorProperties(const AuthenticatorSessionRequest & request)517 ErrCode InnerAppAccountManager::SetAuthenticatorProperties(const AuthenticatorSessionRequest &request)
518 {
519 if (!sessionManagerPtr_) {
520 ACCOUNT_LOGE("sessionManagerPtr_ is nullptr");
521 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
522 }
523 return sessionManagerPtr_->SetAuthenticatorProperties(request);
524 }
525
SubscribeAppAccount(const AppAccountSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & eventListener,const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)526 ErrCode InnerAppAccountManager::SubscribeAppAccount(const AppAccountSubscribeInfo &subscribeInfo,
527 const sptr<IRemoteObject> &eventListener, const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
528 {
529 if (!subscribeManagerPtr_) {
530 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
531 return ERR_APPACCOUNT_SERVICE_SUBSCRIBE_MANAGER_PTR_IS_NULLPTR;
532 }
533
534 auto subscribeInfoPtr = std::make_shared<AppAccountSubscribeInfo>(subscribeInfo);
535 ErrCode result = subscribeManagerPtr_->
536 SubscribeAppAccount(subscribeInfoPtr, eventListener, uid, bundleName, appIndex);
537
538 return result;
539 }
540
UnsubscribeAppAccount(const sptr<IRemoteObject> & eventListener)541 ErrCode InnerAppAccountManager::UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener)
542 {
543 if (!subscribeManagerPtr_) {
544 ACCOUNT_LOGE("subscribeManagerPtr_ is nullptr");
545 return ERR_APPACCOUNT_SERVICE_SUBSCRIBE_MANAGER_PTR_IS_NULLPTR;
546 }
547
548 ErrCode result = subscribeManagerPtr_->UnsubscribeAppAccount(eventListener);
549
550 return result;
551 }
552
OnPackageRemoved(const uid_t & uid,const std::string & bundleName,const uint32_t & appIndex)553 ErrCode InnerAppAccountManager::OnPackageRemoved(
554 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
555 {
556 if (!controlManagerPtr_) {
557 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
558 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
559 }
560
561 ErrCode result = controlManagerPtr_->OnPackageRemoved(uid, bundleName, appIndex);
562 return result;
563 }
564
OnUserRemoved(int32_t userId)565 ErrCode InnerAppAccountManager::OnUserRemoved(int32_t userId)
566 {
567 if (!controlManagerPtr_) {
568 ACCOUNT_LOGE("controlManagerPtr_ is nullptr");
569 return ERR_APPACCOUNT_SERVICE_CONTROL_MANAGER_PTR_IS_NULLPTR;
570 }
571 return controlManagerPtr_->OnUserRemoved(userId);
572 }
573 } // namespace AccountSA
574 } // namespace OHOS
575