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