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
SetDisplayState(DisplayState state)526 bool DisplayManagerLiteProxy::SetDisplayState(DisplayState state)
527 {
528 sptr<IRemoteObject> remote = Remote();
529 if (remote == nullptr) {
530 WLOGFE("[UL_POWER]SetDisplayState remote is nullptr");
531 return false;
532 }
533
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option;
537 if (!data.WriteInterfaceToken(GetDescriptor())) {
538 WLOGFE("[UL_POWER]WriteInterfaceToken failed");
539 return false;
540 }
541 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
542 WLOGFE("[UL_POWER]Write DisplayState failed");
543 return false;
544 }
545 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
546 data, reply, option) != ERR_NONE) {
547 WLOGFW("[UL_POWER]SendRequest failed");
548 return false;
549 }
550 return reply.ReadBool();
551 }
552
GetDisplayState(DisplayId displayId)553 DisplayState DisplayManagerLiteProxy::GetDisplayState(DisplayId displayId)
554 {
555 sptr<IRemoteObject> remote = Remote();
556 if (remote == nullptr) {
557 WLOGFE("GetDisplayState remote is nullptr");
558 return DisplayState::UNKNOWN;
559 }
560
561 MessageParcel data;
562 MessageParcel reply;
563 MessageOption option;
564 if (!data.WriteInterfaceToken(GetDescriptor())) {
565 WLOGFE("WriteInterfaceToken failed");
566 return DisplayState::UNKNOWN;
567 }
568 if (!data.WriteUint64(displayId)) {
569 WLOGFE("Write displayId failed");
570 return DisplayState::UNKNOWN;
571 }
572 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
573 data, reply, option) != ERR_NONE) {
574 WLOGFW("SendRequest failed");
575 return DisplayState::UNKNOWN;
576 }
577 return static_cast<DisplayState>(reply.ReadUint32());
578 }
579
TryToCancelScreenOff()580 bool DisplayManagerLiteProxy::TryToCancelScreenOff()
581 {
582 sptr<IRemoteObject> remote = Remote();
583 if (remote == nullptr) {
584 WLOGFE("[UL_POWER]TryToCancelScreenOff remote is nullptr");
585 return false;
586 }
587
588 MessageParcel data;
589 MessageParcel reply;
590 MessageOption option;
591
592 if (!data.WriteInterfaceToken(GetDescriptor())) {
593 WLOGFE("[UL_POWER]TryToCancelScreenOff: WriteInterfaceToken failed");
594 return false;
595 }
596 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
597 data, reply, option) != ERR_NONE) {
598 WLOGFW("[UL_POWER]TryToCancelScreenOff: SendRequest failed");
599 return false;
600 }
601 return reply.ReadBool();
602 }
603
SetScreenBrightness(uint64_t screenId,uint32_t level)604 bool DisplayManagerLiteProxy::SetScreenBrightness(uint64_t screenId, uint32_t level)
605 {
606 sptr<IRemoteObject> remote = Remote();
607 if (remote == nullptr) {
608 WLOGFE("SetScreenBrightness remote is nullptr");
609 return false;
610 }
611
612 MessageParcel data;
613 MessageParcel reply;
614 MessageOption option;
615 if (!data.WriteInterfaceToken(GetDescriptor())) {
616 WLOGFE("WriteInterfaceToken failed");
617 return false;
618 }
619 if (!data.WriteUint64(screenId)) {
620 WLOGFE("Write screenId failed");
621 return false;
622 }
623 if (!data.WriteUint64(level)) {
624 WLOGFE("Write level failed");
625 return false;
626 }
627 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_BRIGHTNESS),
628 data, reply, option) != ERR_NONE) {
629 WLOGFW("SendRequest failed");
630 return false;
631 }
632 return reply.ReadBool();
633 }
634
GetScreenBrightness(uint64_t screenId)635 uint32_t DisplayManagerLiteProxy::GetScreenBrightness(uint64_t screenId)
636 {
637 sptr<IRemoteObject> remote = Remote();
638 if (remote == nullptr) {
639 WLOGFE("GetScreenBrightness remote is nullptr");
640 return 0;
641 }
642
643 MessageParcel data;
644 MessageParcel reply;
645 MessageOption option;
646 if (!data.WriteInterfaceToken(GetDescriptor())) {
647 WLOGFE("WriteInterfaceToken failed");
648 return 0;
649 }
650 if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
651 WLOGFE("Write screenId failed");
652 return 0;
653 }
654 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_BRIGHTNESS),
655 data, reply, option) != ERR_NONE) {
656 WLOGFW("SendRequest failed");
657 return 0;
658 }
659 return reply.ReadUint32();
660 }
661
GetAllDisplayIds()662 std::vector<DisplayId> DisplayManagerLiteProxy::GetAllDisplayIds()
663 {
664 sptr<IRemoteObject> remote = Remote();
665 if (remote == nullptr) {
666 WLOGFE("[UL_POWER]GetAllDisplayIds remote is nullptr");
667 return {};
668 }
669
670 std::vector<DisplayId> allDisplayIds;
671 MessageParcel data;
672 MessageParcel reply;
673 MessageOption option;
674 if (!data.WriteInterfaceToken(GetDescriptor())) {
675 WLOGFE("WriteInterfaceToken failed");
676 return allDisplayIds;
677 }
678 if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
679 data, reply, option) != ERR_NONE) {
680 WLOGFW("SendRequest failed");
681 return allDisplayIds;
682 }
683 reply.ReadUInt64Vector(&allDisplayIds);
684 return allDisplayIds;
685 }
686
687 } // namespace OHOS::Rosen
688