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