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<WMError()>; 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 WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId); 51 virtual void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty, 52 sptr<MoveDragProperty>& moveDragProperty); 53 virtual void ProcessPointDown(uint32_t windowId, bool isPointDown = true); 54 virtual void ProcessPointUp(uint32_t windowId); 55 virtual WMError MinimizeAllAppWindows(DisplayId displayId); 56 virtual WMError ToggleShownStateForAllAppWindows(); 57 virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); 58 virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action); 59 virtual WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent); 60 virtual WMError GetSystemConfig(SystemConfig& systemConfig); 61 virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones); 62 virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd); 63 virtual WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken); 64 virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type, 65 const sptr<IWindowManagerAgent>& windowManagerAgent); 66 virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, 67 const sptr<IWindowManagerAgent>& windowManagerAgent); 68 virtual WMError CheckWindowId(int32_t windowId, int32_t& pid); 69 70 virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller); 71 virtual WMError NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to); 72 virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener); 73 virtual void ClearWindowAdapter(); 74 75 virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos); 76 virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos); 77 virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos); 78 virtual void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated, 79 sptr<RSIWindowAnimationFinishedCallback>& finishCallback); 80 virtual void SetAnchorAndScale(int32_t x, int32_t y, float scale); 81 virtual void SetAnchorOffset(int32_t deltaX, int32_t deltaY); 82 virtual void OffWindowZoom(); 83 virtual WMError RaiseToAppTop(uint32_t windowId); 84 virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId); 85 virtual WMError SetGestureNavigaionEnabled(bool enable); 86 virtual void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event); 87 virtual void NotifyDumpInfoResult(const std::vector<std::string>& info); 88 virtual WMError DumpSessionAll(std::vector<std::string> &infos); 89 virtual WMError DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos); 90 virtual WMError GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj); 91 virtual WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds, 92 std::vector<sptr<RSWindowAnimationTarget>>& targets); 93 virtual void SetMaximizeMode(MaximizeMode maximizeMode); 94 virtual MaximizeMode GetMaximizeMode(); 95 virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); 96 virtual WMError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); 97 virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); 98 virtual WMError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible); 99 virtual WMError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener); 100 virtual WMError RaiseWindowToTop(int32_t persistentId); 101 virtual WMError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId); 102 virtual void CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 103 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 104 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, 105 SystemSessionConfig& systemConfig, sptr<IRemoteObject> token = nullptr); 106 virtual void RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 107 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 108 sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr); 109 virtual WMError DestroyAndDisconnectSpecificSession(const int32_t persistentId); 110 virtual WMError DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId, 111 const sptr<IRemoteObject>& callback); 112 virtual WMError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage, 113 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 114 sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token = nullptr); 115 WMError GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap); 116 void RegisterSessionRecoverCallbackFunc(int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc); 117 void UnregisterSessionRecoverCallbackFunc(int32_t persistentId); 118 WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc); 119 virtual WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); 120 virtual WMError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken); 121 virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused); 122 virtual void AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage, 123 const sptr<IRemoteObject>& token, uint64_t surfaceNodeId); 124 virtual void RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage, 125 const sptr<IRemoteObject>& token); 126 virtual void UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect); 127 virtual void ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY); 128 virtual WMError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide); 129 virtual WMError UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags, 130 uint32_t extWindowActions); 131 virtual WMError GetHostWindowRect(int32_t hostWindowId, Rect& rect); 132 virtual WMError GetFreeMultiWindowEnableState(bool& enable); 133 virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus); 134 virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect); 135 virtual WMError GetWindowModeType(WindowModeType& windowModeType); 136 virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType); 137 virtual WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, 138 int32_t x, int32_t y, std::vector<int32_t>& windowIds); 139 virtual WMError ReleaseForegroundSessionScreenLock(); 140 virtual WMError GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds, 141 std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap); 142 143 /* 144 * PC Window 145 */ 146 virtual WMError IsPcWindow(bool& isPcWindow); 147 virtual WMError IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode); 148 virtual WMError IsWindowRectAutoSave(const std::string& key, bool& enabled); 149 150 virtual WMError SetGlobalDragResizeType(DragResizeType dragResizeType); 151 virtual WMError GetGlobalDragResizeType(DragResizeType& dragResizeType); 152 virtual WMError SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType); 153 virtual WMError GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType); 154 155 private: 156 static inline SingletonDelegator<WindowAdapter> delegator; 157 void ReregisterWindowManagerAgent(); 158 void OnUserSwitch(); 159 bool InitWMSProxy(); 160 bool InitSSMProxy(); 161 162 void WindowManagerAndSessionRecover(); 163 164 sptr<IWindowManager> GetWindowManagerServiceProxy() const; 165 166 mutable std::mutex mutex_; 167 sptr<IWindowManager> windowManagerServiceProxy_ = nullptr; 168 sptr<WMSDeathRecipient> wmsDeath_ = nullptr; 169 bool isProxyValid_ = false; 170 bool recoverInitialized_ = false; 171 bool isRegisteredUserSwitchListener_ = false; 172 std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap_; 173 std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerAgentMap_; 174 // above guarded by mutex_ 175 }; 176 } // namespace Rosen 177 } // namespace OHOS 178 #endif // OHOS_WINDOW_ADAPTER_H 179