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