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 #include "window_agent.h"
17 #include "window_manager_hilog.h"
18 #include "wm_common.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAgent"};
24 }
25
WindowAgent(sptr<WindowImpl> & windowImpl)26 WindowAgent::WindowAgent(sptr<WindowImpl>& windowImpl)
27 {
28 window_ = windowImpl;
29 }
30
UpdateWindowRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)31 WMError WindowAgent::UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason,
32 const std::shared_ptr<RSTransaction>& rsTransaction)
33 {
34 if (window_ == nullptr) {
35 WLOGFE("window_ is nullptr");
36 return WMError::WM_ERROR_NULLPTR;
37 }
38 window_->UpdateRect(rect, decoStatus, reason, rsTransaction);
39 return WMError::WM_OK;
40 }
41
UpdateWindowMode(WindowMode mode)42 WMError WindowAgent::UpdateWindowMode(WindowMode mode)
43 {
44 if (window_ == nullptr) {
45 WLOGFE("window_ is nullptr");
46 return WMError::WM_ERROR_NULLPTR;
47 }
48 window_->UpdateMode(mode);
49 return WMError::WM_OK;
50 }
51
UpdateWindowModeSupportType(uint32_t windowModeSupportType)52 WMError WindowAgent::UpdateWindowModeSupportType(uint32_t windowModeSupportType)
53 {
54 if (window_ == nullptr) {
55 WLOGFE("window_ is nullptr");
56 return WMError::WM_ERROR_NULLPTR;
57 }
58 window_->UpdateWindowModeSupportType(windowModeSupportType);
59 return WMError::WM_OK;
60 }
61
UpdateFocusStatus(bool focused)62 WMError WindowAgent::UpdateFocusStatus(bool focused)
63 {
64 if (window_ == nullptr) {
65 WLOGFE("window_ is nullptr");
66 return WMError::WM_ERROR_NULLPTR;
67 }
68 window_->UpdateFocusStatus(focused);
69 return WMError::WM_OK;
70 }
71
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)72 WMError WindowAgent::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
73 {
74 if (window_ == nullptr || avoidArea == nullptr) {
75 WLOGFE("window_ or avoidArea is nullptr.");
76 return WMError::WM_ERROR_NULLPTR;
77 }
78 window_->UpdateAvoidArea(avoidArea, type);
79 return WMError::WM_OK;
80 }
81
UpdateWindowState(WindowState state)82 WMError WindowAgent::UpdateWindowState(WindowState state)
83 {
84 if (window_ == nullptr) {
85 WLOGFE("window_ is nullptr");
86 return WMError::WM_ERROR_NULLPTR;
87 }
88 window_->UpdateWindowState(state);
89 return WMError::WM_OK;
90 }
91
UpdateWindowDragInfo(const PointInfo & point,DragEvent event)92 WMError WindowAgent::UpdateWindowDragInfo(const PointInfo& point, DragEvent event)
93 {
94 if (window_ == nullptr) {
95 WLOGFE("window is null");
96 return WMError::WM_ERROR_NULLPTR;
97 }
98 window_->UpdateDragEvent(point, event);
99 return WMError::WM_OK;
100 }
101
UpdateDisplayId(DisplayId from,DisplayId to)102 WMError WindowAgent::UpdateDisplayId(DisplayId from, DisplayId to)
103 {
104 if (window_ == nullptr) {
105 WLOGFE("window is null");
106 return WMError::WM_ERROR_NULLPTR;
107 }
108 window_->UpdateDisplayId(from, to);
109 return WMError::WM_OK;
110 }
111
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)112 WMError WindowAgent::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info,
113 const std::shared_ptr<RSTransaction>& rsTransaction)
114 {
115 if (window_ == nullptr) {
116 WLOGFE("window is null");
117 return WMError::WM_ERROR_NULLPTR;
118 }
119 window_->UpdateOccupiedAreaChangeInfo(info, rsTransaction);
120 return WMError::WM_OK;
121 }
122
UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo> & info,const Rect & rect,const std::shared_ptr<RSTransaction> & rsTransaction)123 WMError WindowAgent::UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo>& info, const Rect& rect,
124 const std::shared_ptr<RSTransaction>& rsTransaction)
125 {
126 if (window_ == nullptr) {
127 WLOGFE("window is null");
128 return WMError::WM_ERROR_NULLPTR;
129 }
130 auto property = window_->GetWindowProperty();
131 if (property) {
132 window_->UpdateRect(rect, property->GetDecoStatus(), WindowSizeChangeReason::UNDEFINED);
133 }
134 window_->UpdateOccupiedAreaChangeInfo(info, rsTransaction);
135 return WMError::WM_OK;
136 }
137
UpdateActiveStatus(bool isActive)138 WMError WindowAgent::UpdateActiveStatus(bool isActive)
139 {
140 if (window_ == nullptr) {
141 WLOGFE("window is null");
142 return WMError::WM_ERROR_NULLPTR;
143 }
144 window_->UpdateActiveStatus(isActive);
145 return WMError::WM_OK;
146 }
147
GetWindowProperty()148 sptr<WindowProperty> WindowAgent::GetWindowProperty()
149 {
150 if (window_ == nullptr) {
151 WLOGFE("window_ is nullptr");
152 return nullptr;
153 }
154 return window_->GetWindowProperty();
155 }
156
RestoreSplitWindowMode(uint32_t mode)157 WMError WindowAgent::RestoreSplitWindowMode(uint32_t mode)
158 {
159 if (window_ == nullptr) {
160 WLOGFE("window_ is nullptr");
161 return WMError::WM_ERROR_NULLPTR;
162 }
163 window_->RestoreSplitWindowMode(mode);
164 return WMError::WM_OK;
165 }
166
NotifyTouchOutside()167 WMError WindowAgent::NotifyTouchOutside()
168 {
169 if (window_ == nullptr) {
170 WLOGI("window is null");
171 return WMError::WM_ERROR_NULLPTR;
172 }
173 WLOGFD("called");
174 window_->NotifyTouchOutside();
175 return WMError::WM_OK;
176 }
177
NotifyScreenshot()178 WMError WindowAgent::NotifyScreenshot()
179 {
180 if (window_ == nullptr) {
181 WLOGFE("notify screenshot failed: window is null.");
182 return WMError::WM_ERROR_NULLPTR;
183 }
184 WLOGFD("called");
185 window_->NotifyScreenshot();
186 return WMError::WM_OK;
187 }
188
NotifyScreenshotAppEvent(ScreenshotEventType type)189 WMError WindowAgent::NotifyScreenshotAppEvent(ScreenshotEventType type)
190 {
191 if (window_ == nullptr) {
192 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "window is null");
193 return WMError::WM_ERROR_NULLPTR;
194 }
195 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}u, event: %{public}d", window_->GetWindowId(), type);
196 window_->NotifyScreenshotAppEvent(type);
197 return WMError::WM_OK;
198 }
199
DumpInfo(const std::vector<std::string> & params)200 WMError WindowAgent::DumpInfo(const std::vector<std::string>& params)
201 {
202 if (window_ == nullptr) {
203 WLOGFE("window_ is nullptr");
204 return WMError::WM_ERROR_NULLPTR;
205 }
206 std::vector<std::string> info;
207 window_->DumpInfo(params, info);
208 return WMError::WM_OK;
209 }
210
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)211 WMError WindowAgent::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
212 {
213 if (window_ == nullptr) {
214 WLOGFE("window_ is nullptr");
215 return WMError::WM_ERROR_NULLPTR;
216 }
217 window_->UpdateZoomTransform(trans, isDisplayZoomOn);
218 return WMError::WM_OK;
219 }
220
NotifyDestroy(void)221 WMError WindowAgent::NotifyDestroy(void)
222 {
223 if (window_ == nullptr) {
224 WLOGFE("window_ is nullptr");
225 return WMError::WM_ERROR_NULLPTR;
226 }
227 window_->NotifyDestroy();
228 return WMError::WM_OK;
229 }
230
NotifyForeground(void)231 WMError WindowAgent::NotifyForeground(void)
232 {
233 if (window_ == nullptr) {
234 WLOGFE("window_ is nullptr");
235 return WMError::WM_ERROR_NULLPTR;
236 }
237 window_->NotifyForeground();
238 return WMError::WM_OK;
239 }
240
NotifyBackground(void)241 WMError WindowAgent::NotifyBackground(void)
242 {
243 if (window_ == nullptr) {
244 WLOGFE("window_ is nullptr");
245 return WMError::WM_ERROR_NULLPTR;
246 }
247 window_->NotifyBackground();
248 return WMError::WM_OK;
249 }
250
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)251 WMError WindowAgent::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
252 {
253 if (window_ == nullptr) {
254 WLOGFE("window_ is nullptr");
255 return WMError::WM_ERROR_NULLPTR;
256 }
257 window_->ConsumePointerEvent(pointerEvent);
258 return WMError::WM_OK;
259 }
260
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)261 void WindowAgent::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)
262 {
263 if (window_ == nullptr) {
264 WLOGFE("window_ is nullptr");
265 return;
266 }
267 window_->ConsumeKeyEvent(event);
268 }
269
NotifyForegroundInteractiveStatus(bool interactive)270 void WindowAgent::NotifyForegroundInteractiveStatus(bool interactive)
271 {
272 if (window_ == nullptr) {
273 WLOGFE("window_ is nullptr");
274 return;
275 }
276 window_->NotifyForegroundInteractiveStatus(interactive);
277 }
278
NotifyMMIServiceOnline(uint32_t winId)279 void WindowAgent::NotifyMMIServiceOnline(uint32_t winId)
280 {
281 if (window_ == nullptr) {
282 WLOGFE("window_ is nullptr, Id:%{public}u", winId);
283 return;
284 }
285 TLOGI(WmsLogTag::WMS_EVENT, "Id:%{public}u", winId);
286 window_->NotifyMMIServiceOnline(winId);
287 }
288
289 } // namespace Rosen
290 } // namespace OHOS
291