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