1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "zidl/display_manager_agent_proxy.h"
17 #include <ipc_types.h>
18 #include "dm_common.h"
19 #include "marshalling_helper.h"
20 #include "window_manager_hilog.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentProxy"};
26 }
27
NotifyDisplayPowerEvent(DisplayPowerEvent event,EventStatus status)28 void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 WLOGFE("WriteInterfaceToken failed");
35 return;
36 }
37
38 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
39 WLOGFE("Write event failed");
40 return;
41 }
42
43 if (!data.WriteUint32(static_cast<uint32_t>(status))) {
44 WLOGFE("Write status failed");
45 return;
46 }
47
48 if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT, data, reply, option) != ERR_NONE) {
49 WLOGFE("SendRequest failed");
50 }
51 }
52
NotifyDisplayStateChanged(DisplayId id,DisplayState state)53 void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
54 {
55 MessageParcel data;
56 MessageParcel reply;
57 MessageOption option;
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 WLOGFE("WriteInterfaceToken failed");
60 return;
61 }
62
63 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
64 WLOGFE("Write DisplayState failed");
65 return;
66 }
67
68 if (!data.WriteUint64(static_cast<uint64_t>(id))) {
69 WLOGFE("Write displayId failed");
70 return;
71 }
72
73 if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) {
74 WLOGFE("SendRequest failed");
75 }
76 }
77
OnScreenConnect(sptr<ScreenInfo> screenInfo)78 void DisplayManagerAgentProxy::OnScreenConnect(sptr<ScreenInfo> screenInfo)
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option(MessageOption::TF_ASYNC);
83 if (!data.WriteInterfaceToken(GetDescriptor())) {
84 WLOGFE("WriteInterfaceToken failed");
85 return;
86 }
87
88 if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
89 WLOGFE("Write ScreenInfo failed");
90 return;
91 }
92
93 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CONNECT, data, reply, option) != ERR_NONE) {
94 WLOGFE("SendRequest failed");
95 }
96 }
97
OnScreenDisconnect(ScreenId screenId)98 void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
99 {
100 MessageParcel data;
101 MessageParcel reply;
102 MessageOption option(MessageOption::TF_ASYNC);
103 if (!data.WriteInterfaceToken(GetDescriptor())) {
104 WLOGFE("WriteInterfaceToken failed");
105 return;
106 }
107
108 if (!data.WriteUint64(screenId)) {
109 WLOGFE("Write ScreenId failed");
110 return;
111 }
112
113 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_DISCONNECT, data, reply, option) != ERR_NONE) {
114 WLOGFE("SendRequest failed");
115 }
116 }
117
OnScreenChange(const sptr<ScreenInfo> & screenInfo,ScreenChangeEvent event)118 void DisplayManagerAgentProxy::OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
119 {
120 MessageParcel data;
121 MessageParcel reply;
122 MessageOption option(MessageOption::TF_ASYNC);
123 if (!data.WriteInterfaceToken(GetDescriptor())) {
124 WLOGFE("WriteInterfaceToken failed");
125 return;
126 }
127
128 if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
129 WLOGFE("Write screenInfo failed");
130 return;
131 }
132
133 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
134 WLOGFE("Write ScreenChangeEvent failed");
135 return;
136 }
137
138 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
139 WLOGFE("SendRequest failed");
140 }
141 }
142
OnScreenGroupChange(const std::string & trigger,const std::vector<sptr<ScreenInfo>> & screenInfos,ScreenGroupChangeEvent event)143 void DisplayManagerAgentProxy::OnScreenGroupChange(const std::string& trigger,
144 const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent event)
145 {
146 MessageParcel data;
147 MessageParcel reply;
148 MessageOption option(MessageOption::TF_ASYNC);
149 if (!data.WriteInterfaceToken(GetDescriptor())) {
150 WLOGFE("WriteInterfaceToken failed");
151 return;
152 }
153
154 if (!data.WriteString(trigger)) {
155 WLOGFE("Write trigger failed");
156 return;
157 }
158
159 if (!MarshallingHelper::MarshallingVectorParcelableObj<ScreenInfo>(data, screenInfos)) {
160 WLOGFE("Write screenInfos failed");
161 return;
162 }
163
164 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
165 WLOGFE("Write ScreenGroupChangeEvent failed");
166 return;
167 }
168
169 if (Remote()->SendRequest(TRANS_ID_ON_SCREENGROUP_CHANGED, data, reply, option) != ERR_NONE) {
170 WLOGFE("SendRequest failed");
171 }
172 }
173
OnDisplayCreate(sptr<DisplayInfo> displayInfo)174 void DisplayManagerAgentProxy::OnDisplayCreate(sptr<DisplayInfo> displayInfo)
175 {
176 MessageParcel data;
177 MessageParcel reply;
178 MessageOption option(MessageOption::TF_ASYNC);
179 if (!data.WriteInterfaceToken(GetDescriptor())) {
180 WLOGFE("WriteInterfaceToken failed");
181 return;
182 }
183
184 if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
185 WLOGFE("Write DisplayInfo failed");
186 return;
187 }
188
189 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CONNECT, data, reply, option) != ERR_NONE) {
190 WLOGFE("SendRequest failed");
191 }
192 }
193
OnDisplayDestroy(DisplayId displayId)194 void DisplayManagerAgentProxy::OnDisplayDestroy(DisplayId displayId)
195 {
196 MessageParcel data;
197 MessageParcel reply;
198 MessageOption option(MessageOption::TF_ASYNC);
199 if (!data.WriteInterfaceToken(GetDescriptor())) {
200 WLOGFE("WriteInterfaceToken failed");
201 return;
202 }
203
204 if (!data.WriteUint64(displayId)) {
205 WLOGFE("Write DisplayId failed");
206 return;
207 }
208
209 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_DISCONNECT, data, reply, option) != ERR_NONE) {
210 WLOGFE("SendRequest failed");
211 }
212 }
213
OnDisplayChange(sptr<DisplayInfo> displayInfo,DisplayChangeEvent event)214 void DisplayManagerAgentProxy::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event)
215 {
216 MessageParcel data;
217 MessageParcel reply;
218 MessageOption option(MessageOption::TF_ASYNC);
219 if (!data.WriteInterfaceToken(GetDescriptor())) {
220 WLOGFE("WriteInterfaceToken failed");
221 return;
222 }
223
224 if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
225 WLOGFE("Write DisplayInfo failed");
226 return;
227 }
228
229 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
230 WLOGFE("Write DisplayChangeEvent failed");
231 return;
232 }
233
234 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CHANGED, data, reply, option) != ERR_NONE) {
235 WLOGFE("SendRequest failed");
236 }
237 }
238
OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)239 void DisplayManagerAgentProxy::OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)
240 {
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option(MessageOption::TF_ASYNC);
244 if (!data.WriteInterfaceToken(GetDescriptor())) {
245 WLOGFE("WriteInterfaceToken failed");
246 return;
247 }
248 if (!data.WriteParcelable(snapshotInfo.GetRefPtr())) {
249 WLOGFE("Write ScreenshotInfo failed");
250 return;
251 }
252 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_SHOT, data, reply, option) != ERR_NONE) {
253 WLOGFE("SendRequest failed");
254 }
255 }
256
NotifyPrivateWindowStateChanged(bool hasPrivate)257 void DisplayManagerAgentProxy::NotifyPrivateWindowStateChanged(bool hasPrivate)
258 {
259 MessageParcel data;
260 MessageParcel reply;
261 MessageOption option(MessageOption::TF_ASYNC);
262 if (!data.WriteInterfaceToken(GetDescriptor())) {
263 WLOGFE("WriteInterfaceToken failed");
264 return;
265 }
266 if (!data.WriteBool(hasPrivate)) {
267 WLOGFE("Write private info failed");
268 return;
269 }
270 if (Remote()->SendRequest(TRANS_ID_ON_PRIVATE_WINDOW, data, reply, option) != ERR_NONE) {
271 WLOGFE("SendRequest failed");
272 }
273 }
274
NotifyFoldStatusChanged(FoldStatus foldStatus)275 void DisplayManagerAgentProxy::NotifyFoldStatusChanged(FoldStatus foldStatus)
276 {
277 MessageParcel data;
278 MessageParcel reply;
279 MessageOption option(MessageOption::TF_ASYNC);
280 if (!data.WriteInterfaceToken(GetDescriptor())) {
281 WLOGFE("WriteInterfaceToken failed");
282 return;
283 }
284 if (!data.WriteUint32(static_cast<uint32_t>(foldStatus))) {
285 WLOGFE("Write foldStatus failed");
286 return;
287 }
288 if (Remote()->SendRequest(TRANS_ID_ON_FOLD_STATUS_CHANGED, data, reply, option) != ERR_NONE) {
289 WLOGFE("SendRequest failed");
290 }
291 }
292
NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo> & info)293 void DisplayManagerAgentProxy::NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info)
294 {
295 MessageParcel data;
296 MessageParcel reply;
297 MessageOption option(MessageOption::TF_ASYNC);
298 if (!data.WriteInterfaceToken(GetDescriptor())) {
299 WLOGFE("WriteInterfaceToken failed");
300 return;
301 }
302 if (!info->Marshalling(data)) {
303 WLOGFE("Write display change info failed");
304 return;
305 }
306 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CHANGE_INFO_CHANGED, data, reply, option) != ERR_NONE) {
307 WLOGFE("SendRequest failed");
308 }
309 }
310
NotifyDisplayModeChanged(FoldDisplayMode displayMode)311 void DisplayManagerAgentProxy::NotifyDisplayModeChanged(FoldDisplayMode displayMode)
312 {
313 MessageParcel data;
314 MessageParcel reply;
315 MessageOption option(MessageOption::TF_ASYNC);
316 if (!data.WriteInterfaceToken(GetDescriptor())) {
317 WLOGFE("WriteInterfaceToken failed");
318 return;
319 }
320 if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
321 WLOGFE("Write displayMode failed");
322 return;
323 }
324 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_MODE_CHANGED, data, reply, option) != ERR_NONE) {
325 WLOGFE("SendRequest failed");
326 }
327 }
328
NotifyAvailableAreaChanged(DMRect area)329 void DisplayManagerAgentProxy::NotifyAvailableAreaChanged(DMRect area)
330 {
331 MessageParcel data;
332 MessageParcel reply;
333 MessageOption option(MessageOption::TF_ASYNC);
334 if (!data.WriteInterfaceToken(GetDescriptor())) {
335 WLOGFE("WriteInterfaceToken failed");
336 return;
337 }
338 if (!data.WriteInt32(area.posX_) || !data.WriteInt32(area.posY_) || !data.WriteUint32(area.width_)
339 ||!data.WriteUint32(area.height_)) {
340 WLOGFE("Write rect failed");
341 return;
342 }
343 if (Remote()->SendRequest(TRANS_ID_ON_AVAILABLE_AREA_CHANGED, data, reply, option) != ERR_NONE) {
344 WLOGFE("SendRequest failed");
345 }
346 }
347 } // namespace Rosen
348 } // namespace OHOS
349
350