1 /* 2 * Copyright (c) 2021-2022 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_H 17 #define OHOS_WINDOW_ADAPTER_H 18 19 #include <refbase.h> 20 #include <zidl/window_manager_agent_interface.h> 21 22 #include "common/include/window_session_property.h" 23 #include "window.h" 24 #include "zidl/window_interface.h" 25 #include "singleton_delegator.h" 26 #include "window_property.h" 27 #include "wm_single_instance.h" 28 #include "zidl/window_manager_interface.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class WMSDeathRecipient : public IRemoteObject::DeathRecipient { 33 public: 34 virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 35 }; 36 37 class WindowAdapter { 38 WM_DECLARE_SINGLE_INSTANCE(WindowAdapter); 39 public: 40 using SessionRecoverCallbackFunc = std::function<void()>; 41 using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>; 42 virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty, 43 std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId, const sptr<IRemoteObject>& token); 44 virtual WMError AddWindow(sptr<WindowProperty>& windowProperty); 45 virtual WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits); 46 virtual WMError DestroyWindow(uint32_t windowId); 47 virtual WMError RequestFocus(uint32_t windowId); 48 virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect); 49 virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); 50 virtual void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty, 51 sptr<MoveDragProperty>& moveDragProperty); 52 virtual void ProcessPointDown(uint32_t windowId, bool isPointDown = true); 53 virtual void ProcessPointUp(uint32_t windowId); 54 virtual WMError MinimizeAllAppWindows(DisplayId displayId); 55 virtual WMError ToggleShownStateForAllAppWindows(); 56 virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); 57 virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action); 58 virtual WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent); 59 virtual WMError GetSystemConfig(SystemConfig& systemConfig); 60 virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones); 61 virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd); 62 virtual WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken); 63 virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type, 64 const sptr<IWindowManagerAgent>& windowManagerAgent); 65 virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, 66 const sptr<IWindowManagerAgent>& windowManagerAgent); 67 virtual WMError CheckWindowId(int32_t windowId, int32_t &pid); 68 69 virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller); 70 virtual WMError NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to); 71 virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener); 72 virtual void ClearWindowAdapter(); 73 74 virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos); 75 virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos); 76 virtual void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated, 77 sptr<RSIWindowAnimationFinishedCallback>& finishCallback); 78 virtual void SetAnchorAndScale(int32_t x, int32_t y, float scale); 79 virtual void SetAnchorOffset(int32_t deltaX, int32_t deltaY); 80 virtual void OffWindowZoom(); 81 virtual WmErrorCode RaiseToAppTop(uint32_t windowId); 82 virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId); 83 virtual WMError SetGestureNavigaionEnabled(bool enable); 84 virtual void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event); 85 virtual void NotifyDumpInfoResult(const std::vector<std::string>& info); 86 virtual WMError DumpSessionAll(std::vector<std::string> &infos); 87 virtual WMError DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos); 88 virtual WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds, 89 std::vector<sptr<RSWindowAnimationTarget>>& targets); 90 virtual void SetMaximizeMode(MaximizeMode maximizeMode); 91 virtual MaximizeMode GetMaximizeMode(); 92 virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); 93 virtual WMError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); 94 virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); 95 virtual WMError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible); 96 virtual WMError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener); 97 virtual void CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 98 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 99 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, 100 sptr<IRemoteObject> token = nullptr); 101 virtual void RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 102 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 103 sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr); 104 virtual void DestroyAndDisconnectSpecificSession(const int32_t& persistentId); 105 virtual WMError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage, 106 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 107 sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token = nullptr); 108 void RegisterSessionRecoverCallbackFunc(int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc); 109 void UnregisterSessionRecoverCallbackFunc(int32_t persistentId); 110 WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); 111 virtual WMError UpdateSessionProperty(const sptr<WindowSessionProperty>& property, WSPropertyChangeAction action); 112 virtual WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); 113 virtual WMError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken); 114 virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused); 115 virtual WMError RaiseWindowToTop(int32_t persistentId); 116 virtual WMError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId); 117 virtual WMError HideNonSecureWindows(bool shouldHide); 118 private: 119 static inline SingletonDelegator<WindowAdapter> delegator; 120 bool InitWMSProxy(); 121 bool InitSSMProxy(); 122 123 void WindowManagerAndSessionRecover(); 124 125 std::recursive_mutex mutex_; 126 sptr<IWindowManager> windowManagerServiceProxy_ = nullptr; 127 sptr<WMSDeathRecipient> wmsDeath_ = nullptr; 128 bool isProxyValid_ { false }; 129 130 bool recoverInitialized = false; 131 std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap_; 132 std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerAgentMap_; 133 }; 134 } // namespace Rosen 135 } // namespace OHOS 136 #endif // OHOS_WINDOW_ADAPTER_H 137