/* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "display_manager_ipc_service.h" #include "scene_board_judgement.h" #include "window_manager_hilog.h" namespace OHOS::Rosen { WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerIpcService) const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false : SystemAbility::MakeAndRegisterAbility(&DisplayManagerIpcService::GetInstance()); DisplayManagerIpcService::DisplayManagerIpcService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true), displayManagerService_(DisplayManagerService::GetInstance()) { } void DisplayManagerIpcService::OnStart() { TLOGI(WmsLogTag::DMS, "start"); if (!displayManagerService_.Init()) { TLOGE(WmsLogTag::DMS, "Init failed"); return; } if (!Publish(this)) { TLOGE(WmsLogTag::DMS, "Publish failed"); } displayManagerService_.SetDisplayState(DisplayState::ON); TLOGI(WmsLogTag::DMS, "end"); } void DisplayManagerIpcService::OnStop() { TLOGI(WmsLogTag::DMS, "ready to stop display service."); } int DisplayManagerIpcService::Dump(int fd, const std::vector& args) { return displayManagerService_.Dump(fd, args); } ErrCode DisplayManagerIpcService::GetDefaultDisplayInfo(sptr& displayInfo) { displayInfo = displayManagerService_.GetDefaultDisplayInfo(); if (displayInfo == nullptr) { return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetDisplayInfoById(uint64_t displayId, sptr& displayInfo) { displayInfo = displayManagerService_.GetDisplayInfoById(displayId); if (displayInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetDisplayInfoById failed, displayId: %{public}" PRIu64, displayId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetVisibleAreaDisplayInfoById(uint64_t displayId, sptr& displayInfo) { displayInfo = displayManagerService_.GetVisibleAreaDisplayInfoById(displayId); if (displayInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetVisibleAreaDisplayInfoById failed, displayId: %{public}" PRIu64, displayId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetDisplayInfoByScreen(uint64_t screenId, sptr& displayInfo) { displayInfo = displayManagerService_.GetDisplayInfoByScreen(screenId); if (displayInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetDisplayInfoByScreen failed, screenId: %{public}" PRIu64, screenId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::CreateVirtualScreen(const DmVirtualScreenOption& virtualOption, const sptr& displayManagerAgent, uint64_t& screenId) { screenId = displayManagerService_.CreateVirtualScreen(virtualOption.GetOption(), displayManagerAgent); return ERR_OK; } ErrCode DisplayManagerIpcService::CreateVirtualScreen(const DmVirtualScreenOption& virtualOption, const sptr& displayManagerAgent, uint64_t& screenId, const sptr& surface) { VirtualScreenOption option = virtualOption.GetOption(); sptr surfaceCopy = surface; option.surface_ = Surface::CreateSurfaceAsProducer(surfaceCopy); screenId = displayManagerService_.CreateVirtualScreen(option, displayManagerAgent); return ERR_OK; } ErrCode DisplayManagerIpcService::DestroyVirtualScreen(uint64_t screenId, int32_t& dmError) { dmError = static_cast(displayManagerService_.DestroyVirtualScreen(screenId)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetVirtualScreenSurface(uint64_t screenId, const sptr& surface, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetVirtualScreenSurface(screenId, surface)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetOrientation(uint64_t screenId, uint32_t orientation, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetOrientation(screenId, static_cast(orientation))); return ERR_OK; } ErrCode DisplayManagerIpcService::GetDisplaySnapshot(uint64_t displayId, int32_t& errorCode, bool isUseDma, bool isCaptureFullOfScreen, std::shared_ptr& pixelMap) { DmErrorCode errorCodeOut = DmErrorCode::DM_OK; pixelMap = displayManagerService_.GetDisplaySnapshot(displayId, &errorCodeOut, isUseDma, isCaptureFullOfScreen); errorCode = static_cast(errorCodeOut); if (pixelMap == nullptr) { TLOGE(WmsLogTag::DMS, "GetDisplaySnapshot failed, displayId: %{public}" PRIu64 ", errorCode: %{public}d", displayId, errorCode); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenSupportedColorGamuts(uint64_t screenId, std::vector& colorGamuts, int32_t& dmError) { std::vector colorGamutsOut; dmError = static_cast(displayManagerService_.GetScreenSupportedColorGamuts(screenId, colorGamutsOut)); for (auto& colorGamut : colorGamutsOut) { colorGamuts.push_back(static_cast(colorGamut)); } return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenColorGamut(uint64_t screenId, uint32_t& colorGamut, int32_t& dmError) { ScreenColorGamut colorGamutOut; dmError = static_cast(displayManagerService_.GetScreenColorGamut(screenId, colorGamutOut)); colorGamut = static_cast(colorGamutOut); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenColorGamut(uint64_t screenId, int32_t colorGamutIdx, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetScreenColorGamut(screenId, colorGamutIdx)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenGamutMap(uint64_t screenId, uint32_t& gamutMap, int32_t& dmError) { ScreenGamutMap gamutMapOut; dmError = static_cast(displayManagerService_.GetScreenGamutMap(screenId, gamutMapOut)); gamutMap = static_cast(gamutMapOut); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenGamutMap(uint64_t screenId, uint32_t gamutMap, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetScreenGamutMap(screenId, static_cast(gamutMap))); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenColorTransform(uint64_t screenId) { displayManagerService_.SetScreenColorTransform(screenId); return ERR_OK; } ErrCode DisplayManagerIpcService::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, uint32_t type, int32_t& dmError) { dmError = static_cast(displayManagerService_.RegisterDisplayManagerAgent(displayManagerAgent, static_cast(type))); return ERR_OK; } ErrCode DisplayManagerIpcService::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, uint32_t type, int32_t& dmError) { dmError = static_cast(displayManagerService_.UnregisterDisplayManagerAgent(displayManagerAgent, static_cast(type))); return ERR_OK; } ErrCode DisplayManagerIpcService::WakeUpBegin(uint32_t reason, bool& isSucc) { isSucc = displayManagerService_.WakeUpBegin(static_cast(reason)); return ERR_OK; } ErrCode DisplayManagerIpcService::WakeUpEnd(bool& isSucc) { isSucc = displayManagerService_.WakeUpEnd(); return ERR_OK; } ErrCode DisplayManagerIpcService::SuspendBegin(uint32_t reason, bool& isSucc) { isSucc = displayManagerService_.SuspendBegin(static_cast(reason)); return ERR_OK; } ErrCode DisplayManagerIpcService::SuspendEnd(bool& isSucc) { isSucc = displayManagerService_.SuspendEnd(); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenPowerForAll(uint32_t screenPowerState, uint32_t reason, bool& isSucc) { isSucc = displayManagerService_.SetScreenPowerForAll(static_cast(screenPowerState), static_cast(reason)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetSpecifiedScreenPower(uint64_t screenId, uint32_t screenPowerState, uint32_t reason, bool& isSucc) { isSucc = displayManagerService_.SetSpecifiedScreenPower(screenId, static_cast(screenPowerState), static_cast(reason)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenPower(uint64_t dmsScreenId, uint32_t& screenPowerState) { screenPowerState = static_cast(displayManagerService_.GetScreenPower(dmsScreenId)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetDisplayState(uint32_t displayState, bool& isSucc) { isSucc = displayManagerService_.SetDisplayState(static_cast(displayState)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetDisplayState(uint64_t displayId, uint32_t& displayState) { displayState = static_cast(displayManagerService_.GetDisplayState(displayId)); return ERR_OK; } ErrCode DisplayManagerIpcService::TryToCancelScreenOff(bool& isSucc) { isSucc = displayManagerService_.TryToCancelScreenOff(); return ERR_OK; } ErrCode DisplayManagerIpcService::GetAllDisplayIds(std::vector& displayIds) { displayIds = displayManagerService_.GetAllDisplayIds(); return ERR_OK; } ErrCode DisplayManagerIpcService::GetCutoutInfo(uint64_t displayId, sptr& cutoutInfo) { cutoutInfo = displayManagerService_.GetCutoutInfo(displayId); if (cutoutInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetCutoutInfo failed, displayId: %{public}" PRIu64, displayId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::AddSurfaceNodeToDisplay(uint64_t displayId, const std::shared_ptr& dmRsSurfaceNode, int32_t& dmError) { std::shared_ptr surfaceNode = dmRsSurfaceNode->GetSurfaceNode(); dmError = static_cast(displayManagerService_.AddSurfaceNodeToDisplay(displayId, surfaceNode, true)); return ERR_OK; } ErrCode DisplayManagerIpcService::RemoveSurfaceNodeFromDisplay(uint64_t displayId, const std::shared_ptr& dmRsSurfaceNode, int32_t& dmError) { std::shared_ptr surfaceNode = dmRsSurfaceNode->GetSurfaceNode(); dmError = static_cast(displayManagerService_.RemoveSurfaceNodeFromDisplay(displayId, surfaceNode)); return ERR_OK; } ErrCode DisplayManagerIpcService::HasPrivateWindow(uint64_t displayId, bool& hasPrivateWindow, int32_t& dmError) { dmError = static_cast(displayManagerService_.HasPrivateWindow(displayId, hasPrivateWindow)); return ERR_OK; } ErrCode DisplayManagerIpcService::NotifyDisplayEvent(uint32_t displayEvent) { displayManagerService_.NotifyDisplayEvent(static_cast(displayEvent)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetFreeze(const std::vector& displayIds, bool isFreeze, bool& isSucc) { isSucc = displayManagerService_.SetFreeze(displayIds, isFreeze); return ERR_OK; } ErrCode DisplayManagerIpcService::MakeMirror(uint64_t mainScreenId, const std::vector& mirrorScreenId, uint64_t& screenGroupId, int32_t& dmError) { dmError = static_cast(displayManagerService_.MakeMirror(mainScreenId, mirrorScreenId, screenGroupId)); return ERR_OK; } ErrCode DisplayManagerIpcService::StopMirror(const std::vector& mirrorScreenIds, int32_t& dmError) { dmError = static_cast(displayManagerService_.StopMirror(mirrorScreenIds)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenInfoById(uint64_t screenId, sptr& screenInfo) { screenInfo = displayManagerService_.GetScreenInfoById(screenId); if (screenInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetScreenInfoById failed, screenId: %{public}" PRIu64, screenId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenGroupInfoById(uint64_t screenId, sptr& screenGroupInfo) { screenGroupInfo = displayManagerService_.GetScreenGroupInfoById(screenId); if (screenGroupInfo == nullptr) { TLOGE(WmsLogTag::DMS, "GetScreenGroupInfoById failed, screenId: %{public}" PRIu64, screenId); return ERR_INVALID_DATA; } return ERR_OK; } ErrCode DisplayManagerIpcService::GetAllScreenInfos(std::vector>& screenInfos, int32_t& dmError) { dmError = static_cast(displayManagerService_.GetAllScreenInfos(screenInfos)); return ERR_OK; } ErrCode DisplayManagerIpcService::MakeExpand(const std::vector& screenId, const std::vector& startPoint, uint64_t& screenGroupId, int32_t& dmError) { dmError = static_cast(displayManagerService_.MakeExpand(screenId, startPoint, screenGroupId)); return ERR_OK; } ErrCode DisplayManagerIpcService::StopExpand(const std::vector& expandScreenIds, int32_t& dmError) { dmError = static_cast(displayManagerService_.StopExpand(expandScreenIds)); return ERR_OK; } ErrCode DisplayManagerIpcService::RemoveVirtualScreenFromGroup(const std::vector& screens) { displayManagerService_.RemoveVirtualScreenFromGroup(screens); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenActiveMode(uint64_t screenId, uint32_t modeId, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetScreenActiveMode(screenId, modeId)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetVirtualPixelRatio(uint64_t screenId, float virtualPixelRatio, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetVirtualPixelRatio(screenId, virtualPixelRatio)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetResolution(uint64_t screenId, uint32_t width, uint32_t height, float virtualPixelRatio, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetResolution(screenId, width, height, virtualPixelRatio)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetDensityInCurResolution(uint64_t screenId, float& virtualPixelRatio, int32_t& dmError) { dmError = static_cast(displayManagerService_.GetDensityInCurResolution(screenId, virtualPixelRatio)); return ERR_OK; } ErrCode DisplayManagerIpcService::IsScreenRotationLocked(bool& isLocked, int32_t& dmError) { dmError = static_cast(displayManagerService_.IsScreenRotationLocked(isLocked)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenRotationLocked(bool isLocked, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetScreenRotationLocked(isLocked)); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenRotationLockedFromJs(bool isLocked, int32_t& dmError) { dmError = static_cast(displayManagerService_.SetScreenRotationLockedFromJs(isLocked)); return ERR_OK; } ErrCode DisplayManagerIpcService::GetAllDisplayPhysicalResolution( std::vector& displayPhysicalResolutions) { displayPhysicalResolutions = displayManagerService_.GetAllDisplayPhysicalResolution(); return ERR_OK; } ErrCode DisplayManagerIpcService::SetScreenBrightness(uint64_t screenId, uint32_t level, bool& isSucc) { isSucc = displayManagerService_.SetScreenBrightness(screenId, level); return ERR_OK; } ErrCode DisplayManagerIpcService::GetScreenBrightness(uint64_t screenId, uint32_t& level) { level = displayManagerService_.GetScreenBrightness(screenId); return ERR_OK; } ErrCode DisplayManagerIpcService::SetVirtualScreenAsDefault(uint64_t screenId, bool& isSucc) { isSucc = displayManagerService_.SetVirtualScreenAsDefault(screenId); return ERR_OK; } } // namespace OHOS::Rosen