1 /* 2 * Copyright (c) 2022 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_AUTHENTICATOR_SESSION_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_AUTHENTICATOR_SESSION_MANAGER_H 18 19 #include "application_state_observer_stub.h" 20 #include "app_account_common.h" 21 #include "app_account_info.h" 22 #include "app_mgr_interface.h" 23 #include "iapp_account_authenticator_callback.h" 24 #include "iremote_object.h" 25 #include "singleton.h" 26 #include "want_params.h" 27 28 namespace OHOS { 29 namespace AccountSA { 30 class AppAccountAuthenticatorSession; 31 class AppAccountCheckLabelsSession; 32 class AppAccountAuthenticatorSessionManager; 33 34 class AppAccountAuthenticatorSessionManager { 35 public: 36 static AppAccountAuthenticatorSessionManager &GetInstance(); 37 ErrCode AddAccountImplicitly(const AuthenticatorSessionRequest &request); 38 ErrCode Authenticate(const AuthenticatorSessionRequest &request); 39 ErrCode CreateAccountImplicitly(const AuthenticatorSessionRequest &request); 40 ErrCode Auth(const AuthenticatorSessionRequest &request); 41 ErrCode GetAuthenticatorCallback(const AuthenticatorSessionRequest &request, sptr<IRemoteObject> &callback); 42 ErrCode VerifyCredential(const AuthenticatorSessionRequest &request); 43 ErrCode CheckAccountLabels(const AuthenticatorSessionRequest &request); 44 ErrCode IsAccountRemovable(const AuthenticatorSessionRequest &request); 45 ErrCode SelectAccountsByOptions( 46 const std::vector<AppAccountInfo> accounts, const AuthenticatorSessionRequest &request); 47 ErrCode SetAuthenticatorProperties(const AuthenticatorSessionRequest &request); 48 void Init(); 49 void CloseSession(const std::string &sessionId); 50 ErrCode OpenSession(const std::shared_ptr<AppAccountAuthenticatorSession> &session); 51 std::shared_ptr<AppAccountAuthenticatorSession> GetSession(const std::string &sessionId); 52 void OnSessionServerDied(const std::string &sessionId); 53 void OnSessionAbilityConnectDone(const std::string &sessionId, const AppExecFwk::ElementName &element, 54 const sptr<IRemoteObject> &remoteObject, int32_t resultCode); 55 void OnSessionAbilityDisconnectDone( 56 const std::string &sessionId, const AppExecFwk::ElementName &element, int resultCode); 57 void OnSessionResult(const std::string &sessionId, int32_t resultCode, const AAFwk::Want &result); 58 void OnSessionRequestRedirected(const std::string &sessionId, AAFwk::Want &request); 59 void OnSessionRequestContinued(const std::string &sessionId); 60 61 private: 62 AppAccountAuthenticatorSessionManager() = default; 63 ~AppAccountAuthenticatorSessionManager(); 64 DISALLOW_COPY_AND_MOVE(AppAccountAuthenticatorSessionManager); 65 66 private: 67 std::mutex mutex_; 68 std::map<std::string, std::shared_ptr<AppAccountAuthenticatorSession>> sessionMap_; 69 std::map<std::string, std::set<std::string>> abilitySessions_; 70 bool isInitialized_ = false; 71 }; 72 } // namespace AccountSA 73 } // namespace OHOS 74 75 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_AUTHENTICATOR_SESSION_MANAGER_H 76