• 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_MANAGER_SERVICE_H
17 #define OHOS_WINDOW_MANAGER_SERVICE_H
18 
19 #include <input_window_monitor.h>
20 #include <map>
21 #include <nocopyable.h>
22 #include <system_ability.h>
23 #include <transaction/rs_interfaces.h>
24 #include <vector>
25 #include <window_manager_service_handler_stub.h>
26 
27 #include "atomic_map.h"
28 #include "display_change_listener.h"
29 #include "drag_controller.h"
30 #include "event_handler.h"
31 #include "freeze_controller.h"
32 #include "perform_reporter.h"
33 #include "singleton_delegator.h"
34 #include "snapshot_controller.h"
35 #include "struct_multimodal.h"
36 #include "window_common_event.h"
37 #include "window_controller.h"
38 #include "window_dumper.h"
39 #include "window_group_mgr.h"
40 #include "window_manager_config.h"
41 #include "window_root.h"
42 #include "window_system_effect.h"
43 #include "wm_common_inner.h"
44 #include "wm_single_instance.h"
45 #include "zidl/window_manager_stub.h"
46 
47 namespace OHOS {
48 namespace Rosen {
49 class DisplayChangeListener : public IDisplayChangeListener {
50 public:
51     virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
52         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override;
53     virtual void OnScreenshot(DisplayId displayId) override;
54 };
55 
56 class WindowInfoQueriedListener : public IWindowInfoQueriedListener {
57 public:
58     virtual void HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override;
59 };
60 
61 class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub {
62 public:
63     virtual void NotifyWindowTransition(
64         sptr<AAFwk::AbilityTransitionInfo> from, sptr<AAFwk::AbilityTransitionInfo> to, bool& animaEnabled) override;
65     int32_t GetFocusWindow(sptr<IRemoteObject>& abilityToken) override;
66     virtual void StartingWindow(
67         sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor) override;
68     virtual void StartingWindow(
69         sptr<AAFwk::AbilityTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap) override;
70     virtual void CancelStartingWindow(sptr<IRemoteObject> abilityToken) override;
71     virtual void NotifyAnimationAbilityDied(sptr<AAFwk::AbilityTransitionInfo> info) override;
72     virtual int32_t MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId) override;
73     virtual int32_t MoveMissionsToBackground(
74         const std::vector<int32_t>& missionIds, std::vector<int32_t>& result) override;
75 };
76 
77 class RSUIDirector;
78 class WindowManagerService : public SystemAbility, public WindowManagerStub {
79 friend class DisplayChangeListener;
80 friend class WindowManagerServiceHandler;
81 DECLARE_SYSTEM_ABILITY(WindowManagerService);
82 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService);
83 
84 public:
85     using Task = std::function<void()>;
86     void OnStart() override;
87     void OnStop() override;
88     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
89     void SetWindowInputEventConsumer();
90     int Dump(int fd, const std::vector<std::u16string>& args) override;
91 
92     WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
93         const std::shared_ptr<RSSurfaceNode>& surfaceNode,
94         uint32_t& windowId, sptr<IRemoteObject> token) override;
95     WMError AddWindow(sptr<WindowProperty>& property) override;
96     WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits) override;
97     WMError NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
98         bool isFromClient = false) override;
99     void NotifyAnimationAbilityDied(sptr<WindowTransitionInfo> info);
100     WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override;
101     WMError RequestFocus(uint32_t windowId) override;
102     AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType,
103         const Rect& rect = Rect::EMPTY_RECT) override;
104     void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
105         sptr<MoveDragProperty>& moveDragProperty) override;
106     void ProcessPointDown(uint32_t windowId, bool isPointDown) override;
107     void ProcessPointUp(uint32_t windowId) override;
108     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override;
109     WMError MinimizeAllAppWindows(DisplayId displayId) override;
110     WMError ToggleShownStateForAllAppWindows() override;
111     WMError SetWindowLayoutMode(WindowLayoutMode mode) override;
112     WMError NotifyScreenshotEvent(ScreenshotEventType type) override;
113     WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
114         bool isAsyncTask = false) override;
115     WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent) override;
116     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) override;
117     WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) override;
118     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
119     WMError RaiseToAppTop(uint32_t windowId) override;
120     std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) override;
121     WMError SetGestureNavigationEnabled(bool enable) override;
122     void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event) override;
123     void NotifyDumpInfoResult(const std::vector<std::string>& info) override;
124     WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
125         std::vector<sptr<RSWindowAnimationTarget>>& targets) override;
126     WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
127         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
128     WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
129         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
130 
131     WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller) override;
132     WMError GetSystemConfig(SystemConfig& systemConfig) override;
133     WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override;
134     WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) override;
135     void StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
136         bool isColdStart, uint32_t bkgColor = 0xffffffff);
137     void CancelStartingWindow(sptr<IRemoteObject> abilityToken);
138     WMError MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId);
139     WMError MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
140         std::vector<int32_t>& result);
141     void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
142         sptr<RSIWindowAnimationFinishedCallback>& finishCallback) override;
143     WMError UpdateRsTree(uint32_t windowId, bool isAdd) override;
144     void OnScreenshot(DisplayId displayId);
145     void OnAccountSwitched(int accountId);
146     WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken) override;
147     void HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
148     void NotifyWindowClientPointUp(uint32_t windowId, const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
149 
150     void SetAnchorAndScale(int32_t x, int32_t y, float scale) override;
151     void SetAnchorOffset(int32_t deltaX, int32_t deltaY) override;
152     void OffWindowZoom() override;
153     void PostAsyncTask(Task task, const std::string& taskName = "WMSTask", uint32_t delay = 0);
154     void SetMaximizeMode(MaximizeMode maximizeMode) override;
155     MaximizeMode GetMaximizeMode() override;
156     void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override;
157 
158 protected:
159     WindowManagerService();
160     virtual ~WindowManagerService() = default;
161 
162 private:
163     bool Init();
164     void InitWithAbilityManagerServiceAdded();
165     void InitWithRanderServiceAdded();
166     void WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData);
167     void OnWindowEvent(Event event, const sptr<IRemoteObject>& remoteObject);
168     void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
169         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
170     WMError GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken, DisplayId displayId = DEFAULT_DISPLAY_ID);
171     bool CheckSystemWindowPermission(const sptr<WindowProperty>& property) const;
172     bool CheckAnimationPermission(const sptr<WindowProperty>& property) const;
173     void LoadWindowParameter();
174     void ConfigureWindowManagerService();
175     void PostVoidSyncTask(Task task, const std::string& taskName = "WMSTask");
176     template<typename SyncTask, typename Return = std::invoke_result_t<SyncTask>>
177     Return PostSyncTask(SyncTask&& task, const std::string& taskName = "WMSTask")
178     {
179         Return ret;
180         std::function<void()> syncTask([&ret, &task]() {ret = task();});
181         if (handler_) {
182             handler_->PostSyncTask(syncTask, "wms:" + taskName, AppExecFwk::EventQueue::Priority::IMMEDIATE);
183         }
184         return ret;
185     }
186     void ConfigHotZones(const std::vector<int>& hotZones);
187     void ConfigDecor(const WindowManagerConfig::ConfigItem& decorConfig);
188     void ConfigWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
189     void ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
190     void ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
191     RSAnimationTimingCurve CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig);
192     void CreateKeyboardCurve(const WindowManagerConfig::ConfigItem& config,
193         AnimationConfig::KeyboardAnimation& animateConfig, KeyboardAnimationCurve& sysCurveConfig);
194     void RecordShowTimeEvent(int64_t costTime);
195     void ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig);
196     bool ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out);
197     bool ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig, WindowShadowParameters& outShadow);
198 
199     /*
200      * RS Client Multi Instance
201      */
202     void InitRSUIDirector();
203 
204     static inline SingletonDelegator<WindowManagerService> delegator;
205     std::string name_ = "WindowManagerService";
206     AtomicMap<uint32_t, uint32_t> accessTokenIdMaps_;
207     sptr<WindowRoot> windowRoot_;
208     sptr<WindowController> windowController_;
209     sptr<InputWindowMonitor> inputWindowMonitor_;
210     sptr<SnapshotController> snapshotController_;
211     sptr<WindowManagerServiceHandler> wmsHandler_;
212     sptr<DragController> dragController_;
213     sptr<FreezeController> freezeDisplayController_;
214     sptr<WindowDumper> windowDumper_;
215     sptr<WindowGroupMgr> windowGroupMgr_;
216     SystemConfig systemConfig_;
217     ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 };
218     std::shared_ptr<WindowCommonEvent> windowCommonEvent_;
219     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
220     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
221     RSInterfaces& rsInterface_;
222     bool startingOpen_ = true;
223     std::shared_ptr<RSUIDirector> rsUiDirector_;
224     std::shared_ptr<PerformReporter> windowShowPerformReport_;
225     MaximizeMode maximizeMode_ = MaximizeMode::MODE_RECOVER;
226 };
227 } // namespace Rosen
228 } // namespace OHOS
229 #endif // OHOS_WINDOW_MANAGER_SERVICE_H
230