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