/* * Copyright (c) 2021-2022 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_proxy.h" #include #include #include #include #include "marshalling_helper.h" #include "window_manager_hilog.h" namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerProxy"}; } sptr DisplayManagerProxy::GetDefaultDisplayInfo() { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDefaultDisplayInfo: remote is nullptr"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetDefaultDisplayInfo: WriteInterfaceToken failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO), data, reply, option) != ERR_NONE) { WLOGFW("GetDefaultDisplayInfo: SendRequest failed"); return nullptr; } sptr info = reply.ReadParcelable(); if (info == nullptr) { WLOGFW("DisplayManagerProxy::GetDefaultDisplayInfo SendRequest nullptr."); } return info; } sptr DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDisplayInfoById: remote is nullptr"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); return nullptr; } if (!data.WriteUint64(displayId)) { WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID), data, reply, option) != ERR_NONE) { WLOGFW("GetDisplayInfoById: SendRequest failed"); return nullptr; } sptr info = reply.ReadParcelable(); if (info == nullptr) { WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); return nullptr; } return info; } sptr DisplayManagerProxy::GetDisplayInfoByScreen(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFE("fail to get displayInfo by screenId: remote is null"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("fail to get displayInfo by screenId: WriteInterfaceToken failed"); return nullptr; } if (!data.WriteUint64(screenId)) { WLOGFW("fail to get displayInfo by screenId: WriteUint64 displayId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_SCREEN), data, reply, option) != ERR_NONE) { WLOGFW("fail to get displayInfo by screenId: SendRequest failed"); return nullptr; } sptr info = reply.ReadParcelable(); if (info == nullptr) { WLOGFW("fail to get displayInfo by screenId: SendRequest null"); return nullptr; } return info; } ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption, const sptr& displayManagerAgent) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("CreateVirtualScreen: remote is nullptr"); return SCREEN_ID_INVALID; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("CreateVirtualScreen: WriteInterfaceToken failed"); return SCREEN_ID_INVALID; } bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) && data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) && data.WriteInt32(virtualOption.flags_) && data.WriteBool(virtualOption.isForShot_) && data.WriteUInt64Vector(virtualOption.missionIds_); if (virtualOption.surface_ != nullptr && virtualOption.surface_->GetProducer() != nullptr) { res = res && data.WriteBool(true) && data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject()); } else { WLOGFW("CreateVirtualScreen: surface is nullptr"); res = res && data.WriteBool(false); } if (displayManagerAgent != nullptr) { res = res && data.WriteRemoteObject(displayManagerAgent); } if (!res) { WLOGFE("Write data failed"); return SCREEN_ID_INVALID; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_CREATE_VIRTUAL_SCREEN), data, reply, option) != ERR_NONE) { WLOGFW("CreateVirtualScreen: SendRequest failed"); return SCREEN_ID_INVALID; } ScreenId screenId = static_cast(reply.ReadUint64()); WLOGFI("CreateVirtualScreen %" PRIu64"", screenId); return screenId; } DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DestroyVirtualScreen: remote is nullptr"); return DMError::DM_ERROR_REMOTE_CREATE_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("DestroyVirtualScreen: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("DestroyVirtualScreen: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_DESTROY_VIRTUAL_SCREEN), data, reply, option) != ERR_NONE) { WLOGFW("DestroyVirtualScreen: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr surface) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetVirtualScreenSurface: remote is nullptr"); return DMError::DM_ERROR_REMOTE_CREATE_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("SetVirtualScreenSurface: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } bool res = data.WriteUint64(static_cast(screenId)); if (surface != nullptr) { res = res && data.WriteBool(true) && data.WriteRemoteObject(surface->AsObject()); } else { WLOGFW("SetVirtualScreenSurface: surface is nullptr"); res = res && data.WriteBool(false); } if (!res) { WLOGFW("SetVirtualScreenSurface: Write screenId/surface failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE), data, reply, option) != ERR_NONE) { WLOGFW("SetVirtualScreenSurface: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetOrientation(ScreenId screenId, Orientation orientation) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("fail to set orientation: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("fail to set orientation: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("fail to set orientation: Write screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint32(static_cast(orientation))) { WLOGFW("fail to set orientation: Write orientation failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_ORIENTATION), data, reply, option) != ERR_NONE) { WLOGFW("fail to set orientation: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } std::shared_ptr DisplayManagerProxy::GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode, bool isUseDma) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDisplaySnapshot: remote is nullptr"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetDisplaySnapshot: WriteInterfaceToken failed"); return nullptr; } if (!data.WriteUint64(displayId)) { WLOGFE("Write displayId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT), data, reply, option) != ERR_NONE) { WLOGFW("GetDisplaySnapshot: SendRequest failed"); return nullptr; } std::shared_ptr pixelMap(reply.ReadParcelable()); DmErrorCode replyErrorCode = static_cast(reply.ReadInt32()); if (errorCode) { *errorCode = replyErrorCode; } if (pixelMap == nullptr) { WLOGFW("DisplayManagerProxy::GetDisplaySnapshot SendRequest nullptr."); return nullptr; } return pixelMap; } DMError DisplayManagerProxy::GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::GetScreenSupportedColorGamuts: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } MarshallingHelper::UnmarshallingVectorObj(reply, colorGamuts, [](Parcel& parcel, ScreenColorGamut& color) { uint32_t value; bool res = parcel.ReadUint32(value); color = static_cast(value); return res; } ); return ret; } DMError DisplayManagerProxy::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::GetScreenColorGamut: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("DisplayManagerProxy::GetScreenColorGamut: WriteUint64 uint64_t failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_GAMUT), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::GetScreenColorGamut: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } colorGamut = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::SetScreenColorGamut: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::SetScreenColorGamut: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId)) || !data.WriteInt32(colorGamutIdx)) { WLOGFW("DisplayManagerProxy::SetScreenColorGamut: Write failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_GAMUT), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::SetScreenColorGamut: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::GetScreenGamutMap: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("DisplayManagerProxy::GetScreenGamutMap: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_GAMUT_MAP), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::GetScreenGamutMap: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } gamutMap = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::SetScreenGamutMap: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::SetScreenGamutMap: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId)) || !data.WriteUint32(static_cast(gamutMap))) { WLOGFW("DisplayManagerProxy::SetScreenGamutMap: Writ failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_GAMUT_MAP), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::SetScreenGamutMap: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetScreenColorTransform(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::SetScreenColorTransform: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("DisplayManagerProxy::SetScreenColorTransform: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_TRANSFORM), data, reply, option) != ERR_NONE) { WLOGFW("DisplayManagerProxy::SetScreenColorTransform: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetPixelFormat: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("GetPixelFormat: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("GetPixelFormat: WriteUint64 uint64_t failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_PIXEL_FORMAT), data, reply, option) != ERR_NONE) { WLOGFW("GetPixelFormat: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } pixelFormat = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetPixelFormat: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("SetPixelFormat: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId)) || !data.WriteInt32(pixelFormat)) { WLOGFW("SetPixelFormat: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_PIXEL_FORMAT), data, reply, option) != ERR_NONE) { WLOGFW("SetPixelFormat: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::GetSupportedHDRFormats(ScreenId screenId, std::vector& hdrFormats) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetSupportedHDRFormats: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("GetSupportedHDRFormats: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("GetSupportedHDRFormats: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_HDR_FORMAT), data, reply, option) != ERR_NONE) { WLOGFW("GetSupportedHDRFormats: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } MarshallingHelper::UnmarshallingVectorObj(reply, hdrFormats, [](Parcel& parcel, ScreenHDRFormat& hdrFormat) { uint32_t value; bool res = parcel.ReadUint32(value); hdrFormat = static_cast(value); return res; } ); return ret; } DMError DisplayManagerProxy::GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetScreenHDRFormat: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("GetScreenHDRFormat: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("GetScreenHDRFormat: WriteUint64 uint64_t failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_HDR_FORMAT), data, reply, option) != ERR_NONE) { WLOGFW("GetScreenHDRFormat: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } hdrFormat = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetScreenHDRFormat: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("SetScreenHDRFormat: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId)) || !data.WriteInt32(modeIdx)) { WLOGFW("SetScreenHDRFormat: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_HDR_FORMAT), data, reply, option) != ERR_NONE) { WLOGFW("SetScreenHDRFormat: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::GetSupportedColorSpaces(ScreenId screenId, std::vector& colorSpaces) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetSupportedColorSpaces: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("GetSupportedColorSpaces: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("GetSupportedColorSpaces: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_SPACE), data, reply, option) != ERR_NONE) { WLOGFW("GetSupportedColorSpaces: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } MarshallingHelper::UnmarshallingVectorObj(reply, colorSpaces, [](Parcel& parcel, GraphicCM_ColorSpaceType& color) { uint32_t value; bool res = parcel.ReadUint32(value); color = static_cast(value); return res; } ); return ret; } DMError DisplayManagerProxy::GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetScreenColorSpace: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("GetScreenColorSpace: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFW("GetScreenColorSpace: WriteUint64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_SPACE), data, reply, option) != ERR_NONE) { WLOGFW("GetScreenColorSpace: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); if (ret != DMError::DM_OK) { return ret; } colorSpace = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetScreenColorSpace: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFW("SetScreenColorSpace: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId)) || !data.WriteInt32(colorSpace)) { WLOGFW("SetScreenColorSpace: Write failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_SPACE), data, reply, option) != ERR_NONE) { WLOGFW("SetScreenColorSpace: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("RegisterDisplayManagerAgent: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) { WLOGFE("Write IDisplayManagerAgent failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint32(static_cast(type))) { WLOGFE("Write DisplayManagerAgent type failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("UnregisterDisplayManagerAgent: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) { WLOGFE("Write IWindowManagerAgent failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint32(static_cast(type))) { WLOGFE("Write DisplayManagerAgent type failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } bool DisplayManagerProxy::WakeUpBegin(PowerStateChangeReason reason) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]WakeUpBegin: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (!data.WriteUint32(static_cast(reason))) { WLOGFE("[UL_POWER]Write PowerStateChangeReason failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } bool DisplayManagerProxy::WakeUpEnd() { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]WakeUpEnd: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_WAKE_UP_END), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } bool DisplayManagerProxy::SuspendBegin(PowerStateChangeReason reason) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]SuspendBegin: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (!data.WriteUint32(static_cast(reason))) { WLOGFE("[UL_POWER]Write PowerStateChangeReason failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } bool DisplayManagerProxy::SuspendEnd() { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]SuspendEnd: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SUSPEND_END), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } bool DisplayManagerProxy::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]SetScreenPowerForAll: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (!data.WriteUint32(static_cast(state))) { WLOGFE("[UL_POWER]Write ScreenPowerState failed"); return false; } if (!data.WriteUint32(static_cast(reason))) { WLOGFE("[UL_POWER]Write PowerStateChangeReason failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } bool DisplayManagerProxy::SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]SetSpecifiedScreenPower: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (!data.WriteUint32(static_cast(screenId))) { WLOGFE("[UL_POWER]Write ScreenId failed"); return false; } if (!data.WriteUint32(static_cast(state))) { WLOGFE("[UL_POWER]Write ScreenPowerState failed"); return false; } if (!data.WriteUint32(static_cast(reason))) { WLOGFE("[UL_POWER]Write PowerStateChangeReason failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } ScreenPowerState DisplayManagerProxy::GetScreenPower(ScreenId dmsScreenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetScreenPower: remote is nullptr"); return ScreenPowerState::INVALID_STATE; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return ScreenPowerState::INVALID_STATE; } if (!data.WriteUint64(static_cast(dmsScreenId))) { WLOGFE("Write dmsScreenId failed"); return ScreenPowerState::INVALID_STATE; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER), data, reply, option) != ERR_NONE) { WLOGFW("SendRequest failed"); return ScreenPowerState::INVALID_STATE; } return static_cast(reply.ReadUint32()); } bool DisplayManagerProxy::SetDisplayState(DisplayState state) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]SetDisplayState: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (!data.WriteUint32(static_cast(state))) { WLOGFE("[UL_POWER]Write DisplayState failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } DisplayState DisplayManagerProxy::GetDisplayState(DisplayId displayId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDisplayState: remote is nullptr"); return DisplayState::UNKNOWN; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DisplayState::UNKNOWN; } if (!data.WriteUint64(displayId)) { WLOGFE("Write displayId failed"); return DisplayState::UNKNOWN; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE), data, reply, option) != ERR_NONE) { WLOGFW("SendRequest failed"); return DisplayState::UNKNOWN; } return static_cast(reply.ReadUint32()); } bool DisplayManagerProxy::TryToCancelScreenOff() { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("[UL_POWER]TryToCancelScreenOff: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_TRY_TO_CANCEL_SCREEN_OFF), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return false; } return reply.ReadBool(); } std::vector DisplayManagerProxy::GetAllDisplayIds() { std::vector allDisplayIds; sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetAllDisplayIds: remote is nullptr"); return allDisplayIds; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return allDisplayIds; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS), data, reply, option) != ERR_NONE) { WLOGFW("SendRequest failed"); return allDisplayIds; } reply.ReadUInt64Vector(&allDisplayIds); return allDisplayIds; } sptr DisplayManagerProxy::GetCutoutInfo(DisplayId displayId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetCutoutInfo: remote is null"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetCutoutInfo: GetCutoutInfo failed"); return nullptr; } if (!data.WriteUint64(displayId)) { WLOGFE("GetCutoutInfo: write displayId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO), data, reply, option) != ERR_NONE) { WLOGFW("GetCutoutInfo: GetCutoutInfo failed"); return nullptr; } sptr info = reply.ReadParcelable(); return info; } DMError DisplayManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr& surfaceNode, bool onTop) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("AddSurfaceNodeToDisplay: remote is nullptr"); return DMError::DM_ERROR_IPC_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint64(displayId)) { WLOGFE("write displayId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) { WLOGFE("Write windowProperty failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE), data, reply, option) != ERR_NONE) { WLOGFW("Send request failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr& surfaceNode) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("RemoveSurfaceNodeFromDisplay: remote is nullptr"); return DMError::DM_ERROR_IPC_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint64(displayId)) { WLOGFE("write displayId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) { WLOGFE("Write windowProperty failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE), data, reply, option) != ERR_NONE) { WLOGFW("Send request failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadUint32()); return ret; } DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("HasPrivateWindow: remote is nullptr"); return DMError::DM_ERROR_IPC_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint64(displayId)) { return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW), data, reply, option) != ERR_NONE) { return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); hasPrivateWindow = reply.ReadBool(); return ret; } void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("NotifyDisplayEvent: remote is nullptr"); return; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("[UL_POWER]WriteInterfaceToken failed"); return; } if (!data.WriteUint32(static_cast(event))) { WLOGFE("[UL_POWER]Write DisplayEvent failed"); return; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT), data, reply, option) != ERR_NONE) { WLOGFW("[UL_POWER]SendRequest failed"); return; } } bool DisplayManagerProxy::SetFreeze(std::vector displayIds, bool isFreeze) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetFreeze: remote is nullptr"); return false; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return false; } if (!data.WriteUInt64Vector(displayIds)) { WLOGFE("set freeze fail: write displayId failed."); return false; } if (!data.WriteBool(isFreeze)) { WLOGFE("set freeze fail: write freeze flag failed."); return false; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return false; } return true; } DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId, ScreenId& screenGroupId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("create mirror fail: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("create mirror fail: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } bool res = data.WriteUint64(static_cast(mainScreenId)) && data.WriteUInt64Vector(mirrorScreenId); if (!res) { WLOGFE("create mirror fail: data write failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR), data, reply, option) != ERR_NONE) { WLOGFW("create mirror fail: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); screenGroupId = static_cast(reply.ReadUint64()); return ret; } DMError DisplayManagerProxy::StopMirror(const std::vector& mirrorScreenIds) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("StopMirror fail: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("StopMirror fail: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } bool res = data.WriteUInt64Vector(mirrorScreenIds); if (!res) { WLOGFE("StopMirror fail: data write failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_MIRROR), data, reply, option) != ERR_NONE) { WLOGFW("StopMirror fail: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } sptr DisplayManagerProxy::GetScreenInfoById(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetScreenInfoById: remote is nullptr"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetScreenInfoById: WriteInterfaceToken failed"); return nullptr; } if (!data.WriteUint64(screenId)) { WLOGFE("GetScreenInfoById: Write screenId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID), data, reply, option) != ERR_NONE) { WLOGFW("GetScreenInfoById: SendRequest failed"); return nullptr; } sptr info = reply.ReadStrongParcelable(); if (info == nullptr) { WLOGFW("GetScreenInfoById SendRequest nullptr."); return nullptr; } for (auto& mode : info->GetModes()) { WLOGFI("info modes is id: %{public}u, width: %{public}u, height: %{public}u, refreshRate: %{public}u", mode->id_, mode->width_, mode->height_, mode->refreshRate_); } return info; } sptr DisplayManagerProxy::GetScreenGroupInfoById(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetScreenGroupInfoById: remote is nullptr"); return nullptr; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetScreenGroupInfoById: WriteInterfaceToken failed"); return nullptr; } if (!data.WriteUint64(screenId)) { WLOGFE("GetScreenGroupInfoById: Write screenId failed"); return nullptr; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID), data, reply, option) != ERR_NONE) { WLOGFW("GetScreenGroupInfoById: SendRequest failed"); return nullptr; } sptr info = reply.ReadStrongParcelable(); if (info == nullptr) { WLOGFW("GetScreenGroupInfoById SendRequest nullptr."); return nullptr; } return info; } DMError DisplayManagerProxy::GetAllScreenInfos(std::vector>& screenInfos) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetAllScreenInfos: remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetAllScreenInfos: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS), data, reply, option) != ERR_NONE) { WLOGFW("GetAllScreenInfos: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); static_cast(MarshallingHelper::UnmarshallingVectorParcelableObj(reply, screenInfos)); return ret; } DMError DisplayManagerProxy::MakeExpand(std::vector screenId, std::vector startPoint, ScreenId& screenGroupId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("MakeExpand: remote is null"); return DMError::DM_ERROR_IPC_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("MakeExpand: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUInt64Vector(screenId)) { WLOGFE("MakeExpand: write screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!MarshallingHelper::MarshallingVectorObj(data, startPoint, [](Parcel& parcel, const Point& point) { return parcel.WriteInt32(point.posX_) && parcel.WriteInt32(point.posY_); })) { WLOGFE("MakeExpand: write startPoint failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND), data, reply, option) != ERR_NONE) { WLOGFE("MakeExpand: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); screenGroupId = static_cast(reply.ReadUint64()); return ret; } DMError DisplayManagerProxy::StopExpand(const std::vector& expandScreenIds) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("StopExpand fail: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("StopExpand fail: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } bool res = data.WriteUInt64Vector(expandScreenIds); if (!res) { WLOGFE("StopExpand fail: data write failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_STOP_EXPAND), data, reply, option) != ERR_NONE) { WLOGFW("StopExpand fail: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } void DisplayManagerProxy::RemoveVirtualScreenFromGroup(std::vector screens) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("cancel make mirror or expand fail: remote is null"); return; } MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("cancel make mirror or expand fail: WriteInterfaceToken failed"); return; } bool res = data.WriteUInt64Vector(screens); if (!res) { WLOGFE("cancel make mirror or expand fail: write screens failed."); return; } if (remote->SendRequest(static_cast( DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP), data, reply, option) != ERR_NONE) { WLOGFW("cancel make mirror or expand fail: SendRequest failed"); } } DMError DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetScreenActiveMode: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) { WLOGFE("SetScreenActiveMode: write screenId/modeId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE), data, reply, option) != ERR_NONE) { WLOGFE("SetScreenActiveMode: SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetVirtualPixelRatio: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) { WLOGFE("write screenId/modeId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetResolution: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(screenId) || !data.WriteUint32(width) || !data.WriteUint32(height) || !data.WriteFloat(virtualPixelRatio)) { WLOGFE("write screenId/width/height/virtualPixelRatio failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_RESOLUTION), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDensityInCurResolution: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(screenId)) { WLOGFE("write screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_DENSITY_IN_CURRENT_RESOLUTION), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } virtualPixelRatio = reply.ReadFloat(); return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::IsScreenRotationLocked(bool& isLocked) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("remote is nullptr"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED), data, reply, option) != ERR_NONE) { WLOGFW("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } DMError ret = static_cast(reply.ReadInt32()); isLocked = reply.ReadBool(); return ret; } DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteBool(isLocked)) { WLOGFE("write isLocked failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::SetScreenRotationLockedFromJs(bool isLocked) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteBool(isLocked)) { WLOGFE("write isLocked failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED_FROM_JS), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); return DMError::DM_ERROR_IPC_FAILED; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) { WLOGFI("DisplayManagerProxy::ResizeVirtualScreen: ENTER"); sptr remote = Remote(); if (remote == nullptr) { WLOGFW("DisplayManagerProxy::ResizeVirtualScreen: remote is nullptr"); return DMError::DM_ERROR_REMOTE_CREATE_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteInterfaceToken failed"); return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } if (!data.WriteUint64(static_cast(screenId))) { WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit64 screenId failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint32(width)) { WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 width failed"); return DMError::DM_ERROR_IPC_FAILED; } if (!data.WriteUint32(height)) { WLOGFE("DisplayManagerProxy::ResizeVirtualScreen: WriteUnit32 height failed"); return DMError::DM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_RESIZE_VIRTUAL_SCREEN), data, reply, option) != ERR_NONE) { WLOGFE("DisplayManagerProxy::ResizeVirtualScreen fail: SendRequest failed"); return DMError::DM_ERROR_NULLPTR; } return static_cast(reply.ReadInt32()); } DMError DisplayManagerProxy::MakeUniqueScreen(const std::vector& screenIds) { WLOGFI("DisplayManagerProxy::MakeUniqueScreen"); sptr remote = Remote(); if (remote == nullptr) { WLOGFW("make unique screen failed: remote is null"); return DMError::DM_ERROR_NULLPTR; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("MakeUniqueScreen writeInterfaceToken failed"); return DMError::DM_ERROR_NULLPTR; } if (!data.WriteUint32(screenIds.size())) { WLOGFE("MakeUniqueScreen write screenIds size failed"); return DMError::DM_ERROR_INVALID_PARAM; } bool res = data.WriteUInt64Vector(screenIds); if (!res) { WLOGFE("MakeUniqueScreen fail: write screens failed"); return DMError::DM_ERROR_NULLPTR; } if (remote->SendRequest( static_cast(DisplayManagerMessage::TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN), data, reply, option) != ERR_NONE) { WLOGFE("MakeUniqueScreen fail: SendRequest failed"); return DMError::DM_ERROR_NULLPTR; } return static_cast(reply.ReadInt32()); } std::vector DisplayManagerProxy::GetAllDisplayPhysicalResolution() { sptr remote = Remote(); if (remote == nullptr) { TLOGE(WmsLogTag::DMS, "remote is nullptr"); return std::vector {}; } MessageOption option; MessageParcel reply; MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed"); return std::vector {}; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION), data, reply, option) != ERR_NONE) { TLOGE(WmsLogTag::DMS, "SendRequest failed"); return std::vector {}; } std::vector allPhysicalSize; int32_t displayInfoSize = 0; bool readRet = reply.ReadInt32(displayInfoSize); if (!readRet || displayInfoSize <= 0) { TLOGE(WmsLogTag::DMS, "read failed"); return std::vector {}; } for (int32_t i = 0; i < displayInfoSize; i++) { DisplayPhysicalResolution physicalItem; physicalItem.foldDisplayMode_ = static_cast(reply.ReadUint32()); physicalItem.physicalWidth_ = reply.ReadUint32(); physicalItem.physicalHeight_ = reply.ReadUint32(); allPhysicalSize.emplace_back(physicalItem); } return allPhysicalSize; } } // namespace OHOS::Rosen