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_service.h"
17
18 #include <hitrace_meter.h>
19 #include <ipc_skeleton.h>
20 #include <iservice_registry.h>
21 #include <system_ability_definition.h>
22
23 #include "display_manager_agent_controller.h"
24 #include "display_manager_config.h"
25 #include "dm_common.h"
26 #include "parameters.h"
27 #include "permission.h"
28 #include "sensor_connector.h"
29 #include "transaction/rs_interfaces.h"
30 #include "window_manager_hilog.h"
31
32 namespace OHOS::Rosen {
33 namespace {
34 const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN";
35 const std::string ACCESS_VIRTUAL_SCREEN_PERMISSION = "ohos.permission.ACCESS_VIRTUAL_SCREEN";
36 }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)37 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)
38
39 #define CHECK_SCREEN_AND_RETURN(screenId, ret) \
40 do { \
41 if ((screenId) == SCREEN_ID_INVALID) { \
42 TLOGE(WmsLogTag::DMS, "screenId invalid"); \
43 return ret; \
44 } \
45 } while (false)
46
47 DisplayManagerService::DisplayManagerService()
48 : abstractDisplayController_(new AbstractDisplayController(mutex_,
49 std::bind(&DisplayManagerService::NotifyDisplayStateChange, this,
50 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))),
51 abstractScreenController_(new AbstractScreenController(mutex_)),
52 displayPowerController_(new DisplayPowerController(mutex_,
53 std::bind(&DisplayManagerService::NotifyDisplayStateChange, this,
54 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))),
55 displayCutoutController_(new DisplayCutoutController()),
56 isAutoRotationOpen_(OHOS::system::GetParameter(
57 "persist.display.ar.enabled", "1") == "1") // autoRotation default enabled
58 {
59 }
60
Dump(int fd,const std::vector<std::u16string> & args)61 int DisplayManagerService::Dump(int fd, const std::vector<std::u16string>& args)
62 {
63 if (displayDumper_ == nullptr) {
64 displayDumper_ = new DisplayDumper(abstractDisplayController_, abstractScreenController_, mutex_);
65 }
66 return static_cast<int>(displayDumper_->Dump(fd, args));
67 }
68
Init()69 bool DisplayManagerService::Init()
70 {
71 TLOGI(WmsLogTag::DMS, "DisplayManagerService::Init start");
72 if (DisplayManagerConfig::LoadConfigXml()) {
73 DisplayManagerConfig::DumpConfig();
74 ConfigureDisplayManagerService();
75 }
76 abstractScreenController_->Init();
77 abstractDisplayController_->Init(abstractScreenController_);
78 TLOGI(WmsLogTag::DMS, "DisplayManagerService::Init success");
79 return true;
80 }
81
ConfigureDisplayManagerService()82 void DisplayManagerService::ConfigureDisplayManagerService()
83 {
84 auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig();
85 auto enableConfig = DisplayManagerConfig::GetEnableConfig();
86 auto stringConfig = DisplayManagerConfig::GetStringConfig();
87 if (numbersConfig.count("defaultDeviceRotationOffset") != 0) {
88 uint32_t defaultDeviceRotationOffset = static_cast<uint32_t>(numbersConfig["defaultDeviceRotationOffset"][0]);
89 ScreenRotationController::SetDefaultDeviceRotationOffset(defaultDeviceRotationOffset);
90 }
91 if (enableConfig.count("isWaterfallDisplay") != 0) {
92 displayCutoutController_->SetIsWaterfallDisplay(
93 static_cast<bool>(enableConfig["isWaterfallDisplay"]));
94 }
95 if (numbersConfig.count("curvedScreenBoundary") != 0) {
96 displayCutoutController_->SetCurvedScreenBoundary(
97 static_cast<std::vector<int>>(numbersConfig["curvedScreenBoundary"]));
98 }
99 if (stringConfig.count("defaultDisplayCutoutPath") != 0) {
100 displayCutoutController_->SetBuiltInDisplayCutoutSvgPath(
101 static_cast<std::string>(stringConfig["defaultDisplayCutoutPath"]));
102 }
103 ConfigureWaterfallDisplayCompressionParams();
104 if (numbersConfig.count("buildInDefaultOrientation") != 0) {
105 Orientation orientation = static_cast<Orientation>(numbersConfig["buildInDefaultOrientation"][0]);
106 abstractScreenController_->SetBuildInDefaultOrientation(orientation);
107 }
108 }
109
ConfigureWaterfallDisplayCompressionParams()110 void DisplayManagerService::ConfigureWaterfallDisplayCompressionParams()
111 {
112 auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig();
113 auto enableConfig = DisplayManagerConfig::GetEnableConfig();
114 if (enableConfig.count("isWaterfallAreaCompressionEnableWhenHorizontal") != 0) {
115 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(
116 static_cast<bool>(enableConfig["isWaterfallAreaCompressionEnableWhenHorizontal"]));
117 }
118 if (numbersConfig.count("waterfallAreaCompressionSizeWhenHorzontal") != 0) {
119 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(
120 static_cast<uint32_t>(numbersConfig["waterfallAreaCompressionSizeWhenHorzontal"][0]));
121 }
122 }
123
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)124 void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
125 {
126 displayChangeListener_ = listener;
127 TLOGD(WmsLogTag::DMS, "IDisplayChangeListener registered");
128 }
129
RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener> & listener)130 void DisplayManagerService::RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener)
131 {
132 windowInfoQueriedListener_ = listener;
133 }
134
HasPrivateWindow(DisplayId displayId,bool & hasPrivateWindow)135 DMError DisplayManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
136 {
137 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
138 TLOGE(WmsLogTag::DMS, "check has private window permission denied!");
139 return DMError::DM_ERROR_NOT_SYSTEM_APP;
140 }
141 std::vector<DisplayId> displayIds = GetAllDisplayIds();
142 auto iter = std::find(displayIds.begin(), displayIds.end(), displayId);
143 if (iter == displayIds.end()) {
144 TLOGE(WmsLogTag::DMS, "invalid displayId");
145 return DMError::DM_ERROR_INVALID_PARAM;
146 }
147 if (windowInfoQueriedListener_ != nullptr) {
148 windowInfoQueriedListener_->HasPrivateWindow(displayId, hasPrivateWindow);
149 return DMError::DM_OK;
150 }
151 return DMError::DM_ERROR_NULLPTR;
152 }
153
NotifyDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)154 void DisplayManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
155 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
156 {
157 DisplayId id = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId();
158 TLOGD(WmsLogTag::DMS, "DisplayId %{public}" PRIu64, id);
159 if (displayChangeListener_ != nullptr) {
160 displayChangeListener_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type);
161 }
162 }
163
NotifyScreenshot(DisplayId displayId)164 void DisplayManagerService::NotifyScreenshot(DisplayId displayId)
165 {
166 if (displayChangeListener_ != nullptr) {
167 displayChangeListener_->OnScreenshot(displayId);
168 }
169 }
170
GetDefaultDisplayInfo()171 sptr<DisplayInfo> DisplayManagerService::GetDefaultDisplayInfo()
172 {
173 ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
174 TLOGD(WmsLogTag::DMS, "GetDefaultDisplayInfo %{public}" PRIu64, dmsScreenId);
175 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(dmsScreenId);
176 if (display == nullptr) {
177 TLOGE(WmsLogTag::DMS, "fail to get displayInfo by id: invalid display");
178 return nullptr;
179 }
180 return display->ConvertToDisplayInfo();
181 }
182
GetDisplayInfoById(DisplayId displayId)183 sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
184 {
185 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplay(displayId);
186 if (display == nullptr) {
187 TLOGI(WmsLogTag::DMS, "fail to get displayInfo by id: %{public}" PRIu64 " invalid display", displayId);
188 sptr<DisplayInfo> displayInfo = GetDisplayInfoByScreenId(displayId);
189 if (displayInfo != nullptr) {
190 return displayInfo;
191 }
192 TLOGW(WmsLogTag::DMS, "fail to get displayInfo by screen id: %{public}" PRIu64 " invalid screen", displayId);
193 return nullptr;
194 }
195 return display->ConvertToDisplayInfo();
196 }
197
GetVisibleAreaDisplayInfoById(DisplayId displayId)198 sptr<DisplayInfo> DisplayManagerService::GetVisibleAreaDisplayInfoById(DisplayId displayId)
199 {
200 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplay(displayId);
201 if (display == nullptr) {
202 TLOGE(WmsLogTag::DMS, "fail to get displayInfo by id: invalid display");
203 return nullptr;
204 }
205 return display->ConvertToDisplayInfo();
206 }
207
GetDisplayInfoByScreen(ScreenId screenId)208 sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoByScreen(ScreenId screenId)
209 {
210 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(screenId);
211 if (display == nullptr) {
212 TLOGE(WmsLogTag::DMS, "fail to get displayInfo by screenId: invalid display");
213 return nullptr;
214 }
215 return display->ConvertToDisplayInfo();
216 }
217
CreateVirtualScreen(VirtualScreenOption option,const sptr<IRemoteObject> & displayManagerAgent)218 ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option,
219 const sptr<IRemoteObject>& displayManagerAgent)
220 {
221 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd() &&
222 !Permission::CheckCallingPermission(ACCESS_VIRTUAL_SCREEN_PERMISSION)) {
223 return ERROR_ID_NOT_SYSTEM_APP;
224 }
225 if (displayManagerAgent == nullptr) {
226 TLOGE(WmsLogTag::DMS, "displayManagerAgent invalid");
227 return SCREEN_ID_INVALID;
228 }
229 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:CreateVirtualScreen(%s)", option.name_.c_str());
230 if (option.surface_ != nullptr && !Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION) &&
231 !Permission::IsStartByHdcd() && !Permission::CheckCallingPermission(ACCESS_VIRTUAL_SCREEN_PERMISSION)) {
232 TLOGE(WmsLogTag::DMS, "permission denied");
233 return SCREEN_ID_INVALID;
234 }
235 ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option, displayManagerAgent);
236 CHECK_SCREEN_AND_RETURN(screenId, SCREEN_ID_INVALID);
237 accessTokenIdMaps_.insert(std::pair(screenId, IPCSkeleton::GetCallingTokenID()));
238 return screenId;
239 }
240
DestroyVirtualScreen(ScreenId screenId)241 DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId)
242 {
243 bool isCallingByThirdParty = Permission::CheckCallingPermission(ACCESS_VIRTUAL_SCREEN_PERMISSION);
244 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd() &&
245 !isCallingByThirdParty) {
246 TLOGE(WmsLogTag::DMS, "destroy virtual screen permission denied!");
247 return DMError::DM_ERROR_NOT_SYSTEM_APP;
248 }
249 if (!accessTokenIdMaps_.isExistAndRemove(screenId, IPCSkeleton::GetCallingTokenID())) {
250 if (isCallingByThirdParty) {
251 return DMError::DM_ERROR_NULLPTR;
252 }
253 return DMError::DM_ERROR_INVALID_CALLING;
254 }
255
256 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
257 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
258
259 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:DestroyVirtualScreen(%" PRIu64 ")", screenId);
260 return abstractScreenController_->DestroyVirtualScreen(screenId);
261 }
262
SetVirtualScreenSurface(ScreenId screenId,sptr<IBufferProducer> surface)263 DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface)
264 {
265 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
266 bool isCallingByThirdParty = Permission::CheckCallingPermission(ACCESS_VIRTUAL_SCREEN_PERMISSION);
267 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
268 if (Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION) ||
269 Permission::IsStartByHdcd() || isCallingByThirdParty) {
270 sptr<Surface> pPurface = Surface::CreateSurfaceAsProducer(surface);
271 return abstractScreenController_->SetVirtualScreenSurface(screenId, pPurface);
272 }
273 TLOGE(WmsLogTag::DMS, "permission denied");
274 if (isCallingByThirdParty) {
275 return DMError::DM_ERROR_NULLPTR;
276 }
277 return DMError::DM_ERROR_INVALID_CALLING;
278 }
279
SetOrientation(ScreenId screenId,Orientation orientation)280 DMError DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
281 {
282 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
283 TLOGE(WmsLogTag::DMS, "set orientation permission denied!");
284 return DMError::DM_ERROR_NOT_SYSTEM_APP;
285 }
286 if (orientation < Orientation::UNSPECIFIED || orientation > Orientation::REVERSE_HORIZONTAL) {
287 TLOGE(WmsLogTag::DMS, "orientation: %{public}u", static_cast<uint32_t>(orientation));
288 return DMError::DM_ERROR_INVALID_PARAM;
289 }
290 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetOrientation(%" PRIu64 ")", screenId);
291 return abstractScreenController_->SetOrientation(screenId, orientation, false);
292 }
293
SetOrientationFromWindow(ScreenId screenId,Orientation orientation,bool withAnimation)294 DMError DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation, bool withAnimation)
295 {
296 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetOrientationFromWindow(%" PRIu64 ")", screenId);
297 return abstractScreenController_->SetOrientation(screenId, orientation, true, withAnimation);
298 }
299
SetRotationFromWindow(ScreenId screenId,Rotation targetRotation,bool withAnimation)300 bool DisplayManagerService::SetRotationFromWindow(ScreenId screenId, Rotation targetRotation, bool withAnimation)
301 {
302 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetRotationFromWindow(%" PRIu64 ")", screenId);
303 return abstractScreenController_->SetRotation(screenId, targetRotation, true, withAnimation);
304 }
305
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode,bool isUseDma,bool isCaptureFullOfScreen)306 std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDisplaySnapshot(DisplayId displayId,
307 DmErrorCode* errorCode, bool isUseDma, bool isCaptureFullOfScreen)
308 {
309 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:GetDisplaySnapshot(%" PRIu64 ")", displayId);
310 if ((Permission::IsSystemCalling() && Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION)) ||
311 Permission::IsStartByHdcd()) {
312 auto res = abstractDisplayController_->GetScreenSnapshot(displayId);
313 if (res != nullptr) {
314 NotifyScreenshot(displayId);
315 }
316 return res;
317 } else if (errorCode) {
318 *errorCode = DmErrorCode::DM_ERROR_NO_PERMISSION;
319 }
320 return nullptr;
321 }
322
GetScreenSupportedColorGamuts(ScreenId screenId,std::vector<ScreenColorGamut> & colorGamuts)323 DMError DisplayManagerService::GetScreenSupportedColorGamuts(ScreenId screenId,
324 std::vector<ScreenColorGamut>& colorGamuts)
325 {
326 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
327 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
328 return abstractScreenController_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
329 }
330
GetScreenColorGamut(ScreenId screenId,ScreenColorGamut & colorGamut)331 DMError DisplayManagerService::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
332 {
333 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
334 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
335 return abstractScreenController_->GetScreenColorGamut(screenId, colorGamut);
336 }
337
SetScreenColorGamut(ScreenId screenId,int32_t colorGamutIdx)338 DMError DisplayManagerService::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
339 {
340 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64 ", colorGamutIdx %{public}d", screenId,
341 colorGamutIdx);
342 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
343 return abstractScreenController_->SetScreenColorGamut(screenId, colorGamutIdx);
344 }
345
GetScreenGamutMap(ScreenId screenId,ScreenGamutMap & gamutMap)346 DMError DisplayManagerService::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
347 {
348 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
349 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
350 return abstractScreenController_->GetScreenGamutMap(screenId, gamutMap);
351 }
352
SetScreenGamutMap(ScreenId screenId,ScreenGamutMap gamutMap)353 DMError DisplayManagerService::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
354 {
355 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64 ", ScreenGamutMap %{public}u",
356 screenId, static_cast<uint32_t>(gamutMap));
357 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
358 return abstractScreenController_->SetScreenGamutMap(screenId, gamutMap);
359 }
360
SetScreenColorTransform(ScreenId screenId)361 DMError DisplayManagerService::SetScreenColorTransform(ScreenId screenId)
362 {
363 TLOGI(WmsLogTag::DMS, "ScreenId: %{public}" PRIu64, screenId);
364 CHECK_SCREEN_AND_RETURN(screenId, DMError::DM_ERROR_INVALID_PARAM);
365 return abstractScreenController_->SetScreenColorTransform(screenId);
366 }
367
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)368 DMError DisplayManagerService::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
369 DisplayManagerAgentType type)
370 {
371 if (type == DisplayManagerAgentType::SCREEN_EVENT_LISTENER && !Permission::IsSystemCalling()
372 && !Permission::IsStartByHdcd()) {
373 TLOGE(WmsLogTag::DMS, "register display manager agent permission denied!");
374 return DMError::DM_ERROR_NOT_SYSTEM_APP;
375 }
376 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
377 TLOGE(WmsLogTag::DMS, "displayManagerAgent invalid");
378 return DMError::DM_ERROR_NULLPTR;
379 }
380 return DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type);
381 }
382
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)383 DMError DisplayManagerService::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
384 DisplayManagerAgentType type)
385 {
386 if (type == DisplayManagerAgentType::SCREEN_EVENT_LISTENER && !Permission::IsSystemCalling()
387 && !Permission::IsStartByHdcd()) {
388 TLOGE(WmsLogTag::DMS, "unregister display manager agent permission denied!");
389 return DMError::DM_ERROR_NOT_SYSTEM_APP;
390 }
391 if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
392 TLOGE(WmsLogTag::DMS, "displayManagerAgent invalid");
393 return DMError::DM_ERROR_NULLPTR;
394 }
395 return DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type);
396 }
397
WakeUpBegin(PowerStateChangeReason reason)398 bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason)
399 {
400 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "[UL_POWER]dms:WakeUpBegin(%u)", reason);
401 if (!Permission::IsSystemServiceCalling()) {
402 TLOGE(WmsLogTag::DMS, "[UL_POWER]wake up begin permission denied!");
403 return false;
404 }
405 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP,
406 EventStatus::BEGIN);
407 }
408
WakeUpEnd()409 bool DisplayManagerService::WakeUpEnd()
410 {
411 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "[UL_POWER]dms:WakeUpEnd");
412 if (!Permission::IsSystemServiceCalling()) {
413 TLOGE(WmsLogTag::DMS, "[UL_POWER]wake up end permission denied!");
414 return false;
415 }
416 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP,
417 EventStatus::END);
418 }
419
SuspendBegin(PowerStateChangeReason reason)420 bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason)
421 {
422 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "[UL_POWER]dms:SuspendBegin(%u)", reason);
423 if (!Permission::IsSystemServiceCalling()) {
424 TLOGE(WmsLogTag::DMS, "[UL_POWER]suspend begin permission denied!");
425 return false;
426 }
427 displayPowerController_->SuspendBegin(reason);
428 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP,
429 EventStatus::BEGIN);
430 }
431
SuspendEnd()432 bool DisplayManagerService::SuspendEnd()
433 {
434 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "[UL_POWER]dms:SuspendEnd");
435 if (!Permission::IsSystemServiceCalling()) {
436 TLOGE(WmsLogTag::DMS, "[UL_POWER]suspend end permission denied!");
437 return false;
438 }
439 return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP,
440 EventStatus::END);
441 }
442
SetSpecifiedScreenPower(ScreenId screenId,ScreenPowerState state,PowerStateChangeReason reason)443 bool DisplayManagerService::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state,
444 PowerStateChangeReason reason)
445 {
446 TLOGE(WmsLogTag::DMS, "[UL_POWER]DMS not support SetSpecifiedScreenPower: screen:%{public}" PRIu64
447 ", state:%{public}u", screenId, state);
448 return false;
449 }
450
SetScreenPowerForAll(ScreenPowerState state,PowerStateChangeReason reason)451 bool DisplayManagerService::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
452 {
453 TLOGI(WmsLogTag::DMS, "[UL_POWER]SetScreenPowerForAll");
454 if (!Permission::IsSystemServiceCalling()) {
455 TLOGE(WmsLogTag::DMS, "[UL_POWER]set screen power for all permission denied!");
456 return false;
457 }
458 return abstractScreenController_->SetScreenPowerForAll(state, reason);
459 }
460
GetScreenPower(ScreenId dmsScreenId)461 ScreenPowerState DisplayManagerService::GetScreenPower(ScreenId dmsScreenId)
462 {
463 return abstractScreenController_->GetScreenPower(dmsScreenId);
464 }
465
SetDisplayState(DisplayState state)466 bool DisplayManagerService::SetDisplayState(DisplayState state)
467 {
468 if (!Permission::IsSystemServiceCalling()) {
469 TLOGE(WmsLogTag::DMS, "[UL_POWER]set display state permission denied!");
470 return false;
471 }
472 ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
473 sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(dmsScreenId);
474 if (display != nullptr) {
475 display->SetDisplayState(state);
476 }
477 return displayPowerController_->SetDisplayState(state);
478 }
479
GetScreenIdByDisplayId(DisplayId displayId) const480 ScreenId DisplayManagerService::GetScreenIdByDisplayId(DisplayId displayId) const
481 {
482 sptr<AbstractDisplay> abstractDisplay = abstractDisplayController_->GetAbstractDisplay(displayId);
483 if (abstractDisplay == nullptr) {
484 TLOGE(WmsLogTag::DMS, "GetScreenIdByDisplayId: GetAbstractDisplay failed");
485 return SCREEN_ID_INVALID;
486 }
487 return abstractDisplay->GetAbstractScreenId();
488 }
489
GetDisplayState(DisplayId displayId)490 DisplayState DisplayManagerService::GetDisplayState(DisplayId displayId)
491 {
492 std::lock_guard<std::recursive_mutex> lock(mutex_);
493 return displayPowerController_->GetDisplayState(displayId);
494 }
495
TryToCancelScreenOff()496 bool DisplayManagerService::TryToCancelScreenOff()
497 {
498 TLOGE(WmsLogTag::DMS, "[UL_POWER]DMS not support TryToCancelScreenOff");
499 return false;
500 }
501
SetScreenBrightness(uint64_t screenId,uint32_t level)502 bool DisplayManagerService::SetScreenBrightness(uint64_t screenId, uint32_t level)
503 {
504 if (!Permission::IsSystemServiceCalling()) {
505 TLOGE(WmsLogTag::DMS, "set screen brightness permission denied!");
506 return false;
507 }
508 RSInterfaces::GetInstance().SetScreenBacklight(screenId, level);
509 return true;
510 }
511
GetScreenBrightness(uint64_t screenId)512 uint32_t DisplayManagerService::GetScreenBrightness(uint64_t screenId)
513 {
514 uint32_t level = static_cast<uint32_t>(RSInterfaces::GetInstance().GetScreenBacklight(screenId));
515 TLOGI(WmsLogTag::DMS, "screenId:%{public}" PRIu64 ", level:%{public}u,", screenId, level);
516 return level;
517 }
518
NotifyDisplayEvent(DisplayEvent event)519 void DisplayManagerService::NotifyDisplayEvent(DisplayEvent event)
520 {
521 if (!Permission::IsSystemServiceCalling()) {
522 TLOGE(WmsLogTag::DMS, "[UL_POWER]notify display event permission denied!");
523 return;
524 }
525 displayPowerController_->NotifyDisplayEvent(event);
526 }
527
SetFreeze(std::vector<DisplayId> displayIds,bool isFreeze)528 bool DisplayManagerService::SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze)
529 {
530 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
531 TLOGE(WmsLogTag::DMS, "set freeze permission denied!");
532 return false;
533 }
534 abstractDisplayController_->SetFreeze(displayIds, isFreeze);
535 return true;
536 }
537
MakeMirror(ScreenId mainScreenId,std::vector<ScreenId> mirrorScreenIds,ScreenId & screenGroupId)538 DMError DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds,
539 ScreenId& screenGroupId)
540 {
541 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
542 TLOGE(WmsLogTag::DMS, "make mirror permission denied!");
543 return DMError::DM_ERROR_NOT_SYSTEM_APP;
544 }
545 TLOGI(WmsLogTag::DMS, "mainScreenId :%{public}" PRIu64, mainScreenId);
546 auto allMirrorScreenIds = abstractScreenController_->GetAllValidScreenIds(mirrorScreenIds);
547 auto iter = std::find(allMirrorScreenIds.begin(), allMirrorScreenIds.end(), mainScreenId);
548 if (iter != allMirrorScreenIds.end()) {
549 allMirrorScreenIds.erase(iter);
550 }
551 auto mainScreen = abstractScreenController_->GetAbstractScreen(mainScreenId);
552 if (mainScreen == nullptr || allMirrorScreenIds.empty()) {
553 TLOGI(WmsLogTag::DMS, "create mirror fail. main screen :%{public}" PRIu64 ", screens' size:%{public}u",
554 mainScreenId, static_cast<uint32_t>(allMirrorScreenIds.size()));
555 return DMError::DM_ERROR_INVALID_PARAM;
556 }
557 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeMirror");
558 DMError ret = abstractScreenController_->MakeMirror(mainScreenId, allMirrorScreenIds);
559 if (ret != DMError::DM_OK) {
560 TLOGE(WmsLogTag::DMS, "make mirror failed.");
561 return ret;
562 }
563 if (abstractScreenController_->GetAbstractScreenGroup(mainScreen->groupDmsId_) == nullptr) {
564 TLOGE(WmsLogTag::DMS, "get screen group failed.");
565 return DMError::DM_ERROR_NULLPTR;
566 }
567 screenGroupId = mainScreen->groupDmsId_;
568 return DMError::DM_OK;
569 }
570
StopMirror(const std::vector<ScreenId> & mirrorScreenIds)571 DMError DisplayManagerService::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
572 {
573 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
574 TLOGE(WmsLogTag::DMS, "stop mirror permission denied!");
575 return DMError::DM_ERROR_NOT_SYSTEM_APP;
576 }
577
578 auto allMirrorScreenIds = abstractScreenController_->GetAllValidScreenIds(mirrorScreenIds);
579 if (allMirrorScreenIds.empty()) {
580 TLOGI(WmsLogTag::DMS, "stop mirror done. screens' size:%{public}u",
581 static_cast<uint32_t>(allMirrorScreenIds.size()));
582 return DMError::DM_OK;
583 }
584
585 DMError ret = abstractScreenController_->StopScreens(allMirrorScreenIds, ScreenCombination::SCREEN_MIRROR);
586 if (ret != DMError::DM_OK) {
587 TLOGE(WmsLogTag::DMS, "stop mirror failed.");
588 return ret;
589 }
590
591 return DMError::DM_OK;
592 }
593
RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)594 void DisplayManagerService::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
595 {
596 abstractScreenController_->RemoveVirtualScreenFromGroup(screens);
597 }
598
UpdateRSTree(DisplayId displayId,DisplayId parentDisplayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool isAdd,bool isMultiDisplay)599 void DisplayManagerService::UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId,
600 std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd, bool isMultiDisplay)
601 {
602 TLOGD(WmsLogTag::DMS, "UpdateRSTree, currentDisplayId: %{public}" PRIu64
603 ", isAdd: %{public}d, isMultiDisplay: %{public}d, parentDisplayId: %{public}" PRIu64,
604 displayId, isAdd, isMultiDisplay, parentDisplayId);
605 ScreenId screenId = GetScreenIdByDisplayId(displayId);
606 ScreenId parentScreenId = GetScreenIdByDisplayId(parentDisplayId);
607 CHECK_SCREEN_AND_RETURN(screenId, void());
608
609 abstractScreenController_->UpdateRSTree(screenId, parentScreenId, surfaceNode, isAdd, isMultiDisplay);
610 }
611
AddSurfaceNodeToDisplay(DisplayId displayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool onTop)612 DMError DisplayManagerService::AddSurfaceNodeToDisplay(DisplayId displayId,
613 std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop)
614 {
615 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
616 TLOGE(WmsLogTag::DMS, "Permission denied!");
617 return DMError::DM_ERROR_NOT_SYSTEM_APP;
618 }
619 TLOGI(WmsLogTag::DMS, "DisplayId: %{public}" PRIu64 ", onTop: %{public}d", displayId, onTop);
620 if (surfaceNode == nullptr) {
621 TLOGW(WmsLogTag::DMS, "Surface is null");
622 return DMError::DM_ERROR_NULLPTR;
623 }
624 ScreenId screenId = GetScreenIdByDisplayId(displayId);
625 return abstractScreenController_->AddSurfaceNodeToScreen(screenId, surfaceNode, true);
626 }
627
RemoveSurfaceNodeFromDisplay(DisplayId displayId,std::shared_ptr<RSSurfaceNode> & surfaceNode)628 DMError DisplayManagerService::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
629 std::shared_ptr<RSSurfaceNode>& surfaceNode)
630 {
631 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
632 TLOGE(WmsLogTag::DMS, "Permission denied!");
633 return DMError::DM_ERROR_NOT_SYSTEM_APP;
634 }
635 TLOGI(WmsLogTag::DMS, "DisplayId: %{public}" PRIu64, displayId);
636 if (surfaceNode == nullptr) {
637 TLOGW(WmsLogTag::DMS, "Surface is null");
638 return DMError::DM_ERROR_NULLPTR;
639 }
640 ScreenId screenId = GetScreenIdByDisplayId(displayId);
641 return abstractScreenController_->RemoveSurfaceNodeFromScreen(screenId, surfaceNode);
642 }
643
GetScreenInfoById(ScreenId screenId)644 sptr<ScreenInfo> DisplayManagerService::GetScreenInfoById(ScreenId screenId)
645 {
646 auto screen = abstractScreenController_->GetAbstractScreen(screenId);
647 if (screen == nullptr) {
648 TLOGE(WmsLogTag::DMS, "cannot find screenInfo: %{public}" PRIu64, screenId);
649 return nullptr;
650 }
651 return screen->ConvertToScreenInfo();
652 }
653
GetDisplayInfoByScreenId(ScreenId screenId) const654 sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoByScreenId(ScreenId screenId) const
655 {
656 auto screen = abstractScreenController_->GetAbstractScreen(screenId);
657 if (screen == nullptr) {
658 TLOGE(WmsLogTag::DMS, "cannot find screenInfo: %{public}" PRIu64, screenId);
659 return nullptr;
660 }
661 sptr<ScreenInfo> screenInfo = screen->ConvertToScreenInfo();
662 if (screenInfo == nullptr) {
663 TLOGE(WmsLogTag::DMS, "cannot get screenInfo: %{public}" PRIu64, screenId);
664 return nullptr;
665 }
666 return screen->ConvertScreenInfoToDisplayInfo(screenInfo);
667 }
668
GetScreenGroupInfoById(ScreenId screenId)669 sptr<ScreenGroupInfo> DisplayManagerService::GetScreenGroupInfoById(ScreenId screenId)
670 {
671 auto screenGroup = abstractScreenController_->GetAbstractScreenGroup(screenId);
672 if (screenGroup == nullptr) {
673 TLOGE(WmsLogTag::DMS, "cannot find screenGroupInfo: %{public}" PRIu64, screenId);
674 return nullptr;
675 }
676 return screenGroup->ConvertToScreenGroupInfo();
677 }
678
GetScreenGroupIdByScreenId(ScreenId screenId)679 ScreenId DisplayManagerService::GetScreenGroupIdByScreenId(ScreenId screenId)
680 {
681 auto screen = abstractScreenController_->GetAbstractScreen(screenId);
682 if (screen == nullptr) {
683 TLOGE(WmsLogTag::DMS, "cannot find screenInfo: %{public}" PRIu64, screenId);
684 return SCREEN_ID_INVALID;
685 }
686 return screen->GetScreenGroupId();
687 }
688
GetAllDisplayIds()689 std::vector<DisplayId> DisplayManagerService::GetAllDisplayIds()
690 {
691 return abstractDisplayController_->GetAllDisplayIds();
692 }
693
GetAllScreenInfos(std::vector<sptr<ScreenInfo>> & screenInfos)694 DMError DisplayManagerService::GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos)
695 {
696 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
697 TLOGE(WmsLogTag::DMS, "get all screen infos permission denied!");
698 return DMError::DM_ERROR_NOT_SYSTEM_APP;
699 }
700 std::vector<ScreenId> screenIds = abstractScreenController_->GetAllScreenIds();
701 for (auto screenId: screenIds) {
702 auto screenInfo = GetScreenInfoById(screenId);
703 if (screenInfo == nullptr) {
704 TLOGE(WmsLogTag::DMS, "cannot find screenInfo: %{public}" PRIu64, screenId);
705 continue;
706 }
707 screenInfos.emplace_back(screenInfo);
708 }
709 return DMError::DM_OK;
710 }
711
MakeExpand(std::vector<ScreenId> expandScreenIds,std::vector<Point> startPoints,ScreenId & screenGroupId)712 DMError DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds, std::vector<Point> startPoints,
713 ScreenId& screenGroupId)
714 {
715 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
716 TLOGE(WmsLogTag::DMS, "make expand permission denied!");
717 return DMError::DM_ERROR_NOT_SYSTEM_APP;
718 }
719 if (expandScreenIds.empty() || startPoints.empty() || expandScreenIds.size() != startPoints.size()) {
720 TLOGE(WmsLogTag::DMS, "create expand fail, input params is invalid. "
721 "screenId vector size :%{public}u, startPoint vector size :%{public}u",
722 static_cast<uint32_t>(expandScreenIds.size()), static_cast<uint32_t>(startPoints.size()));
723 return DMError::DM_ERROR_INVALID_PARAM;
724 }
725 std::map<ScreenId, Point> pointsMap;
726 uint32_t size = expandScreenIds.size();
727 for (uint32_t i = 0; i < size; i++) {
728 if (pointsMap.find(expandScreenIds[i]) != pointsMap.end()) {
729 continue;
730 }
731 pointsMap[expandScreenIds[i]] = startPoints[i];
732 }
733 ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
734 TLOGI(WmsLogTag::DMS, "MakeExpand, defaultScreenId:%{public}" PRIu64, defaultScreenId);
735 auto allExpandScreenIds = abstractScreenController_->GetAllValidScreenIds(expandScreenIds);
736 auto iter = std::find(allExpandScreenIds.begin(), allExpandScreenIds.end(), defaultScreenId);
737 if (iter != allExpandScreenIds.end()) {
738 allExpandScreenIds.erase(iter);
739 }
740 if (allExpandScreenIds.empty()) {
741 TLOGE(WmsLogTag::DMS, "allExpandScreenIds is empty. make expand failed.");
742 return DMError::DM_ERROR_NULLPTR;
743 }
744 std::shared_ptr<RSDisplayNode> rsDisplayNode;
745 std::vector<Point> points;
746 for (uint32_t i = 0; i < allExpandScreenIds.size(); i++) {
747 ScreenId expandScreenId = allExpandScreenIds[i];
748 if (pointsMap.find(expandScreenId) == pointsMap.end()) {
749 continue;
750 }
751 points.emplace_back(pointsMap[expandScreenId]);
752 rsDisplayNode = abstractScreenController_->GetRSDisplayNodeByScreenId(expandScreenId);
753 if (rsDisplayNode != nullptr) {
754 sptr<AbstractScreen> absScreen = abstractScreenController_->GetAbstractScreen(expandScreenId);
755 if (absScreen != nullptr) {
756 RSInterfaces::GetInstance().SetScreenOffset(absScreen->rsId_,
757 pointsMap[expandScreenId].posX_, pointsMap[expandScreenId].posY_);
758 }
759 }
760 }
761 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeExpand");
762 if (!abstractScreenController_->MakeExpand(allExpandScreenIds, points)) {
763 TLOGE(WmsLogTag::DMS, "make expand failed.");
764 return DMError::DM_ERROR_NULLPTR;
765 }
766 auto screen = abstractScreenController_->GetAbstractScreen(allExpandScreenIds[0]);
767 if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) {
768 TLOGE(WmsLogTag::DMS, "get screen group failed.");
769 return DMError::DM_ERROR_NULLPTR;
770 }
771 screenGroupId = screen->groupDmsId_;
772 return DMError::DM_OK;
773 }
774
StopExpand(const std::vector<ScreenId> & expandScreenIds)775 DMError DisplayManagerService::StopExpand(const std::vector<ScreenId>& expandScreenIds)
776 {
777 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
778 TLOGE(WmsLogTag::DMS, "stop expand permission denied!");
779 return DMError::DM_ERROR_NOT_SYSTEM_APP;
780 }
781 auto allExpandScreenIds = abstractScreenController_->GetAllValidScreenIds(expandScreenIds);
782 if (allExpandScreenIds.empty()) {
783 TLOGI(WmsLogTag::DMS, "stop expand done. screens' size:%{public}u",
784 static_cast<uint32_t>(allExpandScreenIds.size()));
785 return DMError::DM_OK;
786 }
787
788 DMError ret = abstractScreenController_->StopScreens(allExpandScreenIds, ScreenCombination::SCREEN_EXPAND);
789 if (ret != DMError::DM_OK) {
790 TLOGE(WmsLogTag::DMS, "stop expand failed.");
791 return ret;
792 }
793
794 return DMError::DM_OK;
795 }
796
SetScreenActiveMode(ScreenId screenId,uint32_t modeId)797 DMError DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
798 {
799 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
800 TLOGE(WmsLogTag::DMS, "set screen active permission denied!");
801 return DMError::DM_ERROR_NOT_SYSTEM_APP;
802 }
803 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetScreenActiveMode(%" PRIu64 ", %u)", screenId, modeId);
804 return abstractScreenController_->SetScreenActiveMode(screenId, modeId);
805 }
806
SetVirtualPixelRatio(ScreenId screenId,float virtualPixelRatio)807 DMError DisplayManagerService::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
808 {
809 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
810 TLOGE(WmsLogTag::DMS, "set virtual pixel permission denied!");
811 return DMError::DM_ERROR_NOT_SYSTEM_APP;
812 }
813 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetVirtualPixelRatio(%" PRIu64 ", %f)", screenId,
814 virtualPixelRatio);
815 return abstractScreenController_->SetVirtualPixelRatio(screenId, virtualPixelRatio);
816 }
817
IsScreenRotationLocked(bool & isLocked)818 DMError DisplayManagerService::IsScreenRotationLocked(bool& isLocked)
819 {
820 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
821 TLOGE(WmsLogTag::DMS, "is screen rotation locked permission denied!");
822 return DMError::DM_ERROR_NOT_SYSTEM_APP;
823 }
824 isLocked = ScreenRotationController::IsScreenRotationLocked();
825 return DMError::DM_OK;
826 }
827
SetScreenRotationLocked(bool isLocked)828 DMError DisplayManagerService::SetScreenRotationLocked(bool isLocked)
829 {
830 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
831 TLOGE(WmsLogTag::DMS, "set screen rotation locked permission denied!");
832 return DMError::DM_ERROR_NOT_SYSTEM_APP;
833 }
834 return ScreenRotationController::SetScreenRotationLocked(isLocked);
835 }
836
SetScreenRotationLockedFromJs(bool isLocked)837 DMError DisplayManagerService::SetScreenRotationLockedFromJs(bool isLocked)
838 {
839 if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
840 TLOGE(WmsLogTag::DMS, "set screen rotation locked from js permission denied!");
841 return DMError::DM_ERROR_NOT_SYSTEM_APP;
842 }
843 return ScreenRotationController::SetScreenRotationLocked(isLocked);
844 }
845
SetGravitySensorSubscriptionEnabled()846 void DisplayManagerService::SetGravitySensorSubscriptionEnabled()
847 {
848 if (!isAutoRotationOpen_) {
849 TLOGE(WmsLogTag::DMS, "autoRotation is not open");
850 ScreenRotationController::Init();
851 return;
852 }
853 SensorConnector::SubscribeRotationSensor();
854 }
855
GetCutoutInfo(DisplayId displayId)856 sptr<CutoutInfo> DisplayManagerService::GetCutoutInfo(DisplayId displayId)
857 {
858 return displayCutoutController_->GetCutoutInfo(displayId);
859 }
860
NotifyPrivateWindowStateChanged(bool hasPrivate)861 void DisplayManagerService::NotifyPrivateWindowStateChanged(bool hasPrivate)
862 {
863 DisplayManagerAgentController::GetInstance().NotifyPrivateWindowStateChanged(hasPrivate);
864 }
865
GetAllDisplayPhysicalResolution()866 std::vector<DisplayPhysicalResolution> DisplayManagerService::GetAllDisplayPhysicalResolution()
867 {
868 if (allDisplayPhysicalResolution_.empty()) {
869 sptr<DisplayInfo> displayInfo = DisplayManagerService::GetDefaultDisplayInfo();
870 if (displayInfo == nullptr) {
871 TLOGE(WmsLogTag::DMS, "default display null");
872 return allDisplayPhysicalResolution_;
873 }
874 DisplayPhysicalResolution defaultResolution;
875 defaultResolution.foldDisplayMode_ = FoldDisplayMode::UNKNOWN;
876 defaultResolution.physicalWidth_ = static_cast<uint32_t>(displayInfo->GetWidth());
877 defaultResolution.physicalHeight_ = static_cast<uint32_t>(displayInfo->GetHeight());
878 allDisplayPhysicalResolution_.emplace_back(defaultResolution);
879 }
880 return allDisplayPhysicalResolution_;
881 }
882
SetVirtualScreenAsDefault(ScreenId screenId)883 bool DisplayManagerService::SetVirtualScreenAsDefault(ScreenId screenId)
884 {
885 TLOGI(WmsLogTag::DMS, "Enter, screenId: %{public}" PRIu64 "", screenId);
886 return abstractScreenController_->SetVirtualScreenAsDefault(screenId);
887 }
888 } // namespace OHOS::Rosen
889