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 "session_manager_service_interface.h" 23 #include "mock_session_manager_service_interface.h" 24 #include "zidl/scene_session_manager_lite_interface.h" 25 #include "zidl/screen_session_manager_lite_interface.h" 26 #include "wm_single_instance.h" 27 #include "wm_common.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 void OnWMSConnectionChanged( 62 int32_t userId, int32_t screenId, bool isConnected, const sptr<ISessionManagerService>& sessionManagerService); 63 using UserSwitchCallbackFunc = std::function<void()>; 64 void RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc); 65 66 /* 67 * Window Recover 68 */ 69 void RecoverSessionManagerService(const sptr<ISessionManagerService>& sessionManagerService); 70 71 protected: 72 SessionManagerLite() = default; 73 virtual ~SessionManagerLite(); 74 75 private: 76 void InitSessionManagerServiceProxy(); 77 void InitSceneSessionManagerLiteProxy(); 78 void InitScreenSessionManagerLiteProxy(); 79 80 void DeleteAllSessionListeners(); 81 void ReregisterSessionListener(); 82 83 WMError InitMockSMSProxy(); 84 85 /* 86 * Multi User 87 */ 88 void OnUserSwitch(const sptr<ISessionManagerService>& sessionManagerService); 89 void OnWMSConnectionChangedCallback(int32_t userId, int32_t screenId, bool isConnected, bool isCallbackRegistered); 90 91 /* 92 * Window Recover 93 */ 94 void RegisterSMSRecoverListener(); 95 96 std::recursive_mutex mutex_; 97 sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr; 98 sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr; 99 sptr<ISceneSessionManagerLite> sceneSessionManagerLiteProxy_ = nullptr; 100 sptr<IScreenSessionManagerLite> screenSessionManagerLiteProxy_ = nullptr; 101 sptr<SSMDeathRecipientLite> ssmDeath_ = nullptr; 102 sptr<IRemoteObject> smsRecoverListener_ = nullptr; 103 sptr<FoundationDeathRecipientLite> foundationDeath_ = nullptr; 104 bool recoverListenerRegistered_ = false; 105 bool isFoundationListenerRegistered_ = false; 106 // above guarded by mutex_ 107 108 std::recursive_mutex listenerLock_; 109 std::vector<sptr<ISessionListener>> sessionListeners_; 110 // above guarded by listenerLock_ 111 112 /* 113 * Multi User 114 */ 115 UserSwitchCallbackFunc userSwitchCallbackFunc_ = nullptr; 116 std::mutex wmsConnectionMutex_; 117 int32_t currentWMSUserId_ = INVALID_USER_ID; 118 int32_t currentScreenId_ = DEFAULT_SCREEN_ID; 119 bool isWMSConnected_ = false; 120 WMSConnectionChangedCallbackFunc wmsConnectionChangedFunc_ = nullptr; 121 // above guarded by wmsConnectionMutex_ 122 }; 123 } // namespace OHOS::Rosen 124 125 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_H 126