• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter)
WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)31 WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)
32 
33 #define INIT_PROXY_CHECK_RETURN(ret) \
34     do { \
35         if (!InitDMSProxy()) { \
36             TLOGE(WmsLogTag::DMS, "InitDMSProxy failed!"); \
37             return ret; \
38         } \
39     } while (false)
40 
41 DMError BaseAdapter::ConvertToDMError(ErrCode errCode, int32_t dmError)
42 {
43     if (FAILED(errCode)) {
44         TLOGE(WmsLogTag::DMS, "ConvertToDMError errCode: %{public}d, dmError: %{public}d", errCode, dmError);
45         return DMError::DM_ERROR_IPC_FAILED;
46     }
47     return static_cast<DMError>(dmError);
48 }
49 
GetDefaultDisplayInfo()50 sptr<DisplayInfo> DisplayManagerAdapter::GetDefaultDisplayInfo()
51 {
52     INIT_PROXY_CHECK_RETURN(nullptr);
53 
54     if (screenSessionManagerServiceProxy_) {
55         return screenSessionManagerServiceProxy_->GetDefaultDisplayInfo();
56     }
57 
58     sptr<DisplayInfo> displayInfo;
59     ErrCode errCode = displayManagerServiceProxy_->GetDefaultDisplayInfo(displayInfo);
60     if (FAILED(errCode) || displayInfo == nullptr) {
61         TLOGE(WmsLogTag::DMS, "GetDefaultDisplayInfo failed, errCode: %{public}d, displayInfo: %{public}s", errCode,
62             displayInfo == nullptr ? "null" : "not null");
63         return nullptr;
64     }
65     return displayInfo;
66 }
67 
SetVirtualScreenAsDefault(ScreenId screenId)68 bool DisplayManagerAdapter::SetVirtualScreenAsDefault(ScreenId screenId)
69 {
70     INIT_PROXY_CHECK_RETURN(false);
71     bool isSuccess = false;
72     if (displayManagerServiceProxy_) {
73         displayManagerServiceProxy_->SetVirtualScreenAsDefault(screenId, isSuccess);
74     }
75     return isSuccess;
76 }
77 
GetDisplayInfoByScreenId(ScreenId screenId)78 sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfoByScreenId(ScreenId screenId)
79 {
80     INIT_PROXY_CHECK_RETURN(nullptr);
81 
82     if (screenSessionManagerServiceProxy_) {
83         return screenSessionManagerServiceProxy_->GetDisplayInfoByScreen(screenId);
84     }
85 
86     sptr<DisplayInfo> displayInfo;
87     ErrCode errCode = displayManagerServiceProxy_->GetDisplayInfoByScreen(screenId, displayInfo);
88     if (FAILED(errCode) || displayInfo == nullptr) {
89         TLOGE(WmsLogTag::DMS, "GetDisplayInfoByScreenId failed, screenId: %{public}" PRIu64 ", errCode: %{public}d"
90             ", displayInfo: %{public}s", screenId, errCode, displayInfo == nullptr ? "null" : "not null");
91         return nullptr;
92     }
93     return displayInfo;
94 }
95 
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode,bool isUseDma,bool isCaptureFullOfScreen)96 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId,
97     DmErrorCode* errorCode, bool isUseDma, bool isCaptureFullOfScreen)
98 {
99     INIT_PROXY_CHECK_RETURN(nullptr);
100 
101     if (screenSessionManagerServiceProxy_) {
102         return screenSessionManagerServiceProxy_->GetDisplaySnapshot(displayId, errorCode, isUseDma,
103             isCaptureFullOfScreen);
104     }
105 
106     auto errorCodeOut = static_cast<int32_t>(DmErrorCode::DM_OK);
107     std::shared_ptr<Media::PixelMap> pixelMap;
108     ErrCode errCode = displayManagerServiceProxy_->GetDisplaySnapshot(displayId, errorCodeOut, isUseDma,
109         isCaptureFullOfScreen, pixelMap);
110     if (errorCode != nullptr) {
111         *errorCode = static_cast<DmErrorCode>(errorCodeOut);
112     }
113     if (FAILED(errCode) || pixelMap == nullptr) {
114         TLOGE(WmsLogTag::DMS, "GetDisplayInfoByScreenId failed, displayId: %{public}" PRIu64 ", errCode: %{public}d"
115             ", pixelMap: %{public}s", displayId, errCode, pixelMap == nullptr ? "null" : "not null");
116         return nullptr;
117     }
118     return pixelMap;
119 }
120 
GetDisplayHDRSnapshot(DisplayId displayId,DmErrorCode & errorCode,bool isUseDma,bool isCaptureFullOfScreen)121 std::vector<std::shared_ptr<Media::PixelMap>> DisplayManagerAdapter::GetDisplayHDRSnapshot(DisplayId displayId,
122     DmErrorCode& errorCode, bool isUseDma, bool isCaptureFullOfScreen)
123 {
124     INIT_PROXY_CHECK_RETURN({});
125 
126     if (screenSessionManagerServiceProxy_) {
127         return screenSessionManagerServiceProxy_->GetDisplayHDRSnapshot(displayId, errorCode, isUseDma,
128             isCaptureFullOfScreen);
129     }
130     errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
131     return { nullptr, nullptr };
132 }
133 
GetSnapshotByPicker(Media::Rect & rect,DmErrorCode * errorCode)134 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetSnapshotByPicker(Media::Rect& rect, DmErrorCode* errorCode)
135 {
136     INIT_PROXY_CHECK_RETURN(nullptr);
137 
138     if (screenSessionManagerServiceProxy_) {
139         return screenSessionManagerServiceProxy_->GetSnapshotByPicker(rect, errorCode);
140     }
141 
142     if (errorCode != nullptr) {
143         *errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
144     }
145     return nullptr;
146 }
147 
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)148 DMError ScreenManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId,
149     std::vector<ScreenColorGamut>& colorGamuts)
150 {
151     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
152 
153     if (screenSessionManagerServiceProxy_) {
154         return screenSessionManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
155     }
156 
157     std::vector<uint32_t> colorGamutsOut;
158     int32_t dmError;
159     ErrCode errCode = displayManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamutsOut, dmError);
160     if (SUCCEEDED(errCode)) {
161         for (auto colorGamut : colorGamutsOut) {
162             colorGamuts.push_back(static_cast<ScreenColorGamut>(colorGamut));
163         }
164     }
165     return ConvertToDMError(errCode, dmError);
166 }
167 
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)168 DMError ScreenManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
169 {
170     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
171 
172     if (screenSessionManagerServiceProxy_) {
173         return screenSessionManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamut);
174     }
175 
176     uint32_t colorGamutOut;
177     int32_t dmError;
178     ErrCode errCode = displayManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamutOut, dmError);
179     if (SUCCEEDED(errCode)) {
180         colorGamut = static_cast<ScreenColorGamut>(colorGamutOut);
181     }
182     return ConvertToDMError(errCode, dmError);
183 }
184 
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)185 DMError ScreenManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
186 {
187     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
188 
189     if (screenSessionManagerServiceProxy_) {
190         return screenSessionManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx);
191     }
192 
193     int32_t dmError;
194     ErrCode errCode = displayManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx, dmError);
195     return ConvertToDMError(errCode, dmError);
196 }
197 
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)198 DMError ScreenManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
199 {
200     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
201 
202     if (screenSessionManagerServiceProxy_) {
203         return screenSessionManagerServiceProxy_->GetScreenGamutMap(screenId, gamutMap);
204     }
205 
206     uint32_t gamutMapOut;
207     int32_t dmError;
208     ErrCode errCode = displayManagerServiceProxy_->GetScreenGamutMap(screenId, gamutMapOut, dmError);
209     if (SUCCEEDED(errCode)) {
210         gamutMap = static_cast<ScreenGamutMap>(gamutMapOut);
211     }
212     return ConvertToDMError(errCode, dmError);
213 }
214 
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)215 DMError ScreenManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
216 {
217     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
218 
219     if (screenSessionManagerServiceProxy_) {
220         return screenSessionManagerServiceProxy_->SetScreenGamutMap(screenId, gamutMap);
221     }
222 
223     int32_t dmError;
224     ErrCode errCode = displayManagerServiceProxy_->SetScreenGamutMap(screenId, static_cast<uint32_t>(gamutMap),
225         dmError);
226     return ConvertToDMError(errCode, dmError);
227 }
228 
SetScreenColorTransform(ScreenId screenId)229 DMError ScreenManagerAdapter::SetScreenColorTransform(ScreenId screenId)
230 {
231     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
232 
233     if (screenSessionManagerServiceProxy_) {
234         return screenSessionManagerServiceProxy_->SetScreenColorTransform(screenId);
235     }
236 
237     ErrCode errCode = displayManagerServiceProxy_->SetScreenColorTransform(screenId);
238     return ConvertToDMError(errCode, static_cast<int32_t>(DMError::DM_OK));
239 }
240 
GetPixelFormat(ScreenId screenId,GraphicPixelFormat & pixelFormat)241 DMError ScreenManagerAdapter::GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat)
242 {
243     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
244 
245     TLOGI(WmsLogTag::DMS, "enter!");
246     if (screenSessionManagerServiceProxy_) {
247         return screenSessionManagerServiceProxy_->GetPixelFormat(screenId, pixelFormat);
248     }
249 
250     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
251 }
252 
SetPixelFormat(ScreenId screenId,GraphicPixelFormat pixelFormat)253 DMError ScreenManagerAdapter::SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat)
254 {
255     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
256 
257     TLOGI(WmsLogTag::DMS, "enter!");
258     if (screenSessionManagerServiceProxy_) {
259         return screenSessionManagerServiceProxy_->SetPixelFormat(screenId, pixelFormat);
260     }
261 
262     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
263 }
264 
GetSupportedHDRFormats(ScreenId screenId,std::vector<ScreenHDRFormat> & hdrFormats)265 DMError ScreenManagerAdapter::GetSupportedHDRFormats(ScreenId screenId,
266     std::vector<ScreenHDRFormat>& hdrFormats)
267 {
268     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
269 
270     TLOGI(WmsLogTag::DMS, "enter!");
271     if (screenSessionManagerServiceProxy_) {
272         return screenSessionManagerServiceProxy_->GetSupportedHDRFormats(screenId, hdrFormats);
273     }
274 
275     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
276 }
277 
GetScreenHDRFormat(ScreenId screenId,ScreenHDRFormat & hdrFormat)278 DMError ScreenManagerAdapter::GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat)
279 {
280     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
281 
282     TLOGI(WmsLogTag::DMS, "enter!");
283     if (screenSessionManagerServiceProxy_) {
284         return screenSessionManagerServiceProxy_->GetScreenHDRFormat(screenId, hdrFormat);
285     }
286 
287     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
288 }
289 
SetScreenHDRFormat(ScreenId screenId,int32_t modeIdx)290 DMError ScreenManagerAdapter::SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx)
291 {
292     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
293 
294     TLOGI(WmsLogTag::DMS, "enter!");
295     if (screenSessionManagerServiceProxy_) {
296         return screenSessionManagerServiceProxy_->SetScreenHDRFormat(screenId, modeIdx);
297     }
298 
299     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
300 }
301 
GetSupportedColorSpaces(ScreenId screenId,std::vector<GraphicCM_ColorSpaceType> & colorSpaces)302 DMError ScreenManagerAdapter::GetSupportedColorSpaces(ScreenId screenId,
303     std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
304 {
305     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
306 
307     TLOGI(WmsLogTag::DMS, "enter!");
308     if (screenSessionManagerServiceProxy_) {
309         return screenSessionManagerServiceProxy_->GetSupportedColorSpaces(screenId, colorSpaces);
310     }
311 
312     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
313 }
314 
GetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType & colorSpace)315 DMError ScreenManagerAdapter::GetScreenColorSpace(ScreenId screenId,
316     GraphicCM_ColorSpaceType& colorSpace)
317 {
318     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
319 
320     TLOGI(WmsLogTag::DMS, "enter!");
321     if (screenSessionManagerServiceProxy_) {
322         return screenSessionManagerServiceProxy_->GetScreenColorSpace(screenId, colorSpace);
323     }
324 
325     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
326 }
327 
SetScreenColorSpace(ScreenId screenId,GraphicCM_ColorSpaceType colorSpace)328 DMError ScreenManagerAdapter::SetScreenColorSpace(ScreenId screenId,
329     GraphicCM_ColorSpaceType colorSpace)
330 {
331     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
332 
333     TLOGI(WmsLogTag::DMS, "enter!");
334     if (screenSessionManagerServiceProxy_) {
335         return screenSessionManagerServiceProxy_->SetScreenColorSpace(screenId, colorSpace);
336     }
337 
338     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
339 }
340 
GetSupportedHDRFormats(ScreenId screenId,std::vector<uint32_t> & hdrFormats)341 DMError ScreenManagerAdapter::GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats)
342 {
343     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
344 
345     std::vector<ScreenHDRFormat> hdrFormatsVec;
346     DMError ret = GetSupportedHDRFormats(screenId, hdrFormatsVec);
347     for (auto value : hdrFormatsVec) {
348         hdrFormats.push_back(static_cast<uint32_t>(value));
349     }
350     TLOGI(WmsLogTag::DMS, "ret: %{public}d", static_cast<int32_t>(ret));
351     return ret;
352 }
353 
GetSupportedColorSpaces(ScreenId screenId,std::vector<uint32_t> & colorSpaces)354 DMError ScreenManagerAdapter::GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces)
355 {
356     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
357 
358     std::vector<GraphicCM_ColorSpaceType> colorSpacesVec;
359     DMError ret = GetSupportedColorSpaces(screenId, colorSpacesVec);
360     for (auto value : colorSpacesVec) {
361         colorSpaces.push_back(static_cast<uint32_t>(value));
362     }
363     TLOGI(WmsLogTag::DMS, "ret: %{public}d", static_cast<int32_t>(ret));
364     return ret;
365 }
366 
CreateVirtualScreen(VirtualScreenOption option,const sptr<IDisplayManagerAgent> & displayManagerAgent)367 ScreenId ScreenManagerAdapter::CreateVirtualScreen(VirtualScreenOption option,
368     const sptr<IDisplayManagerAgent>& displayManagerAgent)
369 {
370     INIT_PROXY_CHECK_RETURN(SCREEN_ID_INVALID);
371 
372     if (displayManagerAgent == nullptr) {
373         TLOGE(WmsLogTag::DMS, "displayManagerAgent is nullptr");
374         return SCREEN_ID_INVALID;
375     }
376 
377     TLOGI(WmsLogTag::DMS, "enter!");
378     if (screenSessionManagerServiceProxy_) {
379         return screenSessionManagerServiceProxy_->CreateVirtualScreen(option, displayManagerAgent->AsObject());
380     }
381 
382     ErrCode errCode;
383     ScreenId screenId = SCREEN_ID_INVALID;
384     DmVirtualScreenOption dmVirtualScreenOption(option);
385     if (option.surface_ && option.surface_->GetProducer()) {
386         errCode = displayManagerServiceProxy_->CreateVirtualScreen(dmVirtualScreenOption,
387             displayManagerAgent->AsObject(), screenId, option.surface_->GetProducer());
388     } else {
389         errCode = displayManagerServiceProxy_->CreateVirtualScreen(dmVirtualScreenOption,
390             displayManagerAgent->AsObject(), screenId);
391     }
392     if (FAILED(errCode)) {
393         TLOGE(WmsLogTag::DMS, "CreateVirtualScreen failed, errCode: %{public}d", errCode);
394         return SCREEN_ID_INVALID;
395     }
396     return screenId;
397 }
398 
DestroyVirtualScreen(ScreenId screenId)399 DMError ScreenManagerAdapter::DestroyVirtualScreen(ScreenId screenId)
400 {
401     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
402 
403     TLOGI(WmsLogTag::DMS, "enter!");
404     if (screenSessionManagerServiceProxy_) {
405         return screenSessionManagerServiceProxy_->DestroyVirtualScreen(screenId);
406     }
407 
408     int32_t dmError;
409     ErrCode errCode = displayManagerServiceProxy_->DestroyVirtualScreen(screenId, dmError);
410     return ConvertToDMError(errCode, dmError);
411 }
412 
SetVirtualScreenSurface(ScreenId screenId,sptr<Surface> surface)413 DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
414 {
415     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
416 
417     if (surface == nullptr) {
418         TLOGE(WmsLogTag::DMS, "Surface is nullptr");
419         return DMError::DM_ERROR_NULLPTR;
420     }
421     TLOGI(WmsLogTag::DMS, "enter!");
422     if (screenSessionManagerServiceProxy_) {
423         return screenSessionManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface->GetProducer());
424     }
425 
426     int32_t dmError;
427     ErrCode errCode = displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface->GetProducer(),
428         dmError);
429     return ConvertToDMError(errCode, dmError);
430 }
431 
AddVirtualScreenBlockList(const std::vector<int32_t> & persistentIds)432 DMError ScreenManagerAdapter::AddVirtualScreenBlockList(const std::vector<int32_t>& persistentIds)
433 {
434     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
435     if (screenSessionManagerServiceProxy_) {
436         return screenSessionManagerServiceProxy_->AddVirtualScreenBlockList(persistentIds);
437     }
438 
439     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
440 }
441 
RemoveVirtualScreenBlockList(const std::vector<int32_t> & persistentIds)442 DMError ScreenManagerAdapter::RemoveVirtualScreenBlockList(const std::vector<int32_t>& persistentIds)
443 {
444     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
445     if (screenSessionManagerServiceProxy_) {
446         return screenSessionManagerServiceProxy_->RemoveVirtualScreenBlockList(persistentIds);
447     }
448 
449     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
450 }
451 
SetScreenPrivacyMaskImage(ScreenId screenId,const std::shared_ptr<Media::PixelMap> & privacyMaskImg)452 DMError ScreenManagerAdapter::SetScreenPrivacyMaskImage(ScreenId screenId,
453     const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
454 {
455     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
456     TLOGI(WmsLogTag::DMS, "enter!");
457     if (screenSessionManagerServiceProxy_) {
458         return screenSessionManagerServiceProxy_->SetScreenPrivacyMaskImage(screenId, privacyMaskImg);
459     }
460 
461     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
462 }
463 
SetVirtualMirrorScreenCanvasRotation(ScreenId screenId,bool canvasRotation)464 DMError ScreenManagerAdapter::SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation)
465 {
466     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
467     TLOGI(WmsLogTag::DMS, "enter!");
468     if (screenSessionManagerServiceProxy_) {
469         return screenSessionManagerServiceProxy_->SetVirtualMirrorScreenCanvasRotation(screenId, canvasRotation);
470     }
471 
472     return DMError::DM_OK;
473 }
474 
SetVirtualMirrorScreenScaleMode(ScreenId screenId,ScreenScaleMode scaleMode)475 DMError ScreenManagerAdapter::SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode)
476 {
477     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
478     TLOGI(WmsLogTag::DMS, "enter!");
479     if (screenSessionManagerServiceProxy_) {
480         return screenSessionManagerServiceProxy_->SetVirtualMirrorScreenScaleMode(screenId, scaleMode);
481     }
482 
483     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
484 }
485 
SetScreenRotationLocked(bool isLocked)486 DMError ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked)
487 {
488     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
489     TLOGI(WmsLogTag::DMS, "enter!");
490     if (screenSessionManagerServiceProxy_) {
491         return screenSessionManagerServiceProxy_->SetScreenRotationLocked(isLocked);
492     }
493 
494     int32_t dmError;
495     ErrCode errCode = displayManagerServiceProxy_->SetScreenRotationLocked(isLocked, dmError);
496     return ConvertToDMError(errCode, dmError);
497 }
498 
SetScreenRotationLockedFromJs(bool isLocked)499 DMError ScreenManagerAdapter::SetScreenRotationLockedFromJs(bool isLocked)
500 {
501     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
502     TLOGI(WmsLogTag::DMS, "enter!");
503     if (screenSessionManagerServiceProxy_) {
504         return screenSessionManagerServiceProxy_->SetScreenRotationLockedFromJs(isLocked);
505     }
506 
507     int32_t dmError;
508     ErrCode errCode = displayManagerServiceProxy_->SetScreenRotationLockedFromJs(isLocked, dmError);
509     return ConvertToDMError(errCode, dmError);
510 }
511 
IsScreenRotationLocked(bool & isLocked)512 DMError ScreenManagerAdapter::IsScreenRotationLocked(bool& isLocked)
513 {
514     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
515     TLOGI(WmsLogTag::DMS, "enter!");
516     if (screenSessionManagerServiceProxy_) {
517         return screenSessionManagerServiceProxy_->IsScreenRotationLocked(isLocked);
518     }
519 
520     int32_t dmError;
521     ErrCode errCode = displayManagerServiceProxy_->IsScreenRotationLocked(isLocked, dmError);
522     return ConvertToDMError(errCode, dmError);
523 }
524 
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)525 bool ScreenManagerAdapter::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
526     PowerStateChangeReason reason)
527 {
528     INIT_PROXY_CHECK_RETURN(false);
529     if (screenSessionManagerServiceProxy_) {
530         return screenSessionManagerServiceProxy_->SetSpecifiedScreenPower(screenId, state, reason);
531     }
532 
533     bool isSucc = false;
534     displayManagerServiceProxy_->SetSpecifiedScreenPower(screenId, static_cast<uint32_t>(state),
535         static_cast<uint32_t>(reason), isSucc);
536     return isSucc;
537 }
538 
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)539 bool ScreenManagerAdapter::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
540 {
541     INIT_PROXY_CHECK_RETURN(false);
542     if (screenSessionManagerServiceProxy_) {
543         return screenSessionManagerServiceProxy_->SetScreenPowerForAll(state, reason);
544     }
545 
546     bool isSucc = false;
547     displayManagerServiceProxy_->SetScreenPowerForAll(static_cast<uint32_t>(state),
548         static_cast<uint32_t>(reason), isSucc);
549     return isSucc;
550 }
551 
GetScreenPower(ScreenId dmsScreenId)552 ScreenPowerState ScreenManagerAdapter::GetScreenPower(ScreenId dmsScreenId)
553 {
554     INIT_PROXY_CHECK_RETURN(ScreenPowerState::INVALID_STATE);
555 
556     if (screenSessionManagerServiceProxy_) {
557         return screenSessionManagerServiceProxy_->GetScreenPower(dmsScreenId);
558     }
559 
560     uint32_t screenPowerState;
561     ErrCode errCode = displayManagerServiceProxy_->GetScreenPower(dmsScreenId, screenPowerState);
562     if (FAILED(errCode)) {
563         TLOGE(WmsLogTag::DMS, "GetScreenPower failed, dmsScreenId: %{public}" PRIu64 ", errCode: %{public}d",
564             dmsScreenId, errCode);
565         return ScreenPowerState::INVALID_STATE;
566     }
567     return static_cast<ScreenPowerState>(screenPowerState);
568 }
569 
GetScreenPower()570 ScreenPowerState ScreenManagerAdapter::GetScreenPower()
571 {
572     INIT_PROXY_CHECK_RETURN(ScreenPowerState::INVALID_STATE);
573     if (screenSessionManagerServiceProxy_) {
574         return screenSessionManagerServiceProxy_->GetScreenPower();
575     }
576 
577     return ScreenPowerState::INVALID_STATE;
578 }
579 
SetOrientation(ScreenId screenId,Orientation orientation)580 DMError ScreenManagerAdapter::SetOrientation(ScreenId screenId, Orientation orientation)
581 {
582     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
583 
584     if (screenSessionManagerServiceProxy_) {
585         return screenSessionManagerServiceProxy_->SetOrientation(screenId, orientation);
586     }
587 
588     int32_t dmError;
589     ErrCode errCode = displayManagerServiceProxy_->SetOrientation(screenId, static_cast<uint32_t>(orientation),
590         dmError);
591     return ConvertToDMError(errCode, dmError);
592 }
593 
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)594 DMError BaseAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
595     DisplayManagerAgentType type)
596 {
597     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
598 
599     if (screenSessionManagerServiceProxy_) {
600         return screenSessionManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
601     }
602 
603     int32_t dmError;
604     ErrCode errCode = displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent,
605         static_cast<uint32_t>(type), dmError);
606     return ConvertToDMError(errCode, dmError);
607 }
608 
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)609 DMError BaseAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
610     DisplayManagerAgentType type)
611 {
612     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
613 
614     if (screenSessionManagerServiceProxy_) {
615         return screenSessionManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
616     }
617 
618     int32_t dmError;
619     ErrCode errCode = displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent,
620         static_cast<uint32_t>(type), dmError);
621     return ConvertToDMError(errCode, dmError);
622 }
623 
WakeUpBegin(PowerStateChangeReason reason)624 bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason)
625 {
626     INIT_PROXY_CHECK_RETURN(false);
627 
628     if (screenSessionManagerServiceProxy_) {
629         return screenSessionManagerServiceProxy_->WakeUpBegin(reason);
630     }
631 
632     bool isSucc = false;
633     displayManagerServiceProxy_->WakeUpBegin(static_cast<uint32_t>(reason), isSucc);
634     return isSucc;
635 }
636 
WakeUpEnd()637 bool DisplayManagerAdapter::WakeUpEnd()
638 {
639     INIT_PROXY_CHECK_RETURN(false);
640 
641     if (screenSessionManagerServiceProxy_) {
642         return screenSessionManagerServiceProxy_->WakeUpEnd();
643     }
644 
645     bool isSucc = false;
646     displayManagerServiceProxy_->WakeUpEnd(isSucc);
647     return isSucc;
648 }
649 
SuspendBegin(PowerStateChangeReason reason)650 bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason)
651 {
652     INIT_PROXY_CHECK_RETURN(false);
653 
654     if (screenSessionManagerServiceProxy_) {
655         return screenSessionManagerServiceProxy_->SuspendBegin(reason);
656     }
657 
658     bool isSucc = false;
659     displayManagerServiceProxy_->SuspendBegin(static_cast<uint32_t>(reason), isSucc);
660     return isSucc;
661 }
662 
SuspendEnd()663 bool DisplayManagerAdapter::SuspendEnd()
664 {
665     INIT_PROXY_CHECK_RETURN(false);
666 
667     if (screenSessionManagerServiceProxy_) {
668         return screenSessionManagerServiceProxy_->SuspendEnd();
669     }
670 
671     bool isSucc = false;
672     displayManagerServiceProxy_->SuspendEnd(isSucc);
673     return isSucc;
674 }
675 
GetInternalScreenId()676 ScreenId DisplayManagerAdapter::GetInternalScreenId()
677 {
678     INIT_PROXY_CHECK_RETURN(false);
679 
680     if (screenSessionManagerServiceProxy_) {
681         return screenSessionManagerServiceProxy_->GetInternalScreenId();
682     }
683 
684     return SCREEN_ID_INVALID;
685 }
686 
SetScreenPowerById(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)687 bool DisplayManagerAdapter::SetScreenPowerById(ScreenId screenId, ScreenPowerState state,
688     PowerStateChangeReason reason)
689 {
690     INIT_PROXY_CHECK_RETURN(false);
691 
692     if (screenSessionManagerServiceProxy_) {
693         return screenSessionManagerServiceProxy_->SetScreenPowerById(screenId, state, reason);
694     }
695 
696     return false;
697 }
698 
SetDisplayState(DisplayState state)699 bool DisplayManagerAdapter::SetDisplayState(DisplayState state)
700 {
701     INIT_PROXY_CHECK_RETURN(false);
702 
703     if (screenSessionManagerServiceProxy_) {
704         return screenSessionManagerServiceProxy_->SetDisplayState(state);
705     }
706 
707     bool isSucc = false;
708     displayManagerServiceProxy_->SetDisplayState(static_cast<uint32_t>(state), isSucc);
709     return isSucc;
710 }
711 
GetDisplayState(DisplayId displayId)712 DisplayState DisplayManagerAdapter::GetDisplayState(DisplayId displayId)
713 {
714     INIT_PROXY_CHECK_RETURN(DisplayState::UNKNOWN);
715 
716     if (screenSessionManagerServiceProxy_) {
717         return screenSessionManagerServiceProxy_->GetDisplayState(displayId);
718     }
719 
720     uint32_t displayState;
721     ErrCode errCode = displayManagerServiceProxy_->GetDisplayState(displayId, displayState);
722     if (FAILED(errCode)) {
723         TLOGE(WmsLogTag::DMS, "GetDisplayState failed, displayId: %{public}" PRIu64 ", errCode: %{public}d",
724             displayId, errCode);
725         return DisplayState::UNKNOWN;
726     }
727     return static_cast<DisplayState>(displayState);
728 }
729 
TryToCancelScreenOff()730 bool DisplayManagerAdapter::TryToCancelScreenOff()
731 {
732     INIT_PROXY_CHECK_RETURN(false);
733 
734     if (screenSessionManagerServiceProxy_) {
735         return screenSessionManagerServiceProxy_->TryToCancelScreenOff();
736     }
737 
738     bool isSucc = false;
739     displayManagerServiceProxy_->TryToCancelScreenOff(isSucc);
740     return isSucc;
741 }
742 
NotifyDisplayEvent(DisplayEvent event)743 void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event)
744 {
745     INIT_PROXY_CHECK_RETURN();
746 
747     if (screenSessionManagerServiceProxy_) {
748         screenSessionManagerServiceProxy_->NotifyDisplayEvent(event);
749     } else {
750         displayManagerServiceProxy_->NotifyDisplayEvent(static_cast<uint32_t>(event));
751     }
752 }
753 
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)754 bool DisplayManagerAdapter::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
755 {
756     INIT_PROXY_CHECK_RETURN(false);
757 
758     if (screenSessionManagerServiceProxy_) {
759         return screenSessionManagerServiceProxy_->SetFreeze(displayIds, isFreeze);
760     }
761 
762     bool isSucc = false;
763     displayManagerServiceProxy_->SetFreeze(displayIds, isFreeze, isSucc);
764     return isSucc;
765 }
766 
InitDMSProxy()767 bool BaseAdapter::InitDMSProxy()
768 {
769     std::lock_guard<std::recursive_mutex> lock(mutex_);
770     if (isProxyValid_) {
771         return true;
772     }
773 
774     sptr<ISystemAbilityManager> systemAbilityManager =
775         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
776     if (!systemAbilityManager) {
777         TLOGE(WmsLogTag::DMS, "Failed to get system ability mgr.");
778         return false;
779     }
780 
781     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID);
782     if (!remoteObject) {
783         TLOGE(WmsLogTag::DMS, "Failed to get display manager service.");
784         return false;
785     }
786 
787     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
788         screenSessionManagerServiceProxy_ = iface_cast<IScreenSessionManager>(remoteObject);
789         if ((!screenSessionManagerServiceProxy_) || (!screenSessionManagerServiceProxy_->AsObject())) {
790             TLOGE(WmsLogTag::DMS, "Failed to get remote object of IScreenSessionManager");
791             return false;
792         }
793     } else {
794         displayManagerServiceProxy_ = iface_cast<IDisplayManager>(remoteObject);
795         if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) {
796             TLOGE(WmsLogTag::DMS, "Failed to get remote object of IDisplayManager");
797             return false;
798         }
799     }
800 
801     dmsDeath_ = new (std::nothrow) DMSDeathRecipient(*this);
802     if (dmsDeath_ == nullptr) {
803         TLOGE(WmsLogTag::DMS, "Failed to create death Recipient ptr DMSDeathRecipient");
804         return false;
805     }
806     if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(dmsDeath_)) {
807         TLOGE(WmsLogTag::DMS, "Failed to add death recipient");
808         return false;
809     }
810 
811     isProxyValid_ = true;
812     return true;
813 }
814 
DMSDeathRecipient(BaseAdapter & adapter)815 DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter)
816 {
817 }
818 
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)819 void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
820 {
821     if (wptrDeath == nullptr) {
822         TLOGE(WmsLogTag::DMS, "wptrDeath is null");
823         return;
824     }
825 
826     sptr<IRemoteObject> object = wptrDeath.promote();
827     if (!object) {
828         TLOGE(WmsLogTag::DMS, "object is null");
829         return;
830     }
831     TLOGI(WmsLogTag::DMS, "dms OnRemoteDied");
832     adapter_.Clear();
833     if (SingletonContainer::IsDestroyed()) {
834         TLOGE(WmsLogTag::DMS, "SingletonContainer is destroyed");
835         return;
836     }
837     SingletonContainer::Get<DisplayManager>().OnRemoteDied();
838     SingletonContainer::Get<ScreenManager>().OnRemoteDied();
839 }
840 
841 
~BaseAdapter()842 BaseAdapter::~BaseAdapter()
843 {
844     TLOGI(WmsLogTag::DMS, "destroy!");
845     std::lock_guard<std::recursive_mutex> lock(mutex_);
846     Clear();
847     screenSessionManagerServiceProxy_ = nullptr;
848     displayManagerServiceProxy_ = nullptr;
849 }
850 
Clear()851 void BaseAdapter::Clear()
852 {
853     TLOGD(WmsLogTag::DMS, "Clear!");
854     std::lock_guard<std::recursive_mutex> lock(mutex_);
855     if ((screenSessionManagerServiceProxy_ != nullptr) && (screenSessionManagerServiceProxy_->AsObject() != nullptr)) {
856         screenSessionManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
857     }
858     if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) {
859         displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
860     }
861     isProxyValid_ = false;
862 }
863 
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)864 DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
865     ScreenId& screenGroupId)
866 {
867     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
868 
869     if (screenSessionManagerServiceProxy_) {
870         return screenSessionManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId);
871     }
872 
873     int32_t dmError;
874     ErrCode errCode = displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId, dmError);
875     return ConvertToDMError(errCode, dmError);
876 }
877 
MakeMirrorForRecord(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,ScreenId & screenGroupId)878 DMError ScreenManagerAdapter::MakeMirrorForRecord(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
879     ScreenId& screenGroupId)
880 {
881     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
882 
883     if (screenSessionManagerServiceProxy_) {
884         return screenSessionManagerServiceProxy_->MakeMirrorForRecord(mainScreenId, mirrorScreenId, screenGroupId);
885     }
886 
887     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
888 }
889 
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenId,DMRect mainScreenRegion,ScreenId & screenGroupId)890 DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
891     DMRect mainScreenRegion, ScreenId& screenGroupId)
892 {
893     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
894 
895     if (screenSessionManagerServiceProxy_) {
896         return screenSessionManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, mainScreenRegion,
897             screenGroupId);
898     }
899 
900     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
901 }
902 
SetMultiScreenMode(ScreenId mainScreenId,ScreenId secondaryScreenId,MultiScreenMode screenMode)903 DMError ScreenManagerAdapter::SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
904     MultiScreenMode screenMode)
905 {
906     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
907 
908     if (screenSessionManagerServiceProxy_) {
909         return screenSessionManagerServiceProxy_->SetMultiScreenMode(mainScreenId, secondaryScreenId, screenMode);
910     }
911 
912     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
913 }
914 
SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,MultiScreenPositionOptions secondScreenOption)915 DMError ScreenManagerAdapter::SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
916     MultiScreenPositionOptions secondScreenOption)
917 {
918     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
919 
920     if (screenSessionManagerServiceProxy_) {
921         return screenSessionManagerServiceProxy_->SetMultiScreenRelativePosition(mainScreenOptions, secondScreenOption);
922     }
923 
924     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
925 }
926 
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)927 DMError ScreenManagerAdapter::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
928 {
929     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
930 
931     if (screenSessionManagerServiceProxy_) {
932         return screenSessionManagerServiceProxy_->StopMirror(mirrorScreenIds);
933     }
934 
935     int32_t dmError;
936     ErrCode errCode = displayManagerServiceProxy_->StopMirror(mirrorScreenIds, dmError);
937     return ConvertToDMError(errCode, dmError);
938 }
939 
DisableMirror(bool disableOrNot)940 DMError ScreenManagerAdapter::DisableMirror(bool disableOrNot)
941 {
942     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
943 
944     if (screenSessionManagerServiceProxy_) {
945         return screenSessionManagerServiceProxy_->DisableMirror(disableOrNot);
946     }
947 
948     return DMError::DM_ERROR_INVALID_PERMISSION;
949 }
950 
GetScreenInfo(ScreenId screenId)951 sptr<ScreenInfo> ScreenManagerAdapter::GetScreenInfo(ScreenId screenId)
952 {
953     if (screenId == SCREEN_ID_INVALID) {
954         TLOGE(WmsLogTag::DMS, "screen id is invalid");
955         return nullptr;
956     }
957     INIT_PROXY_CHECK_RETURN(nullptr);
958 
959     sptr<ScreenInfo> screenInfo;
960     if (screenSessionManagerServiceProxy_) {
961         screenInfo = screenSessionManagerServiceProxy_->GetScreenInfoById(screenId);
962     } else {
963         ErrCode errCode = displayManagerServiceProxy_->GetScreenInfoById(screenId, screenInfo);
964         if (FAILED(errCode) || screenInfo == nullptr) {
965             TLOGE(WmsLogTag::DMS, "GetScreenInfo failed, screenId: %{public}" PRIu64 ", errCode: %{public}d"
966                 ", screenInfo: %{public}s", screenId, errCode, screenInfo == nullptr ? "null" : "not null");
967             return nullptr;
968         }
969     }
970     return screenInfo;
971 }
972 
GetAllDisplayIds()973 std::vector<DisplayId> DisplayManagerAdapter::GetAllDisplayIds()
974 {
975     TLOGD(WmsLogTag::DMS, "DisplayManagerAdapter::GetAllDisplayIds enter");
976     INIT_PROXY_CHECK_RETURN(std::vector<DisplayId>());
977 
978     if (screenSessionManagerServiceProxy_) {
979         return screenSessionManagerServiceProxy_->GetAllDisplayIds();
980     }
981 
982     std::vector<DisplayId> displayIds;
983     displayManagerServiceProxy_->GetAllDisplayIds(displayIds);
984     return displayIds;
985 }
986 
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)987 DMError DisplayManagerAdapter::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
988 {
989     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
990 
991     if (screenSessionManagerServiceProxy_) {
992         return screenSessionManagerServiceProxy_->HasPrivateWindow(displayId, hasPrivateWindow);
993     }
994 
995     int32_t dmError;
996     ErrCode errCode = displayManagerServiceProxy_->HasPrivateWindow(displayId, hasPrivateWindow, dmError);
997     return ConvertToDMError(errCode, dmError);
998 }
999 
ConvertScreenIdToRsScreenId(ScreenId screenId,ScreenId & rsScreenId)1000 bool DisplayManagerAdapter::ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId)
1001 {
1002     INIT_PROXY_CHECK_RETURN(false);
1003 
1004     if (screenSessionManagerServiceProxy_) {
1005         return screenSessionManagerServiceProxy_->ConvertScreenIdToRsScreenId(screenId, rsScreenId);
1006     }
1007 
1008     return false;
1009 }
1010 
HasImmersiveWindow(ScreenId screenId,bool & immersive)1011 DMError DisplayManagerAdapter::HasImmersiveWindow(ScreenId screenId, bool& immersive)
1012 {
1013     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1014 
1015     if (screenSessionManagerServiceProxy_) {
1016         return screenSessionManagerServiceProxy_->HasImmersiveWindow(screenId, immersive);
1017     }
1018 
1019     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1020 }
1021 
GetDisplayInfo(DisplayId displayId)1022 sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
1023 {
1024     TLOGD(WmsLogTag::DMS, "DisplayManagerAdapter::GetDisplayInfo enter, displayId: %{public}" PRIu64, displayId);
1025     if (displayId == DISPLAY_ID_INVALID) {
1026         TLOGE(WmsLogTag::DMS, "screen id is invalid");
1027         return nullptr;
1028     }
1029     INIT_PROXY_CHECK_RETURN(nullptr);
1030 
1031     if (screenSessionManagerServiceProxy_) {
1032         return screenSessionManagerServiceProxy_->GetDisplayInfoById(displayId);
1033     }
1034 
1035     sptr<DisplayInfo> displayInfo;
1036     ErrCode errCode = displayManagerServiceProxy_->GetDisplayInfoById(displayId, displayInfo);
1037     if (FAILED(errCode) || displayInfo == nullptr) {
1038         TLOGE(WmsLogTag::DMS, "GetDisplayInfo failed, displayId: %{public}" PRIu64 ", errCode: %{public}d"
1039             ", displayInfo: %{public}s", displayId, errCode, displayInfo == nullptr ? "null" : "not null");
1040         return nullptr;
1041     }
1042     return displayInfo;
1043 }
1044 
GetVisibleAreaDisplayInfoById(DisplayId displayId)1045 sptr<DisplayInfo> DisplayManagerAdapter::GetVisibleAreaDisplayInfoById(DisplayId displayId)
1046 {
1047     TLOGD(WmsLogTag::DMS, "enter, displayId: %{public}" PRIu64, displayId);
1048     if (displayId == DISPLAY_ID_INVALID) {
1049         TLOGE(WmsLogTag::DMS, "display id is invalid");
1050         return nullptr;
1051     }
1052     INIT_PROXY_CHECK_RETURN(nullptr);
1053 
1054     if (screenSessionManagerServiceProxy_) {
1055         return screenSessionManagerServiceProxy_->GetVisibleAreaDisplayInfoById(displayId);
1056     }
1057 
1058     sptr<DisplayInfo> displayInfo;
1059     ErrCode errCode = displayManagerServiceProxy_->GetVisibleAreaDisplayInfoById(displayId, displayInfo);
1060     if (FAILED(errCode) || displayInfo == nullptr) {
1061         TLOGE(WmsLogTag::DMS, "GetVisibleAreaDisplayInfoById failed, displayId: %{public}" PRIu64 ", errCode: "
1062             "%{public}d, displayInfo: %{public}s", displayId, errCode, displayInfo == nullptr ? "null" : "not null");
1063         return nullptr;
1064     }
1065     return displayInfo;
1066 }
1067 
GetCutoutInfo(DisplayId displayId,int32_t width,int32_t height,Rotation rotation)1068 sptr<CutoutInfo> DisplayManagerAdapter::GetCutoutInfo(DisplayId displayId, int32_t width,
1069                                                       int32_t height, Rotation rotation)
1070 {
1071     TLOGD(WmsLogTag::DMS, "DisplayManagerAdapter::GetCutoutInfo");
1072     if (displayId == DISPLAY_ID_INVALID) {
1073         TLOGE(WmsLogTag::DMS, "display id is invalid");
1074         return nullptr;
1075     }
1076     INIT_PROXY_CHECK_RETURN(nullptr);
1077     if (screenSessionManagerServiceProxy_) {
1078         return screenSessionManagerServiceProxy_->GetCutoutInfo(displayId, width, height, rotation);
1079     }
1080 
1081     sptr<CutoutInfo> cutoutInfo;
1082     ErrCode errCode = displayManagerServiceProxy_->GetCutoutInfo(displayId, cutoutInfo);
1083     if (FAILED(errCode) || cutoutInfo == nullptr) {
1084         TLOGE(WmsLogTag::DMS, "GetCutoutInfo failed, displayId: %{public}" PRIu64 ", errCode: %{public}d"
1085             ", cutoutInfo: %{public}s", displayId, errCode, cutoutInfo == nullptr ? "null" : "not null");
1086         return nullptr;
1087     }
1088     return cutoutInfo;
1089 }
1090 
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)1091 DMError DisplayManagerAdapter::AddSurfaceNodeToDisplay(DisplayId displayId,
1092     std::shared_ptr<class RSSurfaceNode>& surfaceNode)
1093 {
1094     if (displayId == DISPLAY_ID_INVALID) {
1095         TLOGE(WmsLogTag::DMS, "display id is invalid");
1096         return DMError::DM_ERROR_INVALID_PARAM;
1097     }
1098     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1099     if (screenSessionManagerServiceProxy_) {
1100         return screenSessionManagerServiceProxy_->AddSurfaceNodeToDisplay(displayId, surfaceNode);
1101     }
1102 
1103     std::shared_ptr<DmRsSurfaceNode> dmRsSurfaceNode = std::make_shared<DmRsSurfaceNode>(surfaceNode);
1104     int32_t dmError;
1105     ErrCode errCode = displayManagerServiceProxy_->AddSurfaceNodeToDisplay(displayId, dmRsSurfaceNode, dmError);
1106     return ConvertToDMError(errCode, dmError);
1107 }
1108 
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<class RSSurfaceNode> & surfaceNode)1109 DMError DisplayManagerAdapter::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
1110     std::shared_ptr<class RSSurfaceNode>& surfaceNode)
1111 {
1112     if (displayId == DISPLAY_ID_INVALID) {
1113         TLOGE(WmsLogTag::DMS, "display id is invalid");
1114         return DMError::DM_ERROR_INVALID_PARAM;
1115     }
1116     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1117     if (screenSessionManagerServiceProxy_) {
1118         return screenSessionManagerServiceProxy_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
1119     }
1120 
1121     int32_t dmError;
1122     std::shared_ptr<DmRsSurfaceNode> dmRsSurfaceNode = std::make_shared<DmRsSurfaceNode>(surfaceNode);
1123     ErrCode errCode = displayManagerServiceProxy_->RemoveSurfaceNodeFromDisplay(displayId, dmRsSurfaceNode,
1124         dmError);
1125     return ConvertToDMError(errCode, dmError);
1126 }
1127 
IsFoldable()1128 bool DisplayManagerAdapter::IsFoldable()
1129 {
1130     INIT_PROXY_CHECK_RETURN(false);
1131 
1132     if (screenSessionManagerServiceProxy_) {
1133         return screenSessionManagerServiceProxy_->IsFoldable();
1134     }
1135 
1136     return false;
1137 }
1138 
IsCaptured()1139 bool DisplayManagerAdapter::IsCaptured()
1140 {
1141     INIT_PROXY_CHECK_RETURN(false);
1142 
1143     if (screenSessionManagerServiceProxy_) {
1144         return screenSessionManagerServiceProxy_->IsCaptured();
1145     }
1146 
1147     return false;
1148 }
1149 
GetFoldStatus()1150 FoldStatus DisplayManagerAdapter::GetFoldStatus()
1151 {
1152     INIT_PROXY_CHECK_RETURN(FoldStatus::UNKNOWN);
1153 
1154     if (screenSessionManagerServiceProxy_) {
1155         return screenSessionManagerServiceProxy_->GetFoldStatus();
1156     }
1157 
1158     return FoldStatus::UNKNOWN;
1159 }
1160 
GetFoldDisplayMode()1161 FoldDisplayMode DisplayManagerAdapter::GetFoldDisplayMode()
1162 {
1163     INIT_PROXY_CHECK_RETURN(FoldDisplayMode::UNKNOWN);
1164 
1165     if (screenSessionManagerServiceProxy_) {
1166         return screenSessionManagerServiceProxy_->GetFoldDisplayMode();
1167     }
1168 
1169     return FoldDisplayMode::UNKNOWN;
1170 }
1171 
SetFoldDisplayMode(const FoldDisplayMode mode)1172 void DisplayManagerAdapter::SetFoldDisplayMode(const FoldDisplayMode mode)
1173 {
1174     INIT_PROXY_CHECK_RETURN();
1175 
1176     if (screenSessionManagerServiceProxy_) {
1177         screenSessionManagerServiceProxy_->SetFoldDisplayMode(mode);
1178     }
1179 }
1180 
SetFoldDisplayModeAsync(const FoldDisplayMode mode)1181 void DisplayManagerAdapter::SetFoldDisplayModeAsync(const FoldDisplayMode mode)
1182 {
1183     INIT_PROXY_CHECK_RETURN();
1184 
1185     if (screenSessionManagerServiceProxy_) {
1186         screenSessionManagerServiceProxy_->SetFoldDisplayModeAsync(mode);
1187     }
1188 }
1189 
SetFoldDisplayModeFromJs(const FoldDisplayMode mode,std::string reason)1190 DMError DisplayManagerAdapter::SetFoldDisplayModeFromJs(const FoldDisplayMode mode, std::string reason)
1191 {
1192     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1193 
1194     if (screenSessionManagerServiceProxy_) {
1195         return screenSessionManagerServiceProxy_->SetFoldDisplayModeFromJs(mode, reason);
1196     }
1197 
1198     return DMError::DM_OK;
1199 }
1200 
SetDisplayScale(ScreenId screenId,float scaleX,float scaleY,float pivotX,float pivotY)1201 void DisplayManagerAdapter::SetDisplayScale(ScreenId screenId,
1202     float scaleX, float scaleY, float pivotX, float pivotY)
1203 {
1204     INIT_PROXY_CHECK_RETURN();
1205 
1206     if (screenSessionManagerServiceProxy_) {
1207         screenSessionManagerServiceProxy_->SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY);
1208     }
1209 }
1210 
SetFoldStatusLocked(bool locked)1211 void DisplayManagerAdapter::SetFoldStatusLocked(bool locked)
1212 {
1213     INIT_PROXY_CHECK_RETURN();
1214 
1215     if (screenSessionManagerServiceProxy_) {
1216         screenSessionManagerServiceProxy_->SetFoldStatusLocked(locked);
1217     }
1218 }
1219 
SetFoldStatusLockedFromJs(bool locked)1220 DMError DisplayManagerAdapter::SetFoldStatusLockedFromJs(bool locked)
1221 {
1222     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1223 
1224     if (screenSessionManagerServiceProxy_) {
1225         return screenSessionManagerServiceProxy_->SetFoldStatusLockedFromJs(locked);
1226     }
1227 
1228     return DMError::DM_OK;
1229 }
1230 
GetCurrentFoldCreaseRegion()1231 sptr<FoldCreaseRegion> DisplayManagerAdapter::GetCurrentFoldCreaseRegion()
1232 {
1233     INIT_PROXY_CHECK_RETURN(nullptr);
1234 
1235     if (screenSessionManagerServiceProxy_) {
1236         return screenSessionManagerServiceProxy_->GetCurrentFoldCreaseRegion();
1237     }
1238 
1239     return nullptr;
1240 }
1241 
GetLiveCreaseRegion(FoldCreaseRegion & region)1242 DMError DisplayManagerAdapter::GetLiveCreaseRegion(FoldCreaseRegion& region)
1243 {
1244     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1245 
1246     TLOGI(WmsLogTag::DMS, "enter");
1247     if (screenSessionManagerServiceProxy_) {
1248         return screenSessionManagerServiceProxy_->GetLiveCreaseRegion(region);
1249     }
1250     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1251 }
1252 
GetScreenGroupInfoById(ScreenId screenId)1253 sptr<ScreenGroupInfo> ScreenManagerAdapter::GetScreenGroupInfoById(ScreenId screenId)
1254 {
1255     if (screenId == SCREEN_ID_INVALID) {
1256         TLOGE(WmsLogTag::DMS, "screenGroup id is invalid");
1257         return nullptr;
1258     }
1259     INIT_PROXY_CHECK_RETURN(nullptr);
1260 
1261     if (screenSessionManagerServiceProxy_) {
1262         return screenSessionManagerServiceProxy_->GetScreenGroupInfoById(screenId);
1263     }
1264 
1265     sptr<ScreenGroupInfo> screenGroupInfo;
1266     ErrCode errCode = displayManagerServiceProxy_->GetScreenGroupInfoById(screenId, screenGroupInfo);
1267     if (FAILED(errCode) || screenGroupInfo == nullptr) {
1268         TLOGE(WmsLogTag::DMS, "GetScreenGroupInfoById failed, screenId: %{public}" PRIu64 ", errCode: %{public}d, "
1269             "screenGroupInfo: %{public}s", screenId, errCode, screenGroupInfo == nullptr ? "null" : "not null");
1270         return nullptr;
1271     }
1272     return screenGroupInfo;
1273 }
1274 
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)1275 DMError ScreenManagerAdapter::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
1276 {
1277     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1278 
1279     if (screenSessionManagerServiceProxy_) {
1280         return screenSessionManagerServiceProxy_->GetAllScreenInfos(screenInfos);
1281     }
1282 
1283     int32_t dmError;
1284     ErrCode errCode = displayManagerServiceProxy_->GetAllScreenInfos(screenInfos, dmError);
1285     return ConvertToDMError(errCode, dmError);
1286 }
1287 
MakeExpand(std::vector<ScreenId> screenId,std::vector<Point> startPoint,ScreenId & screenGroupId)1288 DMError ScreenManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint,
1289     ScreenId& screenGroupId)
1290 {
1291     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1292 
1293     if (screenSessionManagerServiceProxy_) {
1294         return screenSessionManagerServiceProxy_->MakeExpand(screenId, startPoint, screenGroupId);
1295     }
1296 
1297     int32_t dmError;
1298     ErrCode errCode = displayManagerServiceProxy_->MakeExpand(screenId, startPoint, screenGroupId, dmError);
1299     return ConvertToDMError(errCode, dmError);
1300 }
1301 
StopExpand(const std::vector<ScreenId> & expandScreenIds)1302 DMError ScreenManagerAdapter::StopExpand(const std::vector<ScreenId>& expandScreenIds)
1303 {
1304     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1305 
1306     if (screenSessionManagerServiceProxy_) {
1307         return screenSessionManagerServiceProxy_->StopExpand(expandScreenIds);
1308     }
1309 
1310     int32_t dmError;
1311     ErrCode errCode = displayManagerServiceProxy_->StopExpand(expandScreenIds, dmError);
1312     return ConvertToDMError(errCode, dmError);
1313 }
1314 
1315 
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)1316 void ScreenManagerAdapter::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
1317 {
1318     INIT_PROXY_CHECK_RETURN();
1319 
1320     if (screenSessionManagerServiceProxy_) {
1321         screenSessionManagerServiceProxy_->RemoveVirtualScreenFromGroup(screens);
1322     } else {
1323         displayManagerServiceProxy_->RemoveVirtualScreenFromGroup(screens);
1324     }
1325 }
1326 
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)1327 DMError ScreenManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
1328 {
1329     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1330 
1331     if (screenSessionManagerServiceProxy_) {
1332         return screenSessionManagerServiceProxy_->SetScreenActiveMode(screenId, modeId);
1333     }
1334 
1335     int32_t dmError;
1336     ErrCode errCode = displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId, dmError);
1337     return ConvertToDMError(errCode, dmError);
1338 }
1339 
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)1340 DMError ScreenManagerAdapter::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
1341 {
1342     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1343 
1344     if (screenSessionManagerServiceProxy_) {
1345         return screenSessionManagerServiceProxy_->SetVirtualPixelRatio(screenId, virtualPixelRatio);
1346     }
1347 
1348     int32_t dmError;
1349     ErrCode errCode = displayManagerServiceProxy_->SetVirtualPixelRatio(screenId, virtualPixelRatio, dmError);
1350     return ConvertToDMError(errCode, dmError);
1351 }
1352 
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)1353 DMError ScreenManagerAdapter::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
1354 {
1355     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1356 
1357     if (screenSessionManagerServiceProxy_) {
1358         return screenSessionManagerServiceProxy_->SetVirtualPixelRatioSystem(screenId, virtualPixelRatio);
1359     }
1360 
1361     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1362 }
1363 
SetDefaultDensityDpi(ScreenId screenId,float virtualPixelRatio)1364 DMError ScreenManagerAdapter::SetDefaultDensityDpi(ScreenId screenId, float virtualPixelRatio)
1365 {
1366     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1367 
1368     if (screenSessionManagerServiceProxy_) {
1369         return screenSessionManagerServiceProxy_->SetDefaultDensityDpi(screenId, virtualPixelRatio);
1370     }
1371 
1372     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1373 }
1374 
SetResolution(ScreenId screenId,uint32_t width,uint32_t height,float virtualPixelRatio)1375 DMError ScreenManagerAdapter::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio)
1376 {
1377     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1378 
1379     if (screenSessionManagerServiceProxy_) {
1380         return screenSessionManagerServiceProxy_->SetResolution(screenId, width, height, virtualPixelRatio);
1381     }
1382 
1383     int32_t dmError;
1384     ErrCode errCode = displayManagerServiceProxy_->SetResolution(screenId, width, height, virtualPixelRatio, dmError);
1385     return ConvertToDMError(errCode, dmError);
1386 }
1387 
GetDensityInCurResolution(ScreenId screenId,float & virtualPixelRatio)1388 DMError ScreenManagerAdapter::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio)
1389 {
1390     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1391 
1392     if (screenSessionManagerServiceProxy_) {
1393         return screenSessionManagerServiceProxy_->GetDensityInCurResolution(screenId, virtualPixelRatio);
1394     }
1395 
1396     int32_t dmError;
1397     ErrCode errCode = displayManagerServiceProxy_->GetDensityInCurResolution(screenId, virtualPixelRatio, dmError);
1398     return ConvertToDMError(errCode, dmError);
1399 }
1400 
ResizeVirtualScreen(ScreenId screenId,uint32_t width,uint32_t height)1401 DMError ScreenManagerAdapter::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
1402 {
1403     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1404 
1405     if (screenSessionManagerServiceProxy_) {
1406         return screenSessionManagerServiceProxy_->ResizeVirtualScreen(screenId, width, height);
1407     }
1408 
1409     return DMError::DM_OK;
1410 }
1411 
MakeUniqueScreen(const std::vector<ScreenId> & screenIds,std::vector<DisplayId> & displayIds)1412 DMError ScreenManagerAdapter::MakeUniqueScreen(const std::vector<ScreenId>& screenIds,
1413     std::vector<DisplayId>& displayIds)
1414 {
1415     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1416 
1417     if (screenSessionManagerServiceProxy_) {
1418         return screenSessionManagerServiceProxy_->MakeUniqueScreen(screenIds, displayIds);
1419     }
1420 
1421     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1422 }
1423 
GetAvailableArea(DisplayId displayId,DMRect & area)1424 DMError DisplayManagerAdapter::GetAvailableArea(DisplayId displayId, DMRect& area)
1425 {
1426     if (displayId == DISPLAY_ID_INVALID) {
1427         TLOGE(WmsLogTag::DMS, "display id is invalid");
1428         return DMError::DM_ERROR_INVALID_PARAM;
1429     }
1430     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1431 
1432     if (screenSessionManagerServiceProxy_) {
1433         return screenSessionManagerServiceProxy_->GetAvailableArea(displayId, area);
1434     }
1435 
1436     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1437 }
1438 
GetExpandAvailableArea(DisplayId displayId,DMRect & area)1439 DMError DisplayManagerAdapter::GetExpandAvailableArea(DisplayId displayId, DMRect& area)
1440 {
1441     if (displayId == DISPLAY_ID_INVALID) {
1442         TLOGE(WmsLogTag::DMS, "display id is invalid");
1443         return DMError::DM_ERROR_INVALID_PARAM;
1444     }
1445     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1446 
1447     if (screenSessionManagerServiceProxy_) {
1448         return screenSessionManagerServiceProxy_->GetExpandAvailableArea(displayId, area);
1449     }
1450 
1451     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1452 }
1453 
GetVirtualScreenFlag(ScreenId screenId)1454 VirtualScreenFlag ScreenManagerAdapter::GetVirtualScreenFlag(ScreenId screenId)
1455 {
1456     INIT_PROXY_CHECK_RETURN(VirtualScreenFlag::DEFAULT);
1457     if (screenId == SCREEN_ID_INVALID) {
1458         TLOGE(WmsLogTag::DMS, "screenId invalid");
1459         return VirtualScreenFlag::DEFAULT;
1460     }
1461 
1462     if (screenSessionManagerServiceProxy_) {
1463         return screenSessionManagerServiceProxy_->GetVirtualScreenFlag(screenId);
1464     }
1465 
1466     return VirtualScreenFlag::DEFAULT;
1467 }
1468 
SetVirtualScreenFlag(ScreenId screenId,VirtualScreenFlag screenFlag)1469 DMError ScreenManagerAdapter::SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag)
1470 {
1471     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1472     if (screenId == SCREEN_ID_INVALID) {
1473         TLOGE(WmsLogTag::DMS, "screen id is invalid");
1474         return DMError::DM_ERROR_INVALID_PARAM;
1475     }
1476     if (screenFlag < VirtualScreenFlag::DEFAULT || screenFlag >= VirtualScreenFlag::MAX) {
1477         return DMError::DM_ERROR_INVALID_PARAM;
1478     }
1479     if (screenSessionManagerServiceProxy_) {
1480         return screenSessionManagerServiceProxy_->SetVirtualScreenFlag(screenId, screenFlag);
1481     }
1482 
1483     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1484 }
1485 
SetVirtualScreenRefreshRate(ScreenId screenId,uint32_t refreshInterval)1486 DMError ScreenManagerAdapter::SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval)
1487 {
1488     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1489 
1490     if (screenSessionManagerServiceProxy_) {
1491         return screenSessionManagerServiceProxy_->SetVirtualScreenRefreshRate(screenId, refreshInterval);
1492     }
1493 
1494     return DMError::DM_OK;
1495 }
1496 
SetVirtualScreenBlackList(ScreenId screenId,std::vector<uint64_t> & windowIdList,std::vector<uint64_t> surfaceIdList,std::vector<uint8_t> typeBlackList)1497 void DisplayManagerAdapter::SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList,
1498     std::vector<uint64_t> surfaceIdList, std::vector<uint8_t> typeBlackList)
1499 {
1500     INIT_PROXY_CHECK_RETURN();
1501     if (screenSessionManagerServiceProxy_) {
1502         screenSessionManagerServiceProxy_->SetVirtualScreenBlackList(screenId, windowIdList, surfaceIdList,
1503             typeBlackList);
1504     }
1505 }
1506 
SetVirtualDisplayMuteFlag(ScreenId screenId,bool muteFlag)1507 void DisplayManagerAdapter::SetVirtualDisplayMuteFlag(ScreenId screenId, bool muteFlag)
1508 {
1509     INIT_PROXY_CHECK_RETURN();
1510     if (screenSessionManagerServiceProxy_) {
1511         screenSessionManagerServiceProxy_->SetVirtualDisplayMuteFlag(screenId, muteFlag);
1512     }
1513 }
1514 
DisablePowerOffRenderControl(ScreenId screenId)1515 void DisplayManagerAdapter::DisablePowerOffRenderControl(ScreenId screenId)
1516 {
1517     INIT_PROXY_CHECK_RETURN();
1518     if (screenSessionManagerServiceProxy_) {
1519         screenSessionManagerServiceProxy_->DisablePowerOffRenderControl(screenId);
1520     }
1521 }
1522 
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)1523 DMError DisplayManagerAdapter::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
1524 {
1525     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1526     if (screenSessionManagerServiceProxy_) {
1527         return screenSessionManagerServiceProxy_->ProxyForFreeze(pidList, isProxy);
1528     }
1529 
1530     return DMError::DM_OK;
1531 }
1532 
ResetAllFreezeStatus()1533 DMError DisplayManagerAdapter::ResetAllFreezeStatus()
1534 {
1535     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1536     if (screenSessionManagerServiceProxy_) {
1537         return screenSessionManagerServiceProxy_->ResetAllFreezeStatus();
1538     }
1539 
1540     return DMError::DM_OK;
1541 }
1542 
GetAllDisplayPhysicalResolution()1543 std::vector<DisplayPhysicalResolution> DisplayManagerAdapter::GetAllDisplayPhysicalResolution()
1544 {
1545     INIT_PROXY_CHECK_RETURN(std::vector<DisplayPhysicalResolution>{});
1546     if (screenSessionManagerServiceProxy_) {
1547         return screenSessionManagerServiceProxy_->GetAllDisplayPhysicalResolution();
1548     }
1549 
1550     std::vector<DisplayPhysicalResolution> displayPhysicalResolutions;
1551     displayManagerServiceProxy_->GetAllDisplayPhysicalResolution(displayPhysicalResolutions);
1552     return displayPhysicalResolutions;
1553 }
1554 
GetDisplayCapability(std::string & capabilitInfo)1555 DMError DisplayManagerAdapter::GetDisplayCapability(std::string& capabilitInfo)
1556 {
1557     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1558     if (screenSessionManagerServiceProxy_) {
1559         return screenSessionManagerServiceProxy_->GetDisplayCapability(capabilitInfo);
1560     }
1561 
1562     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1563 }
1564 
SetVirtualScreenSecurityExemption(ScreenId screenId,uint32_t pid,std::vector<uint64_t> & windowIdList)1565 DMError DisplayManagerAdapter::SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid,
1566     std::vector<uint64_t>& windowIdList)
1567 {
1568     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1569     if (screenSessionManagerServiceProxy_) {
1570         return screenSessionManagerServiceProxy_->SetVirtualScreenSecurityExemption(screenId, pid, windowIdList);
1571     }
1572 
1573     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1574 }
1575 
SetVirtualScreenMaxRefreshRate(ScreenId id,uint32_t refreshRate,uint32_t & actualRefreshRate)1576 DMError ScreenManagerAdapter::SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate,
1577     uint32_t& actualRefreshRate)
1578 {
1579     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1580     if (screenSessionManagerServiceProxy_) {
1581         return screenSessionManagerServiceProxy_->SetVirtualScreenMaxRefreshRate(id, refreshRate, actualRefreshRate);
1582     }
1583 
1584     return DMError::DM_OK;
1585 }
1586 
SetVirtualScreenStatus(ScreenId screenId,VirtualScreenStatus screenStatus)1587 bool ScreenManagerAdapter::SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus)
1588 {
1589     INIT_PROXY_CHECK_RETURN(false);
1590     if (screenSessionManagerServiceProxy_) {
1591         return screenSessionManagerServiceProxy_->SetVirtualScreenStatus(screenId, screenStatus);
1592     }
1593 
1594     return false;
1595 }
1596 
GetScreenCapture(const CaptureOption & captureOption,DmErrorCode * errorCode)1597 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetScreenCapture(const CaptureOption& captureOption,
1598     DmErrorCode* errorCode)
1599 {
1600     INIT_PROXY_CHECK_RETURN(nullptr);
1601     if (screenSessionManagerServiceProxy_) {
1602         return screenSessionManagerServiceProxy_->GetScreenCapture(captureOption, errorCode);
1603     }
1604 
1605     if (errorCode != nullptr) {
1606         *errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
1607     }
1608     return nullptr;
1609 }
1610 
GetPrimaryDisplayInfo()1611 sptr<DisplayInfo> DisplayManagerAdapter::GetPrimaryDisplayInfo()
1612 {
1613     INIT_PROXY_CHECK_RETURN(nullptr);
1614     if (screenSessionManagerServiceProxy_) {
1615         return screenSessionManagerServiceProxy_->GetPrimaryDisplayInfo();
1616     }
1617 
1618     sptr<DisplayInfo> displayInfo;
1619     ErrCode errCode = displayManagerServiceProxy_->GetDefaultDisplayInfo(displayInfo);
1620     if (FAILED(errCode) || displayInfo == nullptr) {
1621         TLOGE(WmsLogTag::DMS, "GetPrimaryDisplayInfo failed, errCode: %{public}d, displayInfo: %{public}s",
1622             errCode, displayInfo == nullptr ? "null" : "not null");
1623         return nullptr;
1624     }
1625     return displayInfo;
1626 }
1627 
GetDisplaySnapshotWithOption(const CaptureOption & captureOption,DmErrorCode * errorCode)1628 std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshotWithOption(const CaptureOption& captureOption,
1629     DmErrorCode* errorCode)
1630 {
1631     INIT_PROXY_CHECK_RETURN(nullptr);
1632     if (screenSessionManagerServiceProxy_) {
1633         return screenSessionManagerServiceProxy_->GetDisplaySnapshotWithOption(captureOption, errorCode);
1634     }
1635 
1636     if (errorCode != nullptr) {
1637         *errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
1638     }
1639     return nullptr;
1640 }
1641 
GetDisplayHDRSnapshotWithOption(const CaptureOption & captureOption,DmErrorCode & errorCode)1642 std::vector<std::shared_ptr<Media::PixelMap>> DisplayManagerAdapter::GetDisplayHDRSnapshotWithOption(
1643     const CaptureOption& captureOption, DmErrorCode& errorCode)
1644 {
1645     std::vector<std::shared_ptr<Media::PixelMap>> ret = { nullptr, nullptr };
1646     INIT_PROXY_CHECK_RETURN(ret);
1647     if (screenSessionManagerServiceProxy_) {
1648         return screenSessionManagerServiceProxy_->GetDisplayHDRSnapshotWithOption(captureOption, errorCode);
1649     }
1650     errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
1651     return ret;
1652 }
1653 
SetFoldStatusExpandAndLocked(bool locked)1654 void ScreenManagerAdapter::SetFoldStatusExpandAndLocked(bool locked)
1655 {
1656     INIT_PROXY_CHECK_RETURN();
1657     if (screenSessionManagerServiceProxy_) {
1658         return screenSessionManagerServiceProxy_->SetFoldStatusExpandAndLocked(locked);
1659     }
1660 }
1661 
SetScreenSkipProtectedWindow(const std::vector<ScreenId> & screenIds,bool isEnable)1662 DMError ScreenManagerAdapter::SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable)
1663 {
1664     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1665     if (screenSessionManagerServiceProxy_) {
1666         return screenSessionManagerServiceProxy_->SetScreenSkipProtectedWindow(screenIds, isEnable);
1667     }
1668 
1669     return DMError::DM_OK;
1670 }
1671 
GetScreenAreaOfDisplayArea(DisplayId displayId,const DMRect & displayArea,ScreenId & screenId,DMRect & screenArea)1672 DMError DisplayManagerAdapter::GetScreenAreaOfDisplayArea(DisplayId displayId, const DMRect& displayArea,
1673     ScreenId& screenId, DMRect& screenArea)
1674 {
1675     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1676     if (screenSessionManagerServiceProxy_) {
1677         return screenSessionManagerServiceProxy_->GetScreenAreaOfDisplayArea(
1678             displayId, displayArea, screenId, screenArea);
1679     }
1680     return DMError::DM_OK;
1681 }
1682 
SetVirtualScreenAutoRotation(ScreenId screenId,bool enable)1683 DMError ScreenManagerAdapter::SetVirtualScreenAutoRotation(ScreenId screenId, bool enable)
1684 {
1685     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1686 
1687     TLOGI(WmsLogTag::DMS, "enter!");
1688     if (screenSessionManagerServiceProxy_) {
1689         return screenSessionManagerServiceProxy_->SetVirtualScreenAutoRotation(screenId, enable);
1690     }
1691     return DMError::DM_OK;
1692 }
1693 
SetScreenPrivacyWindowTagSwitch(ScreenId screenId,const std::vector<std::string> & privacyWindowTag,bool enable)1694 DMError ScreenManagerAdapter::SetScreenPrivacyWindowTagSwitch(ScreenId screenId,
1695     const std::vector<std::string>& privacyWindowTag, bool enable)
1696 {
1697     INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
1698     if (screenSessionManagerServiceProxy_) {
1699         return screenSessionManagerServiceProxy_->SetScreenPrivacyWindowTagSwitch(screenId, privacyWindowTag, enable);
1700     }
1701     return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
1702 }
1703 } // namespace OHOS::Rosen
1704