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