• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
17  * @addtogroup AppAccount
18  * @{
19  *
20  * @brief Provides app account management.
21  *
22  * Provides the capability to manage application accounts.
23  *
24  * @since 7.0
25  * @version 7.0
26  */
27 
28 /**
29  * @file app_account_manager.h
30  *
31  * @brief Declares app account manager interfaces.
32  *
33  * @since 7.0
34  * @version 7.0
35  */
36 #ifndef APP_ACCOUNT_INTERFACES_INNERKITS_APPACCOUNT_NATIVE_INCLUDE_APP_ACCOUNT_MANAGER_H
37 #define APP_ACCOUNT_INTERFACES_INNERKITS_APPACCOUNT_NATIVE_INCLUDE_APP_ACCOUNT_MANAGER_H
38 
39 #include "app_account_subscriber.h"
40 #include "app_account_common.h"
41 #include "app_account_info.h"
42 #include "iapp_account_authenticator_callback.h"
43 #include "iremote_object.h"
44 
45 namespace OHOS {
46 namespace AccountSA {
47 class AppAccountManager {
48 public:
49     /**
50      * @brief Adds the account name and extra information of this application to the account management service.
51      * <p>
52      * Only the owner of the application account has the permission to call this method.
53      * @param name - Indicates the name of the application account to add.
54      * @param extraInfo - Indicates the extra information of the application account to add.
55      *        The extra information cannot be sensitive information of the application account.
56      * @return error code, see account_error_no.h
57      */
58     static ErrCode AddAccount(const std::string &name, const std::string &extraInfo = "");
59 
60     /**
61      * @brief Adds an application account of a specified owner implicitly.
62      * @param owner - Indicates the account owner of your application or third-party applications.
63      * @param authType - Indicates the authentication type.
64      * @param options - Indicates the authenticator-specific options for the request.
65      * @param callback - Indicates the callback for get result.
66      * @return error code, see account_error_no.h
67      */
68     static ErrCode AddAccountImplicitly(const std::string &owner, const std::string &authType,
69         const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
70 
71     /**
72      * @brief Creates the account name and extra information of this application to the account management service.
73      * <p>
74      * Only the owner of the application account has the permission to call this method.
75      * @param name - Indicates the name of the application account to add.
76      * @param options - Indicates the extra information of the application account to add.
77      *        The extra information cannot be sensitive information of the application account.
78      * @return account error, see account_error_no.h
79      */
80     static ErrCode CreateAccount(const std::string &name, const CreateAccountOptions &options);
81 
82     /**
83      * @brief Creates an application account of a specified owner implicitly.
84      * @param owner - Indicates the account owner of your application or third-party applications.
85      * @param callback - Indicates the authenticator callback.
86      * @return account error, see account_error_no.h
87      */
88     static ErrCode CreateAccountImplicitly(const std::string &owner, const CreateAccountImplicitlyOptions &options,
89         const sptr<IAppAccountAuthenticatorCallback> &callback);
90 
91     /**
92      * @brief Deletes an application account from the account management service.
93      * <p>
94      * Only the owner of the application account has the permission to call this method.
95      * @param name - Indicates the name of the application account to delete.
96      * @return account error, see account_error_no.h
97      */
98     static ErrCode DeleteAccount(const std::string &name);
99 
100     /**
101      * @brief Gets extra information of this application account.
102      * @param name - Indicates the name of the application account.
103      * @param extraInfo - Indicates the extra information of the account.
104      * @return account error, see account_error_no.h
105      */
106     static ErrCode GetAccountExtraInfo(const std::string &name, std::string &extraInfo);
107 
108     /**
109      * @brief Sets extra information for this application account.
110      * <p>
111      * You can call this method when you forget the extra information of your application account or
112      * need to modify the extra information.
113      * @param name - Indicates the name of the application account.
114      * @param extraInfo - Indicates the extra information to set.
115      * @return account error, see account_error_no.h
116      */
117     static ErrCode SetAccountExtraInfo(const std::string &name, const std::string &extraInfo);
118 
119     /**
120      * @brief Enables a third-party application with the specified bundle name to access the given application
121      * account for data query and listening.
122      * @param name - Indicates the name of the application account.
123      * @param authorizedApp - Indicates the bundle name of the third-party application.
124      * @return account error, see account_error_no.h
125      */
126     static ErrCode EnableAppAccess(const std::string &name, const std::string &authorizedApp);
127 
128     /**
129      * @brief Disables a third-party application with the specified bundle name from
130      * accessing the given application account.
131      * @param name - Indicates the name of the application account to disable access from
132      *        the third-party application.
133      * @param bundleName - Indicates the bundle name of the third-party application.
134      * @return account error, see account_error_no.h
135      */
136     static ErrCode DisableAppAccess(const std::string &name, const std::string &authorizedApp);
137 
138     /**
139      * @brief Sets a third-party application with the specified bundle name to access the given application
140      * account for data query and listening.
141      * @param name - Indicates the name of the application account.
142      * @param bundleName - Indicates the bundle name of the third-party application.
143      * @param isAccessible - Indicates whether the account is accessible for the specified application.
144      * @return account error, see account_error_no.h
145      */
146     static ErrCode SetAppAccess(const std::string &name, const std::string &authorizedApp, bool isAccessible);
147 
148     /**
149      * @brief Checks whether a specified application account allows application data synchronization.
150      * <p>
151      * If the same OHOS account has logged in to multiple devices, these devices constitute a super device
152      * through the distributed networking. On the connected devices, you can call this method to check
153      * whether application data can be synchronized.
154      * <p>
155      * @permission ohos.permission.DISTRIBUTED_DATASYNC
156      * @param name - Indicates the name of the application account.
157      * @param syncEnable - Indicates whether the data sync is enabled.
158      * @return account error, see account_error_no.h
159      */
160     static ErrCode CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable);
161 
162     /**
163      * @brief Sets whether a specified application account allows application data synchronization.
164      * <p>
165      * If the same OHOS account has logged in to multiple devices, these devices constitute a super device
166      * through the distributed networking. On the connected devices, you can call this method to set whether to
167      * allow cross-device data synchronization. If synchronization is allowed, application data can be synchronized
168      * among these devices in the event of any changes related to the application account.
169      * If synchronization is not allowed, the application data is stored only on the local device.
170      * <p>
171      * <b>Application account-related changes</b>: adding or deleting an application account, setting extra
172      * information (such as updating a token), and setting data associated with this application account
173      * <p>
174      * <b>Application data that can be synchronized</b>: application account name, token,
175      * and data associated with this application account
176      * <p>
177      * @permission ohos.permission.DISTRIBUTED_DATASYNC
178      * @param name - Indicates the name of the application account.
179      * @param syncEnable - Specifies whether to allow application data synchronization.
180      * @return account error, see account_error_no.h
181      */
182     static ErrCode SetAppAccountSyncEnable(const std::string &name, const bool &syncEnable);
183 
184     /**
185      * @brief Gets data associated with this application account.
186      * @param name - Indicates the name of the application account.
187      * @param key - Indicates the key of the data.
188      * @param value - Indicates the value of the data.
189      * @return account error, see account_error_no.h
190      */
191     static ErrCode GetAssociatedData(const std::string &name, const std::string &key, std::string &value);
192 
193     /**
194      * @brief Sets data associated with this application account.
195      * @param name - Indicates the name of the application account.
196      * @param key - Indicates the key of the data to set. The key can be customized.
197      * @param value - Indicates the value of the data to set.
198      * @return account error, see account_error_no.h
199      */
200     static ErrCode SetAssociatedData(const std::string &name, const std::string &key, const std::string &value);
201 
202     /**
203      * @brief Gets the credential of this application account.
204      * @param name - Indicates the name of the application account.
205      * @param credentialType - Indicates the type of the credential to obtain.
206      * @param credential - Indicates the credential of the application account.
207      * @return account error, see account_error_no.h
208      */
209     static ErrCode GetAccountCredential(
210         const std::string &name, const std::string &credentialType, std::string &credential);
211 
212     /**
213      * @brief Sets the credential for this application account.
214      * @param name - Indicates the name of the application account.
215      * @param credentialType - Indicates the type of the credential to set.
216      * @param credential - Indicates the credential to set.
217      * @return account error, see account_error_no.h
218      */
219     static ErrCode SetAccountCredential(
220         const std::string &name, const std::string &credentialType, const std::string &credential);
221 
222     /**
223      * @brief Authenticates an application account to get an oauth token.
224      * @param name - Indicates the account name of your application or third-party applications.
225      * @param owner - Indicates the account owner of your application or third-party applications.
226      * @param authType - Indicates the authentication type.
227      * @param options - Indicates the authenticator-specific options for the request.
228      * @param callback - Indicates the authenticator callback.
229      * @return account error, see account_error_no.h
230      */
231     static ErrCode Authenticate(const std::string &name, const std::string &owner, const std::string &authType,
232         const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
233 
234     /**
235      * @brief Gets an oauth token with the specified authentication type from a particular application account.
236      * @param name - Indicates the account name of your application or third-party applications.
237      * @param owner - Indicates the account owner of your application or third-party applications.
238      * @param authType - Indicates the authentication type.
239      * @param token - Indicates the auth token.
240      * @return account error, see account_error_no.h
241      */
242     static ErrCode GetOAuthToken(const std::string &name, const std::string &owner, const std::string &authType,
243         std::string &token);
244 
245     /**
246      * @brief Gets an oauth token with the specified authentication type from a particular application account.
247      * @param name - Indicates the account name of your application or third-party applications.
248      * @param owner - Indicates the account owner of your application or third-party applications.
249      * @param authType - Indicates the authentication type.
250      * @param token - Indicates the auth token.
251      * @return account error, see account_error_no.h
252      */
253     static ErrCode GetAuthToken(const std::string &name, const std::string &owner, const std::string &authType,
254         std::string &token);
255 
256     /**
257      * @brief Sets an oauth token with the specified authentication type for a particular account.
258      * <p>
259      * Only the owner of the application account has the permission to call this method.
260      * @param name - Indicates the account name of your application.
261      * @param authType - Indicates the authentication type.
262      * @param token - Indicates the oauth token.
263      * @return account error, see account_error_no.h
264      */
265     static ErrCode SetOAuthToken(
266         const std::string &name, const std::string &authType, const std::string &token);
267 
268     /**
269      * @brief Deletes an oauth token for the specified application account.
270      * <p>
271      * Only tokens visible to the caller application can be deleted.
272      * @param name - Indicates the account name of your application or third-party applications.
273      * @param owner - Indicates the account owner of your application or third-party applications.
274      * @param authType - Indicates the authentication type.
275      * @param token - Indicates the oauth token.
276      * @return account error, see account_error_no.h
277      */
278     static ErrCode DeleteOAuthToken(
279         const std::string &name, const std::string &owner, const std::string &authType, const std::string &token);
280 
281     /**
282      * @brief Deletes an oauth token for the specified application account.
283      * <p>
284      * Only tokens visible to the caller application can be deleted.
285      * @param name - Indicates the account name of your application or third-party applications.
286      * @param owner - Indicates the account owner of your application or third-party applications.
287      * @param authType - Indicates the authentication type.
288      * @param token - Indicates the oauth token.
289      * @return account error, see account_error_no.h
290      */
291     static ErrCode DeleteAuthToken(
292         const std::string &name, const std::string &owner, const std::string &authType, const std::string &token);
293 
294     /**
295      * @brief Sets the oauth token visibility of the specified authentication type to a third-party application.
296      * <p>
297      * Only the owner of the application account has the permission to call this method.
298      * @param name - Indicates the account name of your application.
299      * @param authType - Indicates the authentication type.
300      * @param bundleName - Indicates the bundle name of the third-party application.
301      * @param isVisible - Indicates the bool value of visibility.
302      * @return account error, see account_error_no.h
303      */
304     static ErrCode SetOAuthTokenVisibility(const std::string &name, const std::string &authType,
305         const std::string &bundleName, bool isVisible);
306 
307     /**
308      * @brief Sets the oauth token visibility of the specified authentication type to a third-party application.
309      * <p>
310      * Only the owner of the application account has the permission to call this method.
311      * @param name - Indicates the account name of your application.
312      * @param authType - Indicates the authentication type.
313      * @param bundleName - Indicates the bundle name of the third-party application.
314      * @param isVisible - Indicates the bool value of visibility.
315      * @return account error, see account_error_no.h
316      */
317     static ErrCode SetAuthTokenVisibility(const std::string &name, const std::string &authType,
318         const std::string &bundleName, bool isVisible);
319 
320     /**
321      * @brief Checks the oauth token visibility of the specified authentication type for a third-party application.
322      * <p>
323      * Only the owner of the application account has the permission to call this method.
324      * @param name - Indicates the account name of your application or third-party applications.
325      * @param authType - Indicates the authentication type.
326      * @param bundleName - Indicates the bundle name of the third-party application.
327      * @param isVisible - Indicates the bool value of visibility.
328      * @return account error, see account_error_no.h
329      */
330     static ErrCode CheckOAuthTokenVisibility(const std::string &name, const std::string &authType,
331         const std::string &bundleName, bool &isVisible);
332 
333     /**
334      * @brief Checks the oauth token visibility of the specified authentication type for a third-party application.
335      * <p>
336      * Only the owner of the application account has the permission to call this method.
337      * @param name - Indicates the account name of your application or third-party applications.
338      * @param authType - Indicates the authentication type.
339      * @param bundleName - Indicates the bundle name of the third-party application.
340      * @param isVisible - Indicates the bool value of visibility.
341      * @return account error, see account_error_no.h
342      */
343     static ErrCode CheckAuthTokenVisibility(const std::string &name, const std::string &authType,
344         const std::string &bundleName, bool &isVisible);
345 
346     /**
347      * @brief Gets the authenticator information of an application account.
348      * @param owner - Indicates the account owner of your application or third-party applications.
349      * @param info - Indicates the authenticator information of the application account.
350      * @return account error, see account_error_no.h
351      */
352     static ErrCode GetAuthenticatorInfo(const std::string &owner, AuthenticatorInfo &info);
353 
354     /**
355      * @brief Gets all oauth tokens visible to the caller application.
356      * @param name - Indicates the account name of your application or third-party applications.
357      * @param owner - Indicates the account owner of your application or third-party applications.
358      * @param tokenInfos - Indicates the list of token.
359      * @return account error, see account_error_no.h
360      */
361     static ErrCode GetAllOAuthTokens(const std::string &name, const std::string &owner,
362         std::vector<OAuthTokenInfo> &tokenInfos);
363 
364     /**
365      * @brief Gets the open authorization list with a specified authentication type
366      * for a particular application account.
367      * <p>
368      * Only the owner of the application account has the permission to call this method.
369      * @param name - Indicates the account name of your application.
370      * @param authType - Indicates the authentication type.
371      * @param oauthList - Indicates the open authorization list of the specified authentication type.
372      * @return account error, see account_error_no.h
373      */
374     static ErrCode GetOAuthList(const std::string &name, const std::string &authType,
375         std::set<std::string> &oauthList);
376 
377     /**
378      * @brief Gets the open authorization list with a specified authentication type
379      * for a particular application account.
380      * <p>
381      * Only the owner of the application account has the permission to call this method.
382      * @param name - Indicates the account name of your application.
383      * @param authType - Indicates the authentication type.
384      * @param authList - Indicates the open authorization list of the specified authentication type.
385      * @return account error, see account_error_no.h
386      */
387     static ErrCode GetAuthList(const std::string &name, const std::string &authType,
388         std::set<std::string> &oauthList);
389 
390     /**
391      * @brief Gets the authenticator callback with the specified session id.
392      * <p>
393      * Only the owner of the authenticator has the permission to call this method.
394      * @param sessionId - Indicates the id of a authentication session.
395      * @param callback - Indicates the authenticator callback related to the session id.
396      * @return account error, see account_error_no.h
397      */
398     static ErrCode GetAuthenticatorCallback(const std::string &sessionId, sptr<IRemoteObject> &callback);
399 
400     /**
401      * @brief Gets information about all accounts of a specified account owner.
402      * <p>
403      * This method applies to the following accounts:
404      * <ul>
405      * <li>Accounts of this application.</li>
406      * <li>Accounts of third-party applications. To obtain such information,
407      * your application must have gained authorization from the third-party applications or
408      * have gained the ohos.permission.GET_ALL_APP_ACCOUNTS permission.</li>
409      * </ul>
410      * @permission ohos.permission.GET_ALL_APP_ACCOUNTS
411      * @param  owner - Indicates the account owner of your application or third-party applications.
412      * @param appAccounts - Indicates a list of application accounts.
413      * @return account error, see account_error_no.h
414      */
415     static ErrCode GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts);
416 
417     /**
418      * @brief Gets information about all accessible accounts.
419      * <p>
420      * This method applies to the following accounts:
421      * <ul>
422      * <li>Accounts of this application.</li>
423      * <li>Accounts of third-party applications. To obtain such information,
424      * your application must have gained authorization from the third-party applications or
425      * have gained the ohos.permission.GET_ALL_APP_ACCOUNTS permission.</li>
426      * </ul>
427      * @permission ohos.permission.GET_ALL_APP_ACCOUNTS
428      * @param appAccounts - Indicates a list of application accounts.
429      * @return account error, see account_error_no.h
430      */
431     static ErrCode GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts);
432 
433     /**
434      * @brief Gets information about all accounts of a specified account owner.
435      * <p>
436      * This method applies to the following accounts:
437      * <ul>
438      * <li>Accounts of this application.</li>
439      * <li>Accounts of third-party applications. To obtain such information,
440      * your application must have gained authorization from the third-party applications or
441      * have gained the ohos.permission.GET_ALL_APP_ACCOUNTS permission.</li>
442      * </ul>
443      * @permission ohos.permission.GET_ALL_APP_ACCOUNTS
444      * @param  owner - Indicates the account owner of your application or third-party applications.
445      * @param appAccounts - Indicates a list of application accounts.
446      * @return account error, see account_error_no.h
447      */
448     static ErrCode QueryAllAccessibleAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts);
449 
450     /**
451      * @brief Checks whether a third-party application with the specified bundle name is allowed to access
452      * the given application account for data query and listening.
453      * @param name - Indicates the name of the application account.
454      * @param bundleName - Indicates the bundle name of the third-party application.
455      * @param isAccessible - Indicates whether the account is accessible for the specified application.
456      * @return account error, see account_error_no.h
457      */
458     static ErrCode CheckAppAccess(const std::string &name, const std::string &authorizedApp, bool &isAccessible);
459 
460     /**
461      * @brief Deletes the credential of the specified application account.
462      * @param name - Indicates the account name.
463      * @param credentialType - Indicates the type of the credential to delete.
464      * @return account error, see account_error_no.h
465      */
466     static ErrCode DeleteAccountCredential(const std::string &name, const std::string &credentialType);
467 
468     /**
469      * @brief Selects a list of accounts that satisfied with the specified options.
470      * @param options - Indicates the options for selecting account.
471      * @param callback - Indicates the authenticator callback.
472      * @return account error, see account_error_no.h
473      */
474     static ErrCode SelectAccountsByOptions(
475         const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
476 
477     /**
478      * @brief Verifies the credential to ensure the user is the owner of the specified account.
479      * @param name - Indicates the account name.
480      * @param owner - Indicates the account owner.
481      * @param callback - Indicates the authenticator callback.
482      * @return account error, see account_error_no.h
483      */
484     static ErrCode VerifyCredential(const std::string &name, const std::string &owner,
485         const VerifyCredentialOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
486 
487     /**
488      * @brief Checks whether a particular account has all specified labels.
489      * @param name - Indicates the account name.
490      * @param labels - Indicates an array of labels to check.
491      * @param callback - Indicates the authenticator callback.
492      * @return account error, see account_error_no.h
493      */
494     static ErrCode CheckAccountLabels(const std::string &name, const std::string &owner,
495         const std::vector<std::string> &labels, const sptr<IAppAccountAuthenticatorCallback> &callback);
496 
497     /**
498      * @brief Sets properties for the specified account authenticator.
499      * <p>
500      * If the authenticator supports setting its properties,
501      * the caller will normally be redirected to an Ability specified by Want for property setting.
502      * @param owner - Indicates the owner of authenticator.
503      * @param callback - Indicates the authenticator callback.
504      * @return account error, see account_error_no.h
505      */
506     static ErrCode SetAuthenticatorProperties(const std::string &owner,
507         const SetPropertiesOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
508 
509     static ErrCode ExecuteRequest(const AccountCapabilityRequest &request,
510         const sptr<IAppAccountAuthorizationExtensionCallback> &callback);
511     /**
512      * @brief Subscribes to the change events of accounts of the specified owners.
513      * <p>
514      * When the account owner updates the account, the subscriber will receive a notification
515      * about the account change event.
516      * @param subscriber - Indicates the subscriber information.
517      * @return account error, see account_error_no.h
518      */
519     static ErrCode SubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber);
520 
521     /**
522      * @brief Unsubscribes from account events.
523      * @param subscriber - Indicates the subscriber information.
524      * @return account error, see account_error_no.h
525      */
526     static ErrCode UnsubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber);
527 };
528 }  // namespace AccountSA
529 }  // namespace OHOS
530 
531 #endif  // APP_ACCOUNT_INTERFACES_INNERKITS_APPACCOUNT_NATIVE_INCLUDE_APP_ACCOUNT_MANAGER_H
532