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