/* * 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_stub.h" #include "dm_common.h" #include #include "marshalling_helper.h" #include "window_manager_hilog.h" #include "transaction/rs_interfaces.h" namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerStub"}; } int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { WLOGFI("OnRemoteRequest code is %{public}u", code); if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return -1; } DisplayManagerMessage msgId = static_cast(code); switch (msgId) { case DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO: { auto info = GetDefaultDisplayInfo(); reply.WriteParcelable(info); break; } case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID: { DisplayId displayId = data.ReadUint64(); auto info = GetDisplayInfoById(displayId); reply.WriteParcelable(info); break; } case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_SCREEN: { ScreenId screenId = data.ReadUint64(); auto info = GetDisplayInfoByScreen(screenId); reply.WriteParcelable(info); break; } case DisplayManagerMessage::TRANS_ID_CREATE_VIRTUAL_SCREEN: { std::string name = data.ReadString(); uint32_t width = data.ReadUint32(); uint32_t height = data.ReadUint32(); float density = data.ReadFloat(); int32_t flags = data.ReadInt32(); bool isForShot = data.ReadBool(); bool isSurfaceValid = data.ReadBool(); sptr surface = nullptr; if (isSurfaceValid) { sptr surfaceObject = data.ReadRemoteObject(); sptr bp = iface_cast(surfaceObject); surface = Surface::CreateSurfaceAsProducer(bp); } sptr virtualScreenAgent = data.ReadRemoteObject(); VirtualScreenOption option = { .name_ = name, .width_ = width, .height_ = height, .density_ = density, .surface_ = surface, .flags_ = flags, .isForShot_ = isForShot }; ScreenId screenId = CreateVirtualScreen(option, virtualScreenAgent); reply.WriteUint64(static_cast(screenId)); break; } case DisplayManagerMessage::TRANS_ID_DESTROY_VIRTUAL_SCREEN: { ScreenId screenId = static_cast(data.ReadUint64()); DMError result = DestroyVirtualScreen(screenId); reply.WriteInt32(static_cast(result)); break; } case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE: { ScreenId screenId = static_cast(data.ReadUint64()); bool isSurfaceValid = data.ReadBool(); sptr surface = nullptr; if (isSurfaceValid) { sptr surfaceObject = data.ReadRemoteObject(); sptr bp = iface_cast(surfaceObject); surface = Surface::CreateSurfaceAsProducer(bp); } DMError result = SetVirtualScreenSurface(screenId, surface); reply.WriteInt32(static_cast(result)); break; } case DisplayManagerMessage::TRANS_ID_SET_ORIENTATION: { ScreenId screenId = static_cast(data.ReadUint64()); Orientation orientation = static_cast(data.ReadUint32()); reply.WriteBool(SetOrientation(screenId, orientation)); break; } case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT: { DisplayId displayId = data.ReadUint64(); std::shared_ptr displaySnapshot = GetDisplaySnapshot(displayId); reply.WriteParcelable(displaySnapshot == nullptr ? nullptr : displaySnapshot.get()); break; } case DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: { auto agent = iface_cast(data.ReadRemoteObject()); auto type = static_cast(data.ReadUint32()); reply.WriteBool(RegisterDisplayManagerAgent(agent, type)); break; } case DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT: { auto agent = iface_cast(data.ReadRemoteObject()); auto type = static_cast(data.ReadUint32()); reply.WriteBool(UnregisterDisplayManagerAgent(agent, type)); break; } case DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN: { PowerStateChangeReason reason = static_cast(data.ReadUint32()); reply.WriteBool(WakeUpBegin(reason)); break; } case DisplayManagerMessage::TRANS_ID_WAKE_UP_END: { reply.WriteBool(WakeUpEnd()); break; } case DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN: { PowerStateChangeReason reason = static_cast(data.ReadUint32()); reply.WriteBool(SuspendBegin(reason)); break; } case DisplayManagerMessage::TRANS_ID_SUSPEND_END: { reply.WriteBool(SuspendEnd()); break; } case DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL: { ScreenPowerState state = static_cast(data.ReadUint32()); PowerStateChangeReason reason = static_cast(data.ReadUint32()); reply.WriteBool(SetScreenPowerForAll(state, reason)); break; } case DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER: { ScreenId dmsScreenId; if (!data.ReadUint64(dmsScreenId)) { WLOGFE("fail to read dmsScreenId."); break; } reply.WriteUint32(static_cast(GetScreenPower(dmsScreenId))); break; } case DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE: { DisplayState state = static_cast(data.ReadUint32()); reply.WriteBool(SetDisplayState(state)); break; } case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE: { DisplayState state = GetDisplayState(data.ReadUint64()); reply.WriteUint32(static_cast(state)); break; } case DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT: { DisplayEvent event = static_cast(data.ReadUint32()); NotifyDisplayEvent(event); break; } case DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT: { std::vector ids; data.ReadUInt64Vector(&ids); SetFreeze(ids, data.ReadBool()); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR: { ScreenId mainScreenId = static_cast(data.ReadUint64()); std::vector mirrorScreenId; if (!data.ReadUInt64Vector(&mirrorScreenId)) { WLOGE("fail to receive mirror screen in stub. screen:%{public}" PRIu64"", mainScreenId); break; } ScreenId result = MakeMirror(mainScreenId, mirrorScreenId); reply.WriteUint64(static_cast(result)); break; } case DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID: { ScreenId screenId = static_cast(data.ReadUint64()); auto screenInfo = GetScreenInfoById(screenId); reply.WriteStrongParcelable(screenInfo); break; } case DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID: { ScreenId screenId = static_cast(data.ReadUint64()); auto screenGroupInfo = GetScreenGroupInfoById(screenId); reply.WriteStrongParcelable(screenGroupInfo); break; } case DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS: { std::vector> screenInfos = GetAllScreenInfos(); if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, screenInfos)) { WLOGE("fail to marshalling screenInfos in stub."); } break; } case DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS: { std::vector allDisplayIds = GetAllDisplayIds(); reply.WriteUInt64Vector(allDisplayIds); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND: { std::vector screenId; if (!data.ReadUInt64Vector(&screenId)) { WLOGE("fail to receive expand screen in stub."); break; } std::vector startPoint; if (!MarshallingHelper::UnmarshallingVectorObj(data, startPoint, [](Parcel& parcel, Point& point) { return parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_); })) { WLOGE("fail to receive startPoint in stub."); break; } ScreenId result = MakeExpand(screenId, startPoint); reply.WriteUint64(static_cast(result)); break; } case DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP: { std::vector screenId; if (!data.ReadUInt64Vector(&screenId)) { WLOGE("fail to receive screens in stub."); break; } RemoveVirtualScreenFromGroup(screenId); break; } case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE: { ScreenId screenId = static_cast(data.ReadUint64()); uint32_t modeId = data.ReadUint32(); bool res = SetScreenActiveMode(screenId, modeId); reply.WriteBool(res); break; } case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO: { ScreenId screenId = static_cast(data.ReadUint64()); float virtualPixelRatio = data.ReadFloat(); bool res = SetVirtualPixelRatio(screenId, virtualPixelRatio); reply.WriteBool(res); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS: { ScreenId screenId = static_cast(data.ReadUint64()); std::vector colorGamuts; DMError ret = GetScreenSupportedColorGamuts(screenId, colorGamuts); reply.WriteInt32(static_cast(ret)); if (ret != DMError::DM_OK) { break; } MarshallingHelper::MarshallingVectorObj(reply, colorGamuts, [](Parcel& parcel, const ScreenColorGamut& color) { return parcel.WriteUint32(static_cast(color)); } ); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_GAMUT: { ScreenId screenId = static_cast(data.ReadUint64()); ScreenColorGamut colorGamut; DMError ret = GetScreenColorGamut(screenId, colorGamut); reply.WriteInt32(static_cast(ret)); if (ret != DMError::DM_OK) { break; } reply.WriteUint32(static_cast(colorGamut)); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_GAMUT: { ScreenId screenId = static_cast(data.ReadUint64()); int32_t colorGamutIdx = data.ReadInt32(); DMError ret = SetScreenColorGamut(screenId, colorGamutIdx); reply.WriteInt32(static_cast(ret)); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_GET_GAMUT_MAP: { ScreenId screenId = static_cast(data.ReadUint64()); ScreenGamutMap gamutMap; DMError ret = GetScreenGamutMap(screenId, gamutMap); reply.WriteInt32(static_cast(ret)); if (ret != DMError::DM_OK) { break; } reply.WriteInt32(static_cast(gamutMap)); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_SET_GAMUT_MAP: { ScreenId screenId = static_cast(data.ReadUint64()); ScreenGamutMap gamutMap = static_cast(data.ReadUint32()); DMError ret = SetScreenGamutMap(screenId, gamutMap); reply.WriteInt32(static_cast(ret)); break; } case DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_TRANSFORM: { ScreenId screenId = static_cast(data.ReadUint64()); DMError ret = SetScreenColorTransform(screenId); reply.WriteInt32(static_cast(ret)); break; } case DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED: { bool isLocked = IsScreenRotationLocked(); reply.WriteBool(isLocked); break; } case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: { bool isLocked = static_cast(data.ReadBool()); SetScreenRotationLocked(isLocked); break; } case DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW: { DisplayId id = static_cast(data.ReadUint64()); bool hasPrivateWindow = false; DMError ret = HasPrivateWindow(id, hasPrivateWindow); reply.WriteInt32(static_cast(ret)); reply.WriteBool(hasPrivateWindow); break; } case DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO: { DisplayId displayId = static_cast(data.ReadUint64()); sptr cutoutInfo = GetCutoutInfo(displayId); reply.WriteParcelable(cutoutInfo); break; } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } return 0; } } // namespace OHOS::Rosen