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