• 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 UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
113         bool isAsyncTask = false) override;
114     WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent) override;
115     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) override;
116     WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) override;
117     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
118     WMError RaiseToAppTop(uint32_t windowId) override;
119     std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) override;
120     WMError SetGestureNavigationEnabled(bool enable) override;
121     void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event) override;
122     void NotifyDumpInfoResult(const std::vector<std::string>& info) override;
123     WMError GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
124         std::vector<sptr<RSWindowAnimationTarget>>& targets) override;
125     WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
126         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
127     WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
128         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
129 
130     WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller) override;
131     WMError GetSystemConfig(SystemConfig& systemConfig) override;
132     WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override;
133     WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) override;
134     void StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap,
135         bool isColdStart, uint32_t bkgColor = 0xffffffff);
136     void CancelStartingWindow(sptr<IRemoteObject> abilityToken);
137     WMError MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId);
138     WMError MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
139         std::vector<int32_t>& result);
140     void MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
141         sptr<RSIWindowAnimationFinishedCallback>& finishCallback) override;
142     WMError UpdateRsTree(uint32_t windowId, bool isAdd) override;
143     void OnScreenshot(DisplayId displayId);
144     void OnAccountSwitched(int accountId);
145     WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken) override;
146     void HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
147     void NotifyWindowClientPointUp(uint32_t windowId, const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
148 
149     void SetAnchorAndScale(int32_t x, int32_t y, float scale) override;
150     void SetAnchorOffset(int32_t deltaX, int32_t deltaY) override;
151     void OffWindowZoom() override;
152     void PostAsyncTask(Task task, const std::string& taskName = "WMSTask", uint32_t delay = 0);
153     void SetMaximizeMode(MaximizeMode maximizeMode) override;
154     MaximizeMode GetMaximizeMode() override;
155     void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override;
156 
157 protected:
158     WindowManagerService();
159     virtual ~WindowManagerService() = default;
160 
161 private:
162     bool Init();
163     void InitWithAbilityManagerServiceAdded();
164     void InitWithRanderServiceAdded();
165     void WindowVisibilityChangeCallback(std::shared_ptr<RSOcclusionData> occlusionData);
166     void OnWindowEvent(Event event, const sptr<IRemoteObject>& remoteObject);
167     void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
168         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
169     WMError GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken, DisplayId displayId = DEFAULT_DISPLAY_ID);
170     bool CheckSystemWindowPermission(const sptr<WindowProperty>& property) const;
171     bool CheckAnimationPermission(const sptr<WindowProperty>& property) const;
172     void LoadWindowParameter();
173     void ConfigureWindowManagerService();
174     void PostVoidSyncTask(Task task, const std::string& taskName = "WMSTask");
175     template<typename SyncTask, typename Return = std::invoke_result_t<SyncTask>>
176     Return PostSyncTask(SyncTask&& task, const std::string& taskName = "WMSTask")
177     {
178         Return ret;
179         std::function<void()> syncTask([&ret, &task]() {ret = task();});
180         if (handler_) {
181             handler_->PostSyncTask(syncTask, "wms:" + taskName, AppExecFwk::EventQueue::Priority::IMMEDIATE);
182         }
183         return ret;
184     }
185     void ConfigHotZones(const std::vector<int>& hotZones);
186     void ConfigDecor(const WindowManagerConfig::ConfigItem& decorConfig);
187     void ConfigWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
188     void ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
189     void ConfigStartingWindowAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
190     RSAnimationTimingCurve CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig);
191     void CreateKeyboardCurve(const WindowManagerConfig::ConfigItem& config,
192         AnimationConfig::KeyboardAnimation& animateConfig, KeyboardAnimationCurve& sysCurveConfig);
193     void RecordShowTimeEvent(int64_t costTime);
194     void ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig);
195     bool ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out);
196     bool ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig, WindowShadowParameters& outShadow);
197 
198     static inline SingletonDelegator<WindowManagerService> delegator;
199     std::string name_ = "WindowManagerService";
200     AtomicMap<uint32_t, uint32_t> accessTokenIdMaps_;
201     sptr<WindowRoot> windowRoot_;
202     sptr<WindowController> windowController_;
203     sptr<InputWindowMonitor> inputWindowMonitor_;
204     sptr<SnapshotController> snapshotController_;
205     sptr<WindowManagerServiceHandler> wmsHandler_;
206     sptr<DragController> dragController_;
207     sptr<FreezeController> freezeDisplayController_;
208     sptr<WindowDumper> windowDumper_;
209     sptr<WindowGroupMgr> windowGroupMgr_;
210     SystemConfig systemConfig_;
211     ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 };
212     std::shared_ptr<WindowCommonEvent> windowCommonEvent_;
213     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
214     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
215     RSInterfaces& rsInterface_;
216     bool startingOpen_ = true;
217     std::shared_ptr<RSUIDirector> rsUiDirector_;
218     std::shared_ptr<PerformReporter> windowShowPerformReport_;
219     MaximizeMode maximizeMode_ = MaximizeMode::MODE_RECOVER;
220 };
221 } // namespace Rosen
222 } // namespace OHOS
223 #endif // OHOS_WINDOW_MANAGER_SERVICE_H
224