• 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 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_H
18 
19 #include <map>
20 
21 #include "app_account_event_listener.h"
22 #include "iapp_account.h"
23 #include "iapp_account_authenticator_callback.h"
24 
25 namespace OHOS {
26 namespace AccountSA {
27 class AppAccount {
28 public:
29     enum SubscribeState {
30         ALREADY_SUBSCRIBED = 0,
31         INITIAL_SUBSCRIPTION,
32         SUBSCRIBE_FAILED,
33     };
34 
35     ErrCode AddAccount(const std::string &name, const std::string &extraInfo);
36     ErrCode AddAccountImplicitly(const std::string &owner, const std::string &authType,
37         const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
38     ErrCode CreateAccount(const std::string &name, const CreateAccountOptions &options);
39     ErrCode CreateAccountImplicitly(const std::string &owner, const CreateAccountImplicitlyOptions &options,
40         const sptr<IAppAccountAuthenticatorCallback> &callback);
41     ErrCode DeleteAccount(const std::string &name);
42 
43     ErrCode GetAccountExtraInfo(const std::string &name, std::string &extraInfo);
44     ErrCode SetAccountExtraInfo(const std::string &name, const std::string &extraInfo);
45 
46     ErrCode EnableAppAccess(const std::string &name, const std::string &bundleName);
47     ErrCode DisableAppAccess(const std::string &name, const std::string &bundleName);
48     ErrCode SetAppAccess(const std::string &name, const std::string &authorizedApp, bool isAccessible);
49 
50     ErrCode CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable);
51     ErrCode SetAppAccountSyncEnable(const std::string &name, const bool &syncEnable);
52 
53     ErrCode GetAssociatedData(const std::string &name, const std::string &key, std::string &value);
54     ErrCode SetAssociatedData(const std::string &name, const std::string &key, const std::string &value);
55 
56     ErrCode GetAccountCredential(const std::string &name, const std::string &credentialType, std::string &credential);
57     ErrCode SetAccountCredential(
58         const std::string &name, const std::string &credentialType, const std::string &credential);
59 
60     ErrCode Authenticate(const std::string &name, const std::string &owner, const std::string &authType,
61         const AAFwk::Want &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
62     ErrCode GetOAuthToken(
63         const std::string &name, const std::string &owner, const std::string &authType, std::string &token);
64     ErrCode GetAuthToken(
65         const std::string &name, const std::string &owner, const std::string &authType, std::string &token);
66     ErrCode SetOAuthToken(const std::string &name, const std::string &authType, const std::string &token);
67     ErrCode DeleteOAuthToken(
68         const std::string &name, const std::string &owner, const std::string &authType, const std::string &token);
69     ErrCode DeleteAuthToken(
70         const std::string &name, const std::string &owner, const std::string &authType, const std::string &token);
71     ErrCode SetOAuthTokenVisibility(
72         const std::string &name, const std::string &authType, const std::string &bundleName, bool isVisible);
73     ErrCode SetAuthTokenVisibility(
74         const std::string &name, const std::string &authType, const std::string &bundleName, bool isVisible);
75     ErrCode CheckOAuthTokenVisibility(
76         const std::string &name, const std::string &authType, const std::string &bundleName, bool &isVisible);
77     ErrCode CheckAuthTokenVisibility(
78         const std::string &name, const std::string &authType, const std::string &bundleName, bool &isVisible);
79     ErrCode GetAuthenticatorInfo(const std::string &owner, AuthenticatorInfo &info);
80     ErrCode GetAllOAuthTokens(
81         const std::string &name, const std::string &owner, std::vector<OAuthTokenInfo> &tokenInfos);
82     ErrCode GetOAuthList(
83         const std::string &name, const std::string &authType, std::set<std::string> &oauthList);
84     ErrCode GetAuthList(
85         const std::string &name, const std::string &authType, std::set<std::string> &oauthList);
86     ErrCode GetAuthenticatorCallback(const std::string &sessionId, sptr<IRemoteObject> &callback);
87 
88     ErrCode GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts);
89     ErrCode GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts);
90     ErrCode QueryAllAccessibleAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts);
91     ErrCode CheckAppAccess(const std::string &name, const std::string &authorizedApp, bool &isAccessible);
92     ErrCode DeleteAccountCredential(const std::string &name, const std::string &credentialType);
93     ErrCode SelectAccountsByOptions(
94         const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
95     ErrCode VerifyCredential(const std::string &name, const std::string &owner,
96         const VerifyCredentialOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
97     ErrCode CheckAccountLabels(const std::string &name, const std::string &owner,
98         const std::vector<std::string> &labels, const sptr<IAppAccountAuthenticatorCallback> &callback);
99     ErrCode SetAuthenticatorProperties(const std::string &owner,
100         const SetPropertiesOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback);
101 
102     ErrCode SubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber);
103     ErrCode UnsubscribeAppAccount(const std::shared_ptr<AppAccountSubscriber> &subscriber);
104 
105     ErrCode ResetAppAccountProxy();
106 
107 private:
108     ErrCode CheckParameters(const std::string &name, const std::string &extraInfo = "");
109     ErrCode CheckSpecialCharacters(const std::string &name);
110     ErrCode CheckTokenVisibilityParam(
111         const std::string &name, const std::string &authType, const std::string &bundleName);
112     ErrCode GetAppAccountProxy();
113     ErrCode CreateAppAccountEventListener(
114         const std::shared_ptr<AppAccountSubscriber> &subscriber, sptr<IRemoteObject> &appAccountEventListener);
115 
116 private:
117     std::mutex mutex_;
118     std::mutex eventListenersMutex_;
119     sptr<IAppAccount> appAccountProxy_;
120     std::map<std::shared_ptr<AppAccountSubscriber>, sptr<AppAccountEventListener>> eventListeners_;
121     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
122 };
123 }  // namespace AccountSA
124 }  // namespace OHOS
125 
126 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_H
127