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