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_INNER_APP_ACCOUNT_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_INNER_APP_ACCOUNT_MANAGER_H 18 19 #include "ability_connect_callback_stub.h" 20 #include "app_account_authenticator_manager.h" 21 #include "app_account_authenticator_session_manager.h" 22 #include "app_account_control_manager.h" 23 #include "app_account_subscribe_manager.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class InnerAppAccountManager { 28 public: 29 InnerAppAccountManager(); 30 virtual ~InnerAppAccountManager(); 31 32 ErrCode AddAccount(const std::string &name, const std::string &extraInfo, 33 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 34 ErrCode AddAccountImplicitly(const AuthenticatorSessionRequest &request); 35 ErrCode CreateAccount(const std::string &name, const CreateAccountOptions &options, 36 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 37 ErrCode CreateAccountImplicitly(const AuthenticatorSessionRequest &request); 38 ErrCode DeleteAccount( 39 const std::string &name, const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 40 41 ErrCode GetAccountExtraInfo(const std::string &name, std::string &extraInfo, 42 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 43 ErrCode SetAccountExtraInfo(const std::string &name, const std::string &extraInfo, 44 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 45 46 ErrCode EnableAppAccess(const std::string &name, const std::string &authorizedApp, 47 AppAccountCallingInfo &appAccountCallingInfo, const uint32_t apiVersion = Constants::API_VERSION7); 48 ErrCode DisableAppAccess(const std::string &name, const std::string &authorizedApp, 49 AppAccountCallingInfo &appAccountCallingInfo, const uint32_t apiVersion = Constants::API_VERSION7); 50 ErrCode CheckAppAccess(const std::string &name, const std::string &authorizedApp, bool &isAccessible, 51 const AppAccountCallingInfo &appAccountCallingInfo); 52 53 ErrCode CheckAppAccountSyncEnable(const std::string &name, bool &syncEnable, 54 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 55 ErrCode SetAppAccountSyncEnable(const std::string &name, const bool &syncEnable, 56 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 57 58 ErrCode GetAssociatedData(const std::string &name, const std::string &key, 59 std::string &value, const uid_t &uid); 60 ErrCode SetAssociatedData(const std::string &name, const std::string &key, const std::string &value, 61 const AppAccountCallingInfo &appAccountCallingInfo); 62 63 ErrCode GetAccountCredential(const std::string &name, const std::string &credentialType, std::string &credential, 64 const AppAccountCallingInfo &appAccountCallingInfo); 65 ErrCode SetAccountCredential(const std::string &name, const std::string &credentialType, 66 const std::string &credential, const AppAccountCallingInfo &appAccountCallingInfo); 67 ErrCode DeleteAccountCredential(const std::string &name, const std::string &credentialType, 68 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 69 70 ErrCode Authenticate(const AuthenticatorSessionRequest &request); 71 ErrCode GetOAuthToken(const AuthenticatorSessionRequest &request, 72 std::string &token, const uint32_t apiVersion = Constants::API_VERSION8); 73 ErrCode SetOAuthToken(const AuthenticatorSessionRequest &request); 74 ErrCode DeleteOAuthToken( 75 const AuthenticatorSessionRequest &request, const uint32_t apiVersion = Constants::API_VERSION8); 76 ErrCode SetOAuthTokenVisibility(const AuthenticatorSessionRequest &request, 77 const uint32_t apiVersion = Constants::API_VERSION8); 78 ErrCode CheckOAuthTokenVisibility(const AuthenticatorSessionRequest &request, 79 bool &isVisible, const uint32_t apiVersion = Constants::API_VERSION8); 80 ErrCode GetAllOAuthTokens(const AuthenticatorSessionRequest &request, std::vector<OAuthTokenInfo> &tokenInfos); 81 ErrCode GetOAuthList(const AuthenticatorSessionRequest &request, 82 std::set<std::string> &oauthList, const uint32_t apiVersion = Constants::API_VERSION8); 83 ErrCode GetAuthenticatorCallback(const AuthenticatorSessionRequest &request, sptr<IRemoteObject> &callback); 84 ErrCode GetAuthenticatorInfo(const AuthenticatorSessionRequest &request, AuthenticatorInfo &info); 85 86 ErrCode GetAllAccounts(const std::string &owner, std::vector<AppAccountInfo> &appAccounts, const uid_t &uid, 87 const std::string &bundleName, const uint32_t &appIndex); 88 ErrCode GetAllAccessibleAccounts(std::vector<AppAccountInfo> &appAccounts, 89 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 90 91 ErrCode SelectAccountsByOptions( 92 const SelectAccountsOptions &options, const sptr<IAppAccountAuthenticatorCallback> &callback, 93 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 94 ErrCode VerifyCredential(const AuthenticatorSessionRequest &request); 95 ErrCode CheckAccountLabels(const AuthenticatorSessionRequest &request); 96 ErrCode SetAuthenticatorProperties(const AuthenticatorSessionRequest &request); 97 98 ErrCode SubscribeAppAccount(const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener, 99 const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 100 ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener); 101 102 ErrCode OnPackageRemoved(const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); 103 ErrCode OnUserRemoved(int32_t userId); 104 105 ErrCode ExecuteRequest(AuthorizationRequest &request, const std::string &bundleName, 106 const std::string &abilityName, const AppExecFwk::ExtensionAbilityInfo &extensionInfo); 107 private: 108 AppAccountControlManager &controlManager_; 109 AppAccountSubscribeManager &subscribeManager_; 110 AppAccountAuthenticatorSessionManager &sessionManager_; 111 112 DISALLOW_COPY_AND_MOVE(InnerAppAccountManager); 113 }; 114 115 class RequestConnection : public AAFwk::AbilityConnectionStub { 116 public: 117 RequestConnection(const int32_t &uid, const AuthorizationRequest &request); 118 ~RequestConnection() override; 119 120 void OnAbilityConnectDone( 121 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override; 122 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 123 124 private: 125 int32_t uid_; 126 AuthorizationRequest request_; 127 }; 128 } // namespace AccountSA 129 } // namespace OHOS 130 131 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_INNER_APP_ACCOUNT_MANAGER_H 132