• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <ipc_types.h>
17 #include <message_option.h>
18 #include <message_parcel.h>
19 #include "display_manager_lite_proxy.h"
20 
21 namespace OHOS::Rosen {
22 // generated by IDisplayManagerLite.idl
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,uint32_t type,int32_t & dmError)23 ErrCode DisplayManagerLiteProxy::RegisterDisplayManagerAgent(
24     const sptr<IDisplayManagerAgent>& displayManagerAgent,
25     uint32_t type,
26     int32_t& dmError)
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option(MessageOption::TF_SYNC);
31 
32     if (!data.WriteInterfaceToken(GetDescriptor())) {
33         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
34         return ERR_INVALID_VALUE;
35     }
36 
37     if (displayManagerAgent == nullptr) {
38         TLOGE(WmsLogTag::DMS, "displayManagerAgent is nullptr!");
39         return ERR_INVALID_DATA;
40     }
41     if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
42         TLOGE(WmsLogTag::DMS, "Write [displayManagerAgent] failed!");
43         return ERR_INVALID_DATA;
44     }
45     if (!data.WriteUint32(type)) {
46         TLOGE(WmsLogTag::DMS, "Write [type] failed!");
47         return ERR_INVALID_DATA;
48     }
49 
50     sptr<IRemoteObject> remote = Remote();
51     if (!remote) {
52         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
53         return ERR_INVALID_DATA;
54     }
55     int32_t result = remote->SendRequest(
56         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_REGISTER_DISPLAY_MANAGER_AGENT), data, reply, option);
57     if (FAILED(result)) {
58         TLOGE(WmsLogTag::DMS, "Send request failed!");
59         return result;
60     }
61 
62     ErrCode errCode = ERR_OK;
63     if (!reply.ReadInt32(errCode)) {
64         TLOGE(WmsLogTag::DMS, "Read result failed!");
65         return ERR_INVALID_DATA;
66     }
67     if (FAILED(errCode)) {
68         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
69             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_REGISTER_DISPLAY_MANAGER_AGENT));
70         return errCode;
71     }
72 
73     if (!reply.ReadInt32(dmError)) {
74         TLOGE(WmsLogTag::DMS, "Read dmError failed!");
75         return ERR_INVALID_DATA;
76     }
77 
78     return ERR_OK;
79 }
80 
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,uint32_t type,int32_t & dmError)81 ErrCode DisplayManagerLiteProxy::UnregisterDisplayManagerAgent(
82     const sptr<IDisplayManagerAgent>& displayManagerAgent,
83     uint32_t type,
84     int32_t& dmError)
85 {
86     MessageParcel data;
87     MessageParcel reply;
88     MessageOption option(MessageOption::TF_SYNC);
89 
90     if (!data.WriteInterfaceToken(GetDescriptor())) {
91         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
92         return ERR_INVALID_VALUE;
93     }
94 
95     if (displayManagerAgent == nullptr) {
96         TLOGE(WmsLogTag::DMS, "displayManagerAgent is nullptr!");
97         return ERR_INVALID_DATA;
98     }
99     if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
100         TLOGE(WmsLogTag::DMS, "Write [displayManagerAgent] failed!");
101         return ERR_INVALID_DATA;
102     }
103     if (!data.WriteUint32(type)) {
104         TLOGE(WmsLogTag::DMS, "Write [type] failed!");
105         return ERR_INVALID_DATA;
106     }
107 
108     sptr<IRemoteObject> remote = Remote();
109     if (!remote) {
110         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
111         return ERR_INVALID_DATA;
112     }
113     int32_t result = remote->SendRequest(
114         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_UNREGISTER_DISPLAY_MANAGER_AGENT), data, reply, option);
115     if (FAILED(result)) {
116         TLOGE(WmsLogTag::DMS, "Send request failed!");
117         return result;
118     }
119 
120     ErrCode errCode = ERR_OK;
121     if (!reply.ReadInt32(errCode)) {
122         TLOGE(WmsLogTag::DMS, "Read result failed!");
123         return ERR_INVALID_DATA;
124     }
125     if (FAILED(errCode)) {
126         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
127             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_UNREGISTER_DISPLAY_MANAGER_AGENT));
128         return errCode;
129     }
130 
131     if (!reply.ReadInt32(dmError)) {
132         TLOGE(WmsLogTag::DMS, "Read dmError failed!");
133         return ERR_INVALID_DATA;
134     }
135 
136     return ERR_OK;
137 }
138 
GetDefaultDisplayInfo(sptr<DisplayInfo> & displayInfo)139 ErrCode DisplayManagerLiteProxy::GetDefaultDisplayInfo(
140     sptr<DisplayInfo>& displayInfo)
141 {
142     MessageParcel data;
143     MessageParcel reply;
144     MessageOption option(MessageOption::TF_SYNC);
145 
146     if (!data.WriteInterfaceToken(GetDescriptor())) {
147         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
148         return ERR_INVALID_VALUE;
149     }
150 
151     sptr<IRemoteObject> remote = Remote();
152     if (!remote) {
153         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
154         return ERR_INVALID_DATA;
155     }
156     int32_t result = remote->SendRequest(
157         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DEFAULT_DISPLAY_INFO), data, reply, option);
158     if (FAILED(result)) {
159         TLOGE(WmsLogTag::DMS, "Send request failed!");
160         return result;
161     }
162 
163     ErrCode errCode = ERR_OK;
164     if (!reply.ReadInt32(errCode)) {
165         TLOGE(WmsLogTag::DMS, "Read result failed!");
166         return ERR_INVALID_DATA;
167     }
168     if (FAILED(errCode)) {
169         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
170             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DEFAULT_DISPLAY_INFO));
171         return errCode;
172     }
173 
174     displayInfo = sptr<DisplayInfo>(reply.ReadParcelable<DisplayInfo>());
175     if (!displayInfo) {
176         TLOGE(WmsLogTag::DMS, "Read [DisplayInfo] failed!");
177         return ERR_INVALID_DATA;
178     }
179 
180     return ERR_OK;
181 }
182 
GetDisplayInfoById(uint64_t displayId,sptr<DisplayInfo> & displayInfo)183 ErrCode DisplayManagerLiteProxy::GetDisplayInfoById(
184     uint64_t displayId,
185     sptr<DisplayInfo>& displayInfo)
186 {
187     MessageParcel data;
188     MessageParcel reply;
189     MessageOption option(MessageOption::TF_SYNC);
190 
191     if (!data.WriteInterfaceToken(GetDescriptor())) {
192         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
193         return ERR_INVALID_VALUE;
194     }
195 
196     if (!data.WriteUint64(displayId)) {
197         TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
198         return ERR_INVALID_DATA;
199     }
200 
201     sptr<IRemoteObject> remote = Remote();
202     if (!remote) {
203         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
204         return ERR_INVALID_DATA;
205     }
206     int32_t result = remote->SendRequest(
207         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_INFO_BY_ID), data, reply, option);
208     if (FAILED(result)) {
209         TLOGE(WmsLogTag::DMS, "Send request failed!");
210         return result;
211     }
212 
213     ErrCode errCode = ERR_OK;
214     if (!reply.ReadInt32(errCode)) {
215         TLOGE(WmsLogTag::DMS, "Read result failed!");
216         return ERR_INVALID_DATA;
217     }
218     if (FAILED(errCode)) {
219         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
220             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_INFO_BY_ID));
221         return errCode;
222     }
223 
224     displayInfo = sptr<DisplayInfo>(reply.ReadParcelable<DisplayInfo>());
225     if (!displayInfo) {
226         TLOGE(WmsLogTag::DMS, "Read [DisplayInfo] failed!");
227         return ERR_INVALID_DATA;
228     }
229 
230     return ERR_OK;
231 }
232 
GetCutoutInfo(uint64_t displayId,sptr<CutoutInfo> & cutoutInfo)233 ErrCode DisplayManagerLiteProxy::GetCutoutInfo(
234     uint64_t displayId,
235     sptr<CutoutInfo>& cutoutInfo)
236 {
237     MessageParcel data;
238     MessageParcel reply;
239     MessageOption option(MessageOption::TF_SYNC);
240 
241     if (!data.WriteInterfaceToken(GetDescriptor())) {
242         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
243         return ERR_INVALID_VALUE;
244     }
245 
246     if (!data.WriteUint64(displayId)) {
247         TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
248         return ERR_INVALID_DATA;
249     }
250 
251     sptr<IRemoteObject> remote = Remote();
252     if (!remote) {
253         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
254         return ERR_INVALID_DATA;
255     }
256     int32_t result = remote->SendRequest(
257         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_CUTOUT_INFO), data, reply, option);
258     if (FAILED(result)) {
259         TLOGE(WmsLogTag::DMS, "Send request failed!");
260         return result;
261     }
262 
263     ErrCode errCode = ERR_OK;
264     if (!reply.ReadInt32(errCode)) {
265         TLOGE(WmsLogTag::DMS, "Read result failed!");
266         return ERR_INVALID_DATA;
267     }
268     if (FAILED(errCode)) {
269         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
270             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_CUTOUT_INFO));
271         return errCode;
272     }
273 
274     cutoutInfo = sptr<CutoutInfo>(reply.ReadParcelable<CutoutInfo>());
275     if (!cutoutInfo) {
276         TLOGE(WmsLogTag::DMS, "Read [CutoutInfo] failed!");
277         return ERR_INVALID_DATA;
278     }
279 
280     return ERR_OK;
281 }
282 
WakeUpBegin(uint32_t reason,bool & isSucc)283 ErrCode DisplayManagerLiteProxy::WakeUpBegin(
284     uint32_t reason,
285     bool& isSucc)
286 {
287     MessageParcel data;
288     MessageParcel reply;
289     MessageOption option(MessageOption::TF_SYNC);
290 
291     if (!data.WriteInterfaceToken(GetDescriptor())) {
292         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
293         return ERR_INVALID_VALUE;
294     }
295 
296     if (!data.WriteUint32(reason)) {
297         TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
298         return ERR_INVALID_DATA;
299     }
300 
301     sptr<IRemoteObject> remote = Remote();
302     if (!remote) {
303         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
304         return ERR_INVALID_DATA;
305     }
306     int32_t result = remote->SendRequest(
307         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_BEGIN), data, reply, option);
308     if (FAILED(result)) {
309         TLOGE(WmsLogTag::DMS, "Send request failed!");
310         return result;
311     }
312 
313     ErrCode errCode = ERR_OK;
314     if (!reply.ReadInt32(errCode)) {
315         TLOGE(WmsLogTag::DMS, "Read result failed!");
316         return ERR_INVALID_DATA;
317     }
318     if (FAILED(errCode)) {
319         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
320             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_BEGIN));
321         return errCode;
322     }
323 
324     int32_t isSuccInt = 0;
325     if (!reply.ReadInt32(isSuccInt)) {
326         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
327         return ERR_INVALID_DATA;
328     }
329     isSucc = isSuccInt == 1;
330     return ERR_OK;
331 }
332 
WakeUpEnd(bool & isSucc)333 ErrCode DisplayManagerLiteProxy::WakeUpEnd(
334     bool& isSucc)
335 {
336     MessageParcel data;
337     MessageParcel reply;
338     MessageOption option(MessageOption::TF_SYNC);
339 
340     if (!data.WriteInterfaceToken(GetDescriptor())) {
341         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
342         return ERR_INVALID_VALUE;
343     }
344 
345     sptr<IRemoteObject> remote = Remote();
346     if (!remote) {
347         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
348         return ERR_INVALID_DATA;
349     }
350     int32_t result = remote->SendRequest(
351         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_END), data, reply, option);
352     if (FAILED(result)) {
353         TLOGE(WmsLogTag::DMS, "Send request failed!");
354         return result;
355     }
356 
357     ErrCode errCode = ERR_OK;
358     if (!reply.ReadInt32(errCode)) {
359         TLOGE(WmsLogTag::DMS, "Read result failed!");
360         return ERR_INVALID_DATA;
361     }
362     if (FAILED(errCode)) {
363         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
364             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_END));
365         return errCode;
366     }
367 
368     int32_t isSuccInt = 0;
369     if (!reply.ReadInt32(isSuccInt)) {
370         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
371         return ERR_INVALID_DATA;
372     }
373     isSucc = isSuccInt == 1;
374     return ERR_OK;
375 }
376 
SuspendBegin(uint32_t reason,bool & isSucc)377 ErrCode DisplayManagerLiteProxy::SuspendBegin(
378     uint32_t reason,
379     bool& isSucc)
380 {
381     MessageParcel data;
382     MessageParcel reply;
383     MessageOption option(MessageOption::TF_SYNC);
384 
385     if (!data.WriteInterfaceToken(GetDescriptor())) {
386         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
387         return ERR_INVALID_VALUE;
388     }
389 
390     if (!data.WriteUint32(reason)) {
391         TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
392         return ERR_INVALID_DATA;
393     }
394 
395     sptr<IRemoteObject> remote = Remote();
396     if (!remote) {
397         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
398         return ERR_INVALID_DATA;
399     }
400     int32_t result = remote->SendRequest(
401         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_BEGIN), data, reply, option);
402     if (FAILED(result)) {
403         TLOGE(WmsLogTag::DMS, "Send request failed!");
404         return result;
405     }
406 
407     ErrCode errCode = ERR_OK;
408     if (!reply.ReadInt32(errCode)) {
409         TLOGE(WmsLogTag::DMS, "Read result failed!");
410         return ERR_INVALID_DATA;
411     }
412     if (FAILED(errCode)) {
413         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
414             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_BEGIN));
415         return errCode;
416     }
417 
418     int32_t isSuccInt = 0;
419     if (!reply.ReadInt32(isSuccInt)) {
420         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
421         return ERR_INVALID_DATA;
422     }
423     isSucc = isSuccInt == 1;
424     return ERR_OK;
425 }
426 
SuspendEnd(bool & isSucc)427 ErrCode DisplayManagerLiteProxy::SuspendEnd(
428     bool& isSucc)
429 {
430     MessageParcel data;
431     MessageParcel reply;
432     MessageOption option(MessageOption::TF_SYNC);
433 
434     if (!data.WriteInterfaceToken(GetDescriptor())) {
435         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
436         return ERR_INVALID_VALUE;
437     }
438 
439     sptr<IRemoteObject> remote = Remote();
440     if (!remote) {
441         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
442         return ERR_INVALID_DATA;
443     }
444     int32_t result = remote->SendRequest(
445         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_END), data, reply, option);
446     if (FAILED(result)) {
447         TLOGE(WmsLogTag::DMS, "Send request failed!");
448         return result;
449     }
450 
451     ErrCode errCode = ERR_OK;
452     if (!reply.ReadInt32(errCode)) {
453         TLOGE(WmsLogTag::DMS, "Read result failed!");
454         return ERR_INVALID_DATA;
455     }
456     if (FAILED(errCode)) {
457         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
458             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_END));
459         return errCode;
460     }
461 
462     int32_t isSuccInt = 0;
463     if (!reply.ReadInt32(isSuccInt)) {
464         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
465         return ERR_INVALID_DATA;
466     }
467     isSucc = isSuccInt == 1;
468     return ERR_OK;
469 }
470 
SetSpecifiedScreenPower(uint64_t screenId,uint32_t screenPowerState,uint32_t reason,bool & isSucc)471 ErrCode DisplayManagerLiteProxy::SetSpecifiedScreenPower(
472     uint64_t screenId,
473     uint32_t screenPowerState,
474     uint32_t reason,
475     bool& isSucc)
476 {
477     MessageParcel data;
478     MessageParcel reply;
479     MessageOption option(MessageOption::TF_SYNC);
480 
481     if (!data.WriteInterfaceToken(GetDescriptor())) {
482         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
483         return ERR_INVALID_VALUE;
484     }
485 
486     if (!data.WriteUint64(screenId)) {
487         TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
488         return ERR_INVALID_DATA;
489     }
490     if (!data.WriteUint32(screenPowerState)) {
491         TLOGE(WmsLogTag::DMS, "Write [screenPowerState] failed!");
492         return ERR_INVALID_DATA;
493     }
494     if (!data.WriteUint32(reason)) {
495         TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
496         return ERR_INVALID_DATA;
497     }
498 
499     sptr<IRemoteObject> remote = Remote();
500     if (!remote) {
501         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
502         return ERR_INVALID_DATA;
503     }
504     int32_t result = remote->SendRequest(
505         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SPECIFIED_SCREEN_POWER), data, reply, option);
506     if (FAILED(result)) {
507         TLOGE(WmsLogTag::DMS, "Send request failed!");
508         return result;
509     }
510 
511     ErrCode errCode = ERR_OK;
512     if (!reply.ReadInt32(errCode)) {
513         TLOGE(WmsLogTag::DMS, "Read result failed!");
514         return ERR_INVALID_DATA;
515     }
516     if (FAILED(errCode)) {
517         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
518             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SPECIFIED_SCREEN_POWER));
519         return errCode;
520     }
521 
522     int32_t isSuccInt = 0;
523     if (!reply.ReadInt32(isSuccInt)) {
524         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
525         return ERR_INVALID_DATA;
526     }
527     isSucc = isSuccInt == 1;
528     return ERR_OK;
529 }
530 
SetScreenPowerForAll(uint32_t screenPowerState,uint32_t reason,bool & isSucc)531 ErrCode DisplayManagerLiteProxy::SetScreenPowerForAll(
532     uint32_t screenPowerState,
533     uint32_t reason,
534     bool& isSucc)
535 {
536     MessageParcel data;
537     MessageParcel reply;
538     MessageOption option(MessageOption::TF_SYNC);
539 
540     if (!data.WriteInterfaceToken(GetDescriptor())) {
541         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
542         return ERR_INVALID_VALUE;
543     }
544 
545     if (!data.WriteUint32(screenPowerState)) {
546         TLOGE(WmsLogTag::DMS, "Write [screenPowerState] failed!");
547         return ERR_INVALID_DATA;
548     }
549     if (!data.WriteUint32(reason)) {
550         TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
551         return ERR_INVALID_DATA;
552     }
553 
554     sptr<IRemoteObject> remote = Remote();
555     if (!remote) {
556         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
557         return ERR_INVALID_DATA;
558     }
559     int32_t result = remote->SendRequest(
560         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_POWER_FOR_ALL), data, reply, option);
561     if (FAILED(result)) {
562         TLOGE(WmsLogTag::DMS, "Send request failed!");
563         return result;
564     }
565 
566     ErrCode errCode = ERR_OK;
567     if (!reply.ReadInt32(errCode)) {
568         TLOGE(WmsLogTag::DMS, "Read result failed!");
569         return ERR_INVALID_DATA;
570     }
571     if (FAILED(errCode)) {
572         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
573             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_POWER_FOR_ALL));
574         return errCode;
575     }
576 
577     int32_t isSuccInt = 0;
578     if (!reply.ReadInt32(isSuccInt)) {
579         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
580         return ERR_INVALID_DATA;
581     }
582     isSucc = isSuccInt == 1;
583     return ERR_OK;
584 }
585 
GetScreenPower(uint64_t dmsScreenId,uint32_t & screenPowerState)586 ErrCode DisplayManagerLiteProxy::GetScreenPower(
587     uint64_t dmsScreenId,
588     uint32_t& screenPowerState)
589 {
590     MessageParcel data;
591     MessageParcel reply;
592     MessageOption option(MessageOption::TF_SYNC);
593 
594     if (!data.WriteInterfaceToken(GetDescriptor())) {
595         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
596         return ERR_INVALID_VALUE;
597     }
598 
599     if (!data.WriteUint64(dmsScreenId)) {
600         TLOGE(WmsLogTag::DMS, "Write [dmsScreenId] failed!");
601         return ERR_INVALID_DATA;
602     }
603 
604     sptr<IRemoteObject> remote = Remote();
605     if (!remote) {
606         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
607         return ERR_INVALID_DATA;
608     }
609     int32_t result = remote->SendRequest(
610         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_POWER), data, reply, option);
611     if (FAILED(result)) {
612         TLOGE(WmsLogTag::DMS, "Send request failed!");
613         return result;
614     }
615 
616     ErrCode errCode = ERR_OK;
617     if (!reply.ReadInt32(errCode)) {
618         TLOGE(WmsLogTag::DMS, "Read result failed!");
619         return ERR_INVALID_DATA;
620     }
621     if (FAILED(errCode)) {
622         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
623             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_POWER));
624         return errCode;
625     }
626 
627     if (!reply.ReadUint32(screenPowerState)) {
628         TLOGE(WmsLogTag::DMS, "Read [screenPowerState] failed!");
629         return ERR_INVALID_DATA;
630     }
631     return ERR_OK;
632 }
633 
SetDisplayState(uint32_t displayState,bool & isSucc)634 ErrCode DisplayManagerLiteProxy::SetDisplayState(
635     uint32_t displayState,
636     bool& isSucc)
637 {
638     MessageParcel data;
639     MessageParcel reply;
640     MessageOption option(MessageOption::TF_SYNC);
641 
642     if (!data.WriteInterfaceToken(GetDescriptor())) {
643         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
644         return ERR_INVALID_VALUE;
645     }
646 
647     if (!data.WriteUint32(displayState)) {
648         TLOGE(WmsLogTag::DMS, "Write [displayState] failed!");
649         return ERR_INVALID_DATA;
650     }
651 
652     sptr<IRemoteObject> remote = Remote();
653     if (!remote) {
654         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
655         return ERR_INVALID_DATA;
656     }
657     int32_t result = remote->SendRequest(
658         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_DISPLAY_STATE), data, reply, option);
659     if (FAILED(result)) {
660         TLOGE(WmsLogTag::DMS, "Send request failed!");
661         return result;
662     }
663 
664     ErrCode errCode = ERR_OK;
665     if (!reply.ReadInt32(errCode)) {
666         TLOGE(WmsLogTag::DMS, "Read result failed!");
667         return ERR_INVALID_DATA;
668     }
669     if (FAILED(errCode)) {
670         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
671             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_DISPLAY_STATE));
672         return errCode;
673     }
674 
675     int32_t isSuccInt = 0;
676     if (!reply.ReadInt32(isSuccInt)) {
677         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
678         return ERR_INVALID_DATA;
679     }
680     isSucc = isSuccInt == 1;
681     return ERR_OK;
682 }
683 
GetDisplayState(uint64_t displayId,uint32_t & displayState)684 ErrCode DisplayManagerLiteProxy::GetDisplayState(
685     uint64_t displayId,
686     uint32_t& displayState)
687 {
688     MessageParcel data;
689     MessageParcel reply;
690     MessageOption option(MessageOption::TF_SYNC);
691 
692     if (!data.WriteInterfaceToken(GetDescriptor())) {
693         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
694         return ERR_INVALID_VALUE;
695     }
696 
697     if (!data.WriteUint64(displayId)) {
698         TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
699         return ERR_INVALID_DATA;
700     }
701 
702     sptr<IRemoteObject> remote = Remote();
703     if (!remote) {
704         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
705         return ERR_INVALID_DATA;
706     }
707     int32_t result = remote->SendRequest(
708         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_STATE), data, reply, option);
709     if (FAILED(result)) {
710         TLOGE(WmsLogTag::DMS, "Send request failed!");
711         return result;
712     }
713 
714     ErrCode errCode = ERR_OK;
715     if (!reply.ReadInt32(errCode)) {
716         TLOGE(WmsLogTag::DMS, "Read result failed!");
717         return ERR_INVALID_DATA;
718     }
719     if (FAILED(errCode)) {
720         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
721             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_STATE));
722         return errCode;
723     }
724 
725     if (!reply.ReadUint32(displayState)) {
726         TLOGE(WmsLogTag::DMS, "Read [displayState] failed!");
727         return ERR_INVALID_DATA;
728     }
729     return ERR_OK;
730 }
731 
TryToCancelScreenOff(bool & isSucc)732 ErrCode DisplayManagerLiteProxy::TryToCancelScreenOff(
733     bool& isSucc)
734 {
735     MessageParcel data;
736     MessageParcel reply;
737     MessageOption option(MessageOption::TF_SYNC);
738 
739     if (!data.WriteInterfaceToken(GetDescriptor())) {
740         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
741         return ERR_INVALID_VALUE;
742     }
743 
744     sptr<IRemoteObject> remote = Remote();
745     if (!remote) {
746         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
747         return ERR_INVALID_DATA;
748     }
749     int32_t result = remote->SendRequest(
750         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_TRY_TO_CANCEL_SCREEN_OFF), data, reply, option);
751     if (FAILED(result)) {
752         TLOGE(WmsLogTag::DMS, "Send request failed!");
753         return result;
754     }
755 
756     ErrCode errCode = ERR_OK;
757     if (!reply.ReadInt32(errCode)) {
758         TLOGE(WmsLogTag::DMS, "Read result failed!");
759         return ERR_INVALID_DATA;
760     }
761     if (FAILED(errCode)) {
762         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
763             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_TRY_TO_CANCEL_SCREEN_OFF));
764         return errCode;
765     }
766 
767     int32_t isSuccInt = 0;
768     if (!reply.ReadInt32(isSuccInt)) {
769         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
770         return ERR_INVALID_DATA;
771     }
772     isSucc = isSuccInt == 1;
773     return ERR_OK;
774 }
775 
GetAllDisplayIds(std::vector<uint64_t> & displayIds)776 ErrCode DisplayManagerLiteProxy::GetAllDisplayIds(
777     std::vector<uint64_t>& displayIds)
778 {
779     MessageParcel data;
780     MessageParcel reply;
781     MessageOption option(MessageOption::TF_SYNC);
782 
783     if (!data.WriteInterfaceToken(GetDescriptor())) {
784         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
785         return ERR_INVALID_VALUE;
786     }
787 
788     sptr<IRemoteObject> remote = Remote();
789     if (!remote) {
790         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
791         return ERR_INVALID_DATA;
792     }
793     int32_t result = remote->SendRequest(
794         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_DISPLAY_IDS), data, reply, option);
795     if (FAILED(result)) {
796         TLOGE(WmsLogTag::DMS, "Send request failed!");
797         return result;
798     }
799 
800     ErrCode errCode = ERR_OK;
801     if (!reply.ReadInt32(errCode)) {
802         TLOGE(WmsLogTag::DMS, "Read result failed!");
803         return ERR_INVALID_DATA;
804     }
805     if (FAILED(errCode)) {
806         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
807             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_DISPLAY_IDS));
808         return errCode;
809     }
810 
811     int32_t displayIdsSize = 0;
812     if (!reply.ReadInt32(displayIdsSize)) {
813         TLOGE(WmsLogTag::DMS, "Read displayIdsSize failed!");
814         return ERR_INVALID_DATA;
815     }
816     if (displayIdsSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {
817         TLOGE(WmsLogTag::DMS, "The vector/array size exceeds the security limit!");
818         return ERR_INVALID_DATA;
819     }
820     for (int32_t i1 = 0; i1 < displayIdsSize; ++i1) {
821         uint64_t value1 = reply.ReadUint64();
822         displayIds.push_back(value1);
823     }
824 
825     return ERR_OK;
826 }
827 
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos,int32_t & dmError)828 ErrCode DisplayManagerLiteProxy::GetAllScreenInfos(
829     std::vector<sptr<ScreenInfo>>& screenInfos,
830     int32_t& dmError)
831 {
832     MessageParcel data;
833     MessageParcel reply;
834     MessageOption option(MessageOption::TF_SYNC);
835 
836     if (!data.WriteInterfaceToken(GetDescriptor())) {
837         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
838         return ERR_INVALID_VALUE;
839     }
840 
841     sptr<IRemoteObject> remote = Remote();
842     if (!remote) {
843         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
844         return ERR_INVALID_DATA;
845     }
846     int32_t result = remote->SendRequest(
847         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_SCREEN_INFOS), data, reply, option);
848     if (FAILED(result)) {
849         TLOGE(WmsLogTag::DMS, "Send request failed!");
850         return result;
851     }
852 
853     ErrCode errCode = ERR_OK;
854     if (!reply.ReadInt32(errCode)) {
855         TLOGE(WmsLogTag::DMS, "Read result failed!");
856         return ERR_INVALID_DATA;
857     }
858     if (FAILED(errCode)) {
859         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
860             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_SCREEN_INFOS));
861         return errCode;
862     }
863 
864     int32_t screenInfosSize = 0;
865     if (!reply.ReadInt32(screenInfosSize)) {
866         TLOGE(WmsLogTag::DMS, "Read screenInfosSize failed!");
867         return ERR_INVALID_DATA;
868     }
869     if (screenInfosSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {
870         TLOGE(WmsLogTag::DMS, "The vector/array size exceeds the security limit!");
871         return ERR_INVALID_DATA;
872     }
873     for (int32_t i2 = 0; i2 < screenInfosSize; ++i2) {
874         sptr<ScreenInfo> value2 = sptr<ScreenInfo>(reply.ReadParcelable<ScreenInfo>());
875         if (!value2) {
876             TLOGE(WmsLogTag::DMS, "Read [ScreenInfo] failed!");
877             return ERR_INVALID_DATA;
878         }
879 
880         screenInfos.push_back(value2);
881     }
882 
883     if (!reply.ReadInt32(dmError)) {
884         TLOGE(WmsLogTag::DMS, "Read dmError failed!");
885         return ERR_INVALID_DATA;
886     }
887 
888     return ERR_OK;
889 }
890 
GetScreenInfoById(uint64_t screenId,sptr<ScreenInfo> & screenInfo)891 ErrCode DisplayManagerLiteProxy::GetScreenInfoById(
892     uint64_t screenId,
893     sptr<ScreenInfo>& screenInfo)
894 {
895     MessageParcel data;
896     MessageParcel reply;
897     MessageOption option(MessageOption::TF_SYNC);
898 
899     if (!data.WriteInterfaceToken(GetDescriptor())) {
900         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
901         return ERR_INVALID_VALUE;
902     }
903 
904     if (!data.WriteUint64(screenId)) {
905         TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
906         return ERR_INVALID_DATA;
907     }
908 
909     sptr<IRemoteObject> remote = Remote();
910     if (!remote) {
911         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
912         return ERR_INVALID_DATA;
913     }
914     int32_t result = remote->SendRequest(
915         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_INFO_BY_ID), data, reply, option);
916     if (FAILED(result)) {
917         TLOGE(WmsLogTag::DMS, "Send request failed!");
918         return result;
919     }
920 
921     ErrCode errCode = ERR_OK;
922     if (!reply.ReadInt32(errCode)) {
923         TLOGE(WmsLogTag::DMS, "Read result failed!");
924         return ERR_INVALID_DATA;
925     }
926     if (FAILED(errCode)) {
927         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
928             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_INFO_BY_ID));
929         return errCode;
930     }
931 
932     screenInfo = sptr<ScreenInfo>(reply.ReadParcelable<ScreenInfo>());
933     if (!screenInfo) {
934         TLOGE(WmsLogTag::DMS, "Read [ScreenInfo] failed!");
935         return ERR_INVALID_DATA;
936     }
937     return ERR_OK;
938 }
939 
SetScreenBrightness(uint64_t screenId,uint32_t level,bool & isSucc)940 ErrCode DisplayManagerLiteProxy::SetScreenBrightness(
941     uint64_t screenId,
942     uint32_t level,
943     bool& isSucc)
944 {
945     MessageParcel data;
946     MessageParcel reply;
947     MessageOption option(MessageOption::TF_SYNC);
948 
949     if (!data.WriteInterfaceToken(GetDescriptor())) {
950         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
951         return ERR_INVALID_VALUE;
952     }
953 
954     if (!data.WriteUint64(screenId)) {
955         TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
956         return ERR_INVALID_DATA;
957     }
958     if (!data.WriteUint32(level)) {
959         TLOGE(WmsLogTag::DMS, "Write [level] failed!");
960         return ERR_INVALID_DATA;
961     }
962 
963     sptr<IRemoteObject> remote = Remote();
964     if (!remote) {
965         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
966         return ERR_INVALID_DATA;
967     }
968     int32_t result = remote->SendRequest(
969         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_BRIGHTNESS), data, reply, option);
970     if (FAILED(result)) {
971         TLOGE(WmsLogTag::DMS, "Send request failed!");
972         return result;
973     }
974 
975     ErrCode errCode = ERR_OK;
976     if (!reply.ReadInt32(errCode)) {
977         TLOGE(WmsLogTag::DMS, "Read result failed!");
978         return ERR_INVALID_DATA;
979     }
980     if (FAILED(errCode)) {
981         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
982             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_BRIGHTNESS));
983         return errCode;
984     }
985 
986     int32_t isSuccInt = 0;
987     if (!reply.ReadInt32(isSuccInt)) {
988         TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
989         return ERR_INVALID_DATA;
990     }
991     isSucc = isSuccInt == 1;
992     return ERR_OK;
993 }
994 
GetScreenBrightness(uint64_t screenId,uint32_t & level)995 ErrCode DisplayManagerLiteProxy::GetScreenBrightness(
996     uint64_t screenId,
997     uint32_t& level)
998 {
999     MessageParcel data;
1000     MessageParcel reply;
1001     MessageOption option(MessageOption::TF_SYNC);
1002 
1003     if (!data.WriteInterfaceToken(GetDescriptor())) {
1004         TLOGE(WmsLogTag::DMS, "Write interface token failed!");
1005         return ERR_INVALID_VALUE;
1006     }
1007 
1008     if (!data.WriteUint64(screenId)) {
1009         TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
1010         return ERR_INVALID_DATA;
1011     }
1012 
1013     sptr<IRemoteObject> remote = Remote();
1014     if (!remote) {
1015         TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
1016         return ERR_INVALID_DATA;
1017     }
1018     int32_t result = remote->SendRequest(
1019         static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_BRIGHTNESS), data, reply, option);
1020     if (FAILED(result)) {
1021         TLOGE(WmsLogTag::DMS, "Send request failed!");
1022         return result;
1023     }
1024 
1025     ErrCode errCode = ERR_OK;
1026     if (!reply.ReadInt32(errCode)) {
1027         TLOGE(WmsLogTag::DMS, "Read result failed!");
1028         return ERR_INVALID_DATA;
1029     }
1030     if (FAILED(errCode)) {
1031         TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
1032             static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_BRIGHTNESS));
1033         return errCode;
1034     }
1035 
1036     if (!reply.ReadUint32(level)) {
1037         TLOGE(WmsLogTag::DMS, "Read [level] failed!");
1038         return ERR_INVALID_DATA;
1039     }
1040     return ERR_OK;
1041 }
1042 } // namespace OHOS::Rosen
1043 
1044