• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_H
18 
19 #include <iremote_stub.h>
20 #include <shared_mutex>
21 
22 #include "imock_session_manager_interface.h"
23 #include "session_manager_service_interface.h"
24 #include "wm_single_instance.h"
25 #include "zidl/scene_session_manager_interface.h"
26 
27 namespace OHOS::Rosen {
28 class SSMDeathRecipient : public IRemoteObject::DeathRecipient {
29 public:
30     void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
31 };
32 class FoundationDeathRecipient : public IRemoteObject::DeathRecipient {
33 public:
34     void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
35 };
36 
37 class SessionManager {
38     WM_DECLARE_SINGLE_INSTANCE_BASE(SessionManager);
39 
40 public:
41     void ClearSessionManagerProxy();
42     void Clear();
43 
44     sptr<ISceneSessionManager> GetSceneSessionManagerProxy();
45     void OnFoundationDied();
46 
47     /*
48      * Multi User
49      */
50     using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>;
51     WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc);
52     WMError UnregisterWMSConnectionChangedListener();
53     void OnWMSConnectionChanged(
54         int32_t userId, int32_t screenId, bool isConnected, const sptr<ISessionManagerService>& sessionManagerService);
55     using UserSwitchCallbackFunc = std::function<void()>;
56     void RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc);
57 
58     /*
59      * Window Recover
60      */
61     using WindowManagerRecoverCallbackFunc = std::function<void()>;
62     void RegisterWindowManagerRecoverCallbackFunc(const WindowManagerRecoverCallbackFunc& callbackFunc);
63     void RecoverSessionManagerService(const sptr<ISessionManagerService>& sessionManagerService);
64 
65 protected:
66     SessionManager() = default;
67     virtual ~SessionManager();
68 
69 private:
70     void InitSessionManagerServiceProxy();
71     WMError InitMockSMSProxy();
72     void InitSceneSessionManagerProxy();
73 
74     /*
75      * Multi User
76      */
77     void OnWMSConnectionChangedCallback(int32_t userId, int32_t screenId, bool isConnected, bool isCallbackRegistered);
78     void OnUserSwitch(const sptr<ISessionManagerService>& sessionManagerService);
79 
80     /*
81      * Window Recover
82      */
83     void RegisterSMSRecoverListener();
84     void UnregisterSMSRecoverListener();
85 
86     std::recursive_mutex mutex_;
87     sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr;
88     sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr;
89     sptr<ISceneSessionManager> sceneSessionManagerProxy_ = nullptr;
90     bool isRecoverListenerRegistered_ = false;
91     sptr<IRemoteObject> smsRecoverListener_ = nullptr;
92     sptr<SSMDeathRecipient> ssmDeath_ = nullptr;
93     sptr<FoundationDeathRecipient> foundationDeath_ = nullptr;
94     bool isFoundationListenerRegistered_ = false;
95     // above guarded by mutex_
96 
97     std::recursive_mutex recoverMutex_;
98     WindowManagerRecoverCallbackFunc windowManagerRecoverFunc_ = nullptr;
99     // above guarded by recoverMutex_
100 
101     /*
102      * Multi User
103      */
104     UserSwitchCallbackFunc userSwitchCallbackFunc_ = nullptr;
105     std::mutex wmsConnectionMutex_;
106     bool isWMSConnected_ = false;
107     int32_t currentWMSUserId_ = INVALID_USER_ID;
108     int32_t currentScreenId_ = DEFAULT_SCREEN_ID;
109     WMSConnectionChangedCallbackFunc wmsConnectionChangedFunc_ = nullptr;
110     // above guarded by wmsConnectionMutex_, among OnWMSConnectionChanged for wms connection event, user switched,
111     // register WMSConnectionChangedListener.
112 };
113 } // namespace OHOS::Rosen
114 
115 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_H
116