• 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 UIEffectRecoverCallbackFunc = std::function<WMError()>;
42     using WMSConnectionChangedCallbackFunc = std::function<void(int32_t, int32_t, bool)>;
43     virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty,
44         std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId, const sptr<IRemoteObject>& token);
45     virtual WMError AddWindow(sptr<WindowProperty>& windowProperty);
46     virtual WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits);
47     virtual WMError DestroyWindow(uint32_t windowId);
48     virtual WMError RequestFocus(uint32_t windowId);
49     virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect,
50         const Rect& rect = Rect::EMPTY_RECT);
51     virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
52     virtual WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId);
53     virtual void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
54         sptr<MoveDragProperty>& moveDragProperty);
55     virtual void ProcessPointDown(uint32_t windowId, bool isPointDown = true);
56     virtual void ProcessPointUp(uint32_t windowId);
57     virtual WMError MinimizeAllAppWindows(DisplayId displayId);
58     virtual WMError ToggleShownStateForAllAppWindows();
59     virtual WMError SetWindowLayoutMode(WindowLayoutMode mode);
60     virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action);
61     virtual WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent);
62     virtual WMError GetSystemConfig(SystemConfig& systemConfig);
63     virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones);
64     virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd);
65     virtual WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken);
66     virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
67         const sptr<IWindowManagerAgent>& windowManagerAgent);
68     virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
69         const sptr<IWindowManagerAgent>& windowManagerAgent);
70     WMError RegisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey, uint32_t interestInfo,
71         const sptr<IWindowManagerAgent>& windowManagerAgent);
72     WMError UnregisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey, uint32_t interestInfo,
73         const sptr<IWindowManagerAgent>& windowManagerAgent);
74     virtual WMError CheckWindowId(int32_t windowId, int32_t& pid);
75 
76     virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller);
77     virtual WMError NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to);
78     virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener);
79     virtual void ClearWindowAdapter();
80 
81     virtual WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos);
82     virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos);
83     virtual WMError ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector<sptr<WindowInfo>>& infos);
84     virtual WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos);
85     virtual WMError GetGlobalWindowMode(DisplayId displayId, GlobalWindowMode& globalWinMode);
86     virtual WMError GetTopNavDestinationName(int32_t windowId, std::string& topNavDestName);
87     virtual WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos);
88     virtual void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
89         sptr<RSIWindowAnimationFinishedCallback>& finishCallback);
90     virtual void SetAnchorAndScale(int32_t x, int32_t y, float scale);
91     virtual void SetAnchorOffset(int32_t deltaX, int32_t deltaY);
92     virtual void OffWindowZoom();
93     virtual WMError RaiseToAppTop(uint32_t windowId);
94     virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId);
95     virtual WMError SetGestureNavigationEnabled(bool enable);
96     virtual void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event);
97     virtual void NotifyDumpInfoResult(const std::vector<std::string>& info);
98     virtual WMError DumpSessionAll(std::vector<std::string>& infos);
99     virtual WMError DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos);
100     virtual WMError GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj);
101     virtual WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
102         std::vector<sptr<RSWindowAnimationTarget>>& targets);
103     virtual void SetMaximizeMode(MaximizeMode maximizeMode);
104     virtual MaximizeMode GetMaximizeMode();
105     virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID);
106     virtual WMError UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener);
107     virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener);
108     virtual WMError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible);
109     virtual WMError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener);
110     virtual WMError RaiseWindowToTop(int32_t persistentId);
111     virtual WMError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId);
112     virtual void CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
113         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
114         sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
115         SystemSessionConfig& systemConfig, sptr<IRemoteObject> token = nullptr);
116     virtual WMError DestroyAndDisconnectSpecificSession(const int32_t persistentId);
117     virtual WMError DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,
118         const sptr<IRemoteObject>& callback);
119     WMError GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap);
120     WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc);
121     WMError UnregisterWMSConnectionChangedListener();
122     virtual WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent);
123     virtual WMError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken);
124     virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused);
125     virtual WMError RequestFocusStatusBySA(int32_t persistentId, bool isFocused = true,
126         bool byForeground = true, FocusChangeReason reason = FocusChangeReason::SA_REQUEST);
127     virtual void AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage,
128         const sptr<IRemoteObject>& token, uint64_t surfaceNodeId, bool isConstrainedModal = false);
129     virtual void RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage,
130         const sptr<IRemoteObject>& token, bool isConstrainedModal = false);
131     virtual void UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect);
132     virtual void ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY);
133     virtual WMError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide);
134     virtual WMError UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags,
135         uint32_t extWindowActions);
136     virtual WMError GetHostWindowRect(int32_t hostWindowId, Rect& rect);
137     virtual WMError GetHostGlobalScaledRect(int32_t hostWindowId, Rect& globalScaledRect);
138     virtual WMError GetFreeMultiWindowEnableState(bool& enable);
139     virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus);
140     virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect);
141     virtual WMError GetWindowModeType(WindowModeType& windowModeType);
142     virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType);
143     virtual WMError SkipSnapshotForAppProcess(int32_t pid, bool skip);
144     virtual WMError SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled);
145     virtual WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
146         int32_t x, int32_t y, std::vector<int32_t>& windowIds);
147     virtual WMError UpdateScreenLockStatusForApp(const std::string& bundleName, bool isRelease);
148     virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed);
149     virtual WMError NotifyWatchFocusActiveChange(bool isActive);
150     virtual WMError MinimizeByWindowId(const std::vector<int32_t>& windowIds);
151     virtual WMError SetForegroundWindowNum(uint32_t windowNum);
152     virtual WMError SetStartWindowBackgroundColor(
153         const std::string& moduleName, const std::string& abilityName, uint32_t color, int32_t uid);
154 
155     /*
156      * Window Recover
157      */
158     void RegisterSessionRecoverCallbackFunc(int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc);
159     void UnregisterSessionRecoverCallbackFunc(int32_t persistentId);
160     virtual WMError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
161         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
162         sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token = nullptr);
163     virtual void RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
164         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
165         sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr);
166     virtual void RegisterUIEffectRecoverCallbackFunc(int32_t id,
167         const UIEffectRecoverCallbackFunc& callbackFunc);
168     virtual void UnregisterUIEffectRecoverCallbackFunc(int32_t id);
169 
170     /*
171      * PC Window
172      */
173     virtual WMError IsPcWindow(bool& isPcWindow);
174     virtual WMError IsFreeMultiWindowMode(bool& isFreeMultiWindow);
175     virtual WMError IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode);
176     virtual WMError IsWindowRectAutoSave(const std::string& key, bool& enabled, int persistentId);
177     virtual WMError ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId, int32_t fingerId);
178     virtual WMError UseImplicitAnimation(int32_t hostWindowId, bool useImplicit);
179 
180     /*
181      * Sub Window
182      */
183     virtual WMError SetParentWindow(int32_t subWindowId, int32_t newParentWindowId);
184 
185     virtual WMError GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
186         std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap);
187     virtual WMError SetGlobalDragResizeType(DragResizeType dragResizeType);
188     virtual WMError GetGlobalDragResizeType(DragResizeType& dragResizeType);
189     virtual WMError SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType);
190     virtual WMError GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType);
191     virtual WMError SetAppKeyFramePolicy(const std::string& bundleName, const KeyFramePolicy& keyFramePolicy);
192     /*
193      * Window Pattern
194      */
195     virtual WMError SetImageForRecent(uint32_t imgResourceId, ImageFit imageFit, int32_t persistentId);
196 
197     /*
198      * Window Animation
199      */
200     virtual WMError AnimateTo(int32_t windowId, const WindowAnimationProperty& animationProperty,
201         const WindowAnimationOption& animationOption);
202 
203     /*
204      * Window Property
205      */
206     virtual WMError NotifyScreenshotEvent(ScreenshotEventType type);
207     virtual WMError CreateUIEffectController(const sptr<IUIEffectControllerClient>& controllerClient,
208         sptr<IUIEffectController>& controller, int32_t& controllerId);
209     virtual WMError AddSessionBlackList(
210         const std::unordered_set<std::string>& bundleNames, const std::unordered_set<std::string>& privacyWindowTags);
211     virtual WMError RemoveSessionBlackList(
212         const std::unordered_set<std::string>& bundleNames, const std::unordered_set<std::string>& privacyWindowTags);
213 
214      /*
215      * PiP Window
216      */
217     WMError GetPiPSettingSwitchStatus(bool& switchStatus);
218 
219 private:
220     static inline SingletonDelegator<WindowAdapter> delegator;
221     bool InitWMSProxy();
222     bool InitSSMProxy();
223 
224     /*
225      * Multi User
226      */
227     void OnUserSwitch();
228 
229     /*
230      * Window Recover
231      */
232     void ReregisterWindowManagerAgent();
233     void WindowManagerAndSessionRecover();
234     WMError RecoverWindowPropertyChangeFlag();
235     uint32_t observedFlags_;
236     uint32_t interestedFlags_;
237 
238     sptr<IWindowManager> GetWindowManagerServiceProxy() const;
239 
240     mutable std::mutex mutex_;
241     sptr<IWindowManager> windowManagerServiceProxy_ = nullptr;
242     sptr<WMSDeathRecipient> wmsDeath_ = nullptr;
243     bool isProxyValid_ = false;
244     bool isRegisteredUserSwitchListener_ = false;
245     std::map<WindowManagerAgentType, std::set<sptr<IWindowManagerAgent>>> windowManagerAgentMap_;
246     std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap_;
247     std::mutex effectMutex_;
248     std::map<int32_t, UIEffectRecoverCallbackFunc> uiEffectRecoverCallbackFuncMap_;
249     bool recoverInitialized_ = false;
250     // above guarded by mutex_
251 };
252 } // namespace Rosen
253 } // namespace OHOS
254 #endif // OHOS_WINDOW_ADAPTER_H
255