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