• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "app_mgr_proxy.h"
24 #include "iapp_account_authenticator_callback.h"
25 #include "iremote_object.h"
26 #include "singleton.h"
27 #include "want_params.h"
28 
29 namespace OHOS {
30 namespace AccountSA {
31 class AppAccountAuthenticatorSession;
32 class AppAccountCheckLabelsSession;
33 class AppAccountAuthenticatorSessionManager;
34 
35 class SessionAppStateObserver : public AppExecFwk::ApplicationStateObserverStub {
36 public:
37     explicit SessionAppStateObserver();
38     virtual ~SessionAppStateObserver() = default;
39 
40     void OnAbilityStateChanged(const AppExecFwk::AbilityStateData &abilityStateData) override;
41 };
42 
43 class AppAccountAuthenticatorSessionManager : public DelayedSingleton<AppAccountAuthenticatorSessionManager> {
44 public:
45     AppAccountAuthenticatorSessionManager();
46     virtual ~AppAccountAuthenticatorSessionManager();
47 
48     ErrCode AddAccountImplicitly(const AuthenticatorSessionRequest &request);
49     ErrCode Authenticate(const AuthenticatorSessionRequest &request);
50     ErrCode CreateAccountImplicitly(const AuthenticatorSessionRequest &request);
51     ErrCode Auth(const AuthenticatorSessionRequest &request);
52     ErrCode GetAuthenticatorCallback(const AuthenticatorSessionRequest &request, sptr<IRemoteObject> &callback);
53     ErrCode VerifyCredential(const AuthenticatorSessionRequest &request);
54     ErrCode CheckAccountLabels(const AuthenticatorSessionRequest &request);
55     ErrCode IsAccountRemovable(const AuthenticatorSessionRequest &request);
56     ErrCode SelectAccountsByOptions(
57         const std::vector<AppAccountInfo> accounts, const AuthenticatorSessionRequest &request);
58     ErrCode SetAuthenticatorProperties(const AuthenticatorSessionRequest &request);
59     void OnAbilityStateChanged(const AppExecFwk::AbilityStateData &abilityStateData);
60     void Init();
61     void CloseSession(const std::string &sessionId);
62     ErrCode OpenSession(const std::shared_ptr<AppAccountAuthenticatorSession> &session);
63     std::shared_ptr<AppAccountAuthenticatorSession> GetSession(const std::string &sessionId);
64     void OnSessionServerDied(const std::string &sessionId);
65     void OnSessionAbilityConnectDone(const std::string &sessionId, const AppExecFwk::ElementName &element,
66         const sptr<IRemoteObject> &remoteObject, int32_t resultCode);
67     void OnSessionAbilityDisconnectDone(
68         const std::string &sessionId, const AppExecFwk::ElementName &element, int resultCode);
69     void OnSessionResult(const std::string &sessionId, int32_t resultCode, const AAFwk::Want &result);
70     void OnSessionRequestRedirected(const std::string &sessionId, AAFwk::Want &request);
71     void OnSessionRequestContinued(const std::string &sessionId);
72 
73 private:
74     void RegisterApplicationStateObserver();
75     void UnregisterApplicationStateObserver();
76 
77 private:
78     std::mutex mutex_;
79     sptr<AppExecFwk::IAppMgr> iAppMgr_;
80     sptr<SessionAppStateObserver> appStateObserver_;
81     std::map<std::string, std::shared_ptr<AppAccountAuthenticatorSession>> sessionMap_;
82     std::map<std::string, std::set<std::string>> abilitySessions_;
83     bool isInitialized_ = false;
84 };
85 }  // namespace AccountSA
86 }  // namespace OHOS
87 
88 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_AUTHENTICATOR_SESSION_MANAGER_H
89