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_adapter.h"
17
18 #include <iremote_broker.h>
19 #include <iservice_registry.h>
20 #include <system_ability_definition.h>
21
22 #include "display_manager.h"
23 #include "dm_common.h"
24 #include "scene_board_judgement.h"
25 #include "screen_manager.h"
26 #include "window_manager_hilog.h"
27 #include "zidl/screen_session_manager_interface.h"
28
29 namespace OHOS::Rosen {
30 namespace {
31 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapter"};
32 }
33 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter)
WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)34 WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)
35
36 #define INIT_PROXY_CHECK_RETURN(ret) \
37 do { \
38 if (!InitDMSProxy()) { \
39 WLOGFE("InitDMSProxy failed!"); \
40 return ret; \
41 } \
42 } while (false)
43
44 sptr<DisplayInfo> DisplayManagerAdapter::GetDefaultDisplayInfo()
45 {
46 INIT_PROXY_CHECK_RETURN(nullptr);
47
48 return displayManagerServiceProxy_->GetDefaultDisplayInfo();
49 }
50
GetDisplayInfoByScreenId(ScreenId screenId)51 sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfoByScreenId(ScreenId screenId)
52 {
53 INIT_PROXY_CHECK_RETURN(nullptr);
54
55 return displayManagerServiceProxy_->GetDisplayInfoByScreen(screenId);
56 }
57
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode,bool isUseDma)58 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId,
59 DmErrorCode* errorCode, bool isUseDma)
60 {
61 INIT_PROXY_CHECK_RETURN(nullptr);
62
63 return displayManagerServiceProxy_->GetDisplaySnapshot(displayId, errorCode, isUseDma);
64 }
65
GetSnapshotByPicker(Media::Rect & rect,DmErrorCode * errorCode)66 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetSnapshotByPicker(Media::Rect &rect, DmErrorCode* errorCode)
67 {
68 INIT_PROXY_CHECK_RETURN(nullptr);
69
70 return displayManagerServiceProxy_->GetSnapshotByPicker(rect, errorCode);
71 }
72
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)73 DMError ScreenManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId,
74 std::vector<ScreenColorGamut>& colorGamuts)
75 {
76 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
77
78 return displayManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
79 }
80
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)81 DMError ScreenManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
82 {
83 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
84
85 return displayManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamut);
86 }
87
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)88 DMError ScreenManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
89 {
90 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
91
92 return displayManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx);
93 }
94
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)95 DMError ScreenManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
96 {
97 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
98
99 return displayManagerServiceProxy_->GetScreenGamutMap(screenId, gamutMap);
100 }
101
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)102 DMError ScreenManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
103 {
104 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
105
106 return displayManagerServiceProxy_->SetScreenGamutMap(screenId, gamutMap);
107 }
108
SetScreenColorTransform(ScreenId screenId)109 DMError ScreenManagerAdapter::SetScreenColorTransform(ScreenId screenId)
110 {
111 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
112
113 return displayManagerServiceProxy_->SetScreenColorTransform(screenId);
114 }
115
GetPixelFormat(ScreenId screenId,GraphicPixelFormat & pixelFormat)116 DMError ScreenManagerAdapter::GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat)
117 {
118 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
119
120 WLOGFI("ScreenManagerAdapter::GetPixelFormat");
121 return displayManagerServiceProxy_->GetPixelFormat(screenId, pixelFormat);
122 }
123
SetPixelFormat(ScreenId screenId,GraphicPixelFormat pixelFormat)124 DMError ScreenManagerAdapter::SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat)
125 {
126 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
127
128 WLOGFI("ScreenManagerAdapter::SetPixelFormat");
129 return displayManagerServiceProxy_->SetPixelFormat(screenId, pixelFormat);
130 }
131
GetSupportedHDRFormats(ScreenId screenId,std::vector<ScreenHDRFormat> & hdrFormats)132 DMError ScreenManagerAdapter::GetSupportedHDRFormats(ScreenId screenId,
133 std::vector<ScreenHDRFormat>& hdrFormats)
134 {
135 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
136
137 WLOGFI("ScreenManagerAdapter::GetSupportedHDRFormats");
138 return displayManagerServiceProxy_->GetSupportedHDRFormats(screenId, hdrFormats);
139 }
140
GetScreenHDRFormat(ScreenId screenId,ScreenHDRFormat & hdrFormat)141 DMError ScreenManagerAdapter::GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat)
142 {
143 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
144
145 WLOGFI("ScreenManagerAdapter::GetScreenHDRFormat");
146 return displayManagerServiceProxy_->GetScreenHDRFormat(screenId, hdrFormat);
147 }
148
SetScreenHDRFormat(ScreenId screenId,int32_t modeIdx)149 DMError ScreenManagerAdapter::SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx)
150 {
151 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
152
153 WLOGFI("ScreenManagerAdapter::SetScreenHDRFormat");
154 return displayManagerServiceProxy_->SetScreenHDRFormat(screenId, modeIdx);
155 }
156
GetSupportedColorSpaces(ScreenId screenId,std::vector<GraphicCM_ColorSpaceType> & colorSpaces)157 DMError ScreenManagerAdapter::GetSupportedColorSpaces(ScreenId screenId,
158 std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
159 {
160 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
161
162 WLOGFI("ScreenManagerAdapter::GetSupportedColorSpaces");
163 return displayManagerServiceProxy_->GetSupportedColorSpaces(screenId, colorSpaces);
164 }
165
GetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType & colorSpace)166 DMError ScreenManagerAdapter::GetScreenColorSpace(ScreenId screenId,
167 GraphicCM_ColorSpaceType& colorSpace)
168 {
169 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
170
171 WLOGFI("ScreenManagerAdapter::GetScreenColorSpace");
172 return displayManagerServiceProxy_->GetScreenColorSpace(screenId, colorSpace);
173 }
174
SetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType colorSpace)175 DMError ScreenManagerAdapter::SetScreenColorSpace(ScreenId screenId,
176 GraphicCM_ColorSpaceType colorSpace)
177 {
178 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
179
180 WLOGFI("ScreenManagerAdapter::SetScreenColorSpace");
181 return displayManagerServiceProxy_->SetScreenColorSpace(screenId, colorSpace);
182 }
183
GetSupportedHDRFormats(ScreenId screenId,std::vector<uint32_t> & hdrFormats)184 DMError ScreenManagerAdapter::GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats)
185 {
186 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
187
188 std::vector<ScreenHDRFormat> hdrFormatsVec;
189 DMError ret = GetSupportedHDRFormats(screenId, hdrFormatsVec);
190 for (auto value : hdrFormatsVec) {
191 hdrFormats.push_back(static_cast<uint32_t>(value));
192 }
193 WLOGFI("ScreenManagerAdapter::GetSupportedHDRFormats ret %{public}d", static_cast<int32_t>(ret));
194 return ret;
195 }
196
GetSupportedColorSpaces(ScreenId screenId,std::vector<uint32_t> & colorSpaces)197 DMError ScreenManagerAdapter::GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces)
198 {
199 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
200
201 std::vector<GraphicCM_ColorSpaceType> colorSpacesVec;
202 DMError ret = GetSupportedColorSpaces(screenId, colorSpacesVec);
203 for (auto value : colorSpacesVec) {
204 colorSpaces.push_back(static_cast<uint32_t>(value));
205 }
206 WLOGFI("ScreenManagerAdapter::GetSupportedColorSpaces ret %{public}d", static_cast<int32_t>(ret));
207 return ret;
208 }
209
CreateVirtualScreen(VirtualScreenOption option,const sptr<IDisplayManagerAgent> & displayManagerAgent)210 ScreenId ScreenManagerAdapter::CreateVirtualScreen(VirtualScreenOption option,
211 const sptr<IDisplayManagerAgent>& displayManagerAgent)
212 {
213 INIT_PROXY_CHECK_RETURN(SCREEN_ID_INVALID);
214
215 WLOGFI("DisplayManagerAdapter::CreateVirtualScreen");
216 return displayManagerServiceProxy_->CreateVirtualScreen(option, displayManagerAgent->AsObject());
217 }
218
DestroyVirtualScreen(ScreenId screenId)219 DMError ScreenManagerAdapter::DestroyVirtualScreen(ScreenId screenId)
220 {
221 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
222
223 WLOGFI("DisplayManagerAdapter::DestroyVirtualScreen");
224 return displayManagerServiceProxy_->DestroyVirtualScreen(screenId);
225 }
226
SetVirtualScreenSurface(ScreenId screenId,sptr<Surface> surface)227 DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
228 {
229 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
230
231 if (surface == nullptr) {
232 WLOGFE("Surface is nullptr");
233 return DMError::DM_ERROR_NULLPTR;
234 }
235 WLOGFI("DisplayManagerAdapter::SetVirtualScreenSurface");
236 return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface->GetProducer());
237 }
238
SetVirtualMirrorScreenCanvasRotation(ScreenId screenId,bool canvasRotation)239 DMError ScreenManagerAdapter::SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation)
240 {
241 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
242 WLOGFI("DisplayManagerAdapter::SetVirtualMirrorScreenCanvasRotation");
243 return displayManagerServiceProxy_->SetVirtualMirrorScreenCanvasRotation(screenId, canvasRotation);
244 }
245
SetVirtualMirrorScreenScaleMode(ScreenId screenId,ScreenScaleMode scaleMode)246 DMError ScreenManagerAdapter::SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode)
247 {
248 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
249 WLOGFI("DisplayManagerAdapter::SetVirtualMirrorScreenScaleMode");
250 return displayManagerServiceProxy_->SetVirtualMirrorScreenScaleMode(screenId, scaleMode);
251 }
252
SetScreenRotationLocked(bool isLocked)253 DMError ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked)
254 {
255 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
256 WLOGFI("DisplayManagerAdapter::SetScreenRotationLocked");
257 return displayManagerServiceProxy_->SetScreenRotationLocked(isLocked);
258 }
259
SetScreenRotationLockedFromJs(bool isLocked)260 DMError ScreenManagerAdapter::SetScreenRotationLockedFromJs(bool isLocked)
261 {
262 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
263 WLOGFI("DisplayManagerAdapter::SetScreenRotationLockedFromJs");
264 return displayManagerServiceProxy_->SetScreenRotationLockedFromJs(isLocked);
265 }
266
IsScreenRotationLocked(bool & isLocked)267 DMError ScreenManagerAdapter::IsScreenRotationLocked(bool& isLocked)
268 {
269 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
270 WLOGFI("DisplayManagerAdapter::IsScreenRotationLocked");
271 return displayManagerServiceProxy_->IsScreenRotationLocked(isLocked);
272 }
273
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)274 bool ScreenManagerAdapter::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
275 PowerStateChangeReason reason)
276 {
277 INIT_PROXY_CHECK_RETURN(false);
278 return displayManagerServiceProxy_->SetSpecifiedScreenPower(screenId, state, reason);
279 }
280
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)281 bool ScreenManagerAdapter::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
282 {
283 INIT_PROXY_CHECK_RETURN(false);
284 return displayManagerServiceProxy_->SetScreenPowerForAll(state, reason);
285 }
286
GetScreenPower(ScreenId dmsScreenId)287 ScreenPowerState ScreenManagerAdapter::GetScreenPower(ScreenId dmsScreenId)
288 {
289 INIT_PROXY_CHECK_RETURN(ScreenPowerState::INVALID_STATE);
290 return displayManagerServiceProxy_->GetScreenPower(dmsScreenId);
291 }
292
GetScreenPower()293 ScreenPowerState ScreenManagerAdapter::GetScreenPower()
294 {
295 INIT_PROXY_CHECK_RETURN(ScreenPowerState::INVALID_STATE);
296 return displayManagerServiceProxy_->GetScreenPower();
297 }
298
SetOrientation(ScreenId screenId,Orientation orientation)299 DMError ScreenManagerAdapter::SetOrientation(ScreenId screenId, Orientation orientation)
300 {
301 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
302
303 return displayManagerServiceProxy_->SetOrientation(screenId, orientation);
304 }
305
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)306 DMError BaseAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
307 DisplayManagerAgentType type)
308 {
309 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
310
311 return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
312 }
313
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)314 DMError BaseAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
315 DisplayManagerAgentType type)
316 {
317 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
318
319 return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
320 }
321
WakeUpBegin(PowerStateChangeReason reason)322 bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason)
323 {
324 INIT_PROXY_CHECK_RETURN(false);
325
326 return displayManagerServiceProxy_->WakeUpBegin(reason);
327 }
328
WakeUpEnd()329 bool DisplayManagerAdapter::WakeUpEnd()
330 {
331 INIT_PROXY_CHECK_RETURN(false);
332
333 return displayManagerServiceProxy_->WakeUpEnd();
334 }
335
SuspendBegin(PowerStateChangeReason reason)336 bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason)
337 {
338 INIT_PROXY_CHECK_RETURN(false);
339
340 return displayManagerServiceProxy_->SuspendBegin(reason);
341 }
342
SuspendEnd()343 bool DisplayManagerAdapter::SuspendEnd()
344 {
345 INIT_PROXY_CHECK_RETURN(false);
346
347 return displayManagerServiceProxy_->SuspendEnd();
348 }
349
SetDisplayState(DisplayState state)350 bool DisplayManagerAdapter::SetDisplayState(DisplayState state)
351 {
352 INIT_PROXY_CHECK_RETURN(false);
353
354 return displayManagerServiceProxy_->SetDisplayState(state);
355 }
356
GetDisplayState(DisplayId displayId)357 DisplayState DisplayManagerAdapter::GetDisplayState(DisplayId displayId)
358 {
359 INIT_PROXY_CHECK_RETURN(DisplayState::UNKNOWN);
360
361 return displayManagerServiceProxy_->GetDisplayState(displayId);
362 }
363
TryToCancelScreenOff()364 bool DisplayManagerAdapter::TryToCancelScreenOff()
365 {
366 INIT_PROXY_CHECK_RETURN(false);
367
368 return displayManagerServiceProxy_->TryToCancelScreenOff();
369 }
370
NotifyDisplayEvent(DisplayEvent event)371 void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event)
372 {
373 INIT_PROXY_CHECK_RETURN();
374
375 displayManagerServiceProxy_->NotifyDisplayEvent(event);
376 }
377
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)378 bool DisplayManagerAdapter::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
379 {
380 INIT_PROXY_CHECK_RETURN(false);
381
382 return displayManagerServiceProxy_->SetFreeze(displayIds, isFreeze);
383 }
384
InitDMSProxy()385 bool BaseAdapter::InitDMSProxy()
386 {
387 std::lock_guard<std::recursive_mutex> lock(mutex_);
388 if (!isProxyValid_) {
389 sptr<ISystemAbilityManager> systemAbilityManager =
390 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
391 if (!systemAbilityManager) {
392 WLOGFE("Failed to get system ability mgr.");
393 return false;
394 }
395
396 sptr<IRemoteObject> remoteObject
397 = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID);
398 if (!remoteObject) {
399 WLOGFE("Failed to get display manager service.");
400 return false;
401 }
402
403 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
404 displayManagerServiceProxy_ = iface_cast<IScreenSessionManager>(remoteObject);
405 } else {
406 displayManagerServiceProxy_ = iface_cast<IDisplayManager>(remoteObject);
407 }
408 if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) {
409 WLOGFW("Failed to get system display manager services");
410 return false;
411 }
412
413 dmsDeath_ = new(std::nothrow) DMSDeathRecipient(*this);
414 if (dmsDeath_ == nullptr) {
415 WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient");
416 return false;
417 }
418 if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(dmsDeath_)) {
419 WLOGFE("Failed to add death recipient");
420 return false;
421 }
422 isProxyValid_ = true;
423 }
424 return true;
425 }
426
DMSDeathRecipient(BaseAdapter & adapter)427 DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter)
428 {
429 }
430
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)431 void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
432 {
433 if (wptrDeath == nullptr) {
434 WLOGFE("wptrDeath is null");
435 return;
436 }
437
438 sptr<IRemoteObject> object = wptrDeath.promote();
439 if (!object) {
440 WLOGFE("object is null");
441 return;
442 }
443 WLOGFI("dms OnRemoteDied");
444 adapter_.Clear();
445 if (SingletonContainer::IsDestroyed()) {
446 WLOGFE("SingletonContainer is destroyed");
447 return;
448 }
449 SingletonContainer::Get<DisplayManager>().OnRemoteDied();
450 SingletonContainer::Get<ScreenManager>().OnRemoteDied();
451 return;
452 }
453
454
~BaseAdapter()455 BaseAdapter::~BaseAdapter()
456 {
457 WLOGFI("BaseAdapter destory!");
458 std::lock_guard<std::recursive_mutex> lock(mutex_);
459 Clear();
460 displayManagerServiceProxy_ = nullptr;
461 }
462
Clear()463 void BaseAdapter::Clear()
464 {
465 WLOGFD("BaseAdapter Clear!");
466 std::lock_guard<std::recursive_mutex> lock(mutex_);
467 if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) {
468 displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
469 }
470 isProxyValid_ = false;
471 }
472
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)473 DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
474 ScreenId& screenGroupId)
475 {
476 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
477
478 return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId);
479 }
480
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,DMRect mainScreenRegion,ScreenId & screenGroupId)481 DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
482 DMRect mainScreenRegion, ScreenId& screenGroupId)
483 {
484 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
485
486 return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, mainScreenRegion, screenGroupId);
487 }
488
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)489 DMError ScreenManagerAdapter::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
490 {
491 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
492
493 return displayManagerServiceProxy_->StopMirror(mirrorScreenIds);
494 }
495
DisableMirror(bool disableOrNot)496 DMError ScreenManagerAdapter::DisableMirror(bool disableOrNot)
497 {
498 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
499
500 return displayManagerServiceProxy_->DisableMirror(disableOrNot);
501 }
502
GetScreenInfo(ScreenId screenId)503 sptr<ScreenInfo> ScreenManagerAdapter::GetScreenInfo(ScreenId screenId)
504 {
505 if (screenId == SCREEN_ID_INVALID) {
506 WLOGFE("screen id is invalid");
507 return nullptr;
508 }
509 INIT_PROXY_CHECK_RETURN(nullptr);
510
511 sptr<ScreenInfo> screenInfo = displayManagerServiceProxy_->GetScreenInfoById(screenId);
512 return screenInfo;
513 }
514
GetAllDisplayIds()515 std::vector<DisplayId> DisplayManagerAdapter::GetAllDisplayIds()
516 {
517 WLOGFD("DisplayManagerAdapter::GetAllDisplayIds enter");
518 INIT_PROXY_CHECK_RETURN(std::vector<DisplayId>());
519
520 return displayManagerServiceProxy_->GetAllDisplayIds();
521 }
522
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)523 DMError DisplayManagerAdapter::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
524 {
525 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
526
527 return displayManagerServiceProxy_->HasPrivateWindow(displayId, hasPrivateWindow);
528 }
529
ConvertScreenIdToRsScreenId(ScreenId screenId,ScreenId & rsScreenId)530 bool DisplayManagerAdapter::ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId)
531 {
532 INIT_PROXY_CHECK_RETURN(false);
533
534 return displayManagerServiceProxy_->ConvertScreenIdToRsScreenId(screenId, rsScreenId);
535 }
536
HasImmersiveWindow(bool & immersive)537 DMError DisplayManagerAdapter::HasImmersiveWindow(bool& immersive)
538 {
539 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
540
541 return displayManagerServiceProxy_->HasImmersiveWindow(immersive);
542 }
543
GetDisplayInfo(DisplayId displayId)544 sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
545 {
546 WLOGFD("DisplayManagerAdapter::GetDisplayInfo enter, displayId: %{public}" PRIu64" ", displayId);
547 if (displayId == DISPLAY_ID_INVALID) {
548 WLOGFE("screen id is invalid");
549 return nullptr;
550 }
551 INIT_PROXY_CHECK_RETURN(nullptr);
552
553 return displayManagerServiceProxy_->GetDisplayInfoById(displayId);
554 }
555
GetCutoutInfo(DisplayId displayId)556 sptr<CutoutInfo> DisplayManagerAdapter::GetCutoutInfo(DisplayId displayId)
557 {
558 WLOGFD("DisplayManagerAdapter::GetCutoutInfo");
559 if (displayId == DISPLAY_ID_INVALID) {
560 WLOGFE("screen id is invalid");
561 return nullptr;
562 }
563 INIT_PROXY_CHECK_RETURN(nullptr);
564 return displayManagerServiceProxy_->GetCutoutInfo(displayId);
565 }
566
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)567 DMError DisplayManagerAdapter::AddSurfaceNodeToDisplay(DisplayId displayId,
568 std::shared_ptr<class RSSurfaceNode>& surfaceNode)
569 {
570 if (displayId == DISPLAY_ID_INVALID) {
571 WLOGFE("screen id is invalid");
572 return DMError::DM_ERROR_INVALID_PARAM;
573 }
574 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
575 return displayManagerServiceProxy_->AddSurfaceNodeToDisplay(displayId, surfaceNode);
576 }
577
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)578 DMError DisplayManagerAdapter::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
579 std::shared_ptr<class RSSurfaceNode>& surfaceNode)
580 {
581 if (displayId == DISPLAY_ID_INVALID) {
582 WLOGFE("screen id is invalid");
583 return DMError::DM_ERROR_INVALID_PARAM;
584 }
585 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
586 return displayManagerServiceProxy_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
587 }
588
IsFoldable()589 bool DisplayManagerAdapter::IsFoldable()
590 {
591 INIT_PROXY_CHECK_RETURN(false);
592
593 return displayManagerServiceProxy_->IsFoldable();
594 }
595
IsCaptured()596 bool DisplayManagerAdapter::IsCaptured()
597 {
598 INIT_PROXY_CHECK_RETURN(false);
599
600 return displayManagerServiceProxy_->IsCaptured();
601 }
602
GetFoldStatus()603 FoldStatus DisplayManagerAdapter::GetFoldStatus()
604 {
605 INIT_PROXY_CHECK_RETURN(FoldStatus::UNKNOWN);
606
607 return displayManagerServiceProxy_->GetFoldStatus();
608 }
609
GetFoldDisplayMode()610 FoldDisplayMode DisplayManagerAdapter::GetFoldDisplayMode()
611 {
612 INIT_PROXY_CHECK_RETURN(FoldDisplayMode::UNKNOWN);
613
614 return displayManagerServiceProxy_->GetFoldDisplayMode();
615 }
616
SetFoldDisplayMode(const FoldDisplayMode mode)617 void DisplayManagerAdapter::SetFoldDisplayMode(const FoldDisplayMode mode)
618 {
619 INIT_PROXY_CHECK_RETURN();
620
621 return displayManagerServiceProxy_->SetFoldDisplayMode(mode);
622 }
623
SetFoldDisplayModeFromJs(const FoldDisplayMode mode,std::string reason)624 DMError DisplayManagerAdapter::SetFoldDisplayModeFromJs(const FoldDisplayMode mode, std::string reason)
625 {
626 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
627
628 return displayManagerServiceProxy_->SetFoldDisplayModeFromJs(mode, reason);
629 }
630
SetDisplayScale(ScreenId screenId,float scaleX,float scaleY,float pivotX,float pivotY)631 void DisplayManagerAdapter::SetDisplayScale(ScreenId screenId,
632 float scaleX, float scaleY, float pivotX, float pivotY)
633 {
634 INIT_PROXY_CHECK_RETURN();
635
636 return displayManagerServiceProxy_->SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY);
637 }
638
SetFoldStatusLocked(bool locked)639 void DisplayManagerAdapter::SetFoldStatusLocked(bool locked)
640 {
641 INIT_PROXY_CHECK_RETURN();
642
643 return displayManagerServiceProxy_->SetFoldStatusLocked(locked);
644 }
645
SetFoldStatusLockedFromJs(bool locked)646 DMError DisplayManagerAdapter::SetFoldStatusLockedFromJs(bool locked)
647 {
648 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
649
650 return displayManagerServiceProxy_->SetFoldStatusLockedFromJs(locked);
651 }
652
GetCurrentFoldCreaseRegion()653 sptr<FoldCreaseRegion> DisplayManagerAdapter::GetCurrentFoldCreaseRegion()
654 {
655 INIT_PROXY_CHECK_RETURN(nullptr);
656
657 return displayManagerServiceProxy_->GetCurrentFoldCreaseRegion();
658 }
659
GetScreenGroupInfoById(ScreenId screenId)660 sptr<ScreenGroupInfo> ScreenManagerAdapter::GetScreenGroupInfoById(ScreenId screenId)
661 {
662 if (screenId == SCREEN_ID_INVALID) {
663 WLOGFE("screenGroup id is invalid");
664 return nullptr;
665 }
666 INIT_PROXY_CHECK_RETURN(nullptr);
667
668 return displayManagerServiceProxy_->GetScreenGroupInfoById(screenId);
669 }
670
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)671 DMError ScreenManagerAdapter::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
672 {
673 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
674
675 return displayManagerServiceProxy_->GetAllScreenInfos(screenInfos);
676 }
677
MakeExpand(std::vector<ScreenId> screenId,std::vector<Point> startPoint,ScreenId & screenGroupId)678 DMError ScreenManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
679 ScreenId& screenGroupId)
680 {
681 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
682
683 return displayManagerServiceProxy_->MakeExpand(screenId, startPoint, screenGroupId);
684 }
685
StopExpand(const std::vector<ScreenId> & expandScreenIds)686 DMError ScreenManagerAdapter::StopExpand(const std::vector<ScreenId>& expandScreenIds)
687 {
688 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
689
690 return displayManagerServiceProxy_->StopExpand(expandScreenIds);
691 }
692
693
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)694 void ScreenManagerAdapter::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
695 {
696 INIT_PROXY_CHECK_RETURN();
697
698 displayManagerServiceProxy_->RemoveVirtualScreenFromGroup(screens);
699 }
700
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)701 DMError ScreenManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
702 {
703 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
704
705 return displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId);
706 }
707
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)708 DMError ScreenManagerAdapter::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
709 {
710 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
711
712 return displayManagerServiceProxy_->SetVirtualPixelRatio(screenId, virtualPixelRatio);
713 }
714
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)715 DMError ScreenManagerAdapter::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
716 {
717 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
718
719 return displayManagerServiceProxy_->SetVirtualPixelRatioSystem(screenId, virtualPixelRatio);
720 }
721
SetResolution(ScreenId screenId,uint32_t width,uint32_t height,float virtualPixelRatio)722 DMError ScreenManagerAdapter::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)
723 {
724 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
725
726 return displayManagerServiceProxy_->SetResolution(screenId, width, height, virtualPixelRatio);
727 }
728
GetDensityInCurResolution(ScreenId screenId,float & virtualPixelRatio)729 DMError ScreenManagerAdapter::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)
730 {
731 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
732
733 return displayManagerServiceProxy_->GetDensityInCurResolution(screenId, virtualPixelRatio);
734 }
735
ResizeVirtualScreen(ScreenId screenId,uint32_t width,uint32_t height)736 DMError ScreenManagerAdapter::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
737 {
738 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
739
740 return displayManagerServiceProxy_->ResizeVirtualScreen(screenId, width, height);
741 }
742
MakeUniqueScreen(const std::vector<ScreenId> & screenIds)743 DMError ScreenManagerAdapter::MakeUniqueScreen(const std::vector<ScreenId>& screenIds)
744 {
745 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
746
747 return displayManagerServiceProxy_->MakeUniqueScreen(screenIds);
748 }
749
GetAvailableArea(DisplayId displayId,DMRect & area)750 DMError DisplayManagerAdapter::GetAvailableArea(DisplayId displayId, DMRect& area)
751 {
752 if (displayId == DISPLAY_ID_INVALID) {
753 WLOGFE("displayId id is invalid");
754 return DMError::DM_ERROR_INVALID_PARAM;
755 }
756 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
757
758 return displayManagerServiceProxy_->GetAvailableArea(displayId, area);
759 }
760
GetVirtualScreenFlag(ScreenId screenId)761 VirtualScreenFlag ScreenManagerAdapter::GetVirtualScreenFlag(ScreenId screenId)
762 {
763 INIT_PROXY_CHECK_RETURN(VirtualScreenFlag::DEFAULT);
764 if (screenId == SCREEN_ID_INVALID) {
765 WLOGFE("screenId id is invalid");
766 return VirtualScreenFlag::DEFAULT;
767 }
768 return displayManagerServiceProxy_->GetVirtualScreenFlag(screenId);
769 }
770
SetVirtualScreenFlag(ScreenId screenId,VirtualScreenFlag screenFlag)771 DMError ScreenManagerAdapter::SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag)
772 {
773 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
774 if (screenId == SCREEN_ID_INVALID) {
775 WLOGFE("displayId id is invalid");
776 return DMError::DM_ERROR_INVALID_PARAM;
777 }
778 if (screenFlag < VirtualScreenFlag::DEFAULT || screenFlag >= VirtualScreenFlag::MAX) {
779 return DMError::DM_ERROR_INVALID_PARAM;
780 }
781 return displayManagerServiceProxy_->SetVirtualScreenFlag(screenId, screenFlag);
782 }
783
SetVirtualScreenRefreshRate(ScreenId screenId,uint32_t refreshInterval)784 DMError ScreenManagerAdapter::SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval)
785 {
786 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
787
788 return displayManagerServiceProxy_->SetVirtualScreenRefreshRate(screenId, refreshInterval);
789 }
790
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)791 DMError DisplayManagerAdapter::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
792 {
793 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
794 return displayManagerServiceProxy_->ProxyForFreeze(pidList, isProxy);
795 }
796
ResetAllFreezeStatus()797 DMError DisplayManagerAdapter::ResetAllFreezeStatus()
798 {
799 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
800 return displayManagerServiceProxy_->ResetAllFreezeStatus();
801 }
802
SetVirtualScreenBlackList(ScreenId screenId,std::vector<uint64_t> & windowIdList,std::vector<uint64_t> surfaceIdList)803 void DisplayManagerAdapter::SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList,
804 std::vector<uint64_t> surfaceIdList)
805 {
806 INIT_PROXY_CHECK_RETURN();
807 displayManagerServiceProxy_->SetVirtualScreenBlackList(screenId, windowIdList, surfaceIdList);
808 }
809
DisablePowerOffRenderControl(ScreenId screenId)810 void DisplayManagerAdapter::DisablePowerOffRenderControl(ScreenId screenId)
811 {
812 INIT_PROXY_CHECK_RETURN();
813 displayManagerServiceProxy_->DisablePowerOffRenderControl(screenId);
814 }
815
GetAllDisplayPhysicalResolution()816 std::vector<DisplayPhysicalResolution> DisplayManagerAdapter::GetAllDisplayPhysicalResolution()
817 {
818 INIT_PROXY_CHECK_RETURN(std::vector<DisplayPhysicalResolution>{});
819 return displayManagerServiceProxy_->GetAllDisplayPhysicalResolution();
820 }
821
GetDisplayCapability()822 std::string DisplayManagerAdapter::GetDisplayCapability()
823 {
824 INIT_PROXY_CHECK_RETURN("");
825 return displayManagerServiceProxy_->GetDisplayCapability();
826 }
827
SetVirtualScreenSecurityExemption(ScreenId screenId,uint32_t pid,std::vector<uint64_t> & windowIdList)828 DMError DisplayManagerAdapter::SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid,
829 std::vector<uint64_t>& windowIdList)
830 {
831 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
832 return displayManagerServiceProxy_->SetVirtualScreenSecurityExemption(screenId, pid, windowIdList);
833 }
834
SetVirtualScreenMaxRefreshRate(ScreenId id,uint32_t refreshRate,uint32_t & actualRefreshRate)835 DMError ScreenManagerAdapter::SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate,
836 uint32_t& actualRefreshRate)
837 {
838 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
839 return displayManagerServiceProxy_->SetVirtualScreenMaxRefreshRate(id, refreshRate, actualRefreshRate);
840 }
841
GetScreenCapture(const CaptureOption & captureOption,DmErrorCode * errorCode)842 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetScreenCapture(const CaptureOption& captureOption,
843 DmErrorCode* errorCode)
844 {
845 INIT_PROXY_CHECK_RETURN(nullptr);
846 return displayManagerServiceProxy_->GetScreenCapture(captureOption, errorCode);
847 }
848
GetPrimaryDisplayInfo()849 sptr<DisplayInfo> DisplayManagerAdapter::GetPrimaryDisplayInfo()
850 {
851 INIT_PROXY_CHECK_RETURN(nullptr);
852 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
853 return displayManagerServiceProxy_->GetPrimaryDisplayInfo();
854 } else {
855 return displayManagerServiceProxy_->GetDefaultDisplayInfo();
856 }
857 }
858
GetDisplaySnapshotWithOption(const CaptureOption & captureOption,DmErrorCode * errorCode)859 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshotWithOption(const CaptureOption& captureOption,
860 DmErrorCode* errorCode)
861 {
862 INIT_PROXY_CHECK_RETURN(nullptr);
863 return displayManagerServiceProxy_->GetDisplaySnapshotWithOption(captureOption, errorCode);
864 }
865
SetScreenSkipProtectedWindow(const std::vector<ScreenId> & screenIds,bool isEnable)866 DMError ScreenManagerAdapter::SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable)
867 {
868 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
869 return displayManagerServiceProxy_->SetScreenSkipProtectedWindow(screenIds, isEnable);
870 }
871 } // namespace OHOS::Rosen