• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_MANAGER_SERVICE_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_MANAGER_SERVICE_H
18 
19 #ifdef HAS_CES_PART
20 #include "app_account_common_event_observer.h"
21 #endif // HAS_CES_PART
22 #include "app_account_stub.h"
23 #include "inner_app_account_manager.h"
24 
25 namespace OHOS {
26 namespace AccountSA {
27 class AppAccountManagerService : public AppAccountStub {
28 public:
29     AppAccountManagerService();
30     ~AppAccountManagerService() override;
31 
32     ErrCode AddAccount(const std::string &name, const std::string &extraInfo, int32_t &funcResult) override;
33     ErrCode AddAccountImplicitly(
34         const std::string &owner, const std::string &authType, const AAFwk::Want &options,
35         const sptr<IAppAccountAuthenticatorCallback> &callback, int32_t &funcResult) override;
36     ErrCode CreateAccount(const std::string &name, const CreateAccountOptions &options, int32_t &funcResult) override;
37     ErrCode CreateAccountImplicitly(const std::string &owner, const CreateAccountImplicitlyOptions &options,
38         const sptr<IAppAccountAuthenticatorCallback> &callback, int32_t &funcResult) override;
39     ErrCode DeleteAccount(const std::string &name, int32_t &funcResult) override;
40 
41     ErrCode GetAccountExtraInfo(const std::string &name, std::string &extraInfo, int32_t &funcResult) override;
42     ErrCode SetAccountExtraInfo(const std::string &name, const std::string &extraInfo, int32_t &funcResult) override;
43 
44     ErrCode EnableAppAccess(const std::string &name, const std::string &authorizedApp, int32_t &funcResult) override;
45     ErrCode DisableAppAccess(const std::string &name, const std::string &authorizedApp, int32_t &funcResult) override;
46     ErrCode SetAppAccess(const std::string &name, const std::string &authorizedApp, bool isAccessible,
47         int32_t &funcResult) override;
48     ErrCode CheckAppAccess(const std::string &name, const std::string &authorizedApp, bool &isAccessible,
49         int32_t &funcResult) override;
50 
51     ErrCode CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable, int32_t &funcResult) override;
52     ErrCode SetAppAccountSyncEnable(const std::string &name, bool syncEnable, int32_t &funcResult) override;
53 
54     ErrCode GetAssociatedData(const std::string &name, const std::string &key, std::string &value,
55         int32_t &funcResult) override;
56     ErrCode SetAssociatedData(
57         const std::string &name, const std::string &key, const std::string &value, int32_t &funcResult) override;
58 
59     ErrCode GetAccountCredential(
60         const std::string &name, const std::string &credentialType, std::string &credential,
61         int32_t &funcResult) override;
62     ErrCode SetAccountCredential(
63         const std::string &name, const std::string &credentialType, const std::string &credential,
64         int32_t &funcResult) override;
65     ErrCode DeleteAccountCredential(const std::string &name, const std::string &credentialType,
66         int32_t &funcResult) override;
67 
68     ErrCode Authenticate(const AppAccountStringInfo &appAccountStringInfo, const AAFwk::Want &options,
69         const sptr<IAppAccountAuthenticatorCallback> &callback, int32_t &funcResult) override;
70     ErrCode GetOAuthToken(
71         const std::string &name, const std::string &owner, const std::string &authType, std::string &token,
72         int32_t &funcResult) override;
73     ErrCode GetAuthToken(
74         const std::string &name, const std::string &owner, const std::string &authType, std::string &token,
75         int32_t &funcResult) override;
76     ErrCode SetOAuthToken(
77         const std::string &name, const std::string &authType, const std::string &token,
78         int32_t &funcResult) override;
79     ErrCode DeleteOAuthToken(const std::string &name, const std::string &owner,
80         const std::string &authType, const std::string &token, int32_t &funcResult) override;
81     ErrCode DeleteAuthToken(const std::string &name, const std::string &owner,
82         const std::string &authType, const std::string &token, int32_t &funcResult) override;
83     ErrCode SetOAuthTokenVisibility(const std::string &name, const std::string &authType,
84         const std::string &bundleName, bool isVisible, int32_t &funcResult) override;
85     ErrCode SetAuthTokenVisibility(const std::string &name, const std::string &authType,
86         const std::string &bundleName, bool isVisible, int32_t &funcResult) override;
87     ErrCode CheckOAuthTokenVisibility(const std::string &name, const std::string &authType,
88         const std::string &bundleName, bool &isVisible, int32_t &funcResult) override;
89     ErrCode CheckAuthTokenVisibility(const std::string &name, const std::string &authType,
90         const std::string &bundleName, bool &isVisible, int32_t &funcResult) override;
91     ErrCode GetAuthenticatorInfo(const std::string &owner, AuthenticatorInfo &info, int32_t &funcResult) override;
92     ErrCode GetAllOAuthTokens(const std::string &name, const std::string &owner,
93         std::vector<OAuthTokenInfo> &tokenInfos, int32_t &funcResult) override;
94     ErrCode GetOAuthList(const std::string &name, const std::string &authType,
95         std::set<std::string> &oauthList, int32_t &funcResult) override;
96     ErrCode GetAuthList(const std::string &name, const std::string &authType,
97         std::set<std::string> &oauthList, int32_t &funcResult) override;
98     ErrCode GetAuthenticatorCallback(const std::string &sessionId, int32_t &funcResult,
99         sptr<IRemoteObject> &callback) override;
100 
101     ErrCode GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts,
102         int32_t &funcResult) override;
103     ErrCode GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts, int32_t &funcResult) override;
104     ErrCode QueryAllAccessibleAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts,
105         int32_t &funcResult) override;
106     ErrCode SelectAccountsByOptions(
107         const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback,
108         int32_t &funcResult) override;
109     ErrCode VerifyCredential(const std::string &name, const std::string &owner,
110         const VerifyCredentialOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback,
111         int32_t &funcResult) override;
112     ErrCode CheckAccountLabels(const std::string &name, const std::string &owner,
113         const std::vector<std::string> &labels, const sptr<IAppAccountAuthenticatorCallback> &callback,
114         int32_t &funcResult) override;
115     ErrCode SetAuthenticatorProperties(const std::string &owner, const SetPropertiesOptions &options,
116         const sptr<IAppAccountAuthenticatorCallback> &callback, int32_t &funcResult) override;
117 
118     ErrCode SubscribeAppAccount(
119         const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener,
120         int32_t &funcResult) override;
121     ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener, const std::vector<std::string> &owners,
122         int32_t &funcResult) override;
123 
124     virtual ErrCode OnPackageRemoved(const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex);
125     virtual ErrCode OnUserRemoved(int32_t userId);
126 
127 private:
128     ErrCode GetBundleNameAndCheckPerm(int32_t &callingUid, std::string &bundleName, const std::string &permName);
129     ErrCode GetBundleNameAndCallingUid(int32_t &callingUid, std::string &bundleName);
130     ErrCode GetCallingTokenInfoAndAppIndex(uint32_t &appIndex);
131     ErrCode GetCallingInfo(int32_t &callingUid, std::string &bundleName, uint32_t &appIndex);
132     ErrCode GetTokenVisibilityParam(const std::string &name,
133         const std::string &authType, const std::string &bundleName, AuthenticatorSessionRequest &request);
134 
135 private:
136     std::shared_ptr<InnerAppAccountManager> innerManager_ = nullptr;
137 #ifdef HAS_CES_PART
138     AppAccountCommonEventObserver &observer_;
139 #endif // HAS_CES_PART
140     DISALLOW_COPY_AND_MOVE(AppAccountManagerService);
141 };
142 }  // namespace AccountSA
143 }  // namespace OHOS
144 
145 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_MANAGER_SERVICE_H
146