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