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 "zidl/window_proxy.h"
17 #include <ipc_types.h>
18 #include "pointer_event.h"
19 #include "message_option.h"
20 #include "window_manager_hilog.h"
21 #include "wm_common.h"
22
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowProxy"};
27 }
28
UpdateWindowRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason)29 WMError WindowProxy::UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason)
30 {
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option(MessageOption::TF_ASYNC);
34 if (!data.WriteInterfaceToken(GetDescriptor())) {
35 WLOGFE("WriteInterfaceToken failed");
36 return WMError::WM_ERROR_IPC_FAILED;
37 }
38 if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
39 data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) {
40 WLOGFE("Write WindowRect failed");
41 return WMError::WM_ERROR_IPC_FAILED;
42 }
43 if (!data.WriteBool(decoStatus)) {
44 WLOGFE("Write deco status failed");
45 return WMError::WM_ERROR_IPC_FAILED;
46 }
47 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
48 WLOGFE("Write WindowSizeChangeReason failed");
49 return WMError::WM_ERROR_IPC_FAILED;
50 }
51
52 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_RECT),
53 data, reply, option) != ERR_NONE) {
54 WLOGFE("SendRequest failed");
55 return WMError::WM_ERROR_IPC_FAILED;
56 }
57 return WMError::WM_OK;
58 }
59
UpdateWindowMode(WindowMode mode)60 WMError WindowProxy::UpdateWindowMode(WindowMode mode)
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option(MessageOption::TF_ASYNC);
65 if (!data.WriteInterfaceToken(GetDescriptor())) {
66 WLOGFE("WriteInterfaceToken failed");
67 return WMError::WM_ERROR_IPC_FAILED;
68 }
69 if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
70 WLOGFE("Write WindowMode failed");
71 return WMError::WM_ERROR_IPC_FAILED;
72 }
73
74 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_MODE),
75 data, reply, option) != ERR_NONE) {
76 WLOGFE("SendRequest failed");
77 return WMError::WM_ERROR_IPC_FAILED;
78 }
79 return WMError::WM_OK;
80 }
81
UpdateWindowModeSupportInfo(uint32_t modeSupportInfo)82 WMError WindowProxy::UpdateWindowModeSupportInfo(uint32_t modeSupportInfo)
83 {
84 MessageParcel data;
85 MessageParcel reply;
86 MessageOption option(MessageOption::TF_ASYNC);
87 if (!data.WriteInterfaceToken(GetDescriptor())) {
88 WLOGFE("WriteInterfaceToken failed");
89 return WMError::WM_ERROR_IPC_FAILED;
90 }
91 if (!data.WriteUint32(modeSupportInfo)) {
92 WLOGFE("Write WindowMode failed");
93 return WMError::WM_ERROR_IPC_FAILED;
94 }
95
96 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO),
97 data, reply, option) != ERR_NONE) {
98 WLOGFE("SendRequest failed");
99 return WMError::WM_ERROR_IPC_FAILED;
100 }
101 return WMError::WM_OK;
102 }
103
UpdateFocusStatus(bool focused)104 WMError WindowProxy::UpdateFocusStatus(bool focused)
105 {
106 MessageParcel data;
107 MessageParcel reply;
108 MessageOption option(MessageOption::TF_ASYNC);
109 if (!data.WriteInterfaceToken(GetDescriptor())) {
110 WLOGFE("WriteInterfaceToken failed");
111 return WMError::WM_ERROR_IPC_FAILED;
112 }
113 if (!data.WriteBool(focused)) {
114 WLOGFE("Write Focus failed");
115 return WMError::WM_ERROR_IPC_FAILED;
116 }
117
118 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_FOCUS_STATUS),
119 data, reply, option) != ERR_NONE) {
120 WLOGFE("SendRequest failed");
121 return WMError::WM_ERROR_IPC_FAILED;
122 }
123 return WMError::WM_OK;
124 }
125
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)126 WMError WindowProxy::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
127 {
128 MessageParcel data;
129 MessageParcel reply;
130 MessageOption option(MessageOption::TF_ASYNC);
131 if (!data.WriteInterfaceToken(GetDescriptor())) {
132 WLOGFE("WriteInterfaceToken failed");
133 return WMError::WM_ERROR_IPC_FAILED;
134 }
135 if (!data.WriteStrongParcelable(avoidArea)) {
136 WLOGFE("Write WindowRect failed");
137 return WMError::WM_ERROR_IPC_FAILED;
138 }
139 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
140 WLOGFE("Write AvoidAreaType failed");
141 return WMError::WM_ERROR_IPC_FAILED;
142 }
143 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_AVOID_AREA),
144 data, reply, option) != ERR_NONE) {
145 WLOGFE("SendRequest failed");
146 return WMError::WM_ERROR_IPC_FAILED;
147 }
148 return WMError::WM_OK;
149 }
150
UpdateWindowState(WindowState state)151 WMError WindowProxy::UpdateWindowState(WindowState state)
152 {
153 MessageParcel data;
154 MessageParcel reply;
155 MessageOption option(MessageOption::TF_ASYNC);
156 if (!data.WriteInterfaceToken(GetDescriptor())) {
157 WLOGFE("WriteInterfaceToken failed");
158 return WMError::WM_ERROR_IPC_FAILED;
159 }
160
161 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
162 WLOGFE("Write isStopped");
163 return WMError::WM_ERROR_IPC_FAILED;
164 }
165 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_STATE),
166 data, reply, option) != ERR_NONE) {
167 WLOGFE("SendRequest failed");
168 return WMError::WM_ERROR_IPC_FAILED;
169 }
170 return WMError::WM_OK;
171 }
172
UpdateWindowDragInfo(const PointInfo & point,DragEvent event)173 WMError WindowProxy::UpdateWindowDragInfo(const PointInfo& point, DragEvent event)
174 {
175 MessageParcel data;
176 MessageParcel reply;
177 MessageOption option(MessageOption::TF_ASYNC);
178 if (!data.WriteInterfaceToken(GetDescriptor())) {
179 WLOGFE("WriteInterfaceToken failed");
180 return WMError::WM_ERROR_IPC_FAILED;
181 }
182 if (!(data.WriteInt32(point.x) and data.WriteInt32(point.y))) {
183 WLOGFE("Write pos failed");
184 return WMError::WM_ERROR_IPC_FAILED;
185 }
186 if (!data.WriteInt32(static_cast<uint32_t>(event))) {
187 WLOGFE("Write event failed");
188 return WMError::WM_ERROR_IPC_FAILED;
189 }
190
191 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_DRAG_EVENT),
192 data, reply, option) != ERR_NONE) {
193 WLOGFE("SendRequest TRANS_ID_UPDATE_DRAG_EVENT failed");
194 return WMError::WM_ERROR_IPC_FAILED;
195 }
196 return WMError::WM_OK;
197 }
198
UpdateDisplayId(DisplayId from,DisplayId to)199 WMError WindowProxy::UpdateDisplayId(DisplayId from, DisplayId to)
200 {
201 MessageParcel data;
202 MessageParcel reply;
203 MessageOption option(MessageOption::TF_ASYNC);
204 if (!data.WriteInterfaceToken(GetDescriptor())) {
205 WLOGFE("WriteInterfaceToken failed");
206 return WMError::WM_ERROR_IPC_FAILED;
207 }
208 if (!(data.WriteUint64(from) and data.WriteUint64(to))) {
209 WLOGFE("Write displayid failed");
210 return WMError::WM_ERROR_IPC_FAILED;
211 }
212 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_DISPLAY_ID),
213 data, reply, option) != ERR_NONE) {
214 WLOGFE("SendRequest TRANS_ID_UPDATE_DISPLAY_ID failed");
215 return WMError::WM_ERROR_IPC_FAILED;
216 }
217 return WMError::WM_OK;
218 }
219
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info)220 WMError WindowProxy::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info)
221 {
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option(MessageOption::TF_ASYNC);
225 if (!data.WriteInterfaceToken(GetDescriptor())) {
226 WLOGFE("WriteInterfaceToken failed");
227 return WMError::WM_ERROR_IPC_FAILED;
228 }
229 if (!data.WriteParcelable(info)) {
230 WLOGFE("Write OccupiedAreaChangeInfo failed");
231 return WMError::WM_ERROR_IPC_FAILED;
232 }
233 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA),
234 data, reply, option) != ERR_NONE) {
235 WLOGFE("SendRequest failed");
236 return WMError::WM_ERROR_IPC_FAILED;
237 }
238 return WMError::WM_OK;
239 }
240
UpdateActiveStatus(bool isActive)241 WMError WindowProxy::UpdateActiveStatus(bool isActive)
242 {
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option(MessageOption::TF_ASYNC);
246 if (!data.WriteInterfaceToken(GetDescriptor())) {
247 WLOGFE("WriteInterfaceToken failed");
248 return WMError::WM_ERROR_IPC_FAILED;
249 }
250 if (!data.WriteBool(isActive)) {
251 WLOGFE("Write Focus failed");
252 return WMError::WM_ERROR_IPC_FAILED;
253 }
254
255 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_ACTIVE_STATUS),
256 data, reply, option) != ERR_NONE) {
257 WLOGFE("SendRequest failed");
258 return WMError::WM_ERROR_IPC_FAILED;
259 }
260 return WMError::WM_OK;
261 }
262
GetWindowProperty()263 sptr<WindowProperty> WindowProxy::GetWindowProperty()
264 {
265 MessageParcel data;
266 MessageParcel reply;
267 MessageOption option;
268 if (!data.WriteInterfaceToken(GetDescriptor())) {
269 WLOGFE("WriteInterfaceToken failed");
270 return nullptr;
271 }
272 uint32_t requestCode = static_cast<uint32_t>(WindowMessage::TRANS_ID_GET_WINDOW_PROPERTY);
273 if (Remote()->SendRequest(requestCode, data, reply, option) != ERR_NONE) {
274 WLOGFE("SendRequest failed");
275 return nullptr;
276 }
277 return reply.ReadParcelable<WindowProperty>();
278 }
279
NotifyTouchOutside()280 WMError WindowProxy::NotifyTouchOutside()
281 {
282 MessageParcel data;
283 MessageParcel reply;
284 MessageOption option(MessageOption::TF_ASYNC);
285 if (!data.WriteInterfaceToken(GetDescriptor())) {
286 WLOGFE("WriteInterfaceToken failed");
287 return WMError::WM_ERROR_IPC_FAILED;
288 }
289
290 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED),
291 data, reply, option) != ERR_NONE) {
292 WLOGFE("SendRequest failed");
293 return WMError::WM_ERROR_IPC_FAILED;
294 }
295 return WMError::WM_OK;
296 }
297
NotifyScreenshot()298 WMError WindowProxy::NotifyScreenshot()
299 {
300 MessageParcel data;
301 MessageParcel reply;
302 MessageOption option(MessageOption::TF_ASYNC);
303 if (!data.WriteInterfaceToken(GetDescriptor())) {
304 WLOGFE("WriteInterfaceToken failed");
305 return WMError::WM_ERROR_IPC_FAILED;
306 }
307
308 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_SCREEN_SHOT),
309 data, reply, option) != ERR_NONE) {
310 WLOGFE("SendRequest failed");
311 return WMError::WM_ERROR_IPC_FAILED;
312 }
313 return WMError::WM_OK;
314 }
315
DumpInfo(const std::vector<std::string> & params)316 WMError WindowProxy::DumpInfo(const std::vector<std::string>& params)
317 {
318 MessageParcel data;
319 MessageParcel reply;
320 MessageOption option(MessageOption::TF_ASYNC);
321 if (!data.WriteInterfaceToken(GetDescriptor())) {
322 WLOGFE("WriteInterfaceToken failed");
323 return WMError::WM_ERROR_IPC_FAILED;
324 }
325 if (!data.WriteStringVector(params)) {
326 WLOGFE("Write params failed");
327 return WMError::WM_ERROR_IPC_FAILED;
328 }
329 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_DUMP_INFO),
330 data, reply, option) != ERR_NONE) {
331 WLOGFE("SendRequest failed");
332 return WMError::WM_ERROR_IPC_FAILED;
333 }
334 return WMError::WM_OK;
335 }
336
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)337 WMError WindowProxy::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
338 {
339 MessageParcel data;
340 MessageParcel reply;
341 MessageOption option;
342 if (!data.WriteInterfaceToken(GetDescriptor())) {
343 WLOGFE("WriteInterfaceToken failed");
344 return WMError::WM_ERROR_IPC_FAILED;
345 }
346 if (!trans.Marshalling(data)) {
347 WLOGFE("Write params failed");
348 return WMError::WM_ERROR_IPC_FAILED;
349 }
350 if (!data.WriteBool(isDisplayZoomOn)) {
351 WLOGFE("Write params failed");
352 return WMError::WM_ERROR_IPC_FAILED;
353 }
354 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_ZOOM_TRANSFORM),
355 data, reply, option) != ERR_NONE) {
356 WLOGFE("SendRequest failed");
357 return WMError::WM_ERROR_IPC_FAILED;
358 }
359 return WMError::WM_OK;
360 }
361
NotifyDestroy(void)362 WMError WindowProxy::NotifyDestroy(void)
363 {
364 MessageParcel data;
365 MessageParcel replay;
366 MessageOption option(MessageOption::TF_ASYNC);
367 if (!data.WriteInterfaceToken(GetDescriptor())) {
368 WLOGFE("WriteInterfaceToken failed");
369 return WMError::WM_ERROR_IPC_FAILED;
370 }
371
372 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_DESTROY),
373 data, replay, option) != ERR_NONE) {
374 WLOGFE("SendRequest failed");
375 return WMError::WM_ERROR_IPC_FAILED;
376 }
377 return WMError::WM_OK;
378 }
379
NotifyForeground(void)380 WMError WindowProxy::NotifyForeground(void)
381 {
382 MessageParcel data;
383 MessageParcel replay;
384 MessageOption option(MessageOption::TF_ASYNC);
385 if (!data.WriteInterfaceToken(GetDescriptor())) {
386 WLOGFE("WriteInterfaceToken failed");
387 return WMError::WM_ERROR_IPC_FAILED;
388 }
389
390 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_FOREGROUND),
391 data, replay, option) != ERR_NONE) {
392 WLOGFE("SendRequest failed");
393 return WMError::WM_ERROR_IPC_FAILED;
394 }
395 return WMError::WM_OK;
396 }
397
NotifyBackground(void)398 WMError WindowProxy::NotifyBackground(void)
399 {
400 MessageParcel data;
401 MessageParcel replay;
402 MessageOption option(MessageOption::TF_ASYNC);
403 if (!data.WriteInterfaceToken(GetDescriptor())) {
404 WLOGFE("WriteInterfaceToken failed");
405 return WMError::WM_ERROR_IPC_FAILED;
406 }
407
408 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_BACKGROUND),
409 data, replay, option) != ERR_NONE) {
410 WLOGFE("SendRequest failed");
411 return WMError::WM_ERROR_IPC_FAILED;
412 }
413 return WMError::WM_OK;
414 }
415
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)416 WMError WindowProxy::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
417 {
418 if (!pointerEvent) {
419 WLOGFE("pointerEvent is nullptr");
420 return WMError::WM_ERROR_NULLPTR;
421 }
422 MessageParcel data;
423 MessageParcel reply;
424 MessageOption option(MessageOption::TF_ASYNC);
425 if (!data.WriteInterfaceToken(GetDescriptor())) {
426 WLOGFE("WriteInterfaceToken failed");
427 return WMError::WM_ERROR_IPC_FAILED;
428 }
429 if (!pointerEvent->WriteToParcel(data)) {
430 WLOGFE("Failed to write point event");
431 return WMError::WM_ERROR_IPC_FAILED;
432 }
433 if (Remote()->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_CLIENT_POINT_UP),
434 data, reply, option) != ERR_NONE) {
435 WLOGFE("SendRequest failed");
436 return WMError::WM_ERROR_IPC_FAILED;
437 }
438 return WMError::WM_OK;
439 }
440
RestoreSplitWindowMode(uint32_t mode)441 WMError WindowProxy::RestoreSplitWindowMode(uint32_t mode)
442 {
443 MessageParcel data;
444 MessageParcel reply;
445 MessageOption option(MessageOption::TF_ASYNC);
446 if (!data.WriteInterfaceToken(GetDescriptor())) {
447 WLOGFE("WriteInterfaceToken failed");
448 return WMError::WM_ERROR_IPC_FAILED;
449 }
450 if (!data.WriteUint32(mode)) {
451 WLOGFE("mode failed");
452 return WMError::WM_ERROR_IPC_FAILED;
453 }
454 uint32_t requestCode = static_cast<uint32_t>(WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE);
455 if (Remote()->SendRequest(requestCode, data, reply, option) != ERR_NONE) {
456 WLOGFE("SendRequest failed");
457 return WMError::WM_ERROR_IPC_FAILED;
458 }
459 return WMError::WM_OK;
460 }
461 } // namespace Rosen
462 } // namespace OHOS
463
464