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
SetOrientation(ScreenId screenId,Orientation orientation)293 DMError ScreenManagerAdapter::SetOrientation(ScreenId screenId, Orientation orientation)
294 {
295 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
296
297 return displayManagerServiceProxy_->SetOrientation(screenId, orientation);
298 }
299
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)300 DMError BaseAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
301 DisplayManagerAgentType type)
302 {
303 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
304
305 return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
306 }
307
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)308 DMError BaseAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
309 DisplayManagerAgentType type)
310 {
311 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
312
313 return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
314 }
315
WakeUpBegin(PowerStateChangeReason reason)316 bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason)
317 {
318 INIT_PROXY_CHECK_RETURN(false);
319
320 return displayManagerServiceProxy_->WakeUpBegin(reason);
321 }
322
WakeUpEnd()323 bool DisplayManagerAdapter::WakeUpEnd()
324 {
325 INIT_PROXY_CHECK_RETURN(false);
326
327 return displayManagerServiceProxy_->WakeUpEnd();
328 }
329
SuspendBegin(PowerStateChangeReason reason)330 bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason)
331 {
332 INIT_PROXY_CHECK_RETURN(false);
333
334 return displayManagerServiceProxy_->SuspendBegin(reason);
335 }
336
SuspendEnd()337 bool DisplayManagerAdapter::SuspendEnd()
338 {
339 INIT_PROXY_CHECK_RETURN(false);
340
341 return displayManagerServiceProxy_->SuspendEnd();
342 }
343
SetDisplayState(DisplayState state)344 bool DisplayManagerAdapter::SetDisplayState(DisplayState state)
345 {
346 INIT_PROXY_CHECK_RETURN(false);
347
348 return displayManagerServiceProxy_->SetDisplayState(state);
349 }
350
GetDisplayState(DisplayId displayId)351 DisplayState DisplayManagerAdapter::GetDisplayState(DisplayId displayId)
352 {
353 INIT_PROXY_CHECK_RETURN(DisplayState::UNKNOWN);
354
355 return displayManagerServiceProxy_->GetDisplayState(displayId);
356 }
357
TryToCancelScreenOff()358 bool DisplayManagerAdapter::TryToCancelScreenOff()
359 {
360 INIT_PROXY_CHECK_RETURN(false);
361
362 return displayManagerServiceProxy_->TryToCancelScreenOff();
363 }
364
NotifyDisplayEvent(DisplayEvent event)365 void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event)
366 {
367 INIT_PROXY_CHECK_RETURN();
368
369 displayManagerServiceProxy_->NotifyDisplayEvent(event);
370 }
371
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)372 bool DisplayManagerAdapter::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
373 {
374 INIT_PROXY_CHECK_RETURN(false);
375
376 return displayManagerServiceProxy_->SetFreeze(displayIds, isFreeze);
377 }
378
InitDMSProxy()379 bool BaseAdapter::InitDMSProxy()
380 {
381 std::lock_guard<std::recursive_mutex> lock(mutex_);
382 if (!isProxyValid_) {
383 sptr<ISystemAbilityManager> systemAbilityManager =
384 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
385 if (!systemAbilityManager) {
386 WLOGFE("Failed to get system ability mgr.");
387 return false;
388 }
389
390 sptr<IRemoteObject> remoteObject
391 = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID);
392 if (!remoteObject) {
393 WLOGFE("Failed to get display manager service.");
394 return false;
395 }
396
397 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
398 displayManagerServiceProxy_ = iface_cast<IScreenSessionManager>(remoteObject);
399 } else {
400 displayManagerServiceProxy_ = iface_cast<IDisplayManager>(remoteObject);
401 }
402 if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) {
403 WLOGFW("Failed to get system display manager services");
404 return false;
405 }
406
407 dmsDeath_ = new(std::nothrow) DMSDeathRecipient(*this);
408 if (dmsDeath_ == nullptr) {
409 WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient");
410 return false;
411 }
412 if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(dmsDeath_)) {
413 WLOGFE("Failed to add death recipient");
414 return false;
415 }
416 isProxyValid_ = true;
417 }
418 return true;
419 }
420
DMSDeathRecipient(BaseAdapter & adapter)421 DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter)
422 {
423 }
424
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)425 void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
426 {
427 if (wptrDeath == nullptr) {
428 WLOGFE("wptrDeath is null");
429 return;
430 }
431
432 sptr<IRemoteObject> object = wptrDeath.promote();
433 if (!object) {
434 WLOGFE("object is null");
435 return;
436 }
437 WLOGFI("dms OnRemoteDied");
438 adapter_.Clear();
439 if (SingletonContainer::IsDestroyed()) {
440 WLOGFE("SingletonContainer is destroyed");
441 return;
442 }
443 SingletonContainer::Get<DisplayManager>().OnRemoteDied();
444 SingletonContainer::Get<ScreenManager>().OnRemoteDied();
445 return;
446 }
447
448
~BaseAdapter()449 BaseAdapter::~BaseAdapter()
450 {
451 WLOGFI("BaseAdapter destory!");
452 std::lock_guard<std::recursive_mutex> lock(mutex_);
453 Clear();
454 displayManagerServiceProxy_ = nullptr;
455 }
456
Clear()457 void BaseAdapter::Clear()
458 {
459 WLOGFD("BaseAdapter Clear!");
460 std::lock_guard<std::recursive_mutex> lock(mutex_);
461 if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) {
462 displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
463 }
464 isProxyValid_ = false;
465 }
466
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)467 DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
468 ScreenId& screenGroupId)
469 {
470 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
471
472 return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId);
473 }
474
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)475 DMError ScreenManagerAdapter::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
476 {
477 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
478
479 return displayManagerServiceProxy_->StopMirror(mirrorScreenIds);
480 }
481
DisableMirror(bool disableOrNot)482 DMError ScreenManagerAdapter::DisableMirror(bool disableOrNot)
483 {
484 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
485
486 return displayManagerServiceProxy_->DisableMirror(disableOrNot);
487 }
488
GetScreenInfo(ScreenId screenId)489 sptr<ScreenInfo> ScreenManagerAdapter::GetScreenInfo(ScreenId screenId)
490 {
491 if (screenId == SCREEN_ID_INVALID) {
492 WLOGFE("screen id is invalid");
493 return nullptr;
494 }
495 INIT_PROXY_CHECK_RETURN(nullptr);
496
497 sptr<ScreenInfo> screenInfo = displayManagerServiceProxy_->GetScreenInfoById(screenId);
498 return screenInfo;
499 }
500
GetAllDisplayIds()501 std::vector<DisplayId> DisplayManagerAdapter::GetAllDisplayIds()
502 {
503 WLOGFD("DisplayManagerAdapter::GetAllDisplayIds enter");
504 INIT_PROXY_CHECK_RETURN(std::vector<DisplayId>());
505
506 return displayManagerServiceProxy_->GetAllDisplayIds();
507 }
508
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)509 DMError DisplayManagerAdapter::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
510 {
511 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
512
513 return displayManagerServiceProxy_->HasPrivateWindow(displayId, hasPrivateWindow);
514 }
515
ConvertScreenIdToRsScreenId(ScreenId screenId,ScreenId & rsScreenId)516 bool DisplayManagerAdapter::ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId)
517 {
518 INIT_PROXY_CHECK_RETURN(false);
519
520 return displayManagerServiceProxy_->ConvertScreenIdToRsScreenId(screenId, rsScreenId);
521 }
522
HasImmersiveWindow(bool & immersive)523 DMError DisplayManagerAdapter::HasImmersiveWindow(bool& immersive)
524 {
525 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
526
527 return displayManagerServiceProxy_->HasImmersiveWindow(immersive);
528 }
529
GetDisplayInfo(DisplayId displayId)530 sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
531 {
532 WLOGFD("DisplayManagerAdapter::GetDisplayInfo enter, displayId: %{public}" PRIu64" ", displayId);
533 if (displayId == DISPLAY_ID_INVALID) {
534 WLOGFE("screen id is invalid");
535 return nullptr;
536 }
537 INIT_PROXY_CHECK_RETURN(nullptr);
538
539 return displayManagerServiceProxy_->GetDisplayInfoById(displayId);
540 }
541
GetCutoutInfo(DisplayId displayId)542 sptr<CutoutInfo> DisplayManagerAdapter::GetCutoutInfo(DisplayId displayId)
543 {
544 WLOGFD("DisplayManagerAdapter::GetCutoutInfo");
545 if (displayId == DISPLAY_ID_INVALID) {
546 WLOGFE("screen id is invalid");
547 return nullptr;
548 }
549 INIT_PROXY_CHECK_RETURN(nullptr);
550 return displayManagerServiceProxy_->GetCutoutInfo(displayId);
551 }
552
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)553 DMError DisplayManagerAdapter::AddSurfaceNodeToDisplay(DisplayId displayId,
554 std::shared_ptr<class RSSurfaceNode>& surfaceNode)
555 {
556 if (displayId == DISPLAY_ID_INVALID) {
557 WLOGFE("screen id is invalid");
558 return DMError::DM_ERROR_INVALID_PARAM;
559 }
560 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
561 return displayManagerServiceProxy_->AddSurfaceNodeToDisplay(displayId, surfaceNode);
562 }
563
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)564 DMError DisplayManagerAdapter::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
565 std::shared_ptr<class RSSurfaceNode>& surfaceNode)
566 {
567 if (displayId == DISPLAY_ID_INVALID) {
568 WLOGFE("screen id is invalid");
569 return DMError::DM_ERROR_INVALID_PARAM;
570 }
571 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
572 return displayManagerServiceProxy_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
573 }
574
IsFoldable()575 bool DisplayManagerAdapter::IsFoldable()
576 {
577 INIT_PROXY_CHECK_RETURN(false);
578
579 return displayManagerServiceProxy_->IsFoldable();
580 }
581
IsCaptured()582 bool DisplayManagerAdapter::IsCaptured()
583 {
584 INIT_PROXY_CHECK_RETURN(false);
585
586 return displayManagerServiceProxy_->IsCaptured();
587 }
588
GetFoldStatus()589 FoldStatus DisplayManagerAdapter::GetFoldStatus()
590 {
591 INIT_PROXY_CHECK_RETURN(FoldStatus::UNKNOWN);
592
593 return displayManagerServiceProxy_->GetFoldStatus();
594 }
595
GetFoldDisplayMode()596 FoldDisplayMode DisplayManagerAdapter::GetFoldDisplayMode()
597 {
598 INIT_PROXY_CHECK_RETURN(FoldDisplayMode::UNKNOWN);
599
600 return displayManagerServiceProxy_->GetFoldDisplayMode();
601 }
602
SetFoldDisplayMode(const FoldDisplayMode mode)603 void DisplayManagerAdapter::SetFoldDisplayMode(const FoldDisplayMode mode)
604 {
605 INIT_PROXY_CHECK_RETURN();
606
607 return displayManagerServiceProxy_->SetFoldDisplayMode(mode);
608 }
609
SetFoldDisplayModeFromJs(const FoldDisplayMode mode)610 DMError DisplayManagerAdapter::SetFoldDisplayModeFromJs(const FoldDisplayMode mode)
611 {
612 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
613
614 return displayManagerServiceProxy_->SetFoldDisplayModeFromJs(mode);
615 }
616
SetDisplayScale(ScreenId screenId,float scaleX,float scaleY,float pivotX,float pivotY)617 void DisplayManagerAdapter::SetDisplayScale(ScreenId screenId,
618 float scaleX, float scaleY, float pivotX, float pivotY)
619 {
620 INIT_PROXY_CHECK_RETURN();
621
622 return displayManagerServiceProxy_->SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY);
623 }
624
SetFoldStatusLocked(bool locked)625 void DisplayManagerAdapter::SetFoldStatusLocked(bool locked)
626 {
627 INIT_PROXY_CHECK_RETURN();
628
629 return displayManagerServiceProxy_->SetFoldStatusLocked(locked);
630 }
631
SetFoldStatusLockedFromJs(bool locked)632 DMError DisplayManagerAdapter::SetFoldStatusLockedFromJs(bool locked)
633 {
634 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
635
636 return displayManagerServiceProxy_->SetFoldStatusLockedFromJs(locked);
637 }
638
GetCurrentFoldCreaseRegion()639 sptr<FoldCreaseRegion> DisplayManagerAdapter::GetCurrentFoldCreaseRegion()
640 {
641 INIT_PROXY_CHECK_RETURN(nullptr);
642
643 return displayManagerServiceProxy_->GetCurrentFoldCreaseRegion();
644 }
645
GetScreenGroupInfoById(ScreenId screenId)646 sptr<ScreenGroupInfo> ScreenManagerAdapter::GetScreenGroupInfoById(ScreenId screenId)
647 {
648 if (screenId == SCREEN_ID_INVALID) {
649 WLOGFE("screenGroup id is invalid");
650 return nullptr;
651 }
652 INIT_PROXY_CHECK_RETURN(nullptr);
653
654 return displayManagerServiceProxy_->GetScreenGroupInfoById(screenId);
655 }
656
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)657 DMError ScreenManagerAdapter::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
658 {
659 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
660
661 return displayManagerServiceProxy_->GetAllScreenInfos(screenInfos);
662 }
663
MakeExpand(std::vector<ScreenId> screenId,std::vector<Point> startPoint,ScreenId & screenGroupId)664 DMError ScreenManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
665 ScreenId& screenGroupId)
666 {
667 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
668
669 return displayManagerServiceProxy_->MakeExpand(screenId, startPoint, screenGroupId);
670 }
671
StopExpand(const std::vector<ScreenId> & expandScreenIds)672 DMError ScreenManagerAdapter::StopExpand(const std::vector<ScreenId>& expandScreenIds)
673 {
674 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
675
676 return displayManagerServiceProxy_->StopExpand(expandScreenIds);
677 }
678
679
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)680 void ScreenManagerAdapter::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
681 {
682 INIT_PROXY_CHECK_RETURN();
683
684 displayManagerServiceProxy_->RemoveVirtualScreenFromGroup(screens);
685 }
686
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)687 DMError ScreenManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
688 {
689 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
690
691 return displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId);
692 }
693
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)694 DMError ScreenManagerAdapter::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
695 {
696 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
697
698 return displayManagerServiceProxy_->SetVirtualPixelRatio(screenId, virtualPixelRatio);
699 }
700
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)701 DMError ScreenManagerAdapter::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
702 {
703 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
704
705 return displayManagerServiceProxy_->SetVirtualPixelRatioSystem(screenId, virtualPixelRatio);
706 }
707
SetResolution(ScreenId screenId,uint32_t width,uint32_t height,float virtualPixelRatio)708 DMError ScreenManagerAdapter::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)
709 {
710 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
711
712 return displayManagerServiceProxy_->SetResolution(screenId, width, height, virtualPixelRatio);
713 }
714
GetDensityInCurResolution(ScreenId screenId,float & virtualPixelRatio)715 DMError ScreenManagerAdapter::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)
716 {
717 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
718
719 return displayManagerServiceProxy_->GetDensityInCurResolution(screenId, virtualPixelRatio);
720 }
721
ResizeVirtualScreen(ScreenId screenId,uint32_t width,uint32_t height)722 DMError ScreenManagerAdapter::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
723 {
724 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
725
726 return displayManagerServiceProxy_->ResizeVirtualScreen(screenId, width, height);
727 }
728
MakeUniqueScreen(const std::vector<ScreenId> & screenIds)729 DMError ScreenManagerAdapter::MakeUniqueScreen(const std::vector<ScreenId>& screenIds)
730 {
731 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
732
733 return displayManagerServiceProxy_->MakeUniqueScreen(screenIds);
734 }
735
GetAvailableArea(DisplayId displayId,DMRect & area)736 DMError DisplayManagerAdapter::GetAvailableArea(DisplayId displayId, DMRect& area)
737 {
738 if (displayId == DISPLAY_ID_INVALID) {
739 WLOGFE("displayId id is invalid");
740 return DMError::DM_ERROR_INVALID_PARAM;
741 }
742 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
743
744 return displayManagerServiceProxy_->GetAvailableArea(displayId, area);
745 }
746
GetVirtualScreenFlag(ScreenId screenId)747 VirtualScreenFlag ScreenManagerAdapter::GetVirtualScreenFlag(ScreenId screenId)
748 {
749 INIT_PROXY_CHECK_RETURN(VirtualScreenFlag::DEFAULT);
750 if (screenId == SCREEN_ID_INVALID) {
751 WLOGFE("screenId id is invalid");
752 return VirtualScreenFlag::DEFAULT;
753 }
754 return displayManagerServiceProxy_->GetVirtualScreenFlag(screenId);
755 }
756
SetVirtualScreenFlag(ScreenId screenId,VirtualScreenFlag screenFlag)757 DMError ScreenManagerAdapter::SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag)
758 {
759 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
760 if (screenId == SCREEN_ID_INVALID) {
761 WLOGFE("displayId id is invalid");
762 return DMError::DM_ERROR_INVALID_PARAM;
763 }
764 if (screenFlag < VirtualScreenFlag::DEFAULT || screenFlag >= VirtualScreenFlag::MAX) {
765 return DMError::DM_ERROR_INVALID_PARAM;
766 }
767 return displayManagerServiceProxy_->SetVirtualScreenFlag(screenId, screenFlag);
768 }
769
SetVirtualScreenRefreshRate(ScreenId screenId,uint32_t refreshInterval)770 DMError ScreenManagerAdapter::SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval)
771 {
772 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
773
774 return displayManagerServiceProxy_->SetVirtualScreenRefreshRate(screenId, refreshInterval);
775 }
776
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)777 DMError DisplayManagerAdapter::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
778 {
779 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
780 return displayManagerServiceProxy_->ProxyForFreeze(pidList, isProxy);
781 }
782
ResetAllFreezeStatus()783 DMError DisplayManagerAdapter::ResetAllFreezeStatus()
784 {
785 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
786 return displayManagerServiceProxy_->ResetAllFreezeStatus();
787 }
788
SetVirtualScreenBlackList(ScreenId screenId,std::vector<uint64_t> & windowIdList)789 void DisplayManagerAdapter::SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList)
790 {
791 INIT_PROXY_CHECK_RETURN();
792 displayManagerServiceProxy_->SetVirtualScreenBlackList(screenId, windowIdList);
793 }
794
DisablePowerOffRenderControl(ScreenId screenId)795 void DisplayManagerAdapter::DisablePowerOffRenderControl(ScreenId screenId)
796 {
797 INIT_PROXY_CHECK_RETURN();
798 displayManagerServiceProxy_->DisablePowerOffRenderControl(screenId);
799 }
800
GetAllDisplayPhysicalResolution()801 std::vector<DisplayPhysicalResolution> DisplayManagerAdapter::GetAllDisplayPhysicalResolution()
802 {
803 INIT_PROXY_CHECK_RETURN(std::vector<DisplayPhysicalResolution>{});
804 return displayManagerServiceProxy_->GetAllDisplayPhysicalResolution();
805 }
806
SetVirtualScreenSecurityExemption(ScreenId screenId,uint32_t pid,std::vector<uint64_t> & windowIdList)807 DMError DisplayManagerAdapter::SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid,
808 std::vector<uint64_t>& windowIdList)
809 {
810 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
811 return displayManagerServiceProxy_->SetVirtualScreenSecurityExemption(screenId, pid, windowIdList);
812 }
813
SetVirtualScreenMaxRefreshRate(ScreenId id,uint32_t refreshRate,uint32_t & actualRefreshRate)814 DMError ScreenManagerAdapter::SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate,
815 uint32_t& actualRefreshRate)
816 {
817 INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
818 return displayManagerServiceProxy_->SetVirtualScreenMaxRefreshRate(id, refreshRate, actualRefreshRate);
819 }
820
GetScreenCapture(const CaptureOption & captureOption,DmErrorCode * errorCode)821 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetScreenCapture(const CaptureOption& captureOption,
822 DmErrorCode* errorCode)
823 {
824 INIT_PROXY_CHECK_RETURN(nullptr);
825 return displayManagerServiceProxy_->GetScreenCapture(captureOption, errorCode);
826 }
827
GetPrimaryDisplayInfo()828 sptr<DisplayInfo> DisplayManagerAdapter::GetPrimaryDisplayInfo()
829 {
830 INIT_PROXY_CHECK_RETURN(nullptr);
831 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
832 return displayManagerServiceProxy_->GetPrimaryDisplayInfo();
833 } else {
834 return displayManagerServiceProxy_->GetDefaultDisplayInfo();
835 }
836 }
837
GetDisplaySnapshotWithOption(const CaptureOption & captureOption,DmErrorCode * errorCode)838 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshotWithOption(const CaptureOption& captureOption,
839 DmErrorCode* errorCode)
840 {
841 INIT_PROXY_CHECK_RETURN(nullptr);
842 return displayManagerServiceProxy_->GetDisplaySnapshotWithOption(captureOption, errorCode);
843 }
844 } // namespace OHOS::Rosen