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 /*
293 * used by powermgr
294 */
WakeUpBegin(PowerStateChangeReason reason)295 bool DisplayManagerLiteProxy::WakeUpBegin(PowerStateChangeReason reason)
296 {
297 sptr<IRemoteObject> remote = Remote();
298 if (remote == nullptr) {
299 WLOGFE("[UL_POWER]WakeUpBegin remote is nullptr");
300 return false;
301 }
302
303 MessageParcel data;
304 MessageParcel reply;
305 MessageOption option;
306
307 if (!data.WriteInterfaceToken(GetDescriptor())) {
308 WLOGFE("[UL_POWER]WakeUpBegin: WriteInterfaceToken failed");
309 return false;
310 }
311 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
312 WLOGFE("[UL_POWER]WakeUpBegin: Write PowerStateChangeReason failed");
313 return false;
314 }
315 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN),
316 data, reply, option) != ERR_NONE) {
317 WLOGFW("[UL_POWER]WakeUpBegin: SendRequest failed");
318 return false;
319 }
320 return reply.ReadBool();
321 }
322
WakeUpEnd()323 bool DisplayManagerLiteProxy::WakeUpEnd()
324 {
325 sptr<IRemoteObject> remote = Remote();
326 if (remote == nullptr) {
327 WLOGFE("[UL_POWER]WakeUpEnd remote is nullptr");
328 return false;
329 }
330
331 MessageParcel data;
332 MessageParcel reply;
333 MessageOption option;
334
335 if (!data.WriteInterfaceToken(GetDescriptor())) {
336 WLOGFE("[UL_POWER]WakeUpEnd: WriteInterfaceToken failed");
337 return false;
338 }
339 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_END),
340 data, reply, option) != ERR_NONE) {
341 WLOGFW("[UL_POWER]WakeUpEnd: SendRequest failed");
342 return false;
343 }
344 return reply.ReadBool();
345 }
346
SuspendBegin(PowerStateChangeReason reason)347 bool DisplayManagerLiteProxy::SuspendBegin(PowerStateChangeReason reason)
348 {
349 sptr<IRemoteObject> remote = Remote();
350 if (remote == nullptr) {
351 WLOGFE("[UL_POWER]SuspendBegin remote is nullptr");
352 return false;
353 }
354
355 MessageParcel data;
356 MessageParcel reply;
357 MessageOption option;
358
359 if (!data.WriteInterfaceToken(GetDescriptor())) {
360 WLOGFE("[UL_POWER]SuspendBegin: WriteInterfaceToken failed");
361 return false;
362 }
363 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
364 WLOGFE("[UL_POWER]SuspendBegin: Write PowerStateChangeReason failed");
365 return false;
366 }
367 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN),
368 data, reply, option) != ERR_NONE) {
369 WLOGFW("[UL_POWER]SuspendBegin: SendRequest failed");
370 return false;
371 }
372 return reply.ReadBool();
373 }
374
SuspendEnd()375 bool DisplayManagerLiteProxy::SuspendEnd()
376 {
377 sptr<IRemoteObject> remote = Remote();
378 if (remote == nullptr) {
379 WLOGFE("[UL_POWER]SuspendEnd remote is nullptr");
380 return false;
381 }
382
383 MessageParcel data;
384 MessageParcel reply;
385 MessageOption option;
386
387 if (!data.WriteInterfaceToken(GetDescriptor())) {
388 WLOGFE("[UL_POWER]SuspendEnd: WriteInterfaceToken failed");
389 return false;
390 }
391 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_END),
392 data, reply, option) != ERR_NONE) {
393 WLOGFW("[UL_POWER]SuspendEnd: SendRequest failed");
394 return false;
395 }
396 return reply.ReadBool();
397 }
398
GetInternalScreenId()399 ScreenId DisplayManagerLiteProxy::GetInternalScreenId()
400 {
401 sptr<IRemoteObject> remote = Remote();
402 if (remote == nullptr) {
403 WLOGFE("[UL_POWER]GetInternalScreenId remote is nullptr");
404 return SCREEN_ID_INVALID;
405 }
406
407 MessageParcel data;
408 MessageParcel reply;
409 MessageOption option(MessageOption::TF_SYNC);
410
411 if (!data.WriteInterfaceToken(GetDescriptor())) {
412 WLOGFE("[UL_POWER]GetInternalScreenId: WriteInterfaceToken failed");
413 return SCREEN_ID_INVALID;
414 }
415 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_INTERNAL_SCREEN_ID),
416 data, reply, option) != ERR_NONE) {
417 WLOGFW("[UL_POWER]GetInternalScreenId: SendRequest failed");
418 return SCREEN_ID_INVALID;
419 }
420 return reply.ReadUint64();
421 }
422
SetScreenPowerById(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason)423 bool DisplayManagerLiteProxy::SetScreenPowerById(ScreenId screenId, ScreenPowerState state,
424 PowerStateChangeReason reason)
425 {
426 sptr<IRemoteObject> remote = Remote();
427 if (remote == nullptr) {
428 WLOGFE("[UL_POWER]SetScreenPowerById remote is nullptr");
429 return false;
430 }
431
432 MessageParcel data;
433 MessageParcel reply;
434 MessageOption option(MessageOption::TF_SYNC);
435 if (!data.WriteInterfaceToken(GetDescriptor())) {
436 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
437 return false;
438 }
439 if (!data.WriteUint64(screenId)) {
440 WLOGFE("[UL_POWER]Write ScreenId failed");
441 return false;
442 }
443 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
444 WLOGFE("[UL_POWER]Write ScreenPowerState failed");
445 return false;
446 }
447 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
448 WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
449 return false;
450 }
451 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_BY_ID),
452 data, reply, option) != ERR_NONE) {
453 WLOGFW("[UL_POWER]SendRequest failed");
454 return false;
455 }
456 return reply.ReadBool();
457 }
458
SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason)459 bool DisplayManagerLiteProxy::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
460 PowerStateChangeReason reason)
461 {
462 sptr<IRemoteObject> remote = Remote();
463 if (remote == nullptr) {
464 WLOGFE("[UL_POWER]SetSpecifiedScreenPower remote is nullptr");
465 return false;
466 }
467
468 MessageParcel data;
469 MessageParcel reply;
470 MessageOption option;
471 if (!data.WriteInterfaceToken(GetDescriptor())) {
472 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
473 return false;
474 }
475 if (!data.WriteUint32(static_cast<uint32_t>(screenId))) {
476 WLOGFE("[UL_POWER]Write ScreenId failed");
477 return false;
478 }
479 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
480 WLOGFE("[UL_POWER]Write ScreenPowerState failed");
481 return false;
482 }
483 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
484 WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
485 return false;
486 }
487 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER),
488 data, reply, option) != ERR_NONE) {
489 WLOGFW("[UL_POWER]SendRequest failed");
490 return false;
491 }
492 return reply.ReadBool();
493 }
494
SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)495 bool DisplayManagerLiteProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
496 {
497 sptr<IRemoteObject> remote = Remote();
498 if (remote == nullptr) {
499 WLOGFE("[UL_POWER]SetScreenPowerForAll remote is nullptr");
500 return false;
501 }
502
503 MessageParcel data;
504 MessageParcel reply;
505 MessageOption option;
506 if (!data.WriteInterfaceToken(GetDescriptor())) {
507 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
508 return false;
509 }
510 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
511 WLOGFE("[UL_POWER]Write ScreenPowerState failed");
512 return false;
513 }
514 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
515 WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
516 return false;
517 }
518 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL),
519 data, reply, option) != ERR_NONE) {
520 WLOGFW("[UL_POWER]SendRequest failed");
521 return false;
522 }
523 return reply.ReadBool();
524 }
525
GetScreenPower(ScreenId dmsScreenId)526 ScreenPowerState DisplayManagerLiteProxy::GetScreenPower(ScreenId dmsScreenId)
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 (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
542 WLOGFE("Write dmsScreenId failed");
543 return ScreenPowerState::INVALID_STATE;
544 }
545 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
546 data, reply, option) != ERR_NONE) {
547 WLOGFW("SendRequest failed");
548 return ScreenPowerState::INVALID_STATE;
549 }
550 return static_cast<ScreenPowerState>(reply.ReadUint32());
551 }
552
SetDisplayState(DisplayState state)553 bool DisplayManagerLiteProxy::SetDisplayState(DisplayState state)
554 {
555 sptr<IRemoteObject> remote = Remote();
556 if (remote == nullptr) {
557 WLOGFE("[UL_POWER]SetDisplayState remote is nullptr");
558 return false;
559 }
560
561 MessageParcel data;
562 MessageParcel reply;
563 MessageOption option;
564 if (!data.WriteInterfaceToken(GetDescriptor())) {
565 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
566 return false;
567 }
568 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
569 WLOGFE("[UL_POWER]Write DisplayState failed");
570 return false;
571 }
572 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
573 data, reply, option) != ERR_NONE) {
574 WLOGFW("[UL_POWER]SendRequest failed");
575 return false;
576 }
577 return reply.ReadBool();
578 }
579
GetDisplayState(DisplayId displayId)580 DisplayState DisplayManagerLiteProxy::GetDisplayState(DisplayId displayId)
581 {
582 sptr<IRemoteObject> remote = Remote();
583 if (remote == nullptr) {
584 WLOGFE("GetDisplayState remote is nullptr");
585 return DisplayState::UNKNOWN;
586 }
587
588 MessageParcel data;
589 MessageParcel reply;
590 MessageOption option;
591 if (!data.WriteInterfaceToken(GetDescriptor())) {
592 WLOGFE("WriteInterfaceToken failed");
593 return DisplayState::UNKNOWN;
594 }
595 if (!data.WriteUint64(displayId)) {
596 WLOGFE("Write displayId failed");
597 return DisplayState::UNKNOWN;
598 }
599 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
600 data, reply, option) != ERR_NONE) {
601 WLOGFW("SendRequest failed");
602 return DisplayState::UNKNOWN;
603 }
604 return static_cast<DisplayState>(reply.ReadUint32());
605 }
606
TryToCancelScreenOff()607 bool DisplayManagerLiteProxy::TryToCancelScreenOff()
608 {
609 sptr<IRemoteObject> remote = Remote();
610 if (remote == nullptr) {
611 WLOGFE("[UL_POWER]TryToCancelScreenOff remote is nullptr");
612 return false;
613 }
614
615 MessageParcel data;
616 MessageParcel reply;
617 MessageOption option;
618
619 if (!data.WriteInterfaceToken(GetDescriptor())) {
620 WLOGFE("[UL_POWER]TryToCancelScreenOff: WriteInterfaceToken failed");
621 return false;
622 }
623 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
624 data, reply, option) != ERR_NONE) {
625 WLOGFW("[UL_POWER]TryToCancelScreenOff: SendRequest failed");
626 return false;
627 }
628 return reply.ReadBool();
629 }
630
SetScreenBrightness(uint64_t screenId, uint32_t level)631 bool DisplayManagerLiteProxy::SetScreenBrightness(uint64_t screenId, uint32_t level)
632 {
633 sptr<IRemoteObject> remote = Remote();
634 if (remote == nullptr) {
635 WLOGFE("SetScreenBrightness remote is nullptr");
636 return false;
637 }
638
639 MessageParcel data;
640 MessageParcel reply;
641 MessageOption option;
642 if (!data.WriteInterfaceToken(GetDescriptor())) {
643 WLOGFE("WriteInterfaceToken failed");
644 return false;
645 }
646 if (!data.WriteUint64(screenId)) {
647 WLOGFE("Write screenId failed");
648 return false;
649 }
650 if (!data.WriteUint64(level)) {
651 WLOGFE("Write level failed");
652 return false;
653 }
654 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_BRIGHTNESS),
655 data, reply, option) != ERR_NONE) {
656 WLOGFW("SendRequest failed");
657 return false;
658 }
659 return reply.ReadBool();
660 }
661
GetScreenBrightness(uint64_t screenId)662 uint32_t DisplayManagerLiteProxy::GetScreenBrightness(uint64_t screenId)
663 {
664 sptr<IRemoteObject> remote = Remote();
665 if (remote == nullptr) {
666 WLOGFE("GetScreenBrightness remote is nullptr");
667 return 0;
668 }
669
670 MessageParcel data;
671 MessageParcel reply;
672 MessageOption option;
673 if (!data.WriteInterfaceToken(GetDescriptor())) {
674 WLOGFE("WriteInterfaceToken failed");
675 return 0;
676 }
677 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
678 WLOGFE("Write screenId failed");
679 return 0;
680 }
681 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_BRIGHTNESS),
682 data, reply, option) != ERR_NONE) {
683 WLOGFW("SendRequest failed");
684 return 0;
685 }
686 return reply.ReadUint32();
687 }
688
GetAllDisplayIds()689 std::vector<DisplayId> DisplayManagerLiteProxy::GetAllDisplayIds()
690 {
691 sptr<IRemoteObject> remote = Remote();
692 if (remote == nullptr) {
693 WLOGFE("[UL_POWER]GetAllDisplayIds remote is nullptr");
694 return {};
695 }
696
697 std::vector<DisplayId> allDisplayIds;
698 MessageParcel data;
699 MessageParcel reply;
700 MessageOption option;
701 if (!data.WriteInterfaceToken(GetDescriptor())) {
702 WLOGFE("WriteInterfaceToken failed");
703 return allDisplayIds;
704 }
705 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
706 data, reply, option) != ERR_NONE) {
707 WLOGFW("SendRequest failed");
708 return allDisplayIds;
709 }
710 reply.ReadUInt64Vector(&allDisplayIds);
711 return allDisplayIds;
712 }
713
714 } // namespace OHOS::Rosen
715