• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     if (!data.WriteInterfaceToken(GetDescriptor())) {
308         WLOGFE("WriteInterfaceToken failed");
309         return VirtualScreenFlag::DEFAULT;
310     }
311     if (!data.WriteUint64(screenId)) {
312         WLOGFE("Write screenId failed");
313         return VirtualScreenFlag::DEFAULT;
314     }
315     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_VIRTUAL_SCREEN_FLAG),
316         data, reply, option) != ERR_NONE) {
317         WLOGFE("SendRequest failed");
318         return VirtualScreenFlag::DEFAULT;
319     }
320     return static_cast<VirtualScreenFlag>(reply.ReadUint32());
321 }
322 
323 /*
324  * used by powermgr
325  */
WakeUpBegin(PowerStateChangeReason reason)326 bool DisplayManagerLiteProxy::WakeUpBegin(PowerStateChangeReason reason)
327 {
328     sptr<IRemoteObject> remote = Remote();
329     if (remote == nullptr) {
330         WLOGFE("[UL_POWER]WakeUpBegin remote is nullptr");
331         return false;
332     }
333 
334     MessageParcel data;
335     MessageParcel reply;
336     MessageOption option;
337 
338     if (!data.WriteInterfaceToken(GetDescriptor())) {
339         WLOGFE("[UL_POWER]WakeUpBegin: WriteInterfaceToken failed");
340         return false;
341     }
342     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
343         WLOGFE("[UL_POWER]WakeUpBegin: Write PowerStateChangeReason failed");
344         return false;
345     }
346     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN),
347         data, reply, option) != ERR_NONE) {
348         WLOGFW("[UL_POWER]WakeUpBegin: SendRequest failed");
349         return false;
350     }
351     return reply.ReadBool();
352 }
353 
WakeUpEnd()354 bool DisplayManagerLiteProxy::WakeUpEnd()
355 {
356     sptr<IRemoteObject> remote = Remote();
357     if (remote == nullptr) {
358         WLOGFE("[UL_POWER]WakeUpEnd remote is nullptr");
359         return false;
360     }
361 
362     MessageParcel data;
363     MessageParcel reply;
364     MessageOption option;
365 
366     if (!data.WriteInterfaceToken(GetDescriptor())) {
367         WLOGFE("[UL_POWER]WakeUpEnd: WriteInterfaceToken failed");
368         return false;
369     }
370     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_END),
371         data, reply, option) != ERR_NONE) {
372         WLOGFW("[UL_POWER]WakeUpEnd: SendRequest failed");
373         return false;
374     }
375     return reply.ReadBool();
376 }
377 
SuspendBegin(PowerStateChangeReason reason)378 bool DisplayManagerLiteProxy::SuspendBegin(PowerStateChangeReason reason)
379 {
380     sptr<IRemoteObject> remote = Remote();
381     if (remote == nullptr) {
382         WLOGFE("[UL_POWER]SuspendBegin remote is nullptr");
383         return false;
384     }
385 
386     MessageParcel data;
387     MessageParcel reply;
388     MessageOption option;
389 
390     if (!data.WriteInterfaceToken(GetDescriptor())) {
391         WLOGFE("[UL_POWER]SuspendBegin: WriteInterfaceToken failed");
392         return false;
393     }
394     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
395         WLOGFE("[UL_POWER]SuspendBegin: Write PowerStateChangeReason failed");
396         return false;
397     }
398     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN),
399         data, reply, option) != ERR_NONE) {
400         WLOGFW("[UL_POWER]SuspendBegin: SendRequest failed");
401         return false;
402     }
403     return reply.ReadBool();
404 }
405 
SuspendEnd()406 bool DisplayManagerLiteProxy::SuspendEnd()
407 {
408     sptr<IRemoteObject> remote = Remote();
409     if (remote == nullptr) {
410         WLOGFE("[UL_POWER]SuspendEnd remote is nullptr");
411         return false;
412     }
413 
414     MessageParcel data;
415     MessageParcel reply;
416     MessageOption option;
417 
418     if (!data.WriteInterfaceToken(GetDescriptor())) {
419         WLOGFE("[UL_POWER]SuspendEnd: WriteInterfaceToken failed");
420         return false;
421     }
422     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_END),
423         data, reply, option) != ERR_NONE) {
424         WLOGFW("[UL_POWER]SuspendEnd: SendRequest failed");
425         return false;
426     }
427     return reply.ReadBool();
428 }
429 
GetInternalScreenId()430 ScreenId DisplayManagerLiteProxy::GetInternalScreenId()
431 {
432     sptr<IRemoteObject> remote = Remote();
433     if (remote == nullptr) {
434         WLOGFE("[UL_POWER]GetInternalScreenId remote is nullptr");
435         return SCREEN_ID_INVALID;
436     }
437 
438     MessageParcel data;
439     MessageParcel reply;
440     MessageOption option(MessageOption::TF_SYNC);
441 
442     if (!data.WriteInterfaceToken(GetDescriptor())) {
443         WLOGFE("[UL_POWER]GetInternalScreenId: WriteInterfaceToken failed");
444         return SCREEN_ID_INVALID;
445     }
446     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_INTERNAL_SCREEN_ID),
447         data, reply, option) != ERR_NONE) {
448         WLOGFW("[UL_POWER]GetInternalScreenId: SendRequest failed");
449         return SCREEN_ID_INVALID;
450     }
451     return reply.ReadUint64();
452 }
453 
SetScreenPowerById(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)454 bool DisplayManagerLiteProxy::SetScreenPowerById(ScreenId screenId, ScreenPowerState state,
455     PowerStateChangeReason reason)
456 {
457     sptr<IRemoteObject> remote = Remote();
458     if (remote == nullptr) {
459         WLOGFE("[UL_POWER]SetScreenPowerById remote is nullptr");
460         return false;
461     }
462 
463     MessageParcel data;
464     MessageParcel reply;
465     MessageOption option(MessageOption::TF_SYNC);
466     if (!data.WriteInterfaceToken(GetDescriptor())) {
467         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
468         return false;
469     }
470     if (!data.WriteUint64(screenId)) {
471         WLOGFE("[UL_POWER]Write ScreenId failed");
472         return false;
473     }
474     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
475         WLOGFE("[UL_POWER]Write ScreenPowerState failed");
476         return false;
477     }
478     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
479         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
480         return false;
481     }
482     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_BY_ID),
483         data, reply, option) != ERR_NONE) {
484         WLOGFW("[UL_POWER]SendRequest failed");
485         return false;
486     }
487     return reply.ReadBool();
488 }
489 
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)490 bool DisplayManagerLiteProxy::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
491     PowerStateChangeReason reason)
492 {
493     sptr<IRemoteObject> remote = Remote();
494     if (remote == nullptr) {
495         WLOGFE("[UL_POWER]SetSpecifiedScreenPower remote is nullptr");
496         return false;
497     }
498 
499     MessageParcel data;
500     MessageParcel reply;
501     MessageOption option;
502     if (!data.WriteInterfaceToken(GetDescriptor())) {
503         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
504         return false;
505     }
506     if (!data.WriteUint32(static_cast<uint32_t>(screenId))) {
507         WLOGFE("[UL_POWER]Write ScreenId 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_SPECIFIED_SCREEN_POWER),
519         data, reply, option) != ERR_NONE) {
520         WLOGFW("[UL_POWER]SendRequest failed");
521         return false;
522     }
523     return reply.ReadBool();
524 }
525 
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)526 bool DisplayManagerLiteProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
527 {
528     sptr<IRemoteObject> remote = Remote();
529     if (remote == nullptr) {
530         WLOGFE("[UL_POWER]SetScreenPowerForAll 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 ScreenPowerState failed");
543         return false;
544     }
545     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
546         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
547         return false;
548     }
549     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL),
550         data, reply, option) != ERR_NONE) {
551         WLOGFW("[UL_POWER]SendRequest failed");
552         return false;
553     }
554     return reply.ReadBool();
555 }
556 
GetScreenPower(ScreenId dmsScreenId)557 ScreenPowerState DisplayManagerLiteProxy::GetScreenPower(ScreenId dmsScreenId)
558 {
559     sptr<IRemoteObject> remote = Remote();
560     if (remote == nullptr) {
561         WLOGFE("GetScreenPower remote is nullptr");
562         return ScreenPowerState::INVALID_STATE;
563     }
564 
565     MessageParcel data;
566     MessageParcel reply;
567     MessageOption option;
568     if (!data.WriteInterfaceToken(GetDescriptor())) {
569         WLOGFE("WriteInterfaceToken failed");
570         return ScreenPowerState::INVALID_STATE;
571     }
572     if (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
573         WLOGFE("Write dmsScreenId failed");
574         return ScreenPowerState::INVALID_STATE;
575     }
576     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
577         data, reply, option) != ERR_NONE) {
578         WLOGFW("SendRequest failed");
579         return ScreenPowerState::INVALID_STATE;
580     }
581     return static_cast<ScreenPowerState>(reply.ReadUint32());
582 }
583 
GetScreenPower()584 ScreenPowerState DisplayManagerLiteProxy::GetScreenPower()
585 {
586     sptr<IRemoteObject> remote = Remote();
587     if (remote == nullptr) {
588         WLOGFE("GetScreenPower remote is nullptr");
589         return ScreenPowerState::INVALID_STATE;
590     }
591 
592     MessageParcel data;
593     MessageParcel reply;
594     MessageOption option;
595     if (!data.WriteInterfaceToken(GetDescriptor())) {
596         WLOGFE("WriteInterfaceToken failed");
597         return ScreenPowerState::INVALID_STATE;
598     }
599     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER_AUTO),
600         data, reply, option) != ERR_NONE) {
601         WLOGFW("SendRequest failed");
602         return ScreenPowerState::INVALID_STATE;
603     }
604     return static_cast<ScreenPowerState>(reply.ReadUint32());
605 }
606 
SetDisplayState(DisplayState state)607 bool DisplayManagerLiteProxy::SetDisplayState(DisplayState state)
608 {
609     sptr<IRemoteObject> remote = Remote();
610     if (remote == nullptr) {
611         WLOGFE("[UL_POWER]SetDisplayState remote is nullptr");
612         return false;
613     }
614 
615     MessageParcel data;
616     MessageParcel reply;
617     MessageOption option;
618     if (!data.WriteInterfaceToken(GetDescriptor())) {
619         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
620         return false;
621     }
622     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
623         WLOGFE("[UL_POWER]Write DisplayState failed");
624         return false;
625     }
626     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
627         data, reply, option) != ERR_NONE) {
628         WLOGFW("[UL_POWER]SendRequest failed");
629         return false;
630     }
631     return reply.ReadBool();
632 }
633 
GetDisplayState(DisplayId displayId)634 DisplayState DisplayManagerLiteProxy::GetDisplayState(DisplayId displayId)
635 {
636     sptr<IRemoteObject> remote = Remote();
637     if (remote == nullptr) {
638         WLOGFE("GetDisplayState remote is nullptr");
639         return DisplayState::UNKNOWN;
640     }
641 
642     MessageParcel data;
643     MessageParcel reply;
644     MessageOption option;
645     if (!data.WriteInterfaceToken(GetDescriptor())) {
646         WLOGFE("WriteInterfaceToken failed");
647         return DisplayState::UNKNOWN;
648     }
649     if (!data.WriteUint64(displayId)) {
650         WLOGFE("Write displayId failed");
651         return DisplayState::UNKNOWN;
652     }
653     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
654         data, reply, option) != ERR_NONE) {
655         WLOGFW("SendRequest failed");
656         return DisplayState::UNKNOWN;
657     }
658     return static_cast<DisplayState>(reply.ReadUint32());
659 }
660 
TryToCancelScreenOff()661 bool DisplayManagerLiteProxy::TryToCancelScreenOff()
662 {
663     sptr<IRemoteObject> remote = Remote();
664     if (remote == nullptr) {
665         WLOGFE("[UL_POWER]TryToCancelScreenOff remote is nullptr");
666         return false;
667     }
668 
669     MessageParcel data;
670     MessageParcel reply;
671     MessageOption option;
672 
673     if (!data.WriteInterfaceToken(GetDescriptor())) {
674         WLOGFE("[UL_POWER]TryToCancelScreenOff: WriteInterfaceToken failed");
675         return false;
676     }
677     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
678         data, reply, option) != ERR_NONE) {
679         WLOGFW("[UL_POWER]TryToCancelScreenOff: SendRequest failed");
680         return false;
681     }
682     return reply.ReadBool();
683 }
684 
SetScreenBrightness(uint64_t screenId,uint32_t level)685 bool DisplayManagerLiteProxy::SetScreenBrightness(uint64_t screenId, uint32_t level)
686 {
687     sptr<IRemoteObject> remote = Remote();
688     if (remote == nullptr) {
689         WLOGFE("SetScreenBrightness remote is nullptr");
690         return false;
691     }
692 
693     MessageParcel data;
694     MessageParcel reply;
695     MessageOption option;
696     if (!data.WriteInterfaceToken(GetDescriptor())) {
697         WLOGFE("WriteInterfaceToken failed");
698         return false;
699     }
700     if (!data.WriteUint64(screenId)) {
701         WLOGFE("Write screenId failed");
702         return false;
703     }
704     if (!data.WriteUint64(level)) {
705         WLOGFE("Write level failed");
706         return false;
707     }
708     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_BRIGHTNESS),
709         data, reply, option) != ERR_NONE) {
710         WLOGFW("SendRequest failed");
711         return false;
712     }
713     return reply.ReadBool();
714 }
715 
GetScreenBrightness(uint64_t screenId)716 uint32_t DisplayManagerLiteProxy::GetScreenBrightness(uint64_t screenId)
717 {
718     sptr<IRemoteObject> remote = Remote();
719     if (remote == nullptr) {
720         WLOGFE("GetScreenBrightness remote is nullptr");
721         return 0;
722     }
723 
724     MessageParcel data;
725     MessageParcel reply;
726     MessageOption option;
727     if (!data.WriteInterfaceToken(GetDescriptor())) {
728         WLOGFE("WriteInterfaceToken failed");
729         return 0;
730     }
731     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
732         WLOGFE("Write screenId failed");
733         return 0;
734     }
735     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_BRIGHTNESS),
736         data, reply, option) != ERR_NONE) {
737         WLOGFW("SendRequest failed");
738         return 0;
739     }
740     return reply.ReadUint32();
741 }
742 
GetAllDisplayIds()743 std::vector<DisplayId> DisplayManagerLiteProxy::GetAllDisplayIds()
744 {
745     sptr<IRemoteObject> remote = Remote();
746     if (remote == nullptr) {
747         WLOGFE("[UL_POWER]GetAllDisplayIds remote is nullptr");
748         return {};
749     }
750 
751     std::vector<DisplayId> allDisplayIds;
752     MessageParcel data;
753     MessageParcel reply;
754     MessageOption option;
755     if (!data.WriteInterfaceToken(GetDescriptor())) {
756         WLOGFE("WriteInterfaceToken failed");
757         return allDisplayIds;
758     }
759     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
760         data, reply, option) != ERR_NONE) {
761         WLOGFW("SendRequest failed");
762         return allDisplayIds;
763     }
764     reply.ReadUInt64Vector(&allDisplayIds);
765     return allDisplayIds;
766 }
767 
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)768 DMError DisplayManagerLiteProxy::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
769 {
770     sptr<IRemoteObject> remote = Remote();
771     if (remote == nullptr) {
772         WLOGFW("GetAllScreenInfos: remote is nullptr");
773         return DMError::DM_ERROR_NULLPTR;
774     }
775 
776     MessageParcel data;
777     MessageParcel reply;
778     MessageOption option;
779     if (!data.WriteInterfaceToken(GetDescriptor())) {
780         WLOGFE("GetAllScreenInfos: WriteInterfaceToken failed");
781         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
782     }
783     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS),
784         data, reply, option) != ERR_NONE) {
785         WLOGFW("GetAllScreenInfos: SendRequest failed");
786         return DMError::DM_ERROR_IPC_FAILED;
787     }
788     DMError ret = static_cast<DMError>(reply.ReadInt32());
789     static_cast<void>(MarshallingHelper::UnmarshallingVectorParcelableObj<ScreenInfo>(reply, screenInfos));
790     return ret;
791 }
792 
SetSystemKeyboardStatus(bool isOn)793 DMError DisplayManagerLiteProxy::SetSystemKeyboardStatus(bool isOn)
794 {
795     sptr<IRemoteObject> remote = Remote();
796     if (remote == nullptr) {
797         WLOGFW("remote is nullptr");
798         return DMError::DM_ERROR_NULLPTR;
799     }
800 
801     MessageParcel data;
802     MessageParcel reply;
803     MessageOption option;
804     if (!data.WriteInterfaceToken(GetDescriptor())) {
805         WLOGFE("WriteInterfaceToken failed");
806         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
807     }
808     if (!data.WriteBool(isOn)) {
809         WLOGFE("Write isOn failed");
810         return DMError::DM_ERROR_WRITE_DATA_FAILED;
811     }
812     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SYSTEM_KEYBOARD_ON),
813         data, reply, option) != ERR_NONE) {
814         WLOGFW("SendRequest failed");
815         return DMError::DM_ERROR_IPC_FAILED;
816     }
817     return static_cast<DMError>(reply.ReadInt32());
818 }
819 } // namespace OHOS::Rosen
820