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, PowerStateChangeReason reason)
946 {
947     sptr<IRemoteObject> remote = Remote();
948     if (remote == nullptr) {
949         WLOGFW("[UL_POWER]SetSpecifiedScreenPower: remote is nullptr");
950         return false;
951     }
952 
953     MessageParcel data;
954     MessageParcel reply;
955     MessageOption option;
956     if (!data.WriteInterfaceToken(GetDescriptor())) {
957         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
958         return false;
959     }
960     if (!data.WriteUint32(static_cast<uint32_t>(screenId))) {
961         WLOGFE("[UL_POWER]Write ScreenId failed");
962         return false;
963     }
964     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
965         WLOGFE("[UL_POWER]Write ScreenPowerState failed");
966         return false;
967     }
968     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
969         WLOGFE("[UL_POWER]Write PowerStateChangeReason failed");
970         return false;
971     }
972     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER),
973         data, reply, option) != ERR_NONE) {
974         WLOGFW("[UL_POWER]SendRequest failed");
975         return false;
976     }
977     return reply.ReadBool();
978 }
979 
GetScreenPower(ScreenId dmsScreenId)980 ScreenPowerState DisplayManagerProxy::GetScreenPower(ScreenId dmsScreenId)
981 {
982     sptr<IRemoteObject> remote = Remote();
983     if (remote == nullptr) {
984         WLOGFW("GetScreenPower: remote is nullptr");
985         return ScreenPowerState::INVALID_STATE;
986     }
987 
988     MessageParcel data;
989     MessageParcel reply;
990     MessageOption option;
991     if (!data.WriteInterfaceToken(GetDescriptor())) {
992         WLOGFE("WriteInterfaceToken failed");
993         return ScreenPowerState::INVALID_STATE;
994     }
995     if (!data.WriteUint64(static_cast<uint64_t>(dmsScreenId))) {
996         WLOGFE("Write dmsScreenId failed");
997         return ScreenPowerState::INVALID_STATE;
998     }
999     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER),
1000         data, reply, option) != ERR_NONE) {
1001         WLOGFW("SendRequest failed");
1002         return ScreenPowerState::INVALID_STATE;
1003     }
1004     return static_cast<ScreenPowerState>(reply.ReadUint32());
1005 }
1006 
SetDisplayState(DisplayState state)1007 bool DisplayManagerProxy::SetDisplayState(DisplayState state)
1008 {
1009     sptr<IRemoteObject> remote = Remote();
1010     if (remote == nullptr) {
1011         WLOGFW("[UL_POWER]SetDisplayState: remote is nullptr");
1012         return false;
1013     }
1014 
1015     MessageParcel data;
1016     MessageParcel reply;
1017     MessageOption option;
1018     if (!data.WriteInterfaceToken(GetDescriptor())) {
1019         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1020         return false;
1021     }
1022     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
1023         WLOGFE("[UL_POWER]Write DisplayState failed");
1024         return false;
1025     }
1026     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE),
1027         data, reply, option) != ERR_NONE) {
1028         WLOGFW("[UL_POWER]SendRequest failed");
1029         return false;
1030     }
1031     return reply.ReadBool();
1032 }
1033 
GetDisplayState(DisplayId displayId)1034 DisplayState DisplayManagerProxy::GetDisplayState(DisplayId displayId)
1035 {
1036     sptr<IRemoteObject> remote = Remote();
1037     if (remote == nullptr) {
1038         WLOGFW("GetDisplayState: remote is nullptr");
1039         return DisplayState::UNKNOWN;
1040     }
1041 
1042     MessageParcel data;
1043     MessageParcel reply;
1044     MessageOption option;
1045     if (!data.WriteInterfaceToken(GetDescriptor())) {
1046         WLOGFE("WriteInterfaceToken failed");
1047         return DisplayState::UNKNOWN;
1048     }
1049     if (!data.WriteUint64(displayId)) {
1050         WLOGFE("Write displayId failed");
1051         return DisplayState::UNKNOWN;
1052     }
1053     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE),
1054         data, reply, option) != ERR_NONE) {
1055         WLOGFW("SendRequest failed");
1056         return DisplayState::UNKNOWN;
1057     }
1058     return static_cast<DisplayState>(reply.ReadUint32());
1059 }
1060 
TryToCancelScreenOff()1061 bool DisplayManagerProxy::TryToCancelScreenOff()
1062 {
1063     sptr<IRemoteObject> remote = Remote();
1064     if (remote == nullptr) {
1065         WLOGFW("[UL_POWER]TryToCancelScreenOff: remote is nullptr");
1066         return false;
1067     }
1068 
1069     MessageParcel data;
1070     MessageParcel reply;
1071     MessageOption option;
1072     if (!data.WriteInterfaceToken(GetDescriptor())) {
1073         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1074         return false;
1075     }
1076     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF),
1077         data, reply, option) != ERR_NONE) {
1078         WLOGFW("[UL_POWER]SendRequest failed");
1079         return false;
1080     }
1081     return reply.ReadBool();
1082 }
1083 
GetAllDisplayIds()1084 std::vector<DisplayId> DisplayManagerProxy::GetAllDisplayIds()
1085 {
1086     std::vector<DisplayId> allDisplayIds;
1087     sptr<IRemoteObject> remote = Remote();
1088     if (remote == nullptr) {
1089         WLOGFW("GetAllDisplayIds: remote is nullptr");
1090         return allDisplayIds;
1091     }
1092 
1093     MessageParcel data;
1094     MessageParcel reply;
1095     MessageOption option;
1096     if (!data.WriteInterfaceToken(GetDescriptor())) {
1097         WLOGFE("WriteInterfaceToken failed");
1098         return allDisplayIds;
1099     }
1100     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS),
1101         data, reply, option) != ERR_NONE) {
1102         WLOGFW("SendRequest failed");
1103         return allDisplayIds;
1104     }
1105     reply.ReadUInt64Vector(&allDisplayIds);
1106     return allDisplayIds;
1107 }
1108 
GetCutoutInfo(DisplayId displayId)1109 sptr<CutoutInfo> DisplayManagerProxy::GetCutoutInfo(DisplayId displayId)
1110 {
1111     sptr<IRemoteObject> remote = Remote();
1112     if (remote == nullptr) {
1113         WLOGFW("GetCutoutInfo: remote is null");
1114         return nullptr;
1115     }
1116     MessageParcel data;
1117     MessageParcel reply;
1118     MessageOption option;
1119     if (!data.WriteInterfaceToken(GetDescriptor())) {
1120         WLOGFE("GetCutoutInfo: GetCutoutInfo failed");
1121         return nullptr;
1122     }
1123     if (!data.WriteUint64(displayId)) {
1124         WLOGFE("GetCutoutInfo: write displayId failed");
1125         return nullptr;
1126     }
1127     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO),
1128         data, reply, option) != ERR_NONE) {
1129         WLOGFW("GetCutoutInfo: GetCutoutInfo failed");
1130         return nullptr;
1131     }
1132     sptr<CutoutInfo> info = reply.ReadParcelable<CutoutInfo>();
1133     return info;
1134 }
1135 
AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop)1136 DMError DisplayManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId,
1137     std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop)
1138 {
1139     sptr<IRemoteObject> remote = Remote();
1140     if (remote == nullptr) {
1141         WLOGFW("AddSurfaceNodeToDisplay: remote is nullptr");
1142         return DMError::DM_ERROR_IPC_FAILED;
1143     }
1144 
1145     MessageParcel data;
1146     MessageParcel reply;
1147     MessageOption option;
1148     if (!data.WriteInterfaceToken(GetDescriptor())) {
1149         WLOGFE("WriteInterfaceToken failed");
1150         return DMError::DM_ERROR_IPC_FAILED;
1151     }
1152     if (!data.WriteUint64(displayId)) {
1153         WLOGFE("write displayId failed");
1154         return DMError::DM_ERROR_IPC_FAILED;
1155     }
1156     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
1157         WLOGFE("Write windowProperty failed");
1158         return DMError::DM_ERROR_IPC_FAILED;
1159     }
1160     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE),
1161         data, reply, option) != ERR_NONE) {
1162         WLOGFW("Send request failed");
1163         return DMError::DM_ERROR_IPC_FAILED;
1164     }
1165     DMError ret = static_cast<DMError>(reply.ReadUint32());
1166     return ret;
1167 }
1168 
RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode)1169 DMError DisplayManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
1170     std::shared_ptr<class RSSurfaceNode>& surfaceNode)
1171 {
1172     sptr<IRemoteObject> remote = Remote();
1173     if (remote == nullptr) {
1174         WLOGFW("RemoveSurfaceNodeFromDisplay: remote is nullptr");
1175         return DMError::DM_ERROR_IPC_FAILED;
1176     }
1177 
1178     MessageParcel data;
1179     MessageParcel reply;
1180     MessageOption option;
1181     if (!data.WriteInterfaceToken(GetDescriptor())) {
1182         WLOGFE("WriteInterfaceToken failed");
1183         return DMError::DM_ERROR_IPC_FAILED;
1184     }
1185     if (!data.WriteUint64(displayId)) {
1186         WLOGFE("write displayId failed");
1187         return DMError::DM_ERROR_IPC_FAILED;
1188     }
1189     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
1190         WLOGFE("Write windowProperty failed");
1191         return DMError::DM_ERROR_IPC_FAILED;
1192     }
1193     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE),
1194         data, reply, option) != ERR_NONE) {
1195         WLOGFW("Send request failed");
1196         return DMError::DM_ERROR_IPC_FAILED;
1197     }
1198     DMError ret = static_cast<DMError>(reply.ReadUint32());
1199     return ret;
1200 }
1201 
HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)1202 DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
1203 {
1204     sptr<IRemoteObject> remote = Remote();
1205     if (remote == nullptr) {
1206         WLOGFW("HasPrivateWindow: remote is nullptr");
1207         return DMError::DM_ERROR_IPC_FAILED;
1208     }
1209 
1210     MessageParcel data;
1211     MessageParcel reply;
1212     MessageOption option;
1213     if (!data.WriteInterfaceToken(GetDescriptor())) {
1214         return DMError::DM_ERROR_IPC_FAILED;
1215     }
1216 
1217     if (!data.WriteUint64(displayId)) {
1218         return DMError::DM_ERROR_IPC_FAILED;
1219     }
1220 
1221     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW),
1222         data, reply, option) != ERR_NONE) {
1223         return DMError::DM_ERROR_IPC_FAILED;
1224     }
1225     DMError ret = static_cast<DMError>(reply.ReadInt32());
1226     hasPrivateWindow = reply.ReadBool();
1227     return ret;
1228 }
1229 
NotifyDisplayEvent(DisplayEvent event)1230 void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
1231 {
1232     sptr<IRemoteObject> remote = Remote();
1233     if (remote == nullptr) {
1234         WLOGFW("NotifyDisplayEvent: remote is nullptr");
1235         return;
1236     }
1237 
1238     MessageParcel data;
1239     MessageParcel reply;
1240     MessageOption option;
1241     if (!data.WriteInterfaceToken(GetDescriptor())) {
1242         WLOGFE("[UL_POWER]WriteInterfaceToken failed");
1243         return;
1244     }
1245     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
1246         WLOGFE("[UL_POWER]Write DisplayEvent failed");
1247         return;
1248     }
1249     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT),
1250         data, reply, option) != ERR_NONE) {
1251         WLOGFW("[UL_POWER]SendRequest failed");
1252         return;
1253     }
1254 }
1255 
SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)1256 bool DisplayManagerProxy::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
1257 {
1258     sptr<IRemoteObject> remote = Remote();
1259     if (remote == nullptr) {
1260         WLOGFW("SetFreeze: remote is nullptr");
1261         return false;
1262     }
1263 
1264     MessageParcel data;
1265     MessageParcel reply;
1266     MessageOption option;
1267     if (!data.WriteInterfaceToken(GetDescriptor())) {
1268         WLOGFE("WriteInterfaceToken failed");
1269         return false;
1270     }
1271     if (!data.WriteUInt64Vector(displayIds)) {
1272         WLOGFE("set freeze fail: write displayId failed.");
1273         return false;
1274     }
1275     if (!data.WriteBool(isFreeze)) {
1276         WLOGFE("set freeze fail: write freeze flag failed.");
1277         return false;
1278     }
1279 
1280     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT),
1281         data, reply, option) != ERR_NONE) {
1282         WLOGFE("SendRequest failed");
1283         return false;
1284     }
1285     return true;
1286 }
1287 
MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId)1288 DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
1289                                         ScreenId& screenGroupId)
1290 {
1291     sptr<IRemoteObject> remote = Remote();
1292     if (remote == nullptr) {
1293         WLOGFW("create mirror fail: remote is null");
1294         return DMError::DM_ERROR_NULLPTR;
1295     }
1296 
1297     MessageParcel data;
1298     MessageParcel reply;
1299     MessageOption option;
1300     if (!data.WriteInterfaceToken(GetDescriptor())) {
1301         WLOGFE("create mirror fail: WriteInterfaceToken failed");
1302         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1303     }
1304     bool res = data.WriteUint64(static_cast<uint64_t>(mainScreenId)) &&
1305         data.WriteUInt64Vector(mirrorScreenId);
1306     if (!res) {
1307         WLOGFE("create mirror fail: data write failed");
1308         return DMError::DM_ERROR_IPC_FAILED;
1309     }
1310     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR),
1311         data, reply, option) != ERR_NONE) {
1312         WLOGFW("create mirror fail: SendRequest failed");
1313         return DMError::DM_ERROR_IPC_FAILED;
1314     }
1315     DMError ret = static_cast<DMError>(reply.ReadInt32());
1316     screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
1317     return ret;
1318 }
1319 
StopMirror(const std::vector<ScreenId>& mirrorScreenIds)1320 DMError DisplayManagerProxy::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
1321 {
1322     sptr<IRemoteObject> remote = Remote();
1323     if (remote == nullptr) {
1324         WLOGFW("StopMirror fail: remote is null");
1325         return DMError::DM_ERROR_NULLPTR;
1326     }
1327 
1328     MessageParcel data;
1329     MessageParcel reply;
1330     MessageOption option;
1331     if (!data.WriteInterfaceToken(GetDescriptor())) {
1332         WLOGFE("StopMirror fail: WriteInterfaceToken failed");
1333         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1334     }
1335     bool res = data.WriteUInt64Vector(mirrorScreenIds);
1336     if (!res) {
1337         WLOGFE("StopMirror fail: data write failed");
1338         return DMError::DM_ERROR_IPC_FAILED;
1339     }
1340     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_MIRROR),
1341         data, reply, option) != ERR_NONE) {
1342         WLOGFW("StopMirror fail: SendRequest failed");
1343         return DMError::DM_ERROR_IPC_FAILED;
1344     }
1345     return static_cast<DMError>(reply.ReadInt32());
1346 }
1347 
GetScreenInfoById(ScreenId screenId)1348 sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
1349 {
1350     sptr<IRemoteObject> remote = Remote();
1351     if (remote == nullptr) {
1352         WLOGFW("GetScreenInfoById: remote is nullptr");
1353         return nullptr;
1354     }
1355 
1356     MessageParcel data;
1357     MessageParcel reply;
1358     MessageOption option;
1359     if (!data.WriteInterfaceToken(GetDescriptor())) {
1360         WLOGFE("GetScreenInfoById: WriteInterfaceToken failed");
1361         return nullptr;
1362     }
1363     if (!data.WriteUint64(screenId)) {
1364         WLOGFE("GetScreenInfoById: Write screenId failed");
1365         return nullptr;
1366     }
1367     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID),
1368         data, reply, option) != ERR_NONE) {
1369         WLOGFW("GetScreenInfoById: SendRequest failed");
1370         return nullptr;
1371     }
1372 
1373     sptr<ScreenInfo> info = reply.ReadStrongParcelable<ScreenInfo>();
1374     if (info == nullptr) {
1375         WLOGFW("GetScreenInfoById SendRequest nullptr.");
1376         return nullptr;
1377     }
1378     for (auto& mode : info->GetModes()) {
1379         WLOGFI("info modes is id: %{public}u, width: %{public}u, height: %{public}u, refreshRate: %{public}u",
1380             mode->id_, mode->width_, mode->height_, mode->refreshRate_);
1381     }
1382     return info;
1383 }
1384 
GetScreenGroupInfoById(ScreenId screenId)1385 sptr<ScreenGroupInfo> DisplayManagerProxy::GetScreenGroupInfoById(ScreenId screenId)
1386 {
1387     sptr<IRemoteObject> remote = Remote();
1388     if (remote == nullptr) {
1389         WLOGFW("GetScreenGroupInfoById: remote is nullptr");
1390         return nullptr;
1391     }
1392 
1393     MessageParcel data;
1394     MessageParcel reply;
1395     MessageOption option;
1396     if (!data.WriteInterfaceToken(GetDescriptor())) {
1397         WLOGFE("GetScreenGroupInfoById: WriteInterfaceToken failed");
1398         return nullptr;
1399     }
1400     if (!data.WriteUint64(screenId)) {
1401         WLOGFE("GetScreenGroupInfoById: Write screenId failed");
1402         return nullptr;
1403     }
1404     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID),
1405         data, reply, option) != ERR_NONE) {
1406         WLOGFW("GetScreenGroupInfoById: SendRequest failed");
1407         return nullptr;
1408     }
1409 
1410     sptr<ScreenGroupInfo> info = reply.ReadStrongParcelable<ScreenGroupInfo>();
1411     if (info == nullptr) {
1412         WLOGFW("GetScreenGroupInfoById SendRequest nullptr.");
1413         return nullptr;
1414     }
1415     return info;
1416 }
1417 
GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)1418 DMError DisplayManagerProxy::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
1419 {
1420     sptr<IRemoteObject> remote = Remote();
1421     if (remote == nullptr) {
1422         WLOGFW("GetAllScreenInfos: remote is nullptr");
1423         return DMError::DM_ERROR_NULLPTR;
1424     }
1425 
1426     MessageParcel data;
1427     MessageParcel reply;
1428     MessageOption option;
1429     if (!data.WriteInterfaceToken(GetDescriptor())) {
1430         WLOGFE("GetAllScreenInfos: WriteInterfaceToken failed");
1431         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1432     }
1433     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS),
1434         data, reply, option) != ERR_NONE) {
1435         WLOGFW("GetAllScreenInfos: SendRequest failed");
1436         return DMError::DM_ERROR_IPC_FAILED;
1437     }
1438     DMError ret = static_cast<DMError>(reply.ReadInt32());
1439     static_cast<void>(MarshallingHelper::UnmarshallingVectorParcelableObj<ScreenInfo>(reply, screenInfos));
1440     return ret;
1441 }
1442 
MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId)1443 DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
1444                                         ScreenId& screenGroupId)
1445 {
1446     sptr<IRemoteObject> remote = Remote();
1447     if (remote == nullptr) {
1448         WLOGFW("MakeExpand: remote is null");
1449         return DMError::DM_ERROR_IPC_FAILED;
1450     }
1451 
1452     MessageParcel data;
1453     MessageParcel reply;
1454     MessageOption option;
1455     if (!data.WriteInterfaceToken(GetDescriptor())) {
1456         WLOGFE("MakeExpand: WriteInterfaceToken failed");
1457         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1458     }
1459     if (!data.WriteUInt64Vector(screenId)) {
1460         WLOGFE("MakeExpand: write screenId failed");
1461         return DMError::DM_ERROR_IPC_FAILED;
1462     }
1463     if (!MarshallingHelper::MarshallingVectorObj<Point>(data, startPoint, [](Parcel& parcel, const Point& point) {
1464             return parcel.WriteInt32(point.posX_) && parcel.WriteInt32(point.posY_);
1465         })) {
1466         WLOGFE("MakeExpand: write startPoint failed");
1467         return DMError::DM_ERROR_IPC_FAILED;
1468     }
1469     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND),
1470         data, reply, option) != ERR_NONE) {
1471         WLOGFE("MakeExpand: SendRequest failed");
1472         return DMError::DM_ERROR_IPC_FAILED;
1473     }
1474     DMError ret = static_cast<DMError>(reply.ReadInt32());
1475     screenGroupId = static_cast<ScreenId>(reply.ReadUint64());
1476     return ret;
1477 }
1478 
StopExpand(const std::vector<ScreenId>& expandScreenIds)1479 DMError DisplayManagerProxy::StopExpand(const std::vector<ScreenId>& expandScreenIds)
1480 {
1481     sptr<IRemoteObject> remote = Remote();
1482     if (remote == nullptr) {
1483         WLOGFW("StopExpand fail: remote is null");
1484         return DMError::DM_ERROR_NULLPTR;
1485     }
1486 
1487     MessageParcel data;
1488     MessageParcel reply;
1489     MessageOption option;
1490     if (!data.WriteInterfaceToken(GetDescriptor())) {
1491         WLOGFE("StopExpand fail: WriteInterfaceToken failed");
1492         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1493     }
1494     bool res = data.WriteUInt64Vector(expandScreenIds);
1495     if (!res) {
1496         WLOGFE("StopExpand fail: data write failed");
1497         return DMError::DM_ERROR_IPC_FAILED;
1498     }
1499     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_EXPAND),
1500         data, reply, option) != ERR_NONE) {
1501         WLOGFW("StopExpand fail: SendRequest failed");
1502         return DMError::DM_ERROR_IPC_FAILED;
1503     }
1504     return static_cast<DMError>(reply.ReadInt32());
1505 }
1506 
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)1507 void DisplayManagerProxy::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
1508 {
1509     sptr<IRemoteObject> remote = Remote();
1510     if (remote == nullptr) {
1511         WLOGFW("cancel make mirror or expand fail: remote is null");
1512         return;
1513     }
1514 
1515     MessageParcel data;
1516     MessageParcel reply;
1517     MessageOption option(MessageOption::TF_ASYNC);
1518     if (!data.WriteInterfaceToken(GetDescriptor())) {
1519         WLOGFE("cancel make mirror or expand fail: WriteInterfaceToken failed");
1520         return;
1521     }
1522     bool res = data.WriteUInt64Vector(screens);
1523     if (!res) {
1524         WLOGFE("cancel make mirror or expand fail: write screens failed.");
1525         return;
1526     }
1527     if (remote->SendRequest(static_cast<uint32_t>(
1528         DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP),
1529         data, reply, option) != ERR_NONE) {
1530         WLOGFW("cancel make mirror or expand fail: SendRequest failed");
1531     }
1532 }
1533 
SetScreenActiveMode(ScreenId screenId, uint32_t modeId)1534 DMError DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
1535 {
1536     sptr<IRemoteObject> remote = Remote();
1537     if (remote == nullptr) {
1538         WLOGFW("SetScreenActiveMode: remote is null");
1539         return DMError::DM_ERROR_NULLPTR;
1540     }
1541 
1542     MessageParcel data;
1543     MessageParcel reply;
1544     MessageOption option;
1545     if (!data.WriteInterfaceToken(GetDescriptor())) {
1546         WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed");
1547         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1548     }
1549     if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) {
1550         WLOGFE("SetScreenActiveMode: write screenId/modeId failed");
1551         return DMError::DM_ERROR_IPC_FAILED;
1552     }
1553     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE),
1554         data, reply, option) != ERR_NONE) {
1555         WLOGFE("SetScreenActiveMode: SendRequest failed");
1556         return DMError::DM_ERROR_IPC_FAILED;
1557     }
1558     return static_cast<DMError>(reply.ReadInt32());
1559 }
1560 
SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)1561 DMError DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
1562 {
1563     sptr<IRemoteObject> remote = Remote();
1564     if (remote == nullptr) {
1565         WLOGFW("SetVirtualPixelRatio: remote is null");
1566         return DMError::DM_ERROR_NULLPTR;
1567     }
1568 
1569     MessageParcel data;
1570     MessageParcel reply;
1571     MessageOption option;
1572     if (!data.WriteInterfaceToken(GetDescriptor())) {
1573         WLOGFE("WriteInterfaceToken failed");
1574         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1575     }
1576     if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) {
1577         WLOGFE("write screenId/modeId failed");
1578         return DMError::DM_ERROR_IPC_FAILED;
1579     }
1580     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO),
1581         data, reply, option) != ERR_NONE) {
1582         WLOGFE("SendRequest failed");
1583         return DMError::DM_ERROR_IPC_FAILED;
1584     }
1585     return static_cast<DMError>(reply.ReadInt32());
1586 }
1587 
SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)1588 DMError DisplayManagerProxy::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)
1589 {
1590     sptr<IRemoteObject> remote = Remote();
1591     if (remote == nullptr) {
1592         WLOGFW("SetResolution: remote is null");
1593         return DMError::DM_ERROR_NULLPTR;
1594     }
1595 
1596     MessageParcel data;
1597     MessageParcel reply;
1598     MessageOption option;
1599     if (!data.WriteInterfaceToken(GetDescriptor())) {
1600         WLOGFE("WriteInterfaceToken failed");
1601         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1602     }
1603     if (!data.WriteUint64(screenId) || !data.WriteUint32(width) ||
1604         !data.WriteUint32(height) || !data.WriteFloat(virtualPixelRatio)) {
1605         WLOGFE("write screenId/width/height/virtualPixelRatio failed");
1606         return DMError::DM_ERROR_IPC_FAILED;
1607     }
1608     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_RESOLUTION),
1609         data, reply, option) != ERR_NONE) {
1610         WLOGFE("SendRequest failed");
1611         return DMError::DM_ERROR_IPC_FAILED;
1612     }
1613     return static_cast<DMError>(reply.ReadInt32());
1614 }
1615 
GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)1616 DMError DisplayManagerProxy::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)
1617 {
1618     sptr<IRemoteObject> remote = Remote();
1619     if (remote == nullptr) {
1620         WLOGFW("GetDensityInCurResolution: remote is null");
1621         return DMError::DM_ERROR_NULLPTR;
1622     }
1623 
1624     MessageParcel data;
1625     MessageParcel reply;
1626     MessageOption option;
1627     if (!data.WriteInterfaceToken(GetDescriptor())) {
1628         WLOGFE("WriteInterfaceToken failed");
1629         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1630     }
1631     if (!data.WriteUint64(screenId)) {
1632         WLOGFE("write screenId failed");
1633         return DMError::DM_ERROR_IPC_FAILED;
1634     }
1635     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_DENSITY_IN_CURRENT_RESOLUTION),
1636         data, reply, option) != ERR_NONE) {
1637         WLOGFE("SendRequest failed");
1638         return DMError::DM_ERROR_IPC_FAILED;
1639     }
1640     virtualPixelRatio = reply.ReadFloat();
1641     return static_cast<DMError>(reply.ReadInt32());
1642 }
1643 
IsScreenRotationLocked(bool& isLocked)1644 DMError DisplayManagerProxy::IsScreenRotationLocked(bool& isLocked)
1645 {
1646     sptr<IRemoteObject> remote = Remote();
1647     if (remote == nullptr) {
1648         WLOGFW("remote is nullptr");
1649         return DMError::DM_ERROR_NULLPTR;
1650     }
1651     MessageParcel data;
1652     MessageParcel reply;
1653     MessageOption option;
1654     if (!data.WriteInterfaceToken(GetDescriptor())) {
1655         WLOGFE("WriteInterfaceToken failed");
1656         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1657     }
1658     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED),
1659         data, reply, option) != ERR_NONE) {
1660         WLOGFW("SendRequest failed");
1661         return DMError::DM_ERROR_IPC_FAILED;
1662     }
1663     DMError ret = static_cast<DMError>(reply.ReadInt32());
1664     isLocked = reply.ReadBool();
1665     return ret;
1666 }
1667 
SetScreenRotationLocked(bool isLocked)1668 DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked)
1669 {
1670     sptr<IRemoteObject> remote = Remote();
1671     if (remote == nullptr) {
1672         WLOGFW("remote is null");
1673         return DMError::DM_ERROR_NULLPTR;
1674     }
1675 
1676     MessageParcel data;
1677     MessageParcel reply;
1678     MessageOption option;
1679     if (!data.WriteInterfaceToken(GetDescriptor())) {
1680         WLOGFE("WriteInterfaceToken failed");
1681         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1682     }
1683     if (!data.WriteBool(isLocked)) {
1684         WLOGFE("write isLocked failed");
1685         return DMError::DM_ERROR_IPC_FAILED;
1686     }
1687     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED),
1688         data, reply, option) != ERR_NONE) {
1689         WLOGFE("SendRequest failed");
1690         return DMError::DM_ERROR_IPC_FAILED;
1691     }
1692     return static_cast<DMError>(reply.ReadInt32());
1693 }
1694 
SetScreenRotationLockedFromJs(bool isLocked)1695 DMError DisplayManagerProxy::SetScreenRotationLockedFromJs(bool isLocked)
1696 {
1697     sptr<IRemoteObject> remote = Remote();
1698     if (remote == nullptr) {
1699         WLOGFW("remote is null");
1700         return DMError::DM_ERROR_NULLPTR;
1701     }
1702 
1703     MessageParcel data;
1704     MessageParcel reply;
1705     MessageOption option;
1706     if (!data.WriteInterfaceToken(GetDescriptor())) {
1707         WLOGFE("WriteInterfaceToken failed");
1708         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1709     }
1710     if (!data.WriteBool(isLocked)) {
1711         WLOGFE("write isLocked failed");
1712         return DMError::DM_ERROR_IPC_FAILED;
1713     }
1714     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED_FROM_JS),
1715         data, reply, option) != ERR_NONE) {
1716         WLOGFE("SendRequest failed");
1717         return DMError::DM_ERROR_IPC_FAILED;
1718     }
1719     return static_cast<DMError>(reply.ReadInt32());
1720 }
1721 
ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)1722 DMError DisplayManagerProxy::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
1723 {
1724     WLOGFI("DisplayManagerProxy::ResizeVirtualScreen: ENTER");
1725     sptr<IRemoteObject> remote = Remote();
1726     if (remote == nullptr) {
1727         WLOGFW("DisplayManagerProxy::ResizeVirtualScreen: remote is nullptr");
1728         return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
1729     }
1730 
1731     MessageParcel data;
1732     MessageParcel reply;
1733     MessageOption option;
1734 
1735     if (!data.WriteInterfaceToken(GetDescriptor())) {
1736         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteInterfaceToken failed");
1737         return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
1738     }
1739     if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
1740         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit64 screenId failed");
1741         return DMError::DM_ERROR_IPC_FAILED;
1742     }
1743     if (!data.WriteUint32(width)) {
1744         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 width failed");
1745         return DMError::DM_ERROR_IPC_FAILED;
1746     }
1747     if (!data.WriteUint32(height)) {
1748         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 height failed");
1749         return DMError::DM_ERROR_IPC_FAILED;
1750     }
1751     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_RESIZE_VIRTUAL_SCREEN),
1752         data, reply, option) != ERR_NONE) {
1753         WLOGFE("DisplayManagerProxy::ResizeVirtualScreen fail: SendRequest failed");
1754         return DMError::DM_ERROR_NULLPTR;
1755     }
1756     return static_cast<DMError>(reply.ReadInt32());
1757 }
1758 
MakeUniqueScreen(const std::vector<ScreenId>& screenIds)1759 DMError DisplayManagerProxy::MakeUniqueScreen(const std::vector<ScreenId>& screenIds)
1760 {
1761     WLOGFI("DisplayManagerProxy::MakeUniqueScreen");
1762     sptr<IRemoteObject> remote = Remote();
1763     if (remote == nullptr) {
1764         WLOGFW("make unique screen failed: remote is null");
1765         return DMError::DM_ERROR_NULLPTR;
1766     }
1767 
1768     MessageParcel data;
1769     MessageParcel reply;
1770     MessageOption option;
1771     if (!data.WriteInterfaceToken(GetDescriptor())) {
1772         WLOGFE("MakeUniqueScreen writeInterfaceToken failed");
1773         return DMError::DM_ERROR_NULLPTR;
1774     }
1775     if (!data.WriteUint32(screenIds.size())) {
1776         WLOGFE("MakeUniqueScreen write screenIds size failed");
1777         return DMError::DM_ERROR_INVALID_PARAM;
1778     }
1779     bool res = data.WriteUInt64Vector(screenIds);
1780     if (!res) {
1781         WLOGFE("MakeUniqueScreen fail: write screens failed");
1782         return DMError::DM_ERROR_NULLPTR;
1783     }
1784     if (remote->SendRequest(
1785         static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN),
1786         data, reply, option) != ERR_NONE) {
1787         WLOGFE("MakeUniqueScreen fail: SendRequest failed");
1788         return DMError::DM_ERROR_NULLPTR;
1789     }
1790     return static_cast<DMError>(reply.ReadInt32());
1791 }
1792 
GetAllDisplayPhysicalResolution()1793 std::vector<DisplayPhysicalResolution> DisplayManagerProxy::GetAllDisplayPhysicalResolution()
1794 {
1795     sptr<IRemoteObject> remote = Remote();
1796     if (remote == nullptr) {
1797         TLOGE(WmsLogTag::DMS, "remote is nullptr");
1798         return std::vector<DisplayPhysicalResolution> {};
1799     }
1800     MessageOption option;
1801     MessageParcel reply;
1802     MessageParcel data;
1803     if (!data.WriteInterfaceToken(GetDescriptor())) {
1804         TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed");
1805         return std::vector<DisplayPhysicalResolution> {};
1806     }
1807     if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION),
1808         data, reply, option) != ERR_NONE) {
1809         TLOGE(WmsLogTag::DMS, "SendRequest failed");
1810         return std::vector<DisplayPhysicalResolution> {};
1811     }
1812     std::vector<DisplayPhysicalResolution> allPhysicalSize;
1813     int32_t displayInfoSize = 0;
1814     bool readRet = reply.ReadInt32(displayInfoSize);
1815     if (!readRet || displayInfoSize <= 0) {
1816         TLOGE(WmsLogTag::DMS, "read failed");
1817         return std::vector<DisplayPhysicalResolution> {};
1818     }
1819     for (int32_t i = 0; i < displayInfoSize; i++) {
1820         DisplayPhysicalResolution physicalItem;
1821         physicalItem.foldDisplayMode_ = static_cast<FoldDisplayMode>(reply.ReadUint32());
1822         physicalItem.physicalWidth_ = reply.ReadUint32();
1823         physicalItem.physicalHeight_ = reply.ReadUint32();
1824         allPhysicalSize.emplace_back(physicalItem);
1825     }
1826     return allPhysicalSize;
1827 }
1828 } // namespace OHOS::Rosen