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 WMError UnregisterWMSConnectionChangedListener(); 53 virtual WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos); 54 virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds); 55 virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds); 56 virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType); 57 virtual WMError TerminateSessionByPersistentId(int32_t persistentId); 58 virtual WMError CloseTargetFloatWindow(const std::string& bundleName); 59 virtual WMError CloseTargetPiPWindow(const std::string& bundleName); 60 virtual WMError GetCurrentPiPWindowInfo(std::string& bundleName); 61 virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos); 62 virtual WMError ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector<sptr<WindowInfo>>& infos); 63 virtual WMError SendPointerEventForHover(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 64 65 private: 66 static inline SingletonDelegator<WindowAdapterLite> delegator; 67 bool InitSSMProxy(); 68 69 /* 70 * Multi User 71 */ 72 void OnUserSwitch(); 73 void ReregisterWindowManagerLiteAgent(); 74 75 sptr<IWindowManagerLite> GetWindowManagerServiceProxy() const; 76 77 mutable std::mutex mutex_; 78 sptr<IWindowManagerLite> windowManagerServiceProxy_ = nullptr; 79 sptr<WMSDeathRecipient> wmsDeath_ = nullptr; 80 bool isProxyValid_ = false; 81 bool isRegisteredUserSwitchListener_ = false; 82 // above guarded by mutex_ 83 84 std::mutex windowManagerLiteAgentMapMutex_; 85 std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerLiteAgentMap_; 86 }; 87 } // namespace Rosen 88 } // namespace OHOS 89 #endif // OHOS_WINDOW_ADAPTER_H 90