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