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_manager.h"
17
18 #include "account_log_wrapper.h"
19 #include "app_account.h"
20 #include "singleton.h"
21
22 namespace OHOS {
23 namespace AccountSA {
AddAccount(const std::string & name,const std::string & extraInfo)24 ErrCode AppAccountManager::AddAccount(const std::string &name, const std::string &extraInfo)
25 {
26 return DelayedSingleton<AppAccount>::GetInstance()->AddAccount(name, extraInfo);
27 }
28
AddAccountImplicitly(const std::string & owner,const std::string & authType,const AAFwk::Want & options,const sptr<IAppAccountAuthenticatorCallback> & callback)29 ErrCode AppAccountManager::AddAccountImplicitly(const std::string &owner, const std::string &authType,
30 const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
31 {
32 return DelayedSingleton<AppAccount>::GetInstance()->AddAccountImplicitly(
33 owner, authType, options, callback);
34 }
35
CreateAccount(const std::string & name,const CreateAccountOptions & options)36 ErrCode AppAccountManager::CreateAccount(const std::string &name, const CreateAccountOptions &options)
37 {
38 return DelayedSingleton<AppAccount>::GetInstance()->CreateAccount(name, options);
39 }
40
CreateAccountImplicitly(const std::string & owner,const CreateAccountImplicitlyOptions & options,const sptr<IAppAccountAuthenticatorCallback> & callback)41 ErrCode AppAccountManager::CreateAccountImplicitly(const std::string &owner,
42 const CreateAccountImplicitlyOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
43 {
44 return DelayedSingleton<AppAccount>::GetInstance()->CreateAccountImplicitly(owner, options, callback);
45 }
46
DeleteAccount(const std::string & name)47 ErrCode AppAccountManager::DeleteAccount(const std::string &name)
48 {
49 return DelayedSingleton<AppAccount>::GetInstance()->DeleteAccount(name);
50 }
51
GetAccountExtraInfo(const std::string & name,std::string & extraInfo)52 ErrCode AppAccountManager::GetAccountExtraInfo(const std::string &name, std::string &extraInfo)
53 {
54 return DelayedSingleton<AppAccount>::GetInstance()->GetAccountExtraInfo(name, extraInfo);
55 }
56
SetAccountExtraInfo(const std::string & name,const std::string & extraInfo)57 ErrCode AppAccountManager::SetAccountExtraInfo(const std::string &name, const std::string &extraInfo)
58 {
59 return DelayedSingleton<AppAccount>::GetInstance()->SetAccountExtraInfo(name, extraInfo);
60 }
61
EnableAppAccess(const std::string & name,const std::string & authorizedApp)62 ErrCode AppAccountManager::EnableAppAccess(const std::string &name, const std::string &authorizedApp)
63 {
64 return DelayedSingleton<AppAccount>::GetInstance()->EnableAppAccess(name, authorizedApp);
65 }
66
DisableAppAccess(const std::string & name,const std::string & authorizedApp)67 ErrCode AppAccountManager::DisableAppAccess(const std::string &name, const std::string &authorizedApp)
68 {
69 return DelayedSingleton<AppAccount>::GetInstance()->DisableAppAccess(name, authorizedApp);
70 }
71
SetAppAccess(const std::string & name,const std::string & authorizedApp,bool isAccessible)72 ErrCode AppAccountManager::SetAppAccess(const std::string &name, const std::string &authorizedApp, bool isAccessible)
73 {
74 return DelayedSingleton<AppAccount>::GetInstance()->SetAppAccess(name, authorizedApp, isAccessible);
75 }
76
CheckAppAccountSyncEnable(const std::string & name,bool & syncEnable)77 ErrCode AppAccountManager::CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable)
78 {
79 return DelayedSingleton<AppAccount>::GetInstance()->CheckAppAccountSyncEnable(name, syncEnable);
80 }
81
SetAppAccountSyncEnable(const std::string & name,const bool & syncEnable)82 ErrCode AppAccountManager::SetAppAccountSyncEnable(const std::string &name, const bool &syncEnable)
83 {
84 return DelayedSingleton<AppAccount>::GetInstance()->SetAppAccountSyncEnable(name, syncEnable);
85 }
86
GetAssociatedData(const std::string & name,const std::string & key,std::string & value)87 ErrCode AppAccountManager::GetAssociatedData(const std::string &name, const std::string &key, std::string &value)
88 {
89 return DelayedSingleton<AppAccount>::GetInstance()->GetAssociatedData(name, key, value);
90 }
91
SetAssociatedData(const std::string & name,const std::string & key,const std::string & value)92 ErrCode AppAccountManager::SetAssociatedData(const std::string &name, const std::string &key, const std::string &value)
93 {
94 return DelayedSingleton<AppAccount>::GetInstance()->SetAssociatedData(name, key, value);
95 }
96
GetAccountCredential(const std::string & name,const std::string & credentialType,std::string & credential)97 ErrCode AppAccountManager::GetAccountCredential(
98 const std::string &name, const std::string &credentialType, std::string &credential)
99 {
100 return DelayedSingleton<AppAccount>::GetInstance()->GetAccountCredential(name, credentialType, credential);
101 }
102
SetAccountCredential(const std::string & name,const std::string & credentialType,const std::string & credential)103 ErrCode AppAccountManager::SetAccountCredential(
104 const std::string &name, const std::string &credentialType, const std::string &credential)
105 {
106 return DelayedSingleton<AppAccount>::GetInstance()->SetAccountCredential(name, credentialType, credential);
107 }
108
Authenticate(const std::string & name,const std::string & owner,const std::string & authType,const AAFwk::Want & options,const sptr<IAppAccountAuthenticatorCallback> & callback)109 ErrCode AppAccountManager::Authenticate(const std::string &name, const std::string &owner,
110 const std::string &authType, const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
111 {
112 return DelayedSingleton<AppAccount>::GetInstance()->Authenticate(name, owner, authType, options, callback);
113 }
114
GetOAuthToken(const std::string & name,const std::string & owner,const std::string & authType,std::string & token)115 ErrCode AppAccountManager::GetOAuthToken(
116 const std::string &name, const std::string &owner, const std::string &authType, std::string &token)
117 {
118 return DelayedSingleton<AppAccount>::GetInstance()->GetOAuthToken(name, owner, authType, token);
119 }
120
GetAuthToken(const std::string & name,const std::string & owner,const std::string & authType,std::string & token)121 ErrCode AppAccountManager::GetAuthToken(
122 const std::string &name, const std::string &owner, const std::string &authType, std::string &token)
123 {
124 return DelayedSingleton<AppAccount>::GetInstance()->GetAuthToken(name, owner, authType, token);
125 }
126
SetOAuthToken(const std::string & name,const std::string & authType,const std::string & token)127 ErrCode AppAccountManager::SetOAuthToken(
128 const std::string &name, const std::string &authType, const std::string &token)
129 {
130 return DelayedSingleton<AppAccount>::GetInstance()->SetOAuthToken(name, authType, token);
131 }
132
DeleteOAuthToken(const std::string & name,const std::string & owner,const std::string & authType,const std::string & token)133 ErrCode AppAccountManager::DeleteOAuthToken(
134 const std::string &name, const std::string &owner, const std::string &authType, const std::string &token)
135 {
136 return DelayedSingleton<AppAccount>::GetInstance()->DeleteOAuthToken(name, owner, authType, token);
137 }
138
DeleteAuthToken(const std::string & name,const std::string & owner,const std::string & authType,const std::string & token)139 ErrCode AppAccountManager::DeleteAuthToken(
140 const std::string &name, const std::string &owner, const std::string &authType, const std::string &token)
141 {
142 return DelayedSingleton<AppAccount>::GetInstance()->DeleteAuthToken(name, owner, authType, token);
143 }
144
SetOAuthTokenVisibility(const std::string & name,const std::string & authType,const std::string & bundleName,bool isVisible)145 ErrCode AppAccountManager::SetOAuthTokenVisibility(
146 const std::string &name, const std::string &authType, const std::string &bundleName, bool isVisible)
147 {
148 return DelayedSingleton<AppAccount>::GetInstance()->SetOAuthTokenVisibility(
149 name, authType, bundleName, isVisible);
150 }
151
SetAuthTokenVisibility(const std::string & name,const std::string & authType,const std::string & bundleName,bool isVisible)152 ErrCode AppAccountManager::SetAuthTokenVisibility(
153 const std::string &name, const std::string &authType, const std::string &bundleName, bool isVisible)
154 {
155 return DelayedSingleton<AppAccount>::GetInstance()->SetAuthTokenVisibility(
156 name, authType, bundleName, isVisible);
157 }
158
CheckOAuthTokenVisibility(const std::string & name,const std::string & authType,const std::string & bundleName,bool & isVisible)159 ErrCode AppAccountManager::CheckOAuthTokenVisibility(
160 const std::string &name, const std::string &authType, const std::string &bundleName, bool &isVisible)
161 {
162 return DelayedSingleton<AppAccount>::GetInstance()->CheckOAuthTokenVisibility(
163 name, authType, bundleName, isVisible);
164 }
165
CheckAuthTokenVisibility(const std::string & name,const std::string & authType,const std::string & bundleName,bool & isVisible)166 ErrCode AppAccountManager::CheckAuthTokenVisibility(
167 const std::string &name, const std::string &authType, const std::string &bundleName, bool &isVisible)
168 {
169 return DelayedSingleton<AppAccount>::GetInstance()->CheckAuthTokenVisibility(
170 name, authType, bundleName, isVisible);
171 }
172
GetAuthenticatorInfo(const std::string & owner,AuthenticatorInfo & info)173 ErrCode AppAccountManager::GetAuthenticatorInfo(const std::string &owner, AuthenticatorInfo &info)
174 {
175 return DelayedSingleton<AppAccount>::GetInstance()->GetAuthenticatorInfo(owner, info);
176 }
177
GetAllOAuthTokens(const std::string & name,const std::string & owner,std::vector<OAuthTokenInfo> & tokenInfos)178 ErrCode AppAccountManager::GetAllOAuthTokens(
179 const std::string &name, const std::string &owner, std::vector<OAuthTokenInfo> &tokenInfos)
180 {
181 return DelayedSingleton<AppAccount>::GetInstance()->GetAllOAuthTokens(name, owner, tokenInfos);
182 }
183
GetOAuthList(const std::string & name,const std::string & authType,std::set<std::string> & oauthList)184 ErrCode AppAccountManager::GetOAuthList(
185 const std::string &name, const std::string &authType, std::set<std::string> &oauthList)
186 {
187 return DelayedSingleton<AppAccount>::GetInstance()->GetOAuthList(name, authType, oauthList);
188 }
189
GetAuthList(const std::string & name,const std::string & authType,std::set<std::string> & oauthList)190 ErrCode AppAccountManager::GetAuthList(
191 const std::string &name, const std::string &authType, std::set<std::string> &oauthList)
192 {
193 return DelayedSingleton<AppAccount>::GetInstance()->GetAuthList(name, authType, oauthList);
194 }
195
GetAuthenticatorCallback(const std::string & sessionId,sptr<IRemoteObject> & callback)196 ErrCode AppAccountManager::GetAuthenticatorCallback(const std::string &sessionId, sptr<IRemoteObject> &callback)
197 {
198 return DelayedSingleton<AppAccount>::GetInstance()->GetAuthenticatorCallback(sessionId, callback);
199 }
200
GetAllAccounts(const std::string & owner,std::vector<AppAccountInfo> & appAccounts)201 ErrCode AppAccountManager::GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts)
202 {
203 return DelayedSingleton<AppAccount>::GetInstance()->GetAllAccounts(owner, appAccounts);
204 }
205
GetAllAccessibleAccounts(std::vector<AppAccountInfo> & appAccounts)206 ErrCode AppAccountManager::GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts)
207 {
208 return DelayedSingleton<AppAccount>::GetInstance()->GetAllAccessibleAccounts(appAccounts);
209 }
210
QueryAllAccessibleAccounts(const std::string & owner,std::vector<AppAccountInfo> & appAccounts)211 ErrCode AppAccountManager::QueryAllAccessibleAccounts(
212 const std::string &owner, std::vector<AppAccountInfo> &appAccounts)
213 {
214 return DelayedSingleton<AppAccount>::GetInstance()->QueryAllAccessibleAccounts(owner, appAccounts);
215 }
216
CheckAppAccess(const std::string & name,const std::string & authorizedApp,bool & isAccessible)217 ErrCode AppAccountManager::CheckAppAccess(const std::string &name, const std::string &authorizedApp, bool &isAccessible)
218 {
219 return DelayedSingleton<AppAccount>::GetInstance()->CheckAppAccess(name, authorizedApp, isAccessible);
220 }
221
DeleteAccountCredential(const std::string & name,const std::string & credentialType)222 ErrCode AppAccountManager::DeleteAccountCredential(const std::string &name, const std::string &credentialType)
223 {
224 return DelayedSingleton<AppAccount>::GetInstance()->DeleteAccountCredential(name, credentialType);
225 }
226
SelectAccountsByOptions(const SelectAccountsOptions & options,const sptr<IAppAccountAuthenticatorCallback> & callback)227 ErrCode AppAccountManager::SelectAccountsByOptions(
228 const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
229 {
230 return DelayedSingleton<AppAccount>::GetInstance()->SelectAccountsByOptions(options, callback);
231 }
232
VerifyCredential(const std::string & name,const std::string & owner,const VerifyCredentialOptions & options,const sptr<IAppAccountAuthenticatorCallback> & callback)233 ErrCode AppAccountManager::VerifyCredential(const std::string &name, const std::string &owner,
234 const VerifyCredentialOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
235 {
236 return DelayedSingleton<AppAccount>::GetInstance()->VerifyCredential(name, owner, options, callback);
237 }
238
CheckAccountLabels(const std::string & name,const std::string & owner,const std::vector<std::string> & labels,const sptr<IAppAccountAuthenticatorCallback> & callback)239 ErrCode AppAccountManager::CheckAccountLabels(const std::string &name, const std::string &owner,
240 const std::vector<std::string> &labels, const sptr<IAppAccountAuthenticatorCallback> &callback)
241 {
242 return DelayedSingleton<AppAccount>::GetInstance()->CheckAccountLabels(name, owner, labels, callback);
243 }
244
SetAuthenticatorProperties(const std::string & owner,const SetPropertiesOptions & options,const sptr<IAppAccountAuthenticatorCallback> & callback)245 ErrCode AppAccountManager::SetAuthenticatorProperties(const std::string &owner,
246 const SetPropertiesOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback)
247 {
248 return DelayedSingleton<AppAccount>::GetInstance()->SetAuthenticatorProperties(owner, options, callback);
249 }
250
SubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> & subscriber)251 ErrCode AppAccountManager::SubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber)
252 {
253 return DelayedSingleton<AppAccount>::GetInstance()->SubscribeAppAccount(subscriber);
254 }
255
UnsubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> & subscriber)256 ErrCode AppAccountManager::UnsubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber)
257 {
258 return DelayedSingleton<AppAccount>::GetInstance()->UnsubscribeAppAccount(subscriber);
259 }
260 } // namespace AccountSA
261 } // namespace OHOS
262