• 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 "mock_session_manager_service_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     void OnWMSConnectionChanged(
53         int32_t userId, int32_t screenId, bool isConnected, const sptr<ISessionManagerService>& sessionManagerService);
54     using UserSwitchCallbackFunc = std::function<void()>;
55     void RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc);
56 
57     /*
58      * Window Recover
59      */
60     using WindowManagerRecoverCallbackFunc = std::function<void()>;
61     void RegisterWindowManagerRecoverCallbackFunc(const WindowManagerRecoverCallbackFunc& callbackFunc);
62     void RecoverSessionManagerService(const sptr<ISessionManagerService>& sessionManagerService);
63 
64 protected:
65     SessionManager() = default;
66     virtual ~SessionManager();
67 
68 private:
69     void InitSessionManagerServiceProxy();
70     WMError InitMockSMSProxy();
71     void InitSceneSessionManagerProxy();
72 
73     /*
74      * Multi User
75      */
76     void OnWMSConnectionChangedCallback(int32_t userId, int32_t screenId, bool isConnected, bool isCallbackRegistered);
77     void OnUserSwitch(const sptr<ISessionManagerService>& sessionManagerService);
78 
79     /*
80      * Window Recover
81      */
82     void RegisterSMSRecoverListener();
83 
84     std::recursive_mutex mutex_;
85     sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr;
86     sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr;
87     sptr<ISceneSessionManager> sceneSessionManagerProxy_ = nullptr;
88     bool isRecoverListenerRegistered_ = false;
89     sptr<IRemoteObject> smsRecoverListener_ = nullptr;
90     sptr<SSMDeathRecipient> ssmDeath_ = nullptr;
91     sptr<FoundationDeathRecipient> foundationDeath_ = nullptr;
92     bool isFoundationListenerRegistered_ = false;
93     // above guarded by mutex_
94 
95     std::recursive_mutex recoverMutex_;
96     WindowManagerRecoverCallbackFunc windowManagerRecoverFunc_ = nullptr;
97     // above guarded by recoverMutex_
98 
99     /*
100      * Multi User
101      */
102     UserSwitchCallbackFunc userSwitchCallbackFunc_ = nullptr;
103     std::mutex wmsConnectionMutex_;
104     bool isWMSConnected_ = false;
105     int32_t currentWMSUserId_ = INVALID_USER_ID;
106     int32_t currentScreenId_ = DEFAULT_SCREEN_ID;
107     WMSConnectionChangedCallbackFunc wmsConnectionChangedFunc_ = nullptr;
108     // above guarded by wmsConnectionMutex_, among OnWMSConnectionChanged for wms connection event, user switched,
109     // register WMSConnectionChangedListener.
110 };
111 } // namespace OHOS::Rosen
112 
113 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_H
114