1 /*
2 * Copyright (c) 2024 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_lite_proxy.h"
17
18 #include <ipc_types.h>
19 #include <message_option.h>
20 #include <message_parcel.h>
21
22 #include "dm_common.h"
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, "DisplayManagerLiteProxy" };
29 }
30
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)31 DMError DisplayManagerLiteProxy::RegisterDisplayManagerAgent(
32 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
33 {
34 sptr<IRemoteObject> remote = Remote();
35 if (remote == nullptr) {
36 WLOGFW("remote is null");
37 return DMError::DM_ERROR_IPC_FAILED;
38 }
39
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option;
43 WLOGFD("DisplayManagerLiteProxy::RegisterDisplayManagerAgent");
44 if (!data.WriteInterfaceToken(GetDescriptor())) {
45 WLOGFE("RegisterDisplayManagerAgent WriteInterfaceToken failed");
46 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
47 }
48
49 if (displayManagerAgent == nullptr) {
50 WLOGFE("IDisplayManagerAgent is null");
51 return DMError::DM_ERROR_INVALID_PARAM;
52 }
53
54 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
55 WLOGFE("Write IDisplayManagerAgent failed");
56 return DMError::DM_ERROR_IPC_FAILED;
57 }
58
59 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
60 WLOGFE("Write DisplayManagerAgent type failed");
61 return DMError::DM_ERROR_IPC_FAILED;
62 }
63
64 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT),
65 data, reply, option) != ERR_NONE) {
66 WLOGFE("SendRequest failed");
67 return DMError::DM_ERROR_IPC_FAILED;
68 }
69 return static_cast<DMError>(reply.ReadInt32());
70 }
71
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)72 DMError DisplayManagerLiteProxy::UnregisterDisplayManagerAgent(
73 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
74 {
75 sptr<IRemoteObject> remote = Remote();
76 if (remote == nullptr) {
77 WLOGFW("remote is null");
78 return DMError::DM_ERROR_IPC_FAILED;
79 }
80
81 MessageParcel data;
82 MessageParcel reply;
83 MessageOption option;
84 WLOGFD("DisplayManagerLiteProxy::UnregisterDisplayManagerAgent");
85 if (!data.WriteInterfaceToken(GetDescriptor())) {
86 WLOGFE("UnregisterDisplayManagerAgent WriteInterfaceToken failed");
87 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
88 }
89
90 if (displayManagerAgent == nullptr) {
91 WLOGFE("IDisplayManagerAgent is null");
92 return DMError::DM_ERROR_INVALID_PARAM;
93 }
94
95 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
96 WLOGFE("Write IWindowManagerAgent failed");
97 return DMError::DM_ERROR_IPC_FAILED;
98 }
99
100 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
101 WLOGFE("Write DisplayManagerAgent type failed");
102 return DMError::DM_ERROR_IPC_FAILED;
103 }
104
105 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT),
106 data, reply, option) != ERR_NONE) {
107 WLOGFE("SendRequest failed");
108 return DMError::DM_ERROR_IPC_FAILED;
109 }
110 return static_cast<DMError>(reply.ReadInt32());
111 }
112
GetFoldDisplayMode()113 FoldDisplayMode DisplayManagerLiteProxy::GetFoldDisplayMode()
114 {
115 sptr<IRemoteObject> remote = Remote();
116 if (remote == nullptr) {
117 WLOGFW("remote is null");
118 return FoldDisplayMode::UNKNOWN;
119 }
120 MessageParcel data;
121 MessageParcel reply;
122 MessageOption option;
123 if (!data.WriteInterfaceToken(GetDescriptor())) {
124 WLOGFE("WriteInterfaceToken Failed");
125 return FoldDisplayMode::UNKNOWN;
126 }
127 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE),
128 data, reply, option) != ERR_NONE) {
129 WLOGFE("Send TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE request failed");
130 return FoldDisplayMode::UNKNOWN;
131 }
132 return static_cast<FoldDisplayMode>(reply.ReadUint32());
133 }
134
SetFoldDisplayMode(const FoldDisplayMode displayMode)135 void DisplayManagerLiteProxy::SetFoldDisplayMode(const FoldDisplayMode displayMode)
136 {
137 sptr<IRemoteObject> remote = Remote();
138 if (remote == nullptr) {
139 WLOGFW("remote is null");
140 return;
141 }
142 MessageParcel data;
143 MessageParcel reply;
144 MessageOption option;
145 if (!data.WriteInterfaceToken(GetDescriptor())) {
146 WLOGFE("WriteInterfaceToken Failed");
147 return;
148 }
149 if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
150 WLOGFE("Write displayMode failed");
151 return;
152 }
153 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE),
154 data, reply, option) != ERR_NONE) {
155 WLOGFE("Send TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE request failed");
156 }
157 }
158
IsFoldable()159 bool DisplayManagerLiteProxy::IsFoldable()
160 {
161 sptr<IRemoteObject> remote = Remote();
162 if (remote == nullptr) {
163 WLOGFW("remote is null");
164 return false;
165 }
166
167 MessageParcel data;
168 MessageParcel reply;
169 MessageOption option;
170 if (!data.WriteInterfaceToken(GetDescriptor())) {
171 WLOGFE("IsFoldable WriteInterfaceToken failed");
172 return false;
173 }
174 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_IS_FOLDABLE),
175 data, reply, option) != ERR_NONE) {
176 WLOGFE("SendRequest failed");
177 return false;
178 }
179 return reply.ReadBool();
180 }
181
GetFoldStatus()182 FoldStatus DisplayManagerLiteProxy::GetFoldStatus()
183 {
184 sptr<IRemoteObject> remote = Remote();
185 if (remote == nullptr) {
186 WLOGFW("remote is null");
187 return FoldStatus::UNKNOWN;
188 }
189
190 MessageParcel data;
191 MessageParcel reply;
192 MessageOption option;
193 if (!data.WriteInterfaceToken(GetDescriptor())) {
194 WLOGFE("WriteInterfaceToken failed");
195 return FoldStatus::UNKNOWN;
196 }
197 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_STATUS),
198 data, reply, option) != ERR_NONE) {
199 WLOGFE("SendRequest failed");
200 return FoldStatus::UNKNOWN;
201 }
202 return static_cast<FoldStatus>(reply.ReadUint32());
203 }
204
GetDefaultDisplayInfo()205 sptr<DisplayInfo> OHOS::Rosen::DisplayManagerLiteProxy::GetDefaultDisplayInfo()
206 {
207 sptr<IRemoteObject> remote = Remote();
208 if (remote == nullptr) {
209 WLOGFW("remote is null");
210 return nullptr;
211 }
212
213 MessageParcel data;
214 MessageParcel reply;
215 MessageOption option;
216 if (!data.WriteInterfaceToken(GetDescriptor())) {
217 WLOGFE("WriteInterfaceToken failed");
218 return nullptr;
219 }
220 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO),
221 data, reply, option) != ERR_NONE) {
222 WLOGFE("SendRequest failed");
223 return nullptr;
224 }
225
226 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
227 if (info == nullptr) {
228 WLOGFW("read display info failed, info is nullptr.");
229 }
230 return info;
231 }
232
GetDisplayInfoById(DisplayId displayId)233 sptr<DisplayInfo> DisplayManagerLiteProxy::GetDisplayInfoById(DisplayId displayId)
234 {
235 sptr<IRemoteObject> remote = Remote();
236 if (remote == nullptr) {
237 WLOGFW("GetDisplayInfoById: remote is nullptr");
238 return nullptr;
239 }
240
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option;
244 if (!data.WriteInterfaceToken(GetDescriptor())) {
245 WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed");
246 return nullptr;
247 }
248 if (!data.WriteUint64(displayId)) {
249 WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed");
250 return nullptr;
251 }
252 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID),
253 data, reply, option) != ERR_NONE) {
254 WLOGFW("GetDisplayInfoById: SendRequest failed");
255 return nullptr;
256 }
257
258 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
259 if (info == nullptr) {
260 WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr.");
261 return nullptr;
262 }
263 return info;
264 }
265
GetCutoutInfo(DisplayId displayId)266 sptr<CutoutInfo> DisplayManagerLiteProxy::GetCutoutInfo(DisplayId displayId)
267 {
268 sptr<IRemoteObject> remote = Remote();
269 if (remote == nullptr) {
270 WLOGFW("get cutout info : remote is null");
271 return nullptr;
272 }
273 MessageParcel data;
274 MessageParcel reply;
275 MessageOption option;
276 if (!data.WriteInterfaceToken(GetDescriptor())) {
277 WLOGFE("get cutout info : failed");
278 return nullptr;
279 }
280 if (!data.WriteUint64(displayId)) {
281 WLOGFE("get cutout info: write displayId failed");
282 return nullptr;
283 }
284 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO),
285 data, reply, option) != ERR_NONE) {
286 WLOGFW("GetCutoutInfo: GetCutoutInfo failed");
287 return nullptr;
288 }
289 sptr<CutoutInfo> info = reply.ReadParcelable<CutoutInfo>();
290 return info;
291 }
292
GetVirtualScreenFlag(ScreenId screenId)293 VirtualScreenFlag DisplayManagerLiteProxy::GetVirtualScreenFlag(ScreenId screenId)
294 {
295 sptr<IRemoteObject> remote = Remote();
296 if (remote == nullptr) {
297 WLOGFE("GetVirtualScreenFlag: remote is null");
298 return VirtualScreenFlag::DEFAULT;
299 }
300
301 if (screenId == SCREEN_ID_INVALID) {
302 return VirtualScreenFlag::DEFAULT;
303 }
304 MessageOption option(MessageOption::TF_SYNC);
305 MessageParcel reply;
306 MessageParcel data;
307 WLOGFE("MessageParcel definded");
308 if (!data.WriteInterfaceToken(GetDescriptor())) {
309 WLOGFE("failed");
310 return VirtualScreenFlag::DEFAULT;
311 }
312 WLOGFE("WriteInterfaceToken success");
313 if (!data.WriteUint64(screenId)) {
314 WLOGFE("Write failed");
315 return VirtualScreenFlag::DEFAULT;
316 }
317 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_VIRTUAL_SCREEN_FLAG),
318 data, reply, option) != ERR_NONE) {
319 WLOGFE("SendRequest failed");
320 return VirtualScreenFlag::DEFAULT;
321 }
322 return static_cast<VirtualScreenFlag>(reply.ReadUint32());
323 }
324
325 /*
326 * used by powermgr
327 */
WakeUpBegin(PowerStateChangeReason reason)328 bool DisplayManagerLiteProxy::WakeUpBegin(PowerStateChangeReason reason)
329 {
330 sptr<IRemoteObject> remote = Remote();
331 if (remote == nullptr) {
332 WLOGFE("[UL_POWER]WakeUpBegin remote is nullptr");
333 return false;
334 }
335
336 MessageParcel data;
337 MessageParcel reply;
338 MessageOption option;
339
340 if (!data.WriteInterfaceToken(GetDescriptor())) {
341 WLOGFE("[UL_POWER]WakeUpBegin: WriteInterfaceToken failed");
342 return false;
343 }
344 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
345 WLOGFE("[UL_POWER]WakeUpBegin: Write PowerStateChangeReason failed");
346 return false;
347 }
348 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN),
349 data, reply, option) != ERR_NONE) {
350 WLOGFW("[UL_POWER]WakeUpBegin: SendRequest failed");
351 return false;
352 }
353 return reply.ReadBool();
354 }
355
WakeUpEnd()356 bool DisplayManagerLiteProxy::WakeUpEnd()
357 {
358 sptr<IRemoteObject> remote = Remote();
359 if (remote == nullptr) {
360 WLOGFE("[UL_POWER]WakeUpEnd remote is nullptr");
361 return false;
362 }
363
364 MessageParcel data;
365 MessageParcel reply;
366 MessageOption option;
367
368 if (!data.WriteInterfaceToken(GetDescriptor())) {
369 WLOGFE("[UL_POWER]WakeUpEnd: WriteInterfaceToken failed");
370 return false;
371 }
372 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_END),
373 data, reply, option) != ERR_NONE) {
374 WLOGFW("[UL_POWER]WakeUpEnd: SendRequest failed");
375 return false;
376 }
377 return reply.ReadBool();
378 }
379
SuspendBegin(PowerStateChangeReason reason)380 bool DisplayManagerLiteProxy::SuspendBegin(PowerStateChangeReason reason)
381 {
382 sptr<IRemoteObject> remote = Remote();
383 if (remote == nullptr) {
384 WLOGFE("[UL_POWER]SuspendBegin remote is nullptr");
385 return false;
386 }
387
388 MessageParcel data;
389 MessageParcel reply;
390 MessageOption option;
391
392 if (!data.WriteInterfaceToken(GetDescriptor())) {
393 WLOGFE("[UL_POWER]SuspendBegin: WriteInterfaceToken failed");
394 return false;
395 }
396 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
397 WLOGFE("[UL_POWER]SuspendBegin: Write PowerStateChangeReason failed");
398 return false;
399 }
400 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN),
401 data, reply, option) != ERR_NONE) {
402 WLOGFW("[UL_POWER]SuspendBegin: SendRequest failed");
403 return false;
404 }
405 return reply.ReadBool();
406 }
407
SuspendEnd()408 bool DisplayManagerLiteProxy::SuspendEnd()
409 {
410 sptr<IRemoteObject> remote = Remote();
411 if (remote == nullptr) {
412 WLOGFE("[UL_POWER]SuspendEnd remote is nullptr");
413 return false;
414 }
415
416 MessageParcel data;
417 MessageParcel reply;
418 MessageOption option;
419
420 if (!data.WriteInterfaceToken(GetDescriptor())) {
421 WLOGFE("[UL_POWER]SuspendEnd: WriteInterfaceToken failed");
422 return false;
423 }
424 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_END),
425 data, reply, option) != ERR_NONE) {
426 WLOGFW("[UL_POWER]SuspendEnd: SendRequest failed");
427 return false;
428 }
429 return reply.ReadBool();
430 }
431
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)432 bool DisplayManagerLiteProxy::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
433 PowerStateChangeReason reason)
434 {
435 sptr<IRemoteObject> remote = Remote();
436 if (remote == nullptr) {
437 WLOGFE("[UL_POWER]SetSpecifiedScreenPower remote is nullptr");
438 return false;
439 }
440
441 MessageParcel data;
442 MessageParcel reply;
443 MessageOption option;
444 if (!data.WriteInterfaceToken(GetDescriptor())) {
445 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
446 return false;
447 }
448 if (!data.WriteUint32(static_cast<uint32_t>(screenId))) {
449 WLOGFE("[UL_POWER]Write ScreenId failed");
450 return false;
451 }
452 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
453 WLOGFE("[UL_POWER]Write ScreenPowerState failed");
454 return false;
455 }
456 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
457 WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
458 return false;
459 }
460 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER),
461 data, reply, option) != ERR_NONE) {
462 WLOGFW("[UL_POWER]SendRequest failed");
463 return false;
464 }
465 return reply.ReadBool();
466 }
467
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)468 bool DisplayManagerLiteProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
469 {
470 sptr<IRemoteObject> remote = Remote();
471 if (remote == nullptr) {
472 WLOGFE("[UL_POWER]SetScreenPowerForAll remote is nullptr");
473 return false;
474 }
475
476 MessageParcel data;
477 MessageParcel reply;
478 MessageOption option;
479 if (!data.WriteInterfaceToken(GetDescriptor())) {
480 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
481 return false;
482 }
483 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
484 WLOGFE("[UL_POWER]Write ScreenPowerState failed");
485 return false;
486 }
487 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
488 WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
489 return false;
490 }
491 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL),
492 data, reply, option) != ERR_NONE) {
493 WLOGFW("[UL_POWER]SendRequest failed");
494 return false;
495 }
496 return reply.ReadBool();
497 }
498
GetScreenPower(ScreenId dmsScreenId)499 ScreenPowerState DisplayManagerLiteProxy::GetScreenPower(ScreenId dmsScreenId)
500 {
501 sptr<IRemoteObject> remote = Remote();
502 if (remote == nullptr) {
503 WLOGFE("GetScreenPower remote is nullptr");
504 return ScreenPowerState::INVALID_STATE;
505 }
506
507 MessageParcel data;
508 MessageParcel reply;
509 MessageOption option;
510 if (!data.WriteInterfaceToken(GetDescriptor())) {
511 WLOGFE("WriteInterfaceToken failed");
512 return ScreenPowerState::INVALID_STATE;
513 }
514 if (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
515 WLOGFE("Write dmsScreenId failed");
516 return ScreenPowerState::INVALID_STATE;
517 }
518 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
519 data, reply, option) != ERR_NONE) {
520 WLOGFW("SendRequest failed");
521 return ScreenPowerState::INVALID_STATE;
522 }
523 return static_cast<ScreenPowerState>(reply.ReadUint32());
524 }
525
GetScreenPower()526 ScreenPowerState DisplayManagerLiteProxy::GetScreenPower()
527 {
528 sptr<IRemoteObject> remote = Remote();
529 if (remote == nullptr) {
530 WLOGFE("GetScreenPower remote is nullptr");
531 return ScreenPowerState::INVALID_STATE;
532 }
533
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option;
537 if (!data.WriteInterfaceToken(GetDescriptor())) {
538 WLOGFE("WriteInterfaceToken failed");
539 return ScreenPowerState::INVALID_STATE;
540 }
541 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER_AUTO),
542 data, reply, option) != ERR_NONE) {
543 WLOGFW("SendRequest failed");
544 return ScreenPowerState::INVALID_STATE;
545 }
546 return static_cast<ScreenPowerState>(reply.ReadUint32());
547 }
548
SetDisplayState(DisplayState state)549 bool DisplayManagerLiteProxy::SetDisplayState(DisplayState state)
550 {
551 sptr<IRemoteObject> remote = Remote();
552 if (remote == nullptr) {
553 WLOGFE("[UL_POWER]SetDisplayState remote is nullptr");
554 return false;
555 }
556
557 MessageParcel data;
558 MessageParcel reply;
559 MessageOption option;
560 if (!data.WriteInterfaceToken(GetDescriptor())) {
561 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
562 return false;
563 }
564 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
565 WLOGFE("[UL_POWER]Write DisplayState failed");
566 return false;
567 }
568 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
569 data, reply, option) != ERR_NONE) {
570 WLOGFW("[UL_POWER]SendRequest failed");
571 return false;
572 }
573 return reply.ReadBool();
574 }
575
GetDisplayState(DisplayId displayId)576 DisplayState DisplayManagerLiteProxy::GetDisplayState(DisplayId displayId)
577 {
578 sptr<IRemoteObject> remote = Remote();
579 if (remote == nullptr) {
580 WLOGFE("GetDisplayState remote is nullptr");
581 return DisplayState::UNKNOWN;
582 }
583
584 MessageParcel data;
585 MessageParcel reply;
586 MessageOption option;
587 if (!data.WriteInterfaceToken(GetDescriptor())) {
588 WLOGFE("WriteInterfaceToken failed");
589 return DisplayState::UNKNOWN;
590 }
591 if (!data.WriteUint64(displayId)) {
592 WLOGFE("Write displayId failed");
593 return DisplayState::UNKNOWN;
594 }
595 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
596 data, reply, option) != ERR_NONE) {
597 WLOGFW("SendRequest failed");
598 return DisplayState::UNKNOWN;
599 }
600 return static_cast<DisplayState>(reply.ReadUint32());
601 }
602
TryToCancelScreenOff()603 bool DisplayManagerLiteProxy::TryToCancelScreenOff()
604 {
605 sptr<IRemoteObject> remote = Remote();
606 if (remote == nullptr) {
607 WLOGFE("[UL_POWER]TryToCancelScreenOff remote is nullptr");
608 return false;
609 }
610
611 MessageParcel data;
612 MessageParcel reply;
613 MessageOption option;
614
615 if (!data.WriteInterfaceToken(GetDescriptor())) {
616 WLOGFE("[UL_POWER]TryToCancelScreenOff: WriteInterfaceToken failed");
617 return false;
618 }
619 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
620 data, reply, option) != ERR_NONE) {
621 WLOGFW("[UL_POWER]TryToCancelScreenOff: SendRequest failed");
622 return false;
623 }
624 return reply.ReadBool();
625 }
626
SetScreenBrightness(uint64_t screenId,uint32_t level)627 bool DisplayManagerLiteProxy::SetScreenBrightness(uint64_t screenId, uint32_t level)
628 {
629 sptr<IRemoteObject> remote = Remote();
630 if (remote == nullptr) {
631 WLOGFE("SetScreenBrightness remote is nullptr");
632 return false;
633 }
634
635 MessageParcel data;
636 MessageParcel reply;
637 MessageOption option;
638 if (!data.WriteInterfaceToken(GetDescriptor())) {
639 WLOGFE("WriteInterfaceToken failed");
640 return false;
641 }
642 if (!data.WriteUint64(screenId)) {
643 WLOGFE("Write screenId failed");
644 return false;
645 }
646 if (!data.WriteUint64(level)) {
647 WLOGFE("Write level failed");
648 return false;
649 }
650 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_BRIGHTNESS),
651 data, reply, option) != ERR_NONE) {
652 WLOGFW("SendRequest failed");
653 return false;
654 }
655 return reply.ReadBool();
656 }
657
GetScreenBrightness(uint64_t screenId)658 uint32_t DisplayManagerLiteProxy::GetScreenBrightness(uint64_t screenId)
659 {
660 sptr<IRemoteObject> remote = Remote();
661 if (remote == nullptr) {
662 WLOGFE("GetScreenBrightness remote is nullptr");
663 return 0;
664 }
665
666 MessageParcel data;
667 MessageParcel reply;
668 MessageOption option;
669 if (!data.WriteInterfaceToken(GetDescriptor())) {
670 WLOGFE("WriteInterfaceToken failed");
671 return 0;
672 }
673 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
674 WLOGFE("Write screenId failed");
675 return 0;
676 }
677 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_BRIGHTNESS),
678 data, reply, option) != ERR_NONE) {
679 WLOGFW("SendRequest failed");
680 return 0;
681 }
682 return reply.ReadUint32();
683 }
684
GetAllDisplayIds()685 std::vector<DisplayId> DisplayManagerLiteProxy::GetAllDisplayIds()
686 {
687 sptr<IRemoteObject> remote = Remote();
688 if (remote == nullptr) {
689 WLOGFE("[UL_POWER]GetAllDisplayIds remote is nullptr");
690 return {};
691 }
692
693 std::vector<DisplayId> allDisplayIds;
694 MessageParcel data;
695 MessageParcel reply;
696 MessageOption option;
697 if (!data.WriteInterfaceToken(GetDescriptor())) {
698 WLOGFE("WriteInterfaceToken failed");
699 return allDisplayIds;
700 }
701 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
702 data, reply, option) != ERR_NONE) {
703 WLOGFW("SendRequest failed");
704 return allDisplayIds;
705 }
706 reply.ReadUInt64Vector(&allDisplayIds);
707 return allDisplayIds;
708 }
709
710 } // namespace OHOS::Rosen
711