• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_proxy.h"
17 
18 #include <cinttypes>
19 #include <ipc_types.h>
20 #include <parcel.h>
21 #include <ui/rs_surface_node.h>
22 #include "marshalling_helper.h"
23 #include "window_manager_hilog.h"
24 
25 namespace OHOS::Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerProxy"};
28 }
29 
GetDefaultDisplayInfo()30 sptr<DisplayInfo> DisplayManagerProxy::GetDefaultDisplayInfo()
31 {
32     sptr<IRemoteObject> remote = Remote();
33     if (remote == nullptr) {
34         WLOGFW("GetDefaultDisplayInfo: remote is nullptr");
35         return nullptr;
36     }
37 
38     MessageParcel data;
39     MessageParcel reply;
40     MessageOption option;
41     if (!data.WriteInterfaceToken(GetDescriptor())) {
42         WLOGFE("GetDefaultDisplayInfo: WriteInterfaceToken failed");
43         return nullptr;
44     }
45     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO),
46         data, reply, option) != ERR_NONE) {
47         WLOGFW("GetDefaultDisplayInfo: SendRequest failed");
48         return nullptr;
49     }
50     sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
51     if (info == nullptr) {
52         WLOGFW("DisplayManagerProxy::GetDefaultDisplayInfo SendRequest nullptr.");
53     }
54     return info;
55 }
56 
GetDisplayInfoById(DisplayId displayId)57 sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
58 {
59     sptr<IRemoteObject> remote = Remote();
60     if (remote == nullptr) {
61         WLOGFW("GetDisplayInfoById: remote is nullptr");
62         return nullptr;
63     }
64 
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68     if (!data.WriteInterfaceToken(GetDescriptor())) {
69         WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed");
70         return nullptr;
71     }
72     if (!data.WriteUint64(displayId)) {
73         WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed");
74         return nullptr;
75     }
76     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID),
77         data, reply, option) != ERR_NONE) {
78         WLOGFW("GetDisplayInfoById: SendRequest failed");
79         return nullptr;
80     }
81 
82     sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
83     if (info == nullptr) {
84         WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr.");
85         return nullptr;
86     }
87     return info;
88 }
89 
GetDisplayInfoByScreen(ScreenId screenId)90 sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoByScreen(ScreenId screenId)
91 {
92     sptr<IRemoteObject> remote = Remote();
93     if (remote == nullptr) {
94         WLOGFE("fail to get displayInfo by screenId: remote is null");
95         return nullptr;
96     }
97 
98     MessageParcel data;
99     MessageParcel reply;
100     MessageOption option;
101     if (!data.WriteInterfaceToken(GetDescriptor())) {
102         WLOGFE("fail to get displayInfo by screenId: WriteInterfaceToken failed");
103         return nullptr;
104     }
105     if (!data.WriteUint64(screenId)) {
106         WLOGFW("fail to get displayInfo by screenId: WriteUint64 displayId failed");
107         return nullptr;
108     }
109     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_SCREEN),
110         data, reply, option) != ERR_NONE) {
111         WLOGFW("fail to get displayInfo by screenId: SendRequest failed");
112         return nullptr;
113     }
114 
115     sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
116     if (info == nullptr) {
117         WLOGFW("fail to get displayInfo by screenId: SendRequest null");
118         return nullptr;
119     }
120     return info;
121 }
122 
CreateVirtualScreen(VirtualScreenOption virtualOption,const sptr<IRemoteObject> & displayManagerAgent)123 ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption,
124     const sptr<IRemoteObject>& displayManagerAgent)
125 {
126     sptr<IRemoteObject> remote = Remote();
127     if (remote == nullptr) {
128         WLOGFW("CreateVirtualScreen: remote is nullptr");
129         return SCREEN_ID_INVALID;
130     }
131 
132     MessageParcel data;
133     MessageParcel reply;
134     MessageOption option;
135     if (!data.WriteInterfaceToken(GetDescriptor())) {
136         WLOGFE("CreateVirtualScreen: WriteInterfaceToken failed");
137         return SCREEN_ID_INVALID;
138     }
139     bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) &&
140         data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) &&
141         data.WriteInt32(virtualOption.flags_) && data.WriteBool(virtualOption.isForShot_) &&
142         data.WriteUInt64Vector(virtualOption.missionIds_);
143     if (virtualOption.surface_ != nullptr && virtualOption.surface_->GetProducer() != nullptr) {
144         res = res &&
145             data.WriteBool(true) &&
146             data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject());
147     } else {
148         WLOGFW("CreateVirtualScreen: surface is nullptr");
149         res = res && data.WriteBool(false);
150     }
151     if (displayManagerAgent != nullptr) {
152         res = res &&
153             data.WriteRemoteObject(displayManagerAgent);
154     }
155     if (!res) {
156         WLOGFE("Write data failed");
157         return SCREEN_ID_INVALID;
158     }
159     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_CREATE_VIRTUAL_SCREEN),
160         data, reply, option) != ERR_NONE) {
161         WLOGFW("CreateVirtualScreen: SendRequest failed");
162         return SCREEN_ID_INVALID;
163     }
164 
165     ScreenId screenId = static_cast<ScreenId>(reply.ReadUint64());
166     WLOGFI("CreateVirtualScreen %" PRIu64"", screenId);
167     return screenId;
168 }
169 
DestroyVirtualScreen(ScreenId screenId)170 DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId)
171 {
172     sptr<IRemoteObject> remote = Remote();
173     if (remote == nullptr) {
174         WLOGFW("DestroyVirtualScreen: remote is nullptr");
175         return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
176     }
177 
178     MessageParcel data;
179     MessageParcel reply;
180     MessageOption option;
181     if (!data.WriteInterfaceToken(GetDescriptor())) {
182         WLOGFE("DestroyVirtualScreen: WriteInterfaceToken failed");
183         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
184     }
185     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
186         WLOGFW("DestroyVirtualScreen: WriteUint64 screenId failed");
187         return DMError::DM_ERROR_IPC_FAILED;
188     }
189     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_DESTROY_VIRTUAL_SCREEN),
190         data, reply, option) != ERR_NONE) {
191         WLOGFW("DestroyVirtualScreen: SendRequest failed");
192         return DMError::DM_ERROR_IPC_FAILED;
193     }
194     return static_cast<DMError>(reply.ReadInt32());
195 }
196 
SetVirtualScreenSurface(ScreenId screenId,sptr<IBufferProducer> surface)197 DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface)
198 {
199     sptr<IRemoteObject> remote = Remote();
200     if (remote == nullptr) {
201         WLOGFW("SetVirtualScreenSurface: remote is nullptr");
202         return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
203     }
204 
205     MessageParcel data;
206     MessageParcel reply;
207     MessageOption option;
208     if (!data.WriteInterfaceToken(GetDescriptor())) {
209         WLOGFE("SetVirtualScreenSurface: WriteInterfaceToken failed");
210         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
211     }
212     bool res = data.WriteUint64(static_cast<uint64_t>(screenId));
213     if (surface != nullptr) {
214         res = res &&
215             data.WriteBool(true) &&
216             data.WriteRemoteObject(surface->AsObject());
217     } else {
218         WLOGFW("SetVirtualScreenSurface: surface is nullptr");
219         res = res && data.WriteBool(false);
220     }
221     if (!res) {
222         WLOGFW("SetVirtualScreenSurface: Write screenId/surface failed");
223         return DMError::DM_ERROR_IPC_FAILED;
224     }
225     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE),
226         data, reply, option) != ERR_NONE) {
227         WLOGFW("SetVirtualScreenSurface: SendRequest failed");
228         return DMError::DM_ERROR_IPC_FAILED;
229     }
230     return static_cast<DMError>(reply.ReadInt32());
231 }
232 
SetOrientation(ScreenId screenId,Orientation orientation)233 DMError DisplayManagerProxy::SetOrientation(ScreenId screenId, Orientation orientation)
234 {
235     sptr<IRemoteObject> remote = Remote();
236     if (remote == nullptr) {
237         WLOGFW("fail to set orientation: remote is null");
238         return DMError::DM_ERROR_NULLPTR;
239     }
240 
241     MessageParcel data;
242     MessageParcel reply;
243     MessageOption option;
244     if (!data.WriteInterfaceToken(GetDescriptor())) {
245         WLOGFE("fail to set orientation: WriteInterfaceToken failed");
246         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
247     }
248     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
249         WLOGFW("fail to set orientation: Write screenId failed");
250         return DMError::DM_ERROR_IPC_FAILED;
251     }
252     if (!data.WriteUint32(static_cast<uint32_t>(orientation))) {
253         WLOGFW("fail to set orientation: Write orientation failed");
254         return DMError::DM_ERROR_IPC_FAILED;
255     }
256     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_ORIENTATION),
257         data, reply, option) != ERR_NONE) {
258         WLOGFW("fail to set orientation: SendRequest failed");
259         return DMError::DM_ERROR_IPC_FAILED;
260     }
261     return static_cast<DMError>(reply.ReadInt32());
262 }
263 
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode)264 std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode)
265 {
266     sptr<IRemoteObject> remote = Remote();
267     if (remote == nullptr) {
268         WLOGFW("GetDisplaySnapshot: remote is nullptr");
269         return nullptr;
270     }
271 
272     MessageParcel data;
273     MessageParcel reply;
274     MessageOption option;
275     if (!data.WriteInterfaceToken(GetDescriptor())) {
276         WLOGFE("GetDisplaySnapshot: WriteInterfaceToken failed");
277         return nullptr;
278     }
279 
280     if (!data.WriteUint64(displayId)) {
281         WLOGFE("Write displayId failed");
282         return nullptr;
283     }
284 
285     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT),
286         data, reply, option) != ERR_NONE) {
287         WLOGFW("GetDisplaySnapshot: SendRequest failed");
288         return nullptr;
289     }
290 
291     std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>());
292     DmErrorCode replyErrorCode = static_cast<DmErrorCode>(reply.ReadInt32());
293     if (errorCode) {
294         *errorCode = replyErrorCode;
295     }
296     if (pixelMap == nullptr) {
297         WLOGFW("DisplayManagerProxy::GetDisplaySnapshot SendRequest nullptr.");
298         return nullptr;
299     }
300     return pixelMap;
301 }
302 
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)303 DMError DisplayManagerProxy::GetScreenSupportedColorGamuts(ScreenId screenId,
304     std::vector<ScreenColorGamut>& colorGamuts)
305 {
306     sptr<IRemoteObject> remote = Remote();
307     if (remote == nullptr) {
308         WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: remote is nullptr");
309         return DMError::DM_ERROR_NULLPTR;
310     }
311 
312     MessageParcel data;
313     MessageParcel reply;
314     MessageOption option;
315     if (!data.WriteInterfaceToken(GetDescriptor())) {
316         WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteInterfaceToken failed");
317         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
318     }
319     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
320         WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteUint64 screenId failed");
321         return DMError::DM_ERROR_IPC_FAILED;
322     }
323     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS),
324         data, reply, option) != ERR_NONE) {
325         WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: SendRequest failed");
326         return DMError::DM_ERROR_IPC_FAILED;
327     }
328     DMError ret = static_cast<DMError>(reply.ReadInt32());
329     if (ret != DMError::DM_OK) {
330         return ret;
331     }
332     MarshallingHelper::UnmarshallingVectorObj<ScreenColorGamut>(reply, colorGamuts,
333         [](Parcel& parcel, ScreenColorGamut& color) {
334             uint32_t value;
335             bool res = parcel.ReadUint32(value);
336             color = static_cast<ScreenColorGamut>(value);
337             return res;
338         }
339     );
340     return ret;
341 }
342 
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)343 DMError DisplayManagerProxy::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
344 {
345     sptr<IRemoteObject> remote = Remote();
346     if (remote == nullptr) {
347         WLOGFW("DisplayManagerProxy::GetScreenColorGamut: remote is nullptr");
348         return DMError::DM_ERROR_NULLPTR;
349     }
350 
351     MessageParcel data;
352     MessageParcel reply;
353     MessageOption option;
354     if (!data.WriteInterfaceToken(GetDescriptor())) {
355         WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteInterfaceToken failed");
356         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
357     }
358     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
359         WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteUint64 uint64_t failed");
360         return DMError::DM_ERROR_IPC_FAILED;
361     }
362     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_GAMUT),
363         data, reply, option) != ERR_NONE) {
364         WLOGFW("DisplayManagerProxy::GetScreenColorGamut: SendRequest failed");
365         return DMError::DM_ERROR_IPC_FAILED;
366     }
367     DMError ret = static_cast<DMError>(reply.ReadInt32());
368     if (ret != DMError::DM_OK) {
369         return ret;
370     }
371     colorGamut = static_cast<ScreenColorGamut>(reply.ReadUint32());
372     return ret;
373 }
374 
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)375 DMError DisplayManagerProxy::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
376 {
377     sptr<IRemoteObject> remote = Remote();
378     if (remote == nullptr) {
379         WLOGFW("DisplayManagerProxy::SetScreenColorGamut: remote is nullptr");
380         return DMError::DM_ERROR_NULLPTR;
381     }
382 
383     MessageParcel data;
384     MessageParcel reply;
385     MessageOption option;
386     if (!data.WriteInterfaceToken(GetDescriptor())) {
387         WLOGFW("DisplayManagerProxy::SetScreenColorGamut: WriteInterfaceToken failed");
388         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
389     }
390     if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteInt32(colorGamutIdx)) {
391         WLOGFW("DisplayManagerProxy::SetScreenColorGamut: Write failed");
392         return DMError::DM_ERROR_IPC_FAILED;
393     }
394     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_GAMUT),
395         data, reply, option) != ERR_NONE) {
396         WLOGFW("DisplayManagerProxy::SetScreenColorGamut: SendRequest failed");
397         return DMError::DM_ERROR_IPC_FAILED;
398     }
399     return static_cast<DMError>(reply.ReadInt32());
400 }
401 
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)402 DMError DisplayManagerProxy::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
403 {
404     sptr<IRemoteObject> remote = Remote();
405     if (remote == nullptr) {
406         WLOGFW("DisplayManagerProxy::GetScreenGamutMap: remote is nullptr");
407         return DMError::DM_ERROR_NULLPTR;
408     }
409 
410     MessageParcel data;
411     MessageParcel reply;
412     MessageOption option;
413     if (!data.WriteInterfaceToken(GetDescriptor())) {
414         WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteInterfaceToken failed");
415         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
416     }
417     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
418         WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteUint64 screenId failed");
419         return DMError::DM_ERROR_IPC_FAILED;
420     }
421     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_GAMUT_MAP),
422         data, reply, option) != ERR_NONE) {
423         WLOGFW("DisplayManagerProxy::GetScreenGamutMap: SendRequest failed");
424         return DMError::DM_ERROR_IPC_FAILED;
425     }
426     DMError ret = static_cast<DMError>(reply.ReadInt32());
427     if (ret != DMError::DM_OK) {
428         return ret;
429     }
430     gamutMap = static_cast<ScreenGamutMap>(reply.ReadUint32());
431     return ret;
432 }
433 
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)434 DMError DisplayManagerProxy::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
435 {
436     sptr<IRemoteObject> remote = Remote();
437     if (remote == nullptr) {
438         WLOGFW("DisplayManagerProxy::SetScreenGamutMap: remote is nullptr");
439         return DMError::DM_ERROR_NULLPTR;
440     }
441 
442     MessageParcel data;
443     MessageParcel reply;
444     MessageOption option;
445     if (!data.WriteInterfaceToken(GetDescriptor())) {
446         WLOGFW("DisplayManagerProxy::SetScreenGamutMap: WriteInterfaceToken failed");
447         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
448     }
449     if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteUint32(static_cast<uint32_t>(gamutMap))) {
450         WLOGFW("DisplayManagerProxy::SetScreenGamutMap: Writ failed");
451         return DMError::DM_ERROR_IPC_FAILED;
452     }
453     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_GAMUT_MAP),
454         data, reply, option) != ERR_NONE) {
455         WLOGFW("DisplayManagerProxy::SetScreenGamutMap: SendRequest failed");
456         return DMError::DM_ERROR_IPC_FAILED;
457     }
458     return static_cast<DMError>(reply.ReadInt32());
459 }
460 
SetScreenColorTransform(ScreenId screenId)461 DMError DisplayManagerProxy::SetScreenColorTransform(ScreenId screenId)
462 {
463     sptr<IRemoteObject> remote = Remote();
464     if (remote == nullptr) {
465         WLOGFW("DisplayManagerProxy::SetScreenColorTransform: remote is nullptr");
466         return DMError::DM_ERROR_NULLPTR;
467     }
468 
469     MessageParcel data;
470     MessageParcel reply;
471     MessageOption option;
472     if (!data.WriteInterfaceToken(GetDescriptor())) {
473         WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteInterfaceToken failed");
474         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
475     }
476     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
477         WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteUint64 screenId failed");
478         return DMError::DM_ERROR_IPC_FAILED;
479     }
480     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_TRANSFORM),
481         data, reply, option) != ERR_NONE) {
482         WLOGFW("DisplayManagerProxy::SetScreenColorTransform: SendRequest failed");
483         return DMError::DM_ERROR_IPC_FAILED;
484     }
485     return static_cast<DMError>(reply.ReadInt32());
486 }
487 
GetPixelFormat(ScreenId screenId,GraphicPixelFormat & pixelFormat)488 DMError DisplayManagerProxy::GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat)
489 {
490     sptr<IRemoteObject> remote = Remote();
491     if (remote == nullptr) {
492         WLOGFW("GetPixelFormat: remote is nullptr");
493         return DMError::DM_ERROR_NULLPTR;
494     }
495 
496     MessageParcel data;
497     MessageParcel reply;
498     MessageOption option;
499     if (!data.WriteInterfaceToken(GetDescriptor())) {
500         WLOGFW("GetPixelFormat: WriteInterfaceToken failed");
501         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
502     }
503     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
504         WLOGFW("GetPixelFormat: WriteUint64 uint64_t failed");
505         return DMError::DM_ERROR_IPC_FAILED;
506     }
507     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_PIXEL_FORMAT),
508         data, reply, option) != ERR_NONE) {
509         WLOGFW("GetPixelFormat: SendRequest failed");
510         return DMError::DM_ERROR_IPC_FAILED;
511     }
512     DMError ret = static_cast<DMError>(reply.ReadInt32());
513     if (ret != DMError::DM_OK) {
514         return ret;
515     }
516     pixelFormat = static_cast<GraphicPixelFormat>(reply.ReadUint32());
517     return ret;
518 }
519 
SetPixelFormat(ScreenId screenId,GraphicPixelFormat pixelFormat)520 DMError DisplayManagerProxy::SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat)
521 {
522     sptr<IRemoteObject> remote = Remote();
523     if (remote == nullptr) {
524         WLOGFW("SetPixelFormat: remote is nullptr");
525         return DMError::DM_ERROR_NULLPTR;
526     }
527 
528     MessageParcel data;
529     MessageParcel reply;
530     MessageOption option;
531     if (!data.WriteInterfaceToken(GetDescriptor())) {
532         WLOGFW("SetPixelFormat: WriteInterfaceToken failed");
533         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
534     }
535     if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteInt32(pixelFormat)) {
536         WLOGFW("SetPixelFormat: WriteUint64 screenId failed");
537         return DMError::DM_ERROR_IPC_FAILED;
538     }
539     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_PIXEL_FORMAT),
540         data, reply, option) != ERR_NONE) {
541         WLOGFW("SetPixelFormat: SendRequest failed");
542         return DMError::DM_ERROR_IPC_FAILED;
543     }
544     return static_cast<DMError>(reply.ReadInt32());
545 }
546 
GetSupportedHDRFormats(ScreenId screenId,std::vector<ScreenHDRFormat> & hdrFormats)547 DMError DisplayManagerProxy::GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats)
548 {
549     sptr<IRemoteObject> remote = Remote();
550     if (remote == nullptr) {
551         WLOGFW("GetSupportedHDRFormats: remote is nullptr");
552         return DMError::DM_ERROR_NULLPTR;
553     }
554 
555     MessageParcel data;
556     MessageParcel reply;
557     MessageOption option;
558     if (!data.WriteInterfaceToken(GetDescriptor())) {
559         WLOGFW("GetSupportedHDRFormats: WriteInterfaceToken failed");
560         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
561     }
562     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
563         WLOGFW("GetSupportedHDRFormats: WriteUint64 screenId failed");
564         return DMError::DM_ERROR_IPC_FAILED;
565     }
566     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_HDR_FORMAT),
567         data, reply, option) != ERR_NONE) {
568         WLOGFW("GetSupportedHDRFormats: SendRequest failed");
569         return DMError::DM_ERROR_IPC_FAILED;
570     }
571     DMError ret = static_cast<DMError>(reply.ReadInt32());
572     if (ret != DMError::DM_OK) {
573         return ret;
574     }
575     MarshallingHelper::UnmarshallingVectorObj<ScreenHDRFormat>(reply, hdrFormats,
576         [](Parcel& parcel, ScreenHDRFormat& hdrFormat) {
577             uint32_t value;
578             bool res = parcel.ReadUint32(value);
579             hdrFormat = static_cast<ScreenHDRFormat>(value);
580             return res;
581         }
582     );
583     return ret;
584 }
585 
GetScreenHDRFormat(ScreenId screenId,ScreenHDRFormat & hdrFormat)586 DMError DisplayManagerProxy::GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat)
587 {
588     sptr<IRemoteObject> remote = Remote();
589     if (remote == nullptr) {
590         WLOGFW("GetScreenHDRFormat: remote is nullptr");
591         return DMError::DM_ERROR_NULLPTR;
592     }
593 
594     MessageParcel data;
595     MessageParcel reply;
596     MessageOption option;
597     if (!data.WriteInterfaceToken(GetDescriptor())) {
598         WLOGFW("GetScreenHDRFormat: WriteInterfaceToken failed");
599         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
600     }
601     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
602         WLOGFW("GetScreenHDRFormat: WriteUint64 uint64_t failed");
603         return DMError::DM_ERROR_IPC_FAILED;
604     }
605     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_HDR_FORMAT),
606         data, reply, option) != ERR_NONE) {
607         WLOGFW("GetScreenHDRFormat: SendRequest failed");
608         return DMError::DM_ERROR_IPC_FAILED;
609     }
610     DMError ret = static_cast<DMError>(reply.ReadInt32());
611     if (ret != DMError::DM_OK) {
612         return ret;
613     }
614     hdrFormat = static_cast<ScreenHDRFormat>(reply.ReadUint32());
615     return ret;
616 }
617 
SetScreenHDRFormat(ScreenId screenId,int32_t modeIdx)618 DMError DisplayManagerProxy::SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx)
619 {
620     sptr<IRemoteObject> remote = Remote();
621     if (remote == nullptr) {
622         WLOGFW("SetScreenHDRFormat: remote is nullptr");
623         return DMError::DM_ERROR_NULLPTR;
624     }
625 
626     MessageParcel data;
627     MessageParcel reply;
628     MessageOption option;
629     if (!data.WriteInterfaceToken(GetDescriptor())) {
630         WLOGFW("SetScreenHDRFormat: WriteInterfaceToken failed");
631         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
632     }
633     if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteInt32(modeIdx)) {
634         WLOGFW("SetScreenHDRFormat: WriteUint64 screenId failed");
635         return DMError::DM_ERROR_IPC_FAILED;
636     }
637     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_HDR_FORMAT),
638         data, reply, option) != ERR_NONE) {
639         WLOGFW("SetScreenHDRFormat: SendRequest failed");
640         return DMError::DM_ERROR_IPC_FAILED;
641     }
642     return static_cast<DMError>(reply.ReadInt32());
643 }
644 
GetSupportedColorSpaces(ScreenId screenId,std::vector<GraphicCM_ColorSpaceType> & colorSpaces)645 DMError DisplayManagerProxy::GetSupportedColorSpaces(ScreenId screenId,
646     std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
647 {
648     sptr<IRemoteObject> remote = Remote();
649     if (remote == nullptr) {
650         WLOGFW("GetSupportedColorSpaces: remote is nullptr");
651         return DMError::DM_ERROR_NULLPTR;
652     }
653 
654     MessageParcel data;
655     MessageParcel reply;
656     MessageOption option;
657     if (!data.WriteInterfaceToken(GetDescriptor())) {
658         WLOGFW("GetSupportedColorSpaces: WriteInterfaceToken failed");
659         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
660     }
661     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
662         WLOGFW("GetSupportedColorSpaces: WriteUint64 screenId failed");
663         return DMError::DM_ERROR_IPC_FAILED;
664     }
665     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_SPACE),
666         data, reply, option) != ERR_NONE) {
667         WLOGFW("GetSupportedColorSpaces: SendRequest failed");
668         return DMError::DM_ERROR_IPC_FAILED;
669     }
670     DMError ret = static_cast<DMError>(reply.ReadInt32());
671     if (ret != DMError::DM_OK) {
672         return ret;
673     }
674     MarshallingHelper::UnmarshallingVectorObj<GraphicCM_ColorSpaceType>(reply, colorSpaces,
675         [](Parcel& parcel, GraphicCM_ColorSpaceType& color) {
676             uint32_t value;
677             bool res = parcel.ReadUint32(value);
678             color = static_cast<GraphicCM_ColorSpaceType>(value);
679             return res;
680         }
681     );
682     return ret;
683 }
684 
GetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType & colorSpace)685 DMError DisplayManagerProxy::GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace)
686 {
687     sptr<IRemoteObject> remote = Remote();
688     if (remote == nullptr) {
689         WLOGFW("GetScreenColorSpace: remote is nullptr");
690         return DMError::DM_ERROR_NULLPTR;
691     }
692 
693     MessageParcel data;
694     MessageParcel reply;
695     MessageOption option;
696     if (!data.WriteInterfaceToken(GetDescriptor())) {
697         WLOGFW("GetScreenColorSpace: WriteInterfaceToken failed");
698         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
699     }
700     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
701         WLOGFW("GetScreenColorSpace: WriteUint64 screenId failed");
702         return DMError::DM_ERROR_IPC_FAILED;
703     }
704     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_SPACE),
705         data, reply, option) != ERR_NONE) {
706         WLOGFW("GetScreenColorSpace: SendRequest failed");
707         return DMError::DM_ERROR_IPC_FAILED;
708     }
709     DMError ret = static_cast<DMError>(reply.ReadInt32());
710     if (ret != DMError::DM_OK) {
711         return ret;
712     }
713     colorSpace = static_cast<GraphicCM_ColorSpaceType>(reply.ReadUint32());
714     return ret;
715 }
716 
SetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType colorSpace)717 DMError DisplayManagerProxy::SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace)
718 {
719     sptr<IRemoteObject> remote = Remote();
720     if (remote == nullptr) {
721         WLOGFW("SetScreenColorSpace: remote is nullptr");
722         return DMError::DM_ERROR_NULLPTR;
723     }
724 
725     MessageParcel data;
726     MessageParcel reply;
727     MessageOption option;
728     if (!data.WriteInterfaceToken(GetDescriptor())) {
729         WLOGFW("SetScreenColorSpace: WriteInterfaceToken failed");
730         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
731     }
732     if (!data.WriteUint64(static_cast<uint64_t>(screenId)) || !data.WriteInt32(colorSpace)) {
733         WLOGFW("SetScreenColorSpace: Write failed");
734         return DMError::DM_ERROR_IPC_FAILED;
735     }
736     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_SPACE),
737         data, reply, option) != ERR_NONE) {
738         WLOGFW("SetScreenColorSpace: SendRequest failed");
739         return DMError::DM_ERROR_IPC_FAILED;
740     }
741     return static_cast<DMError>(reply.ReadInt32());
742 }
743 
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)744 DMError DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
745     DisplayManagerAgentType type)
746 {
747     sptr<IRemoteObject> remote = Remote();
748     if (remote == nullptr) {
749         WLOGFW("RegisterDisplayManagerAgent: remote is nullptr");
750         return DMError::DM_ERROR_NULLPTR;
751     }
752 
753     MessageParcel data;
754     MessageParcel reply;
755     MessageOption option;
756     if (!data.WriteInterfaceToken(GetDescriptor())) {
757         WLOGFE("WriteInterfaceToken failed");
758         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
759     }
760 
761     if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
762         WLOGFE("Write IDisplayManagerAgent failed");
763         return DMError::DM_ERROR_IPC_FAILED;
764     }
765 
766     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
767         WLOGFE("Write DisplayManagerAgent type failed");
768         return DMError::DM_ERROR_IPC_FAILED;
769     }
770 
771     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT),
772         data, reply, option) != ERR_NONE) {
773         WLOGFE("SendRequest failed");
774         return DMError::DM_ERROR_IPC_FAILED;
775     }
776     return static_cast<DMError>(reply.ReadInt32());
777 }
778 
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)779 DMError DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
780     DisplayManagerAgentType type)
781 {
782     sptr<IRemoteObject> remote = Remote();
783     if (remote == nullptr) {
784         WLOGFW("UnregisterDisplayManagerAgent: remote is nullptr");
785         return DMError::DM_ERROR_NULLPTR;
786     }
787 
788     MessageParcel data;
789     MessageParcel reply;
790     MessageOption option;
791     if (!data.WriteInterfaceToken(GetDescriptor())) {
792         WLOGFE("WriteInterfaceToken failed");
793         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
794     }
795 
796     if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
797         WLOGFE("Write IWindowManagerAgent failed");
798         return DMError::DM_ERROR_IPC_FAILED;
799     }
800 
801     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
802         WLOGFE("Write DisplayManagerAgent type failed");
803         return DMError::DM_ERROR_IPC_FAILED;
804     }
805 
806     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT),
807         data, reply, option) != ERR_NONE) {
808         WLOGFE("SendRequest failed");
809         return DMError::DM_ERROR_IPC_FAILED;
810     }
811     return static_cast<DMError>(reply.ReadInt32());
812 }
813 
WakeUpBegin(PowerStateChangeReason reason)814 bool DisplayManagerProxy::WakeUpBegin(PowerStateChangeReason reason)
815 {
816     sptr<IRemoteObject> remote = Remote();
817     if (remote == nullptr) {
818         WLOGFW("[UL_POWER]WakeUpBegin: remote is nullptr");
819         return false;
820     }
821 
822     MessageParcel data;
823     MessageParcel reply;
824     MessageOption option;
825     if (!data.WriteInterfaceToken(GetDescriptor())) {
826         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
827         return false;
828     }
829     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
830         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
831         return false;
832     }
833     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN),
834         data, reply, option) != ERR_NONE) {
835         WLOGFW("[UL_POWER]SendRequest failed");
836         return false;
837     }
838     return reply.ReadBool();
839 }
840 
WakeUpEnd()841 bool DisplayManagerProxy::WakeUpEnd()
842 {
843     sptr<IRemoteObject> remote = Remote();
844     if (remote == nullptr) {
845         WLOGFW("[UL_POWER]WakeUpEnd: remote is nullptr");
846         return false;
847     }
848 
849     MessageParcel data;
850     MessageParcel reply;
851     MessageOption option;
852     if (!data.WriteInterfaceToken(GetDescriptor())) {
853         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
854         return false;
855     }
856     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_WAKE_UP_END),
857         data, reply, option) != ERR_NONE) {
858         WLOGFW("[UL_POWER]SendRequest failed");
859         return false;
860     }
861     return reply.ReadBool();
862 }
863 
SuspendBegin(PowerStateChangeReason reason)864 bool DisplayManagerProxy::SuspendBegin(PowerStateChangeReason reason)
865 {
866     sptr<IRemoteObject> remote = Remote();
867     if (remote == nullptr) {
868         WLOGFW("[UL_POWER]SuspendBegin: remote is nullptr");
869         return false;
870     }
871 
872     MessageParcel data;
873     MessageParcel reply;
874     MessageOption option;
875     if (!data.WriteInterfaceToken(GetDescriptor())) {
876         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
877         return false;
878     }
879     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
880         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
881         return false;
882     }
883     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN),
884         data, reply, option) != ERR_NONE) {
885         WLOGFW("[UL_POWER]SendRequest failed");
886         return false;
887     }
888     return reply.ReadBool();
889 }
890 
SuspendEnd()891 bool DisplayManagerProxy::SuspendEnd()
892 {
893     sptr<IRemoteObject> remote = Remote();
894     if (remote == nullptr) {
895         WLOGFW("[UL_POWER]SuspendEnd: remote is nullptr");
896         return false;
897     }
898 
899     MessageParcel data;
900     MessageParcel reply;
901     MessageOption option;
902     if (!data.WriteInterfaceToken(GetDescriptor())) {
903         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
904         return false;
905     }
906     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SUSPEND_END),
907         data, reply, option) != ERR_NONE) {
908         WLOGFW("[UL_POWER]SendRequest failed");
909         return false;
910     }
911     return reply.ReadBool();
912 }
913 
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)914 bool DisplayManagerProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
915 {
916     sptr<IRemoteObject> remote = Remote();
917     if (remote == nullptr) {
918         WLOGFW("[UL_POWER]SetScreenPowerForAll: remote is nullptr");
919         return false;
920     }
921 
922     MessageParcel data;
923     MessageParcel reply;
924     MessageOption option;
925     if (!data.WriteInterfaceToken(GetDescriptor())) {
926         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
927         return false;
928     }
929     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
930         WLOGFE("[UL_POWER]Write ScreenPowerState failed");
931         return false;
932     }
933     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
934         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
935         return false;
936     }
937     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL),
938         data, reply, option) != ERR_NONE) {
939         WLOGFW("[UL_POWER]SendRequest failed");
940         return false;
941     }
942     return reply.ReadBool();
943 }
944 
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)945 bool DisplayManagerProxy::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
946     PowerStateChangeReason reason)
947 {
948     sptr<IRemoteObject> remote = Remote();
949     if (remote == nullptr) {
950         WLOGFW("[UL_POWER]SetSpecifiedScreenPower: remote is nullptr");
951         return false;
952     }
953 
954     MessageParcel data;
955     MessageParcel reply;
956     MessageOption option;
957     if (!data.WriteInterfaceToken(GetDescriptor())) {
958         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
959         return false;
960     }
961     if (!data.WriteUint32(static_cast<uint32_t>(screenId))) {
962         WLOGFE("[UL_POWER]Write ScreenId failed");
963         return false;
964     }
965     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
966         WLOGFE("[UL_POWER]Write ScreenPowerState failed");
967         return false;
968     }
969     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
970         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
971         return false;
972     }
973     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER),
974         data, reply, option) != ERR_NONE) {
975         WLOGFW("[UL_POWER]SendRequest failed");
976         return false;
977     }
978     return reply.ReadBool();
979 }
980 
GetScreenPower(ScreenId dmsScreenId)981 ScreenPowerState DisplayManagerProxy::GetScreenPower(ScreenId dmsScreenId)
982 {
983     sptr<IRemoteObject> remote = Remote();
984     if (remote == nullptr) {
985         WLOGFW("GetScreenPower: remote is nullptr");
986         return ScreenPowerState::INVALID_STATE;
987     }
988 
989     MessageParcel data;
990     MessageParcel reply;
991     MessageOption option;
992     if (!data.WriteInterfaceToken(GetDescriptor())) {
993         WLOGFE("WriteInterfaceToken failed");
994         return ScreenPowerState::INVALID_STATE;
995     }
996     if (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
997         WLOGFE("Write dmsScreenId failed");
998         return ScreenPowerState::INVALID_STATE;
999     }
1000     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
1001         data, reply, option) != ERR_NONE) {
1002         WLOGFW("SendRequest failed");
1003         return ScreenPowerState::INVALID_STATE;
1004     }
1005     return static_cast<ScreenPowerState>(reply.ReadUint32());
1006 }
1007 
SetDisplayState(DisplayState state)1008 bool DisplayManagerProxy::SetDisplayState(DisplayState state)
1009 {
1010     sptr<IRemoteObject> remote = Remote();
1011     if (remote == nullptr) {
1012         WLOGFW("[UL_POWER]SetDisplayState: remote is nullptr");
1013         return false;
1014     }
1015 
1016     MessageParcel data;
1017     MessageParcel reply;
1018     MessageOption option;
1019     if (!data.WriteInterfaceToken(GetDescriptor())) {
1020         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1021         return false;
1022     }
1023     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
1024         WLOGFE("[UL_POWER]Write DisplayState failed");
1025         return false;
1026     }
1027     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
1028         data, reply, option) != ERR_NONE) {
1029         WLOGFW("[UL_POWER]SendRequest failed");
1030         return false;
1031     }
1032     return reply.ReadBool();
1033 }
1034 
GetDisplayState(DisplayId displayId)1035 DisplayState DisplayManagerProxy::GetDisplayState(DisplayId displayId)
1036 {
1037     sptr<IRemoteObject> remote = Remote();
1038     if (remote == nullptr) {
1039         WLOGFW("GetDisplayState: remote is nullptr");
1040         return DisplayState::UNKNOWN;
1041     }
1042 
1043     MessageParcel data;
1044     MessageParcel reply;
1045     MessageOption option;
1046     if (!data.WriteInterfaceToken(GetDescriptor())) {
1047         WLOGFE("WriteInterfaceToken failed");
1048         return DisplayState::UNKNOWN;
1049     }
1050     if (!data.WriteUint64(displayId)) {
1051         WLOGFE("Write displayId failed");
1052         return DisplayState::UNKNOWN;
1053     }
1054     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
1055         data, reply, option) != ERR_NONE) {
1056         WLOGFW("SendRequest failed");
1057         return DisplayState::UNKNOWN;
1058     }
1059     return static_cast<DisplayState>(reply.ReadUint32());
1060 }
1061 
TryToCancelScreenOff()1062 bool DisplayManagerProxy::TryToCancelScreenOff()
1063 {
1064     sptr<IRemoteObject> remote = Remote();
1065     if (remote == nullptr) {
1066         WLOGFW("[UL_POWER]TryToCancelScreenOff: remote is nullptr");
1067         return false;
1068     }
1069 
1070     MessageParcel data;
1071     MessageParcel reply;
1072     MessageOption option;
1073     if (!data.WriteInterfaceToken(GetDescriptor())) {
1074         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1075         return false;
1076     }
1077     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
1078         data, reply, option) != ERR_NONE) {
1079         WLOGFW("[UL_POWER]SendRequest failed");
1080         return false;
1081     }
1082     return reply.ReadBool();
1083 }
1084 
GetAllDisplayIds()1085 std::vector<DisplayId> DisplayManagerProxy::GetAllDisplayIds()
1086 {
1087     std::vector<DisplayId> allDisplayIds;
1088     sptr<IRemoteObject> remote = Remote();
1089     if (remote == nullptr) {
1090         WLOGFW("GetAllDisplayIds: remote is nullptr");
1091         return allDisplayIds;
1092     }
1093 
1094     MessageParcel data;
1095     MessageParcel reply;
1096     MessageOption option;
1097     if (!data.WriteInterfaceToken(GetDescriptor())) {
1098         WLOGFE("WriteInterfaceToken failed");
1099         return allDisplayIds;
1100     }
1101     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
1102         data, reply, option) != ERR_NONE) {
1103         WLOGFW("SendRequest failed");
1104         return allDisplayIds;
1105     }
1106     reply.ReadUInt64Vector(&allDisplayIds);
1107     return allDisplayIds;
1108 }
1109 
GetCutoutInfo(DisplayId displayId)1110 sptr<CutoutInfo> DisplayManagerProxy::GetCutoutInfo(DisplayId displayId)
1111 {
1112     sptr<IRemoteObject> remote = Remote();
1113     if (remote == nullptr) {
1114         WLOGFW("GetCutoutInfo: remote is null");
1115         return nullptr;
1116     }
1117     MessageParcel data;
1118     MessageParcel reply;
1119     MessageOption option;
1120     if (!data.WriteInterfaceToken(GetDescriptor())) {
1121         WLOGFE("GetCutoutInfo: GetCutoutInfo failed");
1122         return nullptr;
1123     }
1124     if (!data.WriteUint64(displayId)) {
1125         WLOGFE("GetCutoutInfo: write displayId failed");
1126         return nullptr;
1127     }
1128     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO),
1129         data, reply, option) != ERR_NONE) {
1130         WLOGFW("GetCutoutInfo: GetCutoutInfo failed");
1131         return nullptr;
1132     }
1133     sptr<CutoutInfo> info = reply.ReadParcelable<CutoutInfo>();
1134     return info;
1135 }
1136 
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode,bool onTop)1137 DMError DisplayManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId,
1138     std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop)
1139 {
1140     sptr<IRemoteObject> remote = Remote();
1141     if (remote == nullptr) {
1142         WLOGFW("AddSurfaceNodeToDisplay: remote is nullptr");
1143         return DMError::DM_ERROR_IPC_FAILED;
1144     }
1145 
1146     MessageParcel data;
1147     MessageParcel reply;
1148     MessageOption option;
1149     if (!data.WriteInterfaceToken(GetDescriptor())) {
1150         WLOGFE("WriteInterfaceToken failed");
1151         return DMError::DM_ERROR_IPC_FAILED;
1152     }
1153     if (!data.WriteUint64(displayId)) {
1154         WLOGFE("write displayId failed");
1155         return DMError::DM_ERROR_IPC_FAILED;
1156     }
1157     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
1158         WLOGFE("Write windowProperty failed");
1159         return DMError::DM_ERROR_IPC_FAILED;
1160     }
1161     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE),
1162         data, reply, option) != ERR_NONE) {
1163         WLOGFW("Send request failed");
1164         return DMError::DM_ERROR_IPC_FAILED;
1165     }
1166     DMError ret = static_cast<DMError>(reply.ReadUint32());
1167     return ret;
1168 }
1169 
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)1170 DMError DisplayManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
1171     std::shared_ptr<class RSSurfaceNode>& surfaceNode)
1172 {
1173     sptr<IRemoteObject> remote = Remote();
1174     if (remote == nullptr) {
1175         WLOGFW("RemoveSurfaceNodeFromDisplay: remote is nullptr");
1176         return DMError::DM_ERROR_IPC_FAILED;
1177     }
1178 
1179     MessageParcel data;
1180     MessageParcel reply;
1181     MessageOption option;
1182     if (!data.WriteInterfaceToken(GetDescriptor())) {
1183         WLOGFE("WriteInterfaceToken failed");
1184         return DMError::DM_ERROR_IPC_FAILED;
1185     }
1186     if (!data.WriteUint64(displayId)) {
1187         WLOGFE("write displayId failed");
1188         return DMError::DM_ERROR_IPC_FAILED;
1189     }
1190     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
1191         WLOGFE("Write windowProperty failed");
1192         return DMError::DM_ERROR_IPC_FAILED;
1193     }
1194     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE),
1195         data, reply, option) != ERR_NONE) {
1196         WLOGFW("Send request failed");
1197         return DMError::DM_ERROR_IPC_FAILED;
1198     }
1199     DMError ret = static_cast<DMError>(reply.ReadUint32());
1200     return ret;
1201 }
1202 
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)1203 DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1204 {
1205     sptr<IRemoteObject> remote = Remote();
1206     if (remote == nullptr) {
1207         WLOGFW("HasPrivateWindow: remote is nullptr");
1208         return DMError::DM_ERROR_IPC_FAILED;
1209     }
1210 
1211     MessageParcel data;
1212     MessageParcel reply;
1213     MessageOption option;
1214     if (!data.WriteInterfaceToken(GetDescriptor())) {
1215         return DMError::DM_ERROR_IPC_FAILED;
1216     }
1217 
1218     if (!data.WriteUint64(displayId)) {
1219         return DMError::DM_ERROR_IPC_FAILED;
1220     }
1221 
1222     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW),
1223         data, reply, option) != ERR_NONE) {
1224         return DMError::DM_ERROR_IPC_FAILED;
1225     }
1226     DMError ret = static_cast<DMError>(reply.ReadInt32());
1227     hasPrivateWindow = reply.ReadBool();
1228     return ret;
1229 }
1230 
NotifyDisplayEvent(DisplayEvent event)1231 void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
1232 {
1233     sptr<IRemoteObject> remote = Remote();
1234     if (remote == nullptr) {
1235         WLOGFW("NotifyDisplayEvent: remote is nullptr");
1236         return;
1237     }
1238 
1239     MessageParcel data;
1240     MessageParcel reply;
1241     MessageOption option;
1242     if (!data.WriteInterfaceToken(GetDescriptor())) {
1243         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1244         return;
1245     }
1246     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
1247         WLOGFE("[UL_POWER]Write DisplayEvent failed");
1248         return;
1249     }
1250     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT),
1251         data, reply, option) != ERR_NONE) {
1252         WLOGFW("[UL_POWER]SendRequest failed");
1253         return;
1254     }
1255 }
1256 
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)1257 bool DisplayManagerProxy::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
1258 {
1259     sptr<IRemoteObject> remote = Remote();
1260     if (remote == nullptr) {
1261         WLOGFW("SetFreeze: remote is nullptr");
1262         return false;
1263     }
1264 
1265     MessageParcel data;
1266     MessageParcel reply;
1267     MessageOption option;
1268     if (!data.WriteInterfaceToken(GetDescriptor())) {
1269         WLOGFE("WriteInterfaceToken failed");
1270         return false;
1271     }
1272     if (!data.WriteUInt64Vector(displayIds)) {
1273         WLOGFE("set freeze fail: write displayId failed.");
1274         return false;
1275     }
1276     if (!data.WriteBool(isFreeze)) {
1277         WLOGFE("set freeze fail: write freeze flag failed.");
1278         return false;
1279     }
1280 
1281     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT),
1282         data, reply, option) != ERR_NONE) {
1283         WLOGFE("SendRequest failed");
1284         return false;
1285     }
1286     return true;
1287 }
1288 
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)1289 DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
1290                                         ScreenId& screenGroupId)
1291 {
1292     sptr<IRemoteObject> remote = Remote();
1293     if (remote == nullptr) {
1294         WLOGFW("create mirror fail: remote is null");
1295         return DMError::DM_ERROR_NULLPTR;
1296     }
1297 
1298     MessageParcel data;
1299     MessageParcel reply;
1300     MessageOption option;
1301     if (!data.WriteInterfaceToken(GetDescriptor())) {
1302         WLOGFE("create mirror fail: WriteInterfaceToken failed");
1303         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1304     }
1305     bool res = data.WriteUint64(static_cast<uint64_t>(mainScreenId)) &&
1306         data.WriteUInt64Vector(mirrorScreenId);
1307     if (!res) {
1308         WLOGFE("create mirror fail: data write failed");
1309         return DMError::DM_ERROR_IPC_FAILED;
1310     }
1311     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR),
1312         data, reply, option) != ERR_NONE) {
1313         WLOGFW("create mirror fail: SendRequest failed");
1314         return DMError::DM_ERROR_IPC_FAILED;
1315     }
1316     DMError ret = static_cast<DMError>(reply.ReadInt32());
1317     screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
1318     return ret;
1319 }
1320 
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)1321 DMError DisplayManagerProxy::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
1322 {
1323     sptr<IRemoteObject> remote = Remote();
1324     if (remote == nullptr) {
1325         WLOGFW("StopMirror fail: remote is null");
1326         return DMError::DM_ERROR_NULLPTR;
1327     }
1328 
1329     MessageParcel data;
1330     MessageParcel reply;
1331     MessageOption option;
1332     if (!data.WriteInterfaceToken(GetDescriptor())) {
1333         WLOGFE("StopMirror fail: WriteInterfaceToken failed");
1334         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1335     }
1336     bool res = data.WriteUInt64Vector(mirrorScreenIds);
1337     if (!res) {
1338         WLOGFE("StopMirror fail: data write failed");
1339         return DMError::DM_ERROR_IPC_FAILED;
1340     }
1341     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_MIRROR),
1342         data, reply, option) != ERR_NONE) {
1343         WLOGFW("StopMirror fail: SendRequest failed");
1344         return DMError::DM_ERROR_IPC_FAILED;
1345     }
1346     return static_cast<DMError>(reply.ReadInt32());
1347 }
1348 
GetScreenInfoById(ScreenId screenId)1349 sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
1350 {
1351     sptr<IRemoteObject> remote = Remote();
1352     if (remote == nullptr) {
1353         WLOGFW("GetScreenInfoById: remote is nullptr");
1354         return nullptr;
1355     }
1356 
1357     MessageParcel data;
1358     MessageParcel reply;
1359     MessageOption option;
1360     if (!data.WriteInterfaceToken(GetDescriptor())) {
1361         WLOGFE("GetScreenInfoById: WriteInterfaceToken failed");
1362         return nullptr;
1363     }
1364     if (!data.WriteUint64(screenId)) {
1365         WLOGFE("GetScreenInfoById: Write screenId failed");
1366         return nullptr;
1367     }
1368     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID),
1369         data, reply, option) != ERR_NONE) {
1370         WLOGFW("GetScreenInfoById: SendRequest failed");
1371         return nullptr;
1372     }
1373 
1374     sptr<ScreenInfo> info = reply.ReadStrongParcelable<ScreenInfo>();
1375     if (info == nullptr) {
1376         WLOGFW("GetScreenInfoById SendRequest nullptr.");
1377         return nullptr;
1378     }
1379     for (auto& mode : info->GetModes()) {
1380         WLOGFI("info modes is id: %{public}u, width: %{public}u, height: %{public}u, refreshRate: %{public}u",
1381             mode->id_, mode->width_, mode->height_, mode->refreshRate_);
1382     }
1383     return info;
1384 }
1385 
GetScreenGroupInfoById(ScreenId screenId)1386 sptr<ScreenGroupInfo> DisplayManagerProxy::GetScreenGroupInfoById(ScreenId screenId)
1387 {
1388     sptr<IRemoteObject> remote = Remote();
1389     if (remote == nullptr) {
1390         WLOGFW("GetScreenGroupInfoById: remote is nullptr");
1391         return nullptr;
1392     }
1393 
1394     MessageParcel data;
1395     MessageParcel reply;
1396     MessageOption option;
1397     if (!data.WriteInterfaceToken(GetDescriptor())) {
1398         WLOGFE("GetScreenGroupInfoById: WriteInterfaceToken failed");
1399         return nullptr;
1400     }
1401     if (!data.WriteUint64(screenId)) {
1402         WLOGFE("GetScreenGroupInfoById: Write screenId failed");
1403         return nullptr;
1404     }
1405     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID),
1406         data, reply, option) != ERR_NONE) {
1407         WLOGFW("GetScreenGroupInfoById: SendRequest failed");
1408         return nullptr;
1409     }
1410 
1411     sptr<ScreenGroupInfo> info = reply.ReadStrongParcelable<ScreenGroupInfo>();
1412     if (info == nullptr) {
1413         WLOGFW("GetScreenGroupInfoById SendRequest nullptr.");
1414         return nullptr;
1415     }
1416     return info;
1417 }
1418 
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)1419 DMError DisplayManagerProxy::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
1420 {
1421     sptr<IRemoteObject> remote = Remote();
1422     if (remote == nullptr) {
1423         WLOGFW("GetAllScreenInfos: remote is nullptr");
1424         return DMError::DM_ERROR_NULLPTR;
1425     }
1426 
1427     MessageParcel data;
1428     MessageParcel reply;
1429     MessageOption option;
1430     if (!data.WriteInterfaceToken(GetDescriptor())) {
1431         WLOGFE("GetAllScreenInfos: WriteInterfaceToken failed");
1432         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1433     }
1434     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS),
1435         data, reply, option) != ERR_NONE) {
1436         WLOGFW("GetAllScreenInfos: SendRequest failed");
1437         return DMError::DM_ERROR_IPC_FAILED;
1438     }
1439     DMError ret = static_cast<DMError>(reply.ReadInt32());
1440     static_cast<void>(MarshallingHelper::UnmarshallingVectorParcelableObj<ScreenInfo>(reply, screenInfos));
1441     return ret;
1442 }
1443 
MakeExpand(std::vector<ScreenId> screenId,std::vector<Point> startPoint,ScreenId & screenGroupId)1444 DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
1445                                         ScreenId& screenGroupId)
1446 {
1447     sptr<IRemoteObject> remote = Remote();
1448     if (remote == nullptr) {
1449         WLOGFW("MakeExpand: remote is null");
1450         return DMError::DM_ERROR_IPC_FAILED;
1451     }
1452 
1453     MessageParcel data;
1454     MessageParcel reply;
1455     MessageOption option;
1456     if (!data.WriteInterfaceToken(GetDescriptor())) {
1457         WLOGFE("MakeExpand: WriteInterfaceToken failed");
1458         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1459     }
1460     if (!data.WriteUInt64Vector(screenId)) {
1461         WLOGFE("MakeExpand: write screenId failed");
1462         return DMError::DM_ERROR_IPC_FAILED;
1463     }
1464     if (!MarshallingHelper::MarshallingVectorObj<Point>(data, startPoint, [](Parcel& parcel, const Point& point) {
1465             return parcel.WriteInt32(point.posX_) && parcel.WriteInt32(point.posY_);
1466         })) {
1467         WLOGFE("MakeExpand: write startPoint failed");
1468         return DMError::DM_ERROR_IPC_FAILED;
1469     }
1470     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND),
1471         data, reply, option) != ERR_NONE) {
1472         WLOGFE("MakeExpand: SendRequest failed");
1473         return DMError::DM_ERROR_IPC_FAILED;
1474     }
1475     DMError ret = static_cast<DMError>(reply.ReadInt32());
1476     screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
1477     return ret;
1478 }
1479 
StopExpand(const std::vector<ScreenId> & expandScreenIds)1480 DMError DisplayManagerProxy::StopExpand(const std::vector<ScreenId>& expandScreenIds)
1481 {
1482     sptr<IRemoteObject> remote = Remote();
1483     if (remote == nullptr) {
1484         WLOGFW("StopExpand fail: remote is null");
1485         return DMError::DM_ERROR_NULLPTR;
1486     }
1487 
1488     MessageParcel data;
1489     MessageParcel reply;
1490     MessageOption option;
1491     if (!data.WriteInterfaceToken(GetDescriptor())) {
1492         WLOGFE("StopExpand fail: WriteInterfaceToken failed");
1493         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1494     }
1495     bool res = data.WriteUInt64Vector(expandScreenIds);
1496     if (!res) {
1497         WLOGFE("StopExpand fail: data write failed");
1498         return DMError::DM_ERROR_IPC_FAILED;
1499     }
1500     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_EXPAND),
1501         data, reply, option) != ERR_NONE) {
1502         WLOGFW("StopExpand fail: SendRequest failed");
1503         return DMError::DM_ERROR_IPC_FAILED;
1504     }
1505     return static_cast<DMError>(reply.ReadInt32());
1506 }
1507 
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)1508 void DisplayManagerProxy::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
1509 {
1510     sptr<IRemoteObject> remote = Remote();
1511     if (remote == nullptr) {
1512         WLOGFW("cancel make mirror or expand fail: remote is null");
1513         return;
1514     }
1515 
1516     MessageParcel data;
1517     MessageParcel reply;
1518     MessageOption option(MessageOption::TF_ASYNC);
1519     if (!data.WriteInterfaceToken(GetDescriptor())) {
1520         WLOGFE("cancel make mirror or expand fail: WriteInterfaceToken failed");
1521         return;
1522     }
1523     bool res = data.WriteUInt64Vector(screens);
1524     if (!res) {
1525         WLOGFE("cancel make mirror or expand fail: write screens failed.");
1526         return;
1527     }
1528     if (remote->SendRequest(static_cast<uint32_t>(
1529         DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP),
1530         data, reply, option) != ERR_NONE) {
1531         WLOGFW("cancel make mirror or expand fail: SendRequest failed");
1532     }
1533 }
1534 
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)1535 DMError DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
1536 {
1537     sptr<IRemoteObject> remote = Remote();
1538     if (remote == nullptr) {
1539         WLOGFW("SetScreenActiveMode: remote is null");
1540         return DMError::DM_ERROR_NULLPTR;
1541     }
1542 
1543     MessageParcel data;
1544     MessageParcel reply;
1545     MessageOption option;
1546     if (!data.WriteInterfaceToken(GetDescriptor())) {
1547         WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed");
1548         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1549     }
1550     if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) {
1551         WLOGFE("SetScreenActiveMode: write screenId/modeId failed");
1552         return DMError::DM_ERROR_IPC_FAILED;
1553     }
1554     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE),
1555         data, reply, option) != ERR_NONE) {
1556         WLOGFE("SetScreenActiveMode: SendRequest failed");
1557         return DMError::DM_ERROR_IPC_FAILED;
1558     }
1559     return static_cast<DMError>(reply.ReadInt32());
1560 }
1561 
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)1562 DMError DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
1563 {
1564     sptr<IRemoteObject> remote = Remote();
1565     if (remote == nullptr) {
1566         WLOGFW("SetVirtualPixelRatio: remote is null");
1567         return DMError::DM_ERROR_NULLPTR;
1568     }
1569 
1570     MessageParcel data;
1571     MessageParcel reply;
1572     MessageOption option;
1573     if (!data.WriteInterfaceToken(GetDescriptor())) {
1574         WLOGFE("WriteInterfaceToken failed");
1575         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1576     }
1577     if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) {
1578         WLOGFE("write screenId/modeId failed");
1579         return DMError::DM_ERROR_IPC_FAILED;
1580     }
1581     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO),
1582         data, reply, option) != ERR_NONE) {
1583         WLOGFE("SendRequest failed");
1584         return DMError::DM_ERROR_IPC_FAILED;
1585     }
1586     return static_cast<DMError>(reply.ReadInt32());
1587 }
1588 
SetResolution(ScreenId screenId,uint32_t width,uint32_t height,float virtualPixelRatio)1589 DMError DisplayManagerProxy::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)
1590 {
1591     sptr<IRemoteObject> remote = Remote();
1592     if (remote == nullptr) {
1593         WLOGFW("SetResolution: remote is null");
1594         return DMError::DM_ERROR_NULLPTR;
1595     }
1596 
1597     MessageParcel data;
1598     MessageParcel reply;
1599     MessageOption option;
1600     if (!data.WriteInterfaceToken(GetDescriptor())) {
1601         WLOGFE("WriteInterfaceToken failed");
1602         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1603     }
1604     if (!data.WriteUint64(screenId) || !data.WriteUint32(width) ||
1605         !data.WriteUint32(height) || !data.WriteFloat(virtualPixelRatio)) {
1606         WLOGFE("write screenId/width/height/virtualPixelRatio failed");
1607         return DMError::DM_ERROR_IPC_FAILED;
1608     }
1609     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_RESOLUTION),
1610         data, reply, option) != ERR_NONE) {
1611         WLOGFE("SendRequest failed");
1612         return DMError::DM_ERROR_IPC_FAILED;
1613     }
1614     return static_cast<DMError>(reply.ReadInt32());
1615 }
1616 
GetDensityInCurResolution(ScreenId screenId,float & virtualPixelRatio)1617 DMError DisplayManagerProxy::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)
1618 {
1619     sptr<IRemoteObject> remote = Remote();
1620     if (remote == nullptr) {
1621         WLOGFW("GetDensityInCurResolution: remote is null");
1622         return DMError::DM_ERROR_NULLPTR;
1623     }
1624 
1625     MessageParcel data;
1626     MessageParcel reply;
1627     MessageOption option;
1628     if (!data.WriteInterfaceToken(GetDescriptor())) {
1629         WLOGFE("WriteInterfaceToken failed");
1630         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1631     }
1632     if (!data.WriteUint64(screenId)) {
1633         WLOGFE("write screenId failed");
1634         return DMError::DM_ERROR_IPC_FAILED;
1635     }
1636     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DENSITY_IN_CURRENT_RESOLUTION),
1637         data, reply, option) != ERR_NONE) {
1638         WLOGFE("SendRequest failed");
1639         return DMError::DM_ERROR_IPC_FAILED;
1640     }
1641     virtualPixelRatio = reply.ReadFloat();
1642     return static_cast<DMError>(reply.ReadInt32());
1643 }
1644 
IsScreenRotationLocked(bool & isLocked)1645 DMError DisplayManagerProxy::IsScreenRotationLocked(bool& isLocked)
1646 {
1647     sptr<IRemoteObject> remote = Remote();
1648     if (remote == nullptr) {
1649         WLOGFW("remote is nullptr");
1650         return DMError::DM_ERROR_NULLPTR;
1651     }
1652     MessageParcel data;
1653     MessageParcel reply;
1654     MessageOption option;
1655     if (!data.WriteInterfaceToken(GetDescriptor())) {
1656         WLOGFE("WriteInterfaceToken failed");
1657         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1658     }
1659     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED),
1660         data, reply, option) != ERR_NONE) {
1661         WLOGFW("SendRequest failed");
1662         return DMError::DM_ERROR_IPC_FAILED;
1663     }
1664     DMError ret = static_cast<DMError>(reply.ReadInt32());
1665     isLocked = reply.ReadBool();
1666     return ret;
1667 }
1668 
SetScreenRotationLocked(bool isLocked)1669 DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked)
1670 {
1671     sptr<IRemoteObject> remote = Remote();
1672     if (remote == nullptr) {
1673         WLOGFW("remote is null");
1674         return DMError::DM_ERROR_NULLPTR;
1675     }
1676 
1677     MessageParcel data;
1678     MessageParcel reply;
1679     MessageOption option;
1680     if (!data.WriteInterfaceToken(GetDescriptor())) {
1681         WLOGFE("WriteInterfaceToken failed");
1682         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1683     }
1684     if (!data.WriteBool(isLocked)) {
1685         WLOGFE("write isLocked failed");
1686         return DMError::DM_ERROR_IPC_FAILED;
1687     }
1688     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED),
1689         data, reply, option) != ERR_NONE) {
1690         WLOGFE("SendRequest failed");
1691         return DMError::DM_ERROR_IPC_FAILED;
1692     }
1693     return static_cast<DMError>(reply.ReadInt32());
1694 }
1695 
SetScreenRotationLockedFromJs(bool isLocked)1696 DMError DisplayManagerProxy::SetScreenRotationLockedFromJs(bool isLocked)
1697 {
1698     sptr<IRemoteObject> remote = Remote();
1699     if (remote == nullptr) {
1700         WLOGFW("remote is null");
1701         return DMError::DM_ERROR_NULLPTR;
1702     }
1703 
1704     MessageParcel data;
1705     MessageParcel reply;
1706     MessageOption option;
1707     if (!data.WriteInterfaceToken(GetDescriptor())) {
1708         WLOGFE("WriteInterfaceToken failed");
1709         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1710     }
1711     if (!data.WriteBool(isLocked)) {
1712         WLOGFE("write isLocked failed");
1713         return DMError::DM_ERROR_IPC_FAILED;
1714     }
1715     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED_FROM_JS),
1716         data, reply, option) != ERR_NONE) {
1717         WLOGFE("SendRequest failed");
1718         return DMError::DM_ERROR_IPC_FAILED;
1719     }
1720     return static_cast<DMError>(reply.ReadInt32());
1721 }
1722 
ResizeVirtualScreen(ScreenId screenId,uint32_t width,uint32_t height)1723 DMError DisplayManagerProxy::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
1724 {
1725     WLOGFI("DisplayManagerProxy::ResizeVirtualScreen: ENTER");
1726     sptr<IRemoteObject> remote = Remote();
1727     if (remote == nullptr) {
1728         WLOGFW("DisplayManagerProxy::ResizeVirtualScreen: remote is nullptr");
1729         return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
1730     }
1731 
1732     MessageParcel data;
1733     MessageParcel reply;
1734     MessageOption option;
1735 
1736     if (!data.WriteInterfaceToken(GetDescriptor())) {
1737         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteInterfaceToken failed");
1738         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1739     }
1740     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
1741         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit64 screenId failed");
1742         return DMError::DM_ERROR_IPC_FAILED;
1743     }
1744     if (!data.WriteUint32(width)) {
1745         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 width failed");
1746         return DMError::DM_ERROR_IPC_FAILED;
1747     }
1748     if (!data.WriteUint32(height)) {
1749         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 height failed");
1750         return DMError::DM_ERROR_IPC_FAILED;
1751     }
1752     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_RESIZE_VIRTUAL_SCREEN),
1753         data, reply, option) != ERR_NONE) {
1754         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen fail: SendRequest failed");
1755         return DMError::DM_ERROR_NULLPTR;
1756     }
1757     return static_cast<DMError>(reply.ReadInt32());
1758 }
1759 
MakeUniqueScreen(const std::vector<ScreenId> & screenIds)1760 DMError DisplayManagerProxy::MakeUniqueScreen(const std::vector<ScreenId>& screenIds)
1761 {
1762     WLOGFI("DisplayManagerProxy::MakeUniqueScreen");
1763     sptr<IRemoteObject> remote = Remote();
1764     if (remote == nullptr) {
1765         WLOGFW("make unique screen failed: remote is null");
1766         return DMError::DM_ERROR_NULLPTR;
1767     }
1768 
1769     MessageParcel data;
1770     MessageParcel reply;
1771     MessageOption option;
1772     if (!data.WriteInterfaceToken(GetDescriptor())) {
1773         WLOGFE("MakeUniqueScreen writeInterfaceToken failed");
1774         return DMError::DM_ERROR_NULLPTR;
1775     }
1776     if (!data.WriteUint32(screenIds.size())) {
1777         WLOGFE("MakeUniqueScreen write screenIds size failed");
1778         return DMError::DM_ERROR_INVALID_PARAM;
1779     }
1780     bool res = data.WriteUInt64Vector(screenIds);
1781     if (!res) {
1782         WLOGFE("MakeUniqueScreen fail: write screens failed");
1783         return DMError::DM_ERROR_NULLPTR;
1784     }
1785     if (remote->SendRequest(
1786         static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN),
1787         data, reply, option) != ERR_NONE) {
1788         WLOGFE("MakeUniqueScreen fail: SendRequest failed");
1789         return DMError::DM_ERROR_NULLPTR;
1790     }
1791     return static_cast<DMError>(reply.ReadInt32());
1792 }
1793 
GetAllDisplayPhysicalResolution()1794 std::vector<DisplayPhysicalResolution> DisplayManagerProxy::GetAllDisplayPhysicalResolution()
1795 {
1796     sptr<IRemoteObject> remote = Remote();
1797     if (remote == nullptr) {
1798         TLOGE(WmsLogTag::DMS, "remote is nullptr");
1799         return std::vector<DisplayPhysicalResolution> {};
1800     }
1801     MessageOption option;
1802     MessageParcel reply;
1803     MessageParcel data;
1804     if (!data.WriteInterfaceToken(GetDescriptor())) {
1805         TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed");
1806         return std::vector<DisplayPhysicalResolution> {};
1807     }
1808     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION),
1809         data, reply, option) != ERR_NONE) {
1810         TLOGE(WmsLogTag::DMS, "SendRequest failed");
1811         return std::vector<DisplayPhysicalResolution> {};
1812     }
1813     std::vector<DisplayPhysicalResolution> allPhysicalSize;
1814     int32_t displayInfoSize = 0;
1815     bool readRet = reply.ReadInt32(displayInfoSize);
1816     if (!readRet || displayInfoSize <= 0) {
1817         TLOGE(WmsLogTag::DMS, "read failed");
1818         return std::vector<DisplayPhysicalResolution> {};
1819     }
1820     for (int32_t i = 0; i < displayInfoSize; i++) {
1821         DisplayPhysicalResolution physicalItem;
1822         physicalItem.foldDisplayMode_ = static_cast<FoldDisplayMode>(reply.ReadUint32());
1823         physicalItem.physicalWidth_ = reply.ReadUint32();
1824         physicalItem.physicalHeight_ = reply.ReadUint32();
1825         allPhysicalSize.emplace_back(physicalItem);
1826     }
1827     return allPhysicalSize;
1828 }
1829 } // namespace OHOS::Rosen