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_stub.h"
17e0dac50fSopenharmony_ci
18e0dac50fSopenharmony_ci#include "dm_common.h"
19e0dac50fSopenharmony_ci
20e0dac50fSopenharmony_ci#include <ipc_skeleton.h>
21e0dac50fSopenharmony_ci
22e0dac50fSopenharmony_ci#include "marshalling_helper.h"
23e0dac50fSopenharmony_ci#include "window_manager_hilog.h"
24e0dac50fSopenharmony_ci
25e0dac50fSopenharmony_ci#include "transaction/rs_interfaces.h"
26e0dac50fSopenharmony_ci
27e0dac50fSopenharmony_cinamespace OHOS::Rosen {
28e0dac50fSopenharmony_cinamespace {
29e0dac50fSopenharmony_ciconstexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerStub"};
30e0dac50fSopenharmony_ciconst static uint32_t MAX_SCREEN_SIZE = 32;
31e0dac50fSopenharmony_ci}
32e0dac50fSopenharmony_ci
33e0dac50fSopenharmony_ciint32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
34e0dac50fSopenharmony_ci    MessageOption &option)
35e0dac50fSopenharmony_ci{
36e0dac50fSopenharmony_ci    WLOGFD("OnRemoteRequest code is %{public}u", code);
37e0dac50fSopenharmony_ci    if (data.ReadInterfaceToken() != GetDescriptor()) {
38e0dac50fSopenharmony_ci        WLOGFE("InterfaceToken check failed");
39e0dac50fSopenharmony_ci        return -1;
40e0dac50fSopenharmony_ci    }
41e0dac50fSopenharmony_ci    DisplayManagerMessage msgId = static_cast<DisplayManagerMessage>(code);
42e0dac50fSopenharmony_ci    switch (msgId) {
43e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO: {
44e0dac50fSopenharmony_ci            auto info = GetDefaultDisplayInfo();
45e0dac50fSopenharmony_ci            reply.WriteParcelable(info);
46e0dac50fSopenharmony_ci            break;
47e0dac50fSopenharmony_ci        }
48e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_ID: {
49e0dac50fSopenharmony_ci            DisplayId displayId = data.ReadUint64();
50e0dac50fSopenharmony_ci            auto info = GetDisplayInfoById(displayId);
51e0dac50fSopenharmony_ci            reply.WriteParcelable(info);
52e0dac50fSopenharmony_ci            break;
53e0dac50fSopenharmony_ci        }
54e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_BY_SCREEN: {
55e0dac50fSopenharmony_ci            ScreenId screenId = data.ReadUint64();
56e0dac50fSopenharmony_ci            auto info = GetDisplayInfoByScreen(screenId);
57e0dac50fSopenharmony_ci            reply.WriteParcelable(info);
58e0dac50fSopenharmony_ci            break;
59e0dac50fSopenharmony_ci        }
60e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_CREATE_VIRTUAL_SCREEN: {
61e0dac50fSopenharmony_ci            std::string name = data.ReadString();
62e0dac50fSopenharmony_ci            uint32_t width = data.ReadUint32();
63e0dac50fSopenharmony_ci            uint32_t height = data.ReadUint32();
64e0dac50fSopenharmony_ci            float density = data.ReadFloat();
65e0dac50fSopenharmony_ci            int32_t flags = data.ReadInt32();
66e0dac50fSopenharmony_ci            bool isForShot = data.ReadBool();
67e0dac50fSopenharmony_ci            std::vector<uint64_t> missionIds;
68e0dac50fSopenharmony_ci            data.ReadUInt64Vector(&missionIds);
69e0dac50fSopenharmony_ci            bool isSurfaceValid = data.ReadBool();
70e0dac50fSopenharmony_ci            sptr<Surface> surface = nullptr;
71e0dac50fSopenharmony_ci            if (isSurfaceValid) {
72e0dac50fSopenharmony_ci                sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
73e0dac50fSopenharmony_ci                sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
74e0dac50fSopenharmony_ci                surface = Surface::CreateSurfaceAsProducer(bp);
75e0dac50fSopenharmony_ci            }
76e0dac50fSopenharmony_ci            sptr<IRemoteObject> virtualScreenAgent = data.ReadRemoteObject();
77e0dac50fSopenharmony_ci            VirtualScreenOption virScrOption = {
78e0dac50fSopenharmony_ci                .name_ = name,
79e0dac50fSopenharmony_ci                .width_ = width,
80e0dac50fSopenharmony_ci                .height_ = height,
81e0dac50fSopenharmony_ci                .density_ = density,
82e0dac50fSopenharmony_ci                .surface_ = surface,
83e0dac50fSopenharmony_ci                .flags_ = flags,
84e0dac50fSopenharmony_ci                .isForShot_ = isForShot,
85e0dac50fSopenharmony_ci                .missionIds_ = missionIds
86e0dac50fSopenharmony_ci            };
87e0dac50fSopenharmony_ci            ScreenId screenId = CreateVirtualScreen(virScrOption, virtualScreenAgent);
88e0dac50fSopenharmony_ci            reply.WriteUint64(static_cast<uint64_t>(screenId));
89e0dac50fSopenharmony_ci            break;
90e0dac50fSopenharmony_ci        }
91e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_DESTROY_VIRTUAL_SCREEN: {
92e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
93e0dac50fSopenharmony_ci            DMError result = DestroyVirtualScreen(screenId);
94e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(result));
95e0dac50fSopenharmony_ci            break;
96e0dac50fSopenharmony_ci        }
97e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE: {
98e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
99e0dac50fSopenharmony_ci            bool isSurfaceValid = data.ReadBool();
100e0dac50fSopenharmony_ci            sptr<IBufferProducer> bp = nullptr;
101e0dac50fSopenharmony_ci            if (isSurfaceValid) {
102e0dac50fSopenharmony_ci                sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
103e0dac50fSopenharmony_ci                bp = iface_cast<IBufferProducer>(surfaceObject);
104e0dac50fSopenharmony_ci            }
105e0dac50fSopenharmony_ci            DMError result = SetVirtualScreenSurface(screenId, bp);
106e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(result));
107e0dac50fSopenharmony_ci            break;
108e0dac50fSopenharmony_ci        }
109e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_ORIENTATION: {
110e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
111e0dac50fSopenharmony_ci            Orientation orientation = static_cast<Orientation>(data.ReadUint32());
112e0dac50fSopenharmony_ci            DMError ret = SetOrientation(screenId, orientation);
113e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
114e0dac50fSopenharmony_ci            break;
115e0dac50fSopenharmony_ci        }
116e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT: {
117e0dac50fSopenharmony_ci            DisplayId displayId = data.ReadUint64();
118e0dac50fSopenharmony_ci            DmErrorCode errorCode = DmErrorCode::DM_OK;
119e0dac50fSopenharmony_ci            std::shared_ptr<Media::PixelMap> displaySnapshot = GetDisplaySnapshot(displayId, &errorCode);
120e0dac50fSopenharmony_ci            reply.WriteParcelable(displaySnapshot == nullptr ? nullptr : displaySnapshot.get());
121e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(errorCode));
122e0dac50fSopenharmony_ci            break;
123e0dac50fSopenharmony_ci        }
124e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: {
125e0dac50fSopenharmony_ci            auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
126e0dac50fSopenharmony_ci            if (agent == nullptr) {
127e0dac50fSopenharmony_ci                WLOGFE("agent is nullptr");
128e0dac50fSopenharmony_ci                break;
129e0dac50fSopenharmony_ci            }
130e0dac50fSopenharmony_ci            auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
131e0dac50fSopenharmony_ci            DMError ret = RegisterDisplayManagerAgent(agent, type);
132e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
133e0dac50fSopenharmony_ci            break;
134e0dac50fSopenharmony_ci        }
135e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT: {
136e0dac50fSopenharmony_ci            auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
137e0dac50fSopenharmony_ci            if (agent == nullptr) {
138e0dac50fSopenharmony_ci                WLOGFE("agent is nullptr");
139e0dac50fSopenharmony_ci                break;
140e0dac50fSopenharmony_ci            }
141e0dac50fSopenharmony_ci            auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
142e0dac50fSopenharmony_ci            DMError ret = UnregisterDisplayManagerAgent(agent, type);
143e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
144e0dac50fSopenharmony_ci            break;
145e0dac50fSopenharmony_ci        }
146e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_WAKE_UP_BEGIN: {
147e0dac50fSopenharmony_ci            PowerStateChangeReason reason = static_cast<PowerStateChangeReason>(data.ReadUint32());
148e0dac50fSopenharmony_ci            reply.WriteBool(WakeUpBegin(reason));
149e0dac50fSopenharmony_ci            break;
150e0dac50fSopenharmony_ci        }
151e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_WAKE_UP_END: {
152e0dac50fSopenharmony_ci            reply.WriteBool(WakeUpEnd());
153e0dac50fSopenharmony_ci            break;
154e0dac50fSopenharmony_ci        }
155e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SUSPEND_BEGIN: {
156e0dac50fSopenharmony_ci            PowerStateChangeReason reason = static_cast<PowerStateChangeReason>(data.ReadUint32());
157e0dac50fSopenharmony_ci            reply.WriteBool(SuspendBegin(reason));
158e0dac50fSopenharmony_ci            break;
159e0dac50fSopenharmony_ci        }
160e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SUSPEND_END: {
161e0dac50fSopenharmony_ci            reply.WriteBool(SuspendEnd());
162e0dac50fSopenharmony_ci            break;
163e0dac50fSopenharmony_ci        }
164e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SPECIFIED_SCREEN_POWER: {
165e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint32());
166e0dac50fSopenharmony_ci            ScreenPowerState state = static_cast<ScreenPowerState>(data.ReadUint32());
167e0dac50fSopenharmony_ci            PowerStateChangeReason reason = static_cast<PowerStateChangeReason>(data.ReadUint32());
168e0dac50fSopenharmony_ci            reply.WriteBool(SetSpecifiedScreenPower(screenId, state, reason));
169e0dac50fSopenharmony_ci            break;
170e0dac50fSopenharmony_ci        }
171e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SCREEN_POWER_FOR_ALL: {
172e0dac50fSopenharmony_ci            ScreenPowerState state = static_cast<ScreenPowerState>(data.ReadUint32());
173e0dac50fSopenharmony_ci            PowerStateChangeReason reason = static_cast<PowerStateChangeReason>(data.ReadUint32());
174e0dac50fSopenharmony_ci            reply.WriteBool(SetScreenPowerForAll(state, reason));
175e0dac50fSopenharmony_ci            break;
176e0dac50fSopenharmony_ci        }
177e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_SCREEN_POWER: {
178e0dac50fSopenharmony_ci            ScreenId dmsScreenId;
179e0dac50fSopenharmony_ci            if (!data.ReadUint64(dmsScreenId)) {
180e0dac50fSopenharmony_ci                WLOGFE("fail to read dmsScreenId.");
181e0dac50fSopenharmony_ci                break;
182e0dac50fSopenharmony_ci            }
183e0dac50fSopenharmony_ci            reply.WriteUint32(static_cast<uint32_t>(GetScreenPower(dmsScreenId)));
184e0dac50fSopenharmony_ci            break;
185e0dac50fSopenharmony_ci        }
186e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_DISPLAY_STATE: {
187e0dac50fSopenharmony_ci            DisplayState state = static_cast<DisplayState>(data.ReadUint32());
188e0dac50fSopenharmony_ci            reply.WriteBool(SetDisplayState(state));
189e0dac50fSopenharmony_ci            break;
190e0dac50fSopenharmony_ci        }
191e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_STATE: {
192e0dac50fSopenharmony_ci            DisplayState state = GetDisplayState(data.ReadUint64());
193e0dac50fSopenharmony_ci            reply.WriteUint32(static_cast<uint32_t>(state));
194e0dac50fSopenharmony_ci            break;
195e0dac50fSopenharmony_ci        }
196e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SCREEN_BRIGHTNESS: {
197e0dac50fSopenharmony_ci            uint64_t screenId = data.ReadUint64();
198e0dac50fSopenharmony_ci            uint32_t level = data.ReadUint64();
199e0dac50fSopenharmony_ci            reply.WriteBool(SetScreenBrightness(screenId, level));
200e0dac50fSopenharmony_ci            break;
201e0dac50fSopenharmony_ci        }
202e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_SCREEN_BRIGHTNESS: {
203e0dac50fSopenharmony_ci            uint64_t screenId = data.ReadUint64();
204e0dac50fSopenharmony_ci            reply.WriteUint32(GetScreenBrightness(screenId));
205e0dac50fSopenharmony_ci            break;
206e0dac50fSopenharmony_ci        }
207e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_NOTIFY_DISPLAY_EVENT: {
208e0dac50fSopenharmony_ci            DisplayEvent event = static_cast<DisplayEvent>(data.ReadUint32());
209e0dac50fSopenharmony_ci            NotifyDisplayEvent(event);
210e0dac50fSopenharmony_ci            break;
211e0dac50fSopenharmony_ci        }
212e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_FREEZE_EVENT: {
213e0dac50fSopenharmony_ci            std::vector<DisplayId> ids;
214e0dac50fSopenharmony_ci            data.ReadUInt64Vector(&ids);
215e0dac50fSopenharmony_ci            SetFreeze(ids, data.ReadBool());
216e0dac50fSopenharmony_ci            break;
217e0dac50fSopenharmony_ci        }
218e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_MIRROR: {
219e0dac50fSopenharmony_ci            ScreenId mainScreenId = static_cast<ScreenId>(data.ReadUint64());
220e0dac50fSopenharmony_ci            std::vector<ScreenId> mirrorScreenId;
221e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&mirrorScreenId)) {
222e0dac50fSopenharmony_ci                WLOGE("fail to receive mirror screen in stub. screen:%{public}" PRIu64"", mainScreenId);
223e0dac50fSopenharmony_ci                break;
224e0dac50fSopenharmony_ci            }
225e0dac50fSopenharmony_ci            ScreenId screenGroupId = INVALID_SCREEN_ID;
226e0dac50fSopenharmony_ci            DMError ret = MakeMirror(mainScreenId, mirrorScreenId, screenGroupId);
227e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
228e0dac50fSopenharmony_ci            reply.WriteUint64(static_cast<uint64_t>(screenGroupId));
229e0dac50fSopenharmony_ci            break;
230e0dac50fSopenharmony_ci        }
231e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_SCREEN_INFO_BY_ID: {
232e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
233e0dac50fSopenharmony_ci            auto screenInfo = GetScreenInfoById(screenId);
234e0dac50fSopenharmony_ci            reply.WriteStrongParcelable(screenInfo);
235e0dac50fSopenharmony_ci            break;
236e0dac50fSopenharmony_ci        }
237e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID: {
238e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
239e0dac50fSopenharmony_ci            auto screenGroupInfo = GetScreenGroupInfoById(screenId);
240e0dac50fSopenharmony_ci            reply.WriteStrongParcelable(screenGroupInfo);
241e0dac50fSopenharmony_ci            break;
242e0dac50fSopenharmony_ci        }
243e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_ALL_SCREEN_INFOS: {
244e0dac50fSopenharmony_ci            std::vector<sptr<ScreenInfo>> screenInfos;
245e0dac50fSopenharmony_ci            DMError ret  = GetAllScreenInfos(screenInfos);
246e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
247e0dac50fSopenharmony_ci            if (!MarshallingHelper::MarshallingVectorParcelableObj<ScreenInfo>(reply, screenInfos)) {
248e0dac50fSopenharmony_ci                WLOGE("fail to marshalling screenInfos in stub.");
249e0dac50fSopenharmony_ci            }
250e0dac50fSopenharmony_ci            break;
251e0dac50fSopenharmony_ci        }
252e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_ALL_DISPLAYIDS: {
253e0dac50fSopenharmony_ci            std::vector<DisplayId> allDisplayIds = GetAllDisplayIds();
254e0dac50fSopenharmony_ci            reply.WriteUInt64Vector(allDisplayIds);
255e0dac50fSopenharmony_ci            break;
256e0dac50fSopenharmony_ci        }
257e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND: {
258e0dac50fSopenharmony_ci            std::vector<ScreenId> screenId;
259e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&screenId)) {
260e0dac50fSopenharmony_ci                WLOGE("fail to receive expand screen in stub.");
261e0dac50fSopenharmony_ci                break;
262e0dac50fSopenharmony_ci            }
263e0dac50fSopenharmony_ci            std::vector<Point> startPoint;
264e0dac50fSopenharmony_ci            if (!MarshallingHelper::UnmarshallingVectorObj<Point>(data, startPoint, [](Parcel& parcel, Point& point) {
265e0dac50fSopenharmony_ci                    return parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_);
266e0dac50fSopenharmony_ci                })) {
267e0dac50fSopenharmony_ci                WLOGE("fail to receive startPoint in stub.");
268e0dac50fSopenharmony_ci                break;
269e0dac50fSopenharmony_ci            }
270e0dac50fSopenharmony_ci            ScreenId screenGroupId = INVALID_SCREEN_ID;
271e0dac50fSopenharmony_ci            DMError ret = MakeExpand(screenId, startPoint, screenGroupId);
272e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
273e0dac50fSopenharmony_ci            reply.WriteUint64(static_cast<uint64_t>(screenGroupId));
274e0dac50fSopenharmony_ci            break;
275e0dac50fSopenharmony_ci        }
276e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_REMOVE_VIRTUAL_SCREEN_FROM_SCREEN_GROUP: {
277e0dac50fSopenharmony_ci            std::vector<ScreenId> screenId;
278e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&screenId)) {
279e0dac50fSopenharmony_ci                WLOGE("fail to receive screens in stub.");
280e0dac50fSopenharmony_ci                break;
281e0dac50fSopenharmony_ci            }
282e0dac50fSopenharmony_ci            RemoveVirtualScreenFromGroup(screenId);
283e0dac50fSopenharmony_ci            break;
284e0dac50fSopenharmony_ci        }
285e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE: {
286e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
287e0dac50fSopenharmony_ci            uint32_t modeId = data.ReadUint32();
288e0dac50fSopenharmony_ci            DMError ret = SetScreenActiveMode(screenId, modeId);
289e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
290e0dac50fSopenharmony_ci            break;
291e0dac50fSopenharmony_ci        }
292e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO: {
293e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
294e0dac50fSopenharmony_ci            float virtualPixelRatio = data.ReadFloat();
295e0dac50fSopenharmony_ci            DMError ret = SetVirtualPixelRatio(screenId, virtualPixelRatio);
296e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
297e0dac50fSopenharmony_ci            break;
298e0dac50fSopenharmony_ci        }
299e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS: {
300e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
301e0dac50fSopenharmony_ci            std::vector<ScreenColorGamut> colorGamuts;
302e0dac50fSopenharmony_ci            DMError ret = GetScreenSupportedColorGamuts(screenId, colorGamuts);
303e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
304e0dac50fSopenharmony_ci            if (ret != DMError::DM_OK) {
305e0dac50fSopenharmony_ci                break;
306e0dac50fSopenharmony_ci            }
307e0dac50fSopenharmony_ci            MarshallingHelper::MarshallingVectorObj<ScreenColorGamut>(reply, colorGamuts,
308e0dac50fSopenharmony_ci                [](Parcel& parcel, const ScreenColorGamut& color) {
309e0dac50fSopenharmony_ci                    return parcel.WriteUint32(static_cast<uint32_t>(color));
310e0dac50fSopenharmony_ci                }
311e0dac50fSopenharmony_ci            );
312e0dac50fSopenharmony_ci            break;
313e0dac50fSopenharmony_ci        }
314e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_GET_COLOR_GAMUT: {
315e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
316e0dac50fSopenharmony_ci            ScreenColorGamut colorGamut;
317e0dac50fSopenharmony_ci            DMError ret = GetScreenColorGamut(screenId, colorGamut);
318e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
319e0dac50fSopenharmony_ci            if (ret != DMError::DM_OK) {
320e0dac50fSopenharmony_ci                break;
321e0dac50fSopenharmony_ci            }
322e0dac50fSopenharmony_ci            reply.WriteUint32(static_cast<uint32_t>(colorGamut));
323e0dac50fSopenharmony_ci            break;
324e0dac50fSopenharmony_ci        }
325e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_GAMUT: {
326e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
327e0dac50fSopenharmony_ci            int32_t colorGamutIdx = data.ReadInt32();
328e0dac50fSopenharmony_ci            DMError ret = SetScreenColorGamut(screenId, colorGamutIdx);
329e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
330e0dac50fSopenharmony_ci            break;
331e0dac50fSopenharmony_ci        }
332e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_GET_GAMUT_MAP: {
333e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
334e0dac50fSopenharmony_ci            ScreenGamutMap gamutMap;
335e0dac50fSopenharmony_ci            DMError ret = GetScreenGamutMap(screenId, gamutMap);
336e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
337e0dac50fSopenharmony_ci            if (ret != DMError::DM_OK) {
338e0dac50fSopenharmony_ci                break;
339e0dac50fSopenharmony_ci            }
340e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<uint32_t>(gamutMap));
341e0dac50fSopenharmony_ci            break;
342e0dac50fSopenharmony_ci        }
343e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_SET_GAMUT_MAP: {
344e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
345e0dac50fSopenharmony_ci            ScreenGamutMap gamutMap = static_cast<ScreenGamutMap>(data.ReadUint32());
346e0dac50fSopenharmony_ci            DMError ret = SetScreenGamutMap(screenId, gamutMap);
347e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
348e0dac50fSopenharmony_ci            break;
349e0dac50fSopenharmony_ci        }
350e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_SET_COLOR_TRANSFORM: {
351e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
352e0dac50fSopenharmony_ci            DMError ret = SetScreenColorTransform(screenId);
353e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
354e0dac50fSopenharmony_ci            break;
355e0dac50fSopenharmony_ci        }
356e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED: {
357e0dac50fSopenharmony_ci            bool isLocked = false;
358e0dac50fSopenharmony_ci            DMError ret = IsScreenRotationLocked(isLocked);
359e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
360e0dac50fSopenharmony_ci            reply.WriteBool(isLocked);
361e0dac50fSopenharmony_ci            break;
362e0dac50fSopenharmony_ci        }
363e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: {
364e0dac50fSopenharmony_ci            bool isLocked = static_cast<bool>(data.ReadBool());
365e0dac50fSopenharmony_ci            DMError ret = SetScreenRotationLocked(isLocked);
366e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
367e0dac50fSopenharmony_ci            break;
368e0dac50fSopenharmony_ci        }
369e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED_FROM_JS: {
370e0dac50fSopenharmony_ci            bool isLocked = static_cast<bool>(data.ReadBool());
371e0dac50fSopenharmony_ci            DMError ret = SetScreenRotationLockedFromJs(isLocked);
372e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
373e0dac50fSopenharmony_ci            break;
374e0dac50fSopenharmony_ci        }
375e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW: {
376e0dac50fSopenharmony_ci            DisplayId id = static_cast<DisplayId>(data.ReadUint64());
377e0dac50fSopenharmony_ci            bool hasPrivateWindow = false;
378e0dac50fSopenharmony_ci            DMError ret = HasPrivateWindow(id, hasPrivateWindow);
379e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
380e0dac50fSopenharmony_ci            reply.WriteBool(hasPrivateWindow);
381e0dac50fSopenharmony_ci            break;
382e0dac50fSopenharmony_ci        }
383e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_CUTOUT_INFO: {
384e0dac50fSopenharmony_ci            DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
385e0dac50fSopenharmony_ci            sptr<CutoutInfo> cutoutInfo = GetCutoutInfo(displayId);
386e0dac50fSopenharmony_ci            reply.WriteParcelable(cutoutInfo);
387e0dac50fSopenharmony_ci            break;
388e0dac50fSopenharmony_ci        }
389e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE: {
390e0dac50fSopenharmony_ci            DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
391e0dac50fSopenharmony_ci            std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
392e0dac50fSopenharmony_ci            auto ret = AddSurfaceNodeToDisplay(displayId, surfaceNode, true);
393e0dac50fSopenharmony_ci            reply.WriteUint32(static_cast<uint32_t>(ret));
394e0dac50fSopenharmony_ci            break;
395e0dac50fSopenharmony_ci        }
396e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE: {
397e0dac50fSopenharmony_ci            DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
398e0dac50fSopenharmony_ci            std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
399e0dac50fSopenharmony_ci            auto ret = RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
400e0dac50fSopenharmony_ci            reply.WriteUint32(static_cast<uint32_t>(ret));
401e0dac50fSopenharmony_ci            break;
402e0dac50fSopenharmony_ci        }
403e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_STOP_MIRROR: {
404e0dac50fSopenharmony_ci            std::vector<ScreenId> mirrorScreenIds;
405e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&mirrorScreenIds)) {
406e0dac50fSopenharmony_ci                WLOGE("fail to receive mirror screens in stub.");
407e0dac50fSopenharmony_ci                break;
408e0dac50fSopenharmony_ci            }
409e0dac50fSopenharmony_ci            DMError ret = StopMirror(mirrorScreenIds);
410e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
411e0dac50fSopenharmony_ci            break;
412e0dac50fSopenharmony_ci        }
413e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCREEN_STOP_EXPAND: {
414e0dac50fSopenharmony_ci            std::vector<ScreenId> expandScreenIds;
415e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&expandScreenIds)) {
416e0dac50fSopenharmony_ci                WLOGE("fail to receive expand screens in stub.");
417e0dac50fSopenharmony_ci                break;
418e0dac50fSopenharmony_ci            }
419e0dac50fSopenharmony_ci            DMError ret = StopExpand(expandScreenIds);
420e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
421e0dac50fSopenharmony_ci            break;
422e0dac50fSopenharmony_ci        }
423e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_RESIZE_VIRTUAL_SCREEN: {
424e0dac50fSopenharmony_ci            ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
425e0dac50fSopenharmony_ci            uint32_t width = data.ReadUint32();
426e0dac50fSopenharmony_ci            uint32_t height = data.ReadUint32();
427e0dac50fSopenharmony_ci            DMError ret = ResizeVirtualScreen(screenId, width, height);
428e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
429e0dac50fSopenharmony_ci            break;
430e0dac50fSopenharmony_ci        }
431e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN: {
432e0dac50fSopenharmony_ci            std::vector<ScreenId> uniqueScreenIds;
433e0dac50fSopenharmony_ci            uint32_t size = data.ReadUint32();
434e0dac50fSopenharmony_ci            if (size > MAX_SCREEN_SIZE) {
435e0dac50fSopenharmony_ci                WLOGFE("screenIds size is bigger than %{public}u", MAX_SCREEN_SIZE);
436e0dac50fSopenharmony_ci                break;
437e0dac50fSopenharmony_ci            }
438e0dac50fSopenharmony_ci            if (!data.ReadUInt64Vector(&uniqueScreenIds)) {
439e0dac50fSopenharmony_ci                WLOGFE("failed to receive unique screens in stub");
440e0dac50fSopenharmony_ci                break;
441e0dac50fSopenharmony_ci            }
442e0dac50fSopenharmony_ci            DMError ret = MakeUniqueScreen(uniqueScreenIds);
443e0dac50fSopenharmony_ci            reply.WriteInt32(static_cast<int32_t>(ret));
444e0dac50fSopenharmony_ci            break;
445e0dac50fSopenharmony_ci        }
446e0dac50fSopenharmony_ci        case DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION: {
447e0dac50fSopenharmony_ci            auto physicalInfos = GetAllDisplayPhysicalResolution();
448e0dac50fSopenharmony_ci            size_t infoSize = physicalInfos.size();
449e0dac50fSopenharmony_ci            bool writeRet = reply.WriteInt32(static_cast<int32_t>(infoSize));
450e0dac50fSopenharmony_ci            if (!writeRet) {
451e0dac50fSopenharmony_ci                WLOGFE("write physical size error");
452e0dac50fSopenharmony_ci                break;
453e0dac50fSopenharmony_ci            }
454e0dac50fSopenharmony_ci            for (const auto &physicalItem : physicalInfos) {
455e0dac50fSopenharmony_ci                writeRet = reply.WriteUint32(static_cast<uint32_t>(physicalItem.foldDisplayMode_));
456e0dac50fSopenharmony_ci                if (!writeRet) {
457e0dac50fSopenharmony_ci                    WLOGFE("write display mode error");
458e0dac50fSopenharmony_ci                    break;
459e0dac50fSopenharmony_ci                }
460e0dac50fSopenharmony_ci                writeRet = reply.WriteUint32(physicalItem.physicalWidth_);
461e0dac50fSopenharmony_ci                if (!writeRet) {
462e0dac50fSopenharmony_ci                    WLOGFE("write physical width error");
463e0dac50fSopenharmony_ci                    break;
464e0dac50fSopenharmony_ci                }
465e0dac50fSopenharmony_ci                writeRet = reply.WriteUint32(physicalItem.physicalHeight_);
466e0dac50fSopenharmony_ci                if (!writeRet) {
467e0dac50fSopenharmony_ci                    WLOGFE("write physical height error");
468e0dac50fSopenharmony_ci                    break;
469e0dac50fSopenharmony_ci                }
470e0dac50fSopenharmony_ci            }
471e0dac50fSopenharmony_ci            break;
472e0dac50fSopenharmony_ci        }
473e0dac50fSopenharmony_ci        default:
474e0dac50fSopenharmony_ci            WLOGFW("unknown transaction code");
475e0dac50fSopenharmony_ci            return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
476e0dac50fSopenharmony_ci    }
477e0dac50fSopenharmony_ci    return 0;
478e0dac50fSopenharmony_ci}
479e0dac50fSopenharmony_ci} // namespace OHOS::Rosen