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 "display_manager_proxy.h"
17
18 #include <cinttypes>
19 #include <ipc_types.h>
20 #include <parcel.h>
21 #include <ui/rs_surface_node.h>
22
23 #include "marshalling_helper.h"
24 #include "window_manager_hilog.h"
25
26 namespace OHOS::Rosen {
27 namespace {
28 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerProxy"};
29 }
30
GetDefaultDisplayInfo()31 sptr<DisplayInfo> DisplayManagerProxy::GetDefaultDisplayInfo()
32 {
33 sptr<IRemoteObject> remote = Remote();
34 if (remote == nullptr) {
35 WLOGFW("GetDefaultDisplayInfo: remote is nullptr");
36 return nullptr;
37 }
38
39 MessageParcel data;
40 MessageParcel reply;
41 MessageOption option;
42 if (!data.WriteInterfaceToken(GetDescriptor())) {
43 WLOGFE("GetDefaultDisplayInfo: WriteInterfaceToken failed");
44 return nullptr;
45 }
46 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO),
47 data, reply, option) != ERR_NONE) {
48 WLOGFW("GetDefaultDisplayInfo: SendRequest failed");
49 return nullptr;
50 }
51 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
52 if (info == nullptr) {
53 WLOGFW("DisplayManagerProxy::GetDefaultDisplayInfo SendRequest nullptr.");
54 }
55 return info;
56 }
57
GetDisplayInfoById(DisplayId displayId)58 sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
59 {
60 sptr<IRemoteObject> remote = Remote();
61 if (remote == nullptr) {
62 WLOGFW("GetDisplayInfoById: remote is nullptr");
63 return nullptr;
64 }
65
66 MessageParcel data;
67 MessageParcel reply;
68 MessageOption option;
69 if (!data.WriteInterfaceToken(GetDescriptor())) {
70 WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed");
71 return nullptr;
72 }
73 if (!data.WriteUint64(displayId)) {
74 WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed");
75 return nullptr;
76 }
77 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID),
78 data, reply, option) != ERR_NONE) {
79 WLOGFW("GetDisplayInfoById: SendRequest failed");
80 return nullptr;
81 }
82
83 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
84 if (info == nullptr) {
85 WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr.");
86 return nullptr;
87 }
88 return info;
89 }
90
GetDisplayInfoByScreen(ScreenId screenId)91 sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoByScreen(ScreenId screenId)
92 {
93 sptr<IRemoteObject> remote = Remote();
94 if (remote == nullptr) {
95 WLOGFE("fail to get displayInfo by screenId: remote is null");
96 return nullptr;
97 }
98
99 MessageParcel data;
100 MessageParcel reply;
101 MessageOption option;
102 if (!data.WriteInterfaceToken(GetDescriptor())) {
103 WLOGFE("fail to get displayInfo by screenId: WriteInterfaceToken failed");
104 return nullptr;
105 }
106 if (!data.WriteUint64(screenId)) {
107 WLOGFW("fail to get displayInfo by screenId: WriteUint64 displayId failed");
108 return nullptr;
109 }
110 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_SCREEN),
111 data, reply, option) != ERR_NONE) {
112 WLOGFW("fail to get displayInfo by screenId: SendRequest failed");
113 return nullptr;
114 }
115
116 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
117 if (info == nullptr) {
118 WLOGFW("fail to get displayInfo by screenId: SendRequest null");
119 return nullptr;
120 }
121 return info;
122 }
123
CreateVirtualScreen(VirtualScreenOption virtualOption,const sptr<IRemoteObject> & displayManagerAgent)124 ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption,
125 const sptr<IRemoteObject>& displayManagerAgent)
126 {
127 sptr<IRemoteObject> remote = Remote();
128 if (remote == nullptr) {
129 WLOGFW("CreateVirtualScreen: remote is nullptr");
130 return SCREEN_ID_INVALID;
131 }
132
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option;
136 if (!data.WriteInterfaceToken(GetDescriptor())) {
137 WLOGFE("CreateVirtualScreen: WriteInterfaceToken failed");
138 return SCREEN_ID_INVALID;
139 }
140 bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) &&
141 data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) &&
142 data.WriteInt32(virtualOption.flags_) && data.WriteBool(virtualOption.isForShot_);
143 if (virtualOption.surface_ != nullptr && virtualOption.surface_->GetProducer() != nullptr) {
144 res = res &&
145 data.WriteBool(true) &&
146 data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject());
147 } else {
148 WLOGFW("CreateVirtualScreen: surface is nullptr");
149 res = res && data.WriteBool(false);
150 }
151 if (displayManagerAgent != nullptr) {
152 res = res &&
153 data.WriteRemoteObject(displayManagerAgent);
154 }
155 if (!res) {
156 WLOGFE("Write data failed");
157 return SCREEN_ID_INVALID;
158 }
159 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_CREATE_VIRTUAL_SCREEN),
160 data, reply, option) != ERR_NONE) {
161 WLOGFW("CreateVirtualScreen: SendRequest failed");
162 return SCREEN_ID_INVALID;
163 }
164
165 ScreenId screenId = static_cast<ScreenId>(reply.ReadUint64());
166 WLOGFI("CreateVirtualScreen %" PRIu64"", screenId);
167 return screenId;
168 }
169
DestroyVirtualScreen(ScreenId screenId)170 DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId)
171 {
172 sptr<IRemoteObject> remote = Remote();
173 if (remote == nullptr) {
174 WLOGFW("DestroyVirtualScreen: remote is nullptr");
175 return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
176 }
177
178 MessageParcel data;
179 MessageParcel reply;
180 MessageOption option;
181 if (!data.WriteInterfaceToken(GetDescriptor())) {
182 WLOGFE("DestroyVirtualScreen: WriteInterfaceToken failed");
183 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
184 }
185 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
186 WLOGFW("DestroyVirtualScreen: WriteUint64 screenId failed");
187 return DMError::DM_ERROR_IPC_FAILED;
188 }
189 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_DESTROY_VIRTUAL_SCREEN),
190 data, reply, option) != ERR_NONE) {
191 WLOGFW("DestroyVirtualScreen: SendRequest failed");
192 return DMError::DM_ERROR_IPC_FAILED;
193 }
194 return static_cast<DMError>(reply.ReadInt32());
195 }
196
SetVirtualScreenSurface(ScreenId screenId,sptr<IBufferProducer> surface)197 DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface)
198 {
199 sptr<IRemoteObject> remote = Remote();
200 if (remote == nullptr) {
201 WLOGFW("SetVirtualScreenSurface: remote is nullptr");
202 return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
203 }
204
205 MessageParcel data;
206 MessageParcel reply;
207 MessageOption option;
208 if (!data.WriteInterfaceToken(GetDescriptor())) {
209 WLOGFE("SetVirtualScreenSurface: WriteInterfaceToken failed");
210 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
211 }
212 bool res = data.WriteUint64(static_cast<uint64_t>(screenId));
213 if (surface != nullptr) {
214 res = res &&
215 data.WriteBool(true) &&
216 data.WriteRemoteObject(surface->AsObject());
217 } else {
218 WLOGFW("SetVirtualScreenSurface: surface is nullptr");
219 res = res && data.WriteBool(false);
220 }
221 if (!res) {
222 WLOGFW("SetVirtualScreenSurface: Write screenId/surface failed");
223 return DMError::DM_ERROR_IPC_FAILED;
224 }
225 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE),
226 data, reply, option) != ERR_NONE) {
227 WLOGFW("SetVirtualScreenSurface: SendRequest failed");
228 return DMError::DM_ERROR_IPC_FAILED;
229 }
230 return static_cast<DMError>(reply.ReadInt32());
231 }
232
SetOrientation(ScreenId screenId,Orientation orientation)233 DMError DisplayManagerProxy::SetOrientation(ScreenId screenId, Orientation orientation)
234 {
235 sptr<IRemoteObject> remote = Remote();
236 if (remote == nullptr) {
237 WLOGFW("fail to set orientation: remote is null");
238 return DMError::DM_ERROR_NULLPTR;
239 }
240
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option;
244 if (!data.WriteInterfaceToken(GetDescriptor())) {
245 WLOGFE("fail to set orientation: WriteInterfaceToken failed");
246 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
247 }
248 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
249 WLOGFW("fail to set orientation: Write screenId failed");
250 return DMError::DM_ERROR_IPC_FAILED;
251 }
252 if (!data.WriteUint32(static_cast<uint32_t>(orientation))) {
253 WLOGFW("fail to set orientation: Write orientation failed");
254 return DMError::DM_ERROR_IPC_FAILED;
255 }
256 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_ORIENTATION),
257 data, reply, option) != ERR_NONE) {
258 WLOGFW("fail to set orientation: SendRequest failed");
259 return DMError::DM_ERROR_IPC_FAILED;
260 }
261 return static_cast<DMError>(reply.ReadInt32());
262 }
263
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode)264 std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode)
265 {
266 sptr<IRemoteObject> remote = Remote();
267 if (remote == nullptr) {
268 WLOGFW("GetDisplaySnapshot: remote is nullptr");
269 return nullptr;
270 }
271
272 MessageParcel data;
273 MessageParcel reply;
274 MessageOption option;
275 if (!data.WriteInterfaceToken(GetDescriptor())) {
276 WLOGFE("GetDisplaySnapshot: WriteInterfaceToken failed");
277 return nullptr;
278 }
279
280 if (!data.WriteUint64(displayId)) {
281 WLOGFE("Write displayId failed");
282 return nullptr;
283 }
284
285 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT),
286 data, reply, option) != ERR_NONE) {
287 WLOGFW("GetDisplaySnapshot: SendRequest failed");
288 return nullptr;
289 }
290
291 std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>());
292 DmErrorCode replyErreoCode = static_cast<DmErrorCode>(reply.ReadInt32());
293 if (errorCode) {
294 *errorCode = replyErreoCode;
295 }
296 if (pixelMap == nullptr) {
297 WLOGFW("DisplayManagerProxy::GetDisplaySnapshot SendRequest nullptr.");
298 return nullptr;
299 }
300 return pixelMap;
301 }
302
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)303 DMError DisplayManagerProxy::GetScreenSupportedColorGamuts(ScreenId screenId,
304 std::vector<ScreenColorGamut>& colorGamuts)
305 {
306 sptr<IRemoteObject> remote = Remote();
307 if (remote == nullptr) {
308 WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: remote is nullptr");
309 return DMError::DM_ERROR_NULLPTR;
310 }
311
312 MessageParcel data;
313 MessageParcel reply;
314 MessageOption option;
315 if (!data.WriteInterfaceToken(GetDescriptor())) {
316 WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteInterfaceToken failed");
317 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
318 }
319 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
320 WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteUint64 screenId failed");
321 return DMError::DM_ERROR_IPC_FAILED;
322 }
323 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS),
324 data, reply, option) != ERR_NONE) {
325 WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: SendRequest failed");
326 return DMError::DM_ERROR_IPC_FAILED;
327 }
328 DMError ret = static_cast<DMError>(reply.ReadInt32());
329 if (ret != DMError::DM_OK) {
330 return ret;
331 }
332 MarshallingHelper::UnmarshallingVectorObj<ScreenColorGamut>(reply, colorGamuts,
333 [](Parcel& parcel, ScreenColorGamut& color) {
334 uint32_t value;
335 bool res = parcel.ReadUint32(value);
336 color = static_cast<ScreenColorGamut>(value);
337 return res;
338 }
339 );
340 return ret;
341 }
342
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)343 DMError DisplayManagerProxy::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
344 {
345 sptr<IRemoteObject> remote = Remote();
346 if (remote == nullptr) {
347 WLOGFW("DisplayManagerProxy::GetScreenColorGamut: remote is nullptr");
348 return DMError::DM_ERROR_NULLPTR;
349 }
350
351 MessageParcel data;
352 MessageParcel reply;
353 MessageOption option;
354 if (!data.WriteInterfaceToken(GetDescriptor())) {
355 WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteInterfaceToken failed");
356 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
357 }
358 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
359 WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteUint64 uint64_t failed");
360 return DMError::DM_ERROR_IPC_FAILED;
361 }
362 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_GAMUT),
363 data, reply, option) != ERR_NONE) {
364 WLOGFW("DisplayManagerProxy::GetScreenColorGamut: SendRequest failed");
365 return DMError::DM_ERROR_IPC_FAILED;
366 }
367 DMError ret = static_cast<DMError>(reply.ReadInt32());
368 if (ret != DMError::DM_OK) {
369 return ret;
370 }
371 colorGamut = static_cast<ScreenColorGamut>(reply.ReadUint32());
372 return ret;
373 }
374
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)375 DMError DisplayManagerProxy::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
376 {
377 sptr<IRemoteObject> remote = Remote();
378 if (remote == nullptr) {
379 WLOGFW("DisplayManagerProxy::SetScreenColorGamut: remote is nullptr");
380 return DMError::DM_ERROR_NULLPTR;
381 }
382
383 MessageParcel data;
384 MessageParcel reply;
385 MessageOption option;
386 if (!data.WriteInterfaceToken(GetDescriptor())) {
387 WLOGFW("DisplayManagerProxy::SetScreenColorGamut: WriteInterfaceToken failed");
388 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
389 }
390 if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteInt32(colorGamutIdx)) {
391 WLOGFW("DisplayManagerProxy::SetScreenColorGamut: Write failed");
392 return DMError::DM_ERROR_IPC_FAILED;
393 }
394 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_GAMUT),
395 data, reply, option) != ERR_NONE) {
396 WLOGFW("DisplayManagerProxy::SetScreenColorGamut: SendRequest failed");
397 return DMError::DM_ERROR_IPC_FAILED;
398 }
399 return static_cast<DMError>(reply.ReadInt32());
400 }
401
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)402 DMError DisplayManagerProxy::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
403 {
404 sptr<IRemoteObject> remote = Remote();
405 if (remote == nullptr) {
406 WLOGFW("DisplayManagerProxy::GetScreenGamutMap: remote is nullptr");
407 return DMError::DM_ERROR_NULLPTR;
408 }
409
410 MessageParcel data;
411 MessageParcel reply;
412 MessageOption option;
413 if (!data.WriteInterfaceToken(GetDescriptor())) {
414 WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteInterfaceToken failed");
415 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
416 }
417 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
418 WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteUint64 screenId failed");
419 return DMError::DM_ERROR_IPC_FAILED;
420 }
421 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_GAMUT_MAP),
422 data, reply, option) != ERR_NONE) {
423 WLOGFW("DisplayManagerProxy::GetScreenGamutMap: SendRequest failed");
424 return DMError::DM_ERROR_IPC_FAILED;
425 }
426 DMError ret = static_cast<DMError>(reply.ReadInt32());
427 if (ret != DMError::DM_OK) {
428 return ret;
429 }
430 gamutMap = static_cast<ScreenGamutMap>(reply.ReadUint32());
431 return ret;
432 }
433
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)434 DMError DisplayManagerProxy::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
435 {
436 sptr<IRemoteObject> remote = Remote();
437 if (remote == nullptr) {
438 WLOGFW("DisplayManagerProxy::SetScreenGamutMap: remote is nullptr");
439 return DMError::DM_ERROR_NULLPTR;
440 }
441
442 MessageParcel data;
443 MessageParcel reply;
444 MessageOption option;
445 if (!data.WriteInterfaceToken(GetDescriptor())) {
446 WLOGFW("DisplayManagerProxy::SetScreenGamutMap: WriteInterfaceToken failed");
447 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
448 }
449 if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteUint32(static_cast<uint32_t>(gamutMap))) {
450 WLOGFW("DisplayManagerProxy::SetScreenGamutMap: Writ failed");
451 return DMError::DM_ERROR_IPC_FAILED;
452 }
453 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_GAMUT_MAP),
454 data, reply, option) != ERR_NONE) {
455 WLOGFW("DisplayManagerProxy::SetScreenGamutMap: SendRequest failed");
456 return DMError::DM_ERROR_IPC_FAILED;
457 }
458 return static_cast<DMError>(reply.ReadInt32());
459 }
460
SetScreenColorTransform(ScreenId screenId)461 DMError DisplayManagerProxy::SetScreenColorTransform(ScreenId screenId)
462 {
463 sptr<IRemoteObject> remote = Remote();
464 if (remote == nullptr) {
465 WLOGFW("DisplayManagerProxy::SetScreenColorTransform: remote is nullptr");
466 return DMError::DM_ERROR_NULLPTR;
467 }
468
469 MessageParcel data;
470 MessageParcel reply;
471 MessageOption option;
472 if (!data.WriteInterfaceToken(GetDescriptor())) {
473 WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteInterfaceToken failed");
474 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
475 }
476 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
477 WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteUint64 screenId failed");
478 return DMError::DM_ERROR_IPC_FAILED;
479 }
480 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_TRANSFORM),
481 data, reply, option) != ERR_NONE) {
482 WLOGFW("DisplayManagerProxy::SetScreenColorTransform: SendRequest failed");
483 return DMError::DM_ERROR_IPC_FAILED;
484 }
485 return static_cast<DMError>(reply.ReadInt32());
486 }
487
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)488 DMError DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
489 DisplayManagerAgentType type)
490 {
491 MessageParcel data;
492 MessageParcel reply;
493 MessageOption option;
494 if (!data.WriteInterfaceToken(GetDescriptor())) {
495 WLOGFE("WriteInterfaceToken failed");
496 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
497 }
498
499 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
500 WLOGFE("Write IDisplayManagerAgent failed");
501 return DMError::DM_ERROR_IPC_FAILED;
502 }
503
504 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
505 WLOGFE("Write DisplayManagerAgent type failed");
506 return DMError::DM_ERROR_IPC_FAILED;
507 }
508
509 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT),
510 data, reply, option) != ERR_NONE) {
511 WLOGFE("SendRequest failed");
512 return DMError::DM_ERROR_IPC_FAILED;
513 }
514 return static_cast<DMError>(reply.ReadInt32());
515 }
516
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)517 DMError DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
518 DisplayManagerAgentType type)
519 {
520 MessageParcel data;
521 MessageParcel reply;
522 MessageOption option;
523 if (!data.WriteInterfaceToken(GetDescriptor())) {
524 WLOGFE("WriteInterfaceToken failed");
525 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
526 }
527
528 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
529 WLOGFE("Write IWindowManagerAgent failed");
530 return DMError::DM_ERROR_IPC_FAILED;
531 }
532
533 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
534 WLOGFE("Write DisplayManagerAgent type failed");
535 return DMError::DM_ERROR_IPC_FAILED;
536 }
537
538 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT),
539 data, reply, option) != ERR_NONE) {
540 WLOGFE("SendRequest failed");
541 return DMError::DM_ERROR_IPC_FAILED;
542 }
543 return static_cast<DMError>(reply.ReadInt32());
544 }
545
WakeUpBegin(PowerStateChangeReason reason)546 bool DisplayManagerProxy::WakeUpBegin(PowerStateChangeReason reason)
547 {
548 MessageParcel data;
549 MessageParcel reply;
550 MessageOption option;
551 if (!data.WriteInterfaceToken(GetDescriptor())) {
552 WLOGFE("WriteInterfaceToken failed");
553 return false;
554 }
555 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
556 WLOGFE("Write PowerStateChangeReason failed");
557 return false;
558 }
559 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN),
560 data, reply, option) != ERR_NONE) {
561 WLOGFW("SendRequest failed");
562 return false;
563 }
564 return reply.ReadBool();
565 }
566
WakeUpEnd()567 bool DisplayManagerProxy::WakeUpEnd()
568 {
569 MessageParcel data;
570 MessageParcel reply;
571 MessageOption option;
572 if (!data.WriteInterfaceToken(GetDescriptor())) {
573 WLOGFE("WriteInterfaceToken failed");
574 return false;
575 }
576 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_END),
577 data, reply, option) != ERR_NONE) {
578 WLOGFW("SendRequest failed");
579 return false;
580 }
581 return reply.ReadBool();
582 }
583
SuspendBegin(PowerStateChangeReason reason)584 bool DisplayManagerProxy::SuspendBegin(PowerStateChangeReason reason)
585 {
586 MessageParcel data;
587 MessageParcel reply;
588 MessageOption option;
589 if (!data.WriteInterfaceToken(GetDescriptor())) {
590 WLOGFE("WriteInterfaceToken failed");
591 return false;
592 }
593 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
594 WLOGFE("Write PowerStateChangeReason failed");
595 return false;
596 }
597 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN),
598 data, reply, option) != ERR_NONE) {
599 WLOGFW("SendRequest failed");
600 return false;
601 }
602 return reply.ReadBool();
603 }
604
SuspendEnd()605 bool DisplayManagerProxy::SuspendEnd()
606 {
607 MessageParcel data;
608 MessageParcel reply;
609 MessageOption option;
610 if (!data.WriteInterfaceToken(GetDescriptor())) {
611 WLOGFE("WriteInterfaceToken failed");
612 return false;
613 }
614 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_END),
615 data, reply, option) != ERR_NONE) {
616 WLOGFW("SendRequest failed");
617 return false;
618 }
619 return reply.ReadBool();
620 }
621
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)622 bool DisplayManagerProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
623 {
624 MessageParcel data;
625 MessageParcel reply;
626 MessageOption option;
627 if (!data.WriteInterfaceToken(GetDescriptor())) {
628 WLOGFE("WriteInterfaceToken failed");
629 return false;
630 }
631 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
632 WLOGFE("Write ScreenPowerState failed");
633 return false;
634 }
635 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
636 WLOGFE("Write PowerStateChangeReason failed");
637 return false;
638 }
639 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL),
640 data, reply, option) != ERR_NONE) {
641 WLOGFW("SendRequest failed");
642 return false;
643 }
644 return reply.ReadBool();
645 }
646
GetScreenPower(ScreenId dmsScreenId)647 ScreenPowerState DisplayManagerProxy::GetScreenPower(ScreenId dmsScreenId)
648 {
649 MessageParcel data;
650 MessageParcel reply;
651 MessageOption option;
652 if (!data.WriteInterfaceToken(GetDescriptor())) {
653 WLOGFE("WriteInterfaceToken failed");
654 return ScreenPowerState::INVALID_STATE;
655 }
656 if (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
657 WLOGFE("Write dmsScreenId failed");
658 return ScreenPowerState::INVALID_STATE;
659 }
660 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
661 data, reply, option) != ERR_NONE) {
662 WLOGFW("SendRequest failed");
663 return ScreenPowerState::INVALID_STATE;
664 }
665 return static_cast<ScreenPowerState>(reply.ReadUint32());
666 }
667
SetDisplayState(DisplayState state)668 bool DisplayManagerProxy::SetDisplayState(DisplayState state)
669 {
670 MessageParcel data;
671 MessageParcel reply;
672 MessageOption option;
673 if (!data.WriteInterfaceToken(GetDescriptor())) {
674 WLOGFE("WriteInterfaceToken failed");
675 return false;
676 }
677 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
678 WLOGFE("Write DisplayState failed");
679 return false;
680 }
681 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
682 data, reply, option) != ERR_NONE) {
683 WLOGFW("SendRequest failed");
684 return false;
685 }
686 return reply.ReadBool();
687 }
688
GetDisplayState(DisplayId displayId)689 DisplayState DisplayManagerProxy::GetDisplayState(DisplayId displayId)
690 {
691 MessageParcel data;
692 MessageParcel reply;
693 MessageOption option;
694 if (!data.WriteInterfaceToken(GetDescriptor())) {
695 WLOGFE("WriteInterfaceToken failed");
696 return DisplayState::UNKNOWN;
697 }
698 if (!data.WriteUint64(displayId)) {
699 WLOGFE("Write displayId failed");
700 return DisplayState::UNKNOWN;
701 }
702 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
703 data, reply, option) != ERR_NONE) {
704 WLOGFW("SendRequest failed");
705 return DisplayState::UNKNOWN;
706 }
707 return static_cast<DisplayState>(reply.ReadUint32());
708 }
709
GetAllDisplayIds()710 std::vector<DisplayId> DisplayManagerProxy::GetAllDisplayIds()
711 {
712 std::vector<DisplayId> allDisplayIds;
713 MessageParcel data;
714 MessageParcel reply;
715 MessageOption option;
716 if (!data.WriteInterfaceToken(GetDescriptor())) {
717 WLOGFE("WriteInterfaceToken failed");
718 return allDisplayIds;
719 }
720 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
721 data, reply, option) != ERR_NONE) {
722 WLOGFW("SendRequest failed");
723 return allDisplayIds;
724 }
725 reply.ReadUInt64Vector(&allDisplayIds);
726 return allDisplayIds;
727 }
728
GetCutoutInfo(DisplayId displayId)729 sptr<CutoutInfo> DisplayManagerProxy::GetCutoutInfo(DisplayId displayId)
730 {
731 sptr<IRemoteObject> remote = Remote();
732 if (remote == nullptr) {
733 WLOGFW("GetCutoutInfo: remote is null");
734 return nullptr;
735 }
736 MessageParcel data;
737 MessageParcel reply;
738 MessageOption option;
739 if (!data.WriteInterfaceToken(GetDescriptor())) {
740 WLOGFE("GetCutoutInfo: GetCutoutInfo failed");
741 return nullptr;
742 }
743 if (!data.WriteUint64(displayId)) {
744 WLOGFE("GetCutoutInfo: write displayId failed");
745 return nullptr;
746 }
747 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO),
748 data, reply, option) != ERR_NONE) {
749 WLOGFW("GetCutoutInfo: GetCutoutInfo failed");
750 return nullptr;
751 }
752 sptr<CutoutInfo> info = reply.ReadParcelable<CutoutInfo>();
753 return info;
754 }
755
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode,bool onTop)756 DMError DisplayManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId,
757 std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop)
758 {
759 MessageParcel data;
760 MessageParcel reply;
761 MessageOption option;
762 if (!data.WriteInterfaceToken(GetDescriptor())) {
763 WLOGFE("WriteInterfaceToken failed");
764 return DMError::DM_ERROR_IPC_FAILED;
765 }
766 if (!data.WriteUint64(displayId)) {
767 WLOGFE("write displayId failed");
768 return DMError::DM_ERROR_IPC_FAILED;
769 }
770 if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
771 WLOGFE("Write windowProperty failed");
772 return DMError::DM_ERROR_IPC_FAILED;
773 }
774 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE),
775 data, reply, option) != ERR_NONE) {
776 WLOGFW("Send request failed");
777 return DMError::DM_ERROR_IPC_FAILED;
778 }
779 DMError ret = static_cast<DMError>(reply.ReadUint32());
780 return ret;
781 }
782
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)783 DMError DisplayManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
784 std::shared_ptr<class RSSurfaceNode>& surfaceNode)
785 {
786 MessageParcel data;
787 MessageParcel reply;
788 MessageOption option;
789 if (!data.WriteInterfaceToken(GetDescriptor())) {
790 WLOGFE("WriteInterfaceToken failed");
791 return DMError::DM_ERROR_IPC_FAILED;
792 }
793 if (!data.WriteUint64(displayId)) {
794 WLOGFE("write displayId failed");
795 return DMError::DM_ERROR_IPC_FAILED;
796 }
797 if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
798 WLOGFE("Write windowProperty failed");
799 return DMError::DM_ERROR_IPC_FAILED;
800 }
801 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE),
802 data, reply, option) != ERR_NONE) {
803 WLOGFW("Send request failed");
804 return DMError::DM_ERROR_IPC_FAILED;
805 }
806 DMError ret = static_cast<DMError>(reply.ReadUint32());
807 return ret;
808 }
809
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)810 DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
811 {
812 MessageParcel data;
813 MessageParcel reply;
814 MessageOption option;
815 if (!data.WriteInterfaceToken(GetDescriptor())) {
816 return DMError::DM_ERROR_IPC_FAILED;
817 }
818
819 if (!data.WriteUint64(displayId)) {
820 return DMError::DM_ERROR_IPC_FAILED;
821 }
822
823 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW),
824 data, reply, option) != ERR_NONE) {
825 return DMError::DM_ERROR_IPC_FAILED;
826 }
827 DMError ret = static_cast<DMError>(reply.ReadInt32());
828 hasPrivateWindow = reply.ReadBool();
829 return ret;
830 }
831
NotifyDisplayEvent(DisplayEvent event)832 void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
833 {
834 MessageParcel data;
835 MessageParcel reply;
836 MessageOption option;
837 if (!data.WriteInterfaceToken(GetDescriptor())) {
838 WLOGFE("WriteInterfaceToken failed");
839 return;
840 }
841 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
842 WLOGFE("Write DisplayEvent failed");
843 return;
844 }
845 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT),
846 data, reply, option) != ERR_NONE) {
847 WLOGFW("SendRequest failed");
848 return;
849 }
850 }
851
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)852 bool DisplayManagerProxy::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
853 {
854 MessageParcel data;
855 MessageParcel reply;
856 MessageOption option;
857 if (!data.WriteInterfaceToken(GetDescriptor())) {
858 WLOGFE("WriteInterfaceToken failed");
859 return false;
860 }
861 if (!data.WriteUInt64Vector(displayIds)) {
862 WLOGFE("set freeze fail: write displayId failed.");
863 return false;
864 }
865 if (!data.WriteBool(isFreeze)) {
866 WLOGFE("set freeze fail: write freeze flag failed.");
867 return false;
868 }
869
870 if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT),
871 data, reply, option) != ERR_NONE) {
872 WLOGFE("SendRequest failed");
873 return false;
874 }
875 return true;
876 }
877
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)878 DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
879 ScreenId& screenGroupId)
880 {
881 sptr<IRemoteObject> remote = Remote();
882 if (remote == nullptr) {
883 WLOGFW("create mirror fail: remote is null");
884 return DMError::DM_ERROR_NULLPTR;
885 }
886
887 MessageParcel data;
888 MessageParcel reply;
889 MessageOption option;
890 if (!data.WriteInterfaceToken(GetDescriptor())) {
891 WLOGFE("create mirror fail: WriteInterfaceToken failed");
892 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
893 }
894 bool res = data.WriteUint64(static_cast<uint64_t>(mainScreenId)) &&
895 data.WriteUInt64Vector(mirrorScreenId);
896 if (!res) {
897 WLOGFE("create mirror fail: data write failed");
898 return DMError::DM_ERROR_IPC_FAILED;
899 }
900 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR),
901 data, reply, option) != ERR_NONE) {
902 WLOGFW("create mirror fail: SendRequest failed");
903 return DMError::DM_ERROR_IPC_FAILED;
904 }
905 DMError ret = static_cast<DMError>(reply.ReadInt32());
906 screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
907 return ret;
908 }
909
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)910 DMError DisplayManagerProxy::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
911 {
912 sptr<IRemoteObject> remote = Remote();
913 if (remote == nullptr) {
914 WLOGFW("StopMirror fail: remote is null");
915 return DMError::DM_ERROR_NULLPTR;
916 }
917
918 MessageParcel data;
919 MessageParcel reply;
920 MessageOption option;
921 if (!data.WriteInterfaceToken(GetDescriptor())) {
922 WLOGFE("StopMirror fail: WriteInterfaceToken failed");
923 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
924 }
925 bool res = data.WriteUInt64Vector(mirrorScreenIds);
926 if (!res) {
927 WLOGFE("StopMirror fail: data write failed");
928 return DMError::DM_ERROR_IPC_FAILED;
929 }
930 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_MIRROR),
931 data, reply, option) != ERR_NONE) {
932 WLOGFW("StopMirror fail: SendRequest failed");
933 return DMError::DM_ERROR_IPC_FAILED;
934 }
935 return static_cast<DMError>(reply.ReadInt32());
936 }
937
GetScreenInfoById(ScreenId screenId)938 sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
939 {
940 sptr<IRemoteObject> remote = Remote();
941 if (remote == nullptr) {
942 WLOGFW("GetScreenInfoById: remote is nullptr");
943 return nullptr;
944 }
945
946 MessageParcel data;
947 MessageParcel reply;
948 MessageOption option;
949 if (!data.WriteInterfaceToken(GetDescriptor())) {
950 WLOGFE("GetScreenInfoById: WriteInterfaceToken failed");
951 return nullptr;
952 }
953 if (!data.WriteUint64(screenId)) {
954 WLOGFE("GetScreenInfoById: Write screenId failed");
955 return nullptr;
956 }
957 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID),
958 data, reply, option) != ERR_NONE) {
959 WLOGFW("GetScreenInfoById: SendRequest failed");
960 return nullptr;
961 }
962
963 sptr<ScreenInfo> info = reply.ReadStrongParcelable<ScreenInfo>();
964 if (info == nullptr) {
965 WLOGFW("GetScreenInfoById SendRequest nullptr.");
966 return nullptr;
967 }
968 for (auto& mode : info->GetModes()) {
969 WLOGFI("info modes is width: %{public}u, height: %{public}u, refreshRate: %{public}u",
970 mode->width_, mode->height_, mode->refreshRate_);
971 }
972 return info;
973 }
974
GetScreenGroupInfoById(ScreenId screenId)975 sptr<ScreenGroupInfo> DisplayManagerProxy::GetScreenGroupInfoById(ScreenId screenId)
976 {
977 sptr<IRemoteObject> remote = Remote();
978 if (remote == nullptr) {
979 WLOGFW("GetScreenGroupInfoById: remote is nullptr");
980 return nullptr;
981 }
982
983 MessageParcel data;
984 MessageParcel reply;
985 MessageOption option;
986 if (!data.WriteInterfaceToken(GetDescriptor())) {
987 WLOGFE("GetScreenGroupInfoById: WriteInterfaceToken failed");
988 return nullptr;
989 }
990 if (!data.WriteUint64(screenId)) {
991 WLOGFE("GetScreenGroupInfoById: Write screenId failed");
992 return nullptr;
993 }
994 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID),
995 data, reply, option) != ERR_NONE) {
996 WLOGFW("GetScreenGroupInfoById: SendRequest failed");
997 return nullptr;
998 }
999
1000 sptr<ScreenGroupInfo> info = reply.ReadStrongParcelable<ScreenGroupInfo>();
1001 if (info == nullptr) {
1002 WLOGFW("GetScreenGroupInfoById SendRequest nullptr.");
1003 return nullptr;
1004 }
1005 return info;
1006 }
1007
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)1008 DMError DisplayManagerProxy::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
1009 {
1010 sptr<IRemoteObject> remote = Remote();
1011 if (remote == nullptr) {
1012 WLOGFW("GetAllScreenInfos: remote is nullptr");
1013 return DMError::DM_ERROR_NULLPTR;
1014 }
1015
1016 MessageParcel data;
1017 MessageParcel reply;
1018 MessageOption option;
1019 if (!data.WriteInterfaceToken(GetDescriptor())) {
1020 WLOGFE("GetAllScreenInfos: WriteInterfaceToken failed");
1021 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1022 }
1023 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS),
1024 data, reply, option) != ERR_NONE) {
1025 WLOGFW("GetAllScreenInfos: SendRequest failed");
1026 return DMError::DM_ERROR_IPC_FAILED;
1027 }
1028 DMError ret = static_cast<DMError>(reply.ReadInt32());
1029 MarshallingHelper::UnmarshallingVectorParcelableObj<ScreenInfo>(reply, screenInfos);
1030 return ret;
1031 }
1032
MakeExpand(std::vector<ScreenId> screenId,std::vector<Point> startPoint,ScreenId & screenGroupId)1033 DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
1034 ScreenId& screenGroupId)
1035 {
1036 sptr<IRemoteObject> remote = Remote();
1037 if (remote == nullptr) {
1038 WLOGFW("MakeExpand: remote is null");
1039 return DMError::DM_ERROR_IPC_FAILED;
1040 }
1041
1042 MessageParcel data;
1043 MessageParcel reply;
1044 MessageOption option;
1045 if (!data.WriteInterfaceToken(GetDescriptor())) {
1046 WLOGFE("MakeExpand: WriteInterfaceToken failed");
1047 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1048 }
1049 if (!data.WriteUInt64Vector(screenId)) {
1050 WLOGFE("MakeExpand: write screenId failed");
1051 return DMError::DM_ERROR_IPC_FAILED;
1052 }
1053 if (!MarshallingHelper::MarshallingVectorObj<Point>(data, startPoint, [](Parcel& parcel, const Point& point) {
1054 return parcel.WriteInt32(point.posX_) && parcel.WriteInt32(point.posY_);
1055 })) {
1056 WLOGFE("MakeExpand: write startPoint failed");
1057 return DMError::DM_ERROR_IPC_FAILED;
1058 }
1059 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND),
1060 data, reply, option) != ERR_NONE) {
1061 WLOGFE("MakeExpand: SendRequest failed");
1062 return DMError::DM_ERROR_IPC_FAILED;
1063 }
1064 DMError ret = static_cast<DMError>(reply.ReadInt32());
1065 screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
1066 return ret;
1067 }
1068
StopExpand(const std::vector<ScreenId> & expandScreenIds)1069 DMError DisplayManagerProxy::StopExpand(const std::vector<ScreenId>& expandScreenIds)
1070 {
1071 sptr<IRemoteObject> remote = Remote();
1072 if (remote == nullptr) {
1073 WLOGFW("StopExpand fail: remote is null");
1074 return DMError::DM_ERROR_NULLPTR;
1075 }
1076
1077 MessageParcel data;
1078 MessageParcel reply;
1079 MessageOption option;
1080 if (!data.WriteInterfaceToken(GetDescriptor())) {
1081 WLOGFE("StopExpand fail: WriteInterfaceToken failed");
1082 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1083 }
1084 bool res = data.WriteUInt64Vector(expandScreenIds);
1085 if (!res) {
1086 WLOGFE("StopExpand fail: data write failed");
1087 return DMError::DM_ERROR_IPC_FAILED;
1088 }
1089 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_EXPAND),
1090 data, reply, option) != ERR_NONE) {
1091 WLOGFW("StopExpand fail: SendRequest failed");
1092 return DMError::DM_ERROR_IPC_FAILED;
1093 }
1094 return static_cast<DMError>(reply.ReadInt32());
1095 }
1096
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)1097 void DisplayManagerProxy::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
1098 {
1099 sptr<IRemoteObject> remote = Remote();
1100 if (remote == nullptr) {
1101 WLOGFW("cancel make mirror or expand fail: remote is null");
1102 return;
1103 }
1104
1105 MessageParcel data;
1106 MessageParcel reply;
1107 MessageOption option(MessageOption::TF_ASYNC);
1108 if (!data.WriteInterfaceToken(GetDescriptor())) {
1109 WLOGFE("cancel make mirror or expand fail: WriteInterfaceToken failed");
1110 return;
1111 }
1112 bool res = data.WriteUInt64Vector(screens);
1113 if (!res) {
1114 WLOGFE("cancel make mirror or expand fail: write screens failed.");
1115 return;
1116 }
1117 if (remote->SendRequest(static_cast<uint32_t>(
1118 DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP),
1119 data, reply, option) != ERR_NONE) {
1120 WLOGFW("cancel make mirror or expand fail: SendRequest failed");
1121 }
1122 }
1123
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)1124 DMError DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
1125 {
1126 sptr<IRemoteObject> remote = Remote();
1127 if (remote == nullptr) {
1128 WLOGFW("SetScreenActiveMode: remote is null");
1129 return DMError::DM_ERROR_NULLPTR;
1130 }
1131
1132 MessageParcel data;
1133 MessageParcel reply;
1134 MessageOption option;
1135 if (!data.WriteInterfaceToken(GetDescriptor())) {
1136 WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed");
1137 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1138 }
1139 if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) {
1140 WLOGFE("SetScreenActiveMode: write screenId/modeId failed");
1141 return DMError::DM_ERROR_IPC_FAILED;
1142 }
1143 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE),
1144 data, reply, option) != ERR_NONE) {
1145 WLOGFE("SetScreenActiveMode: SendRequest failed");
1146 return DMError::DM_ERROR_IPC_FAILED;
1147 }
1148 return static_cast<DMError>(reply.ReadInt32());
1149 }
1150
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)1151 DMError DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
1152 {
1153 sptr<IRemoteObject> remote = Remote();
1154 if (remote == nullptr) {
1155 WLOGFW("SetVirtualPixelRatio: remote is null");
1156 return DMError::DM_ERROR_NULLPTR;
1157 }
1158
1159 MessageParcel data;
1160 MessageParcel reply;
1161 MessageOption option;
1162 if (!data.WriteInterfaceToken(GetDescriptor())) {
1163 WLOGFE("WriteInterfaceToken failed");
1164 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1165 }
1166 if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) {
1167 WLOGFE("write screenId/modeId failed");
1168 return DMError::DM_ERROR_IPC_FAILED;
1169 }
1170 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO),
1171 data, reply, option) != ERR_NONE) {
1172 WLOGFE("SendRequest failed");
1173 return DMError::DM_ERROR_IPC_FAILED;
1174 }
1175 return static_cast<DMError>(reply.ReadInt32());
1176 }
1177
IsScreenRotationLocked(bool & isLocked)1178 DMError DisplayManagerProxy::IsScreenRotationLocked(bool& isLocked)
1179 {
1180 sptr<IRemoteObject> remote = Remote();
1181 if (remote == nullptr) {
1182 WLOGFW("remote is nullptr");
1183 return DMError::DM_ERROR_NULLPTR;
1184 }
1185 MessageParcel data;
1186 MessageParcel reply;
1187 MessageOption option;
1188 if (!data.WriteInterfaceToken(GetDescriptor())) {
1189 WLOGFE("WriteInterfaceToken failed");
1190 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1191 }
1192 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED),
1193 data, reply, option) != ERR_NONE) {
1194 WLOGFW("SendRequest failed");
1195 return DMError::DM_ERROR_IPC_FAILED;
1196 }
1197 DMError ret = static_cast<DMError>(reply.ReadInt32());
1198 isLocked = reply.ReadBool();
1199 return ret;
1200 }
1201
SetScreenRotationLocked(bool isLocked)1202 DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked)
1203 {
1204 sptr<IRemoteObject> remote = Remote();
1205 if (remote == nullptr) {
1206 WLOGFW("remote is null");
1207 return DMError::DM_ERROR_NULLPTR;
1208 }
1209
1210 MessageParcel data;
1211 MessageParcel reply;
1212 MessageOption option;
1213 if (!data.WriteInterfaceToken(GetDescriptor())) {
1214 WLOGFE("WriteInterfaceToken failed");
1215 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1216 }
1217 if (!data.WriteBool(isLocked)) {
1218 WLOGFE("write isLocked failed");
1219 return DMError::DM_ERROR_IPC_FAILED;
1220 }
1221 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED),
1222 data, reply, option) != ERR_NONE) {
1223 WLOGFE("SendRequest failed");
1224 return DMError::DM_ERROR_IPC_FAILED;
1225 }
1226 return static_cast<DMError>(reply.ReadInt32());
1227 }
1228 } // namespace OHOS::Rosen