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_LITE_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_H 18 19 #include <functional> 20 #include <shared_mutex> 21 22 #include "imock_session_manager_interface.h" 23 #include "session_manager_service_interface.h" 24 #include "wm_common.h" 25 #include "wm_single_instance.h" 26 #include "zidl/scene_session_manager_lite_interface.h" 27 #include "zidl/screen_session_manager_lite_interface.h" 28 29 namespace OHOS::Rosen { 30 class SSMDeathRecipientLite : public IRemoteObject::DeathRecipient { 31 public: 32 void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 33 }; 34 35 class FoundationDeathRecipientLite : public IRemoteObject::DeathRecipient { 36 public: 37 void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 38 }; 39 40 class SessionManagerLite { 41 WM_DECLARE_SINGLE_INSTANCE_BASE(SessionManagerLite); 42 public: 43 void ClearSessionManagerProxy(); 44 void Clear(); 45 46 sptr<ISceneSessionManagerLite> GetSceneSessionManagerLiteProxy(); 47 sptr<IScreenSessionManagerLite> GetScreenSessionManagerLiteProxy(); 48 49 sptr<ISessionManagerService> GetSessionManagerServiceProxy(); 50 51 void SaveSessionListener(const sptr<ISessionListener>& listener); 52 void DeleteSessionListener(const sptr<ISessionListener>& listener); 53 54 void OnFoundationDied(); 55 56 /* 57 * Multi User 58 */ 59 using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>; 60 WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); 61 WMError UnregisterWMSConnectionChangedListener(); 62 void OnWMSConnectionChanged( 63 int32_t userId, int32_t screenId, bool isConnected, const sptr<ISessionManagerService>& sessionManagerService); 64 using UserSwitchCallbackFunc = std::function<void()>; 65 void RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc); 66 67 /* 68 * Window Recover 69 */ 70 void RecoverSessionManagerService(const sptr<ISessionManagerService>& sessionManagerService); 71 72 protected: 73 SessionManagerLite() = default; 74 virtual ~SessionManagerLite(); 75 76 private: 77 void InitSessionManagerServiceProxy(); 78 void InitSceneSessionManagerLiteProxy(); 79 void InitScreenSessionManagerLiteProxy(); 80 81 void DeleteAllSessionListeners(); 82 void ReregisterSessionListener(); 83 84 WMError InitMockSMSProxy(); 85 86 /* 87 * Multi User 88 */ 89 void OnUserSwitch(const sptr<ISessionManagerService>& sessionManagerService); 90 void OnWMSConnectionChangedCallback(int32_t userId, int32_t screenId, bool isConnected, bool isCallbackRegistered); 91 92 /* 93 * Window Recover 94 */ 95 void RegisterSMSRecoverListener(); 96 void UnregisterSMSRecoverListener(); 97 98 std::recursive_mutex mutex_; 99 sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr; 100 sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr; 101 sptr<ISceneSessionManagerLite> sceneSessionManagerLiteProxy_ = nullptr; 102 sptr<IScreenSessionManagerLite> screenSessionManagerLiteProxy_ = nullptr; 103 sptr<SSMDeathRecipientLite> ssmDeath_ = nullptr; 104 sptr<IRemoteObject> smsRecoverListener_ = nullptr; 105 sptr<FoundationDeathRecipientLite> foundationDeath_ = nullptr; 106 bool recoverListenerRegistered_ = false; 107 bool isFoundationListenerRegistered_ = false; 108 // above guarded by mutex_ 109 110 std::recursive_mutex listenerLock_; 111 std::vector<sptr<ISessionListener>> sessionListeners_; 112 // above guarded by listenerLock_ 113 114 /* 115 * Multi User 116 */ 117 UserSwitchCallbackFunc userSwitchCallbackFunc_ = nullptr; 118 std::mutex wmsConnectionMutex_; 119 int32_t currentWMSUserId_ = INVALID_USER_ID; 120 int32_t currentScreenId_ = DEFAULT_SCREEN_ID; 121 bool isWMSConnected_ = false; 122 WMSConnectionChangedCallbackFunc wmsConnectionChangedFunc_ = nullptr; 123 // above guarded by wmsConnectionMutex_ 124 }; 125 } // namespace OHOS::Rosen 126 127 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_H 128