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_WINDOW_ADAPTER_LITE_H 17 #define OHOS_WINDOW_ADAPTER_LITE_H 18 19 #include <shared_mutex> 20 #include <refbase.h> 21 #include <zidl/window_manager_agent_interface.h> 22 23 #include "singleton_delegator.h" 24 #include "window_property.h" 25 #include "wm_single_instance.h" 26 #include "zidl/window_manager_lite_interface.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class WMSDeathRecipient : public IRemoteObject::DeathRecipient { 31 public: 32 virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 33 }; 34 35 class WindowAdapterLite { 36 WM_DECLARE_SINGLE_INSTANCE(WindowAdapterLite); 37 public: 38 using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>; 39 virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID); 40 virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type, 41 const sptr<IWindowManagerAgent>& windowManagerAgent); 42 virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, 43 const sptr<IWindowManagerAgent>& windowManagerAgent); 44 virtual WMError CheckWindowId(int32_t windowId, int32_t& pid); 45 virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos); 46 virtual void ClearWindowAdapter(); 47 virtual WMError GetWindowModeType(WindowModeType& windowModeType); 48 virtual WMError RaiseWindowToTop(int32_t persistentId); 49 virtual WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo); 50 virtual WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo); 51 WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); 52 virtual WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos); 53 virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds); 54 virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds); 55 virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType); 56 virtual WMError TerminateSessionByPersistentId(int32_t persistentId); 57 virtual WMError CloseTargetFloatWindow(const std::string& bundleName); 58 virtual WMError CloseTargetPiPWindow(const std::string& bundleName); 59 virtual WMError GetCurrentPiPWindowInfo(std::string& bundleName); 60 virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos); 61 virtual WMError ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector<sptr<WindowInfo>>& infos); 62 63 private: 64 static inline SingletonDelegator<WindowAdapterLite> delegator; 65 bool InitSSMProxy(); 66 67 /* 68 * Multi User 69 */ 70 void OnUserSwitch(); 71 void ReregisterWindowManagerLiteAgent(); 72 73 sptr<IWindowManagerLite> GetWindowManagerServiceProxy() const; 74 75 mutable std::mutex mutex_; 76 sptr<IWindowManagerLite> windowManagerServiceProxy_ = nullptr; 77 sptr<WMSDeathRecipient> wmsDeath_ = nullptr; 78 bool isProxyValid_ = false; 79 bool isRegisteredUserSwitchListener_ = false; 80 // above guarded by mutex_ 81 82 std::mutex windowManagerLiteAgentMapMutex_; 83 std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerLiteAgentMap_; 84 }; 85 } // namespace Rosen 86 } // namespace OHOS 87 #endif // OHOS_WINDOW_ADAPTER_H 88