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 "marshalling_helper.h"
19 #include "window_manager_hilog.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentProxy"};
25 }
26
NotifyDisplayPowerEvent(DisplayPowerEvent event,EventStatus status)27 void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
28 {
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option(MessageOption::TF_ASYNC);
32 if (!data.WriteInterfaceToken(GetDescriptor())) {
33 WLOGFE("WriteInterfaceToken failed");
34 return;
35 }
36
37 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
38 WLOGFE("Write event failed");
39 return;
40 }
41
42 if (!data.WriteUint32(static_cast<uint32_t>(status))) {
43 WLOGFE("Write status failed");
44 return;
45 }
46
47 if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT, data, reply, option) != ERR_NONE) {
48 WLOGFE("SendRequest failed");
49 }
50 }
51
NotifyDisplayStateChanged(DisplayId id,DisplayState state)52 void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option(MessageOption::TF_ASYNC);
57 if (!data.WriteInterfaceToken(GetDescriptor())) {
58 WLOGFE("WriteInterfaceToken failed");
59 return;
60 }
61
62 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
63 WLOGFE("Write DisplayState failed");
64 return;
65 }
66
67 if (!data.WriteUint64(static_cast<uint64_t>(id))) {
68 WLOGFE("Write displayId failed");
69 return;
70 }
71
72 if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) {
73 WLOGFE("SendRequest failed");
74 }
75 }
76
OnScreenConnect(sptr<ScreenInfo> screenInfo)77 void DisplayManagerAgentProxy::OnScreenConnect(sptr<ScreenInfo> screenInfo)
78 {
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option(MessageOption::TF_ASYNC);
82 if (!data.WriteInterfaceToken(GetDescriptor())) {
83 WLOGFE("WriteInterfaceToken failed");
84 return;
85 }
86
87 if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
88 WLOGFE("Write ScreenInfo failed");
89 return;
90 }
91
92 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CONNECT, data, reply, option) != ERR_NONE) {
93 WLOGFE("SendRequest failed");
94 }
95 }
96
OnScreenDisconnect(ScreenId screenId)97 void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
98 {
99 MessageParcel data;
100 MessageParcel reply;
101 MessageOption option(MessageOption::TF_ASYNC);
102 if (!data.WriteInterfaceToken(GetDescriptor())) {
103 WLOGFE("WriteInterfaceToken failed");
104 return;
105 }
106
107 if (!data.WriteUint64(screenId)) {
108 WLOGFE("Write ScreenId failed");
109 return;
110 }
111
112 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_DISCONNECT, data, reply, option) != ERR_NONE) {
113 WLOGFE("SendRequest failed");
114 }
115 }
116
OnScreenChange(const sptr<ScreenInfo> & screenInfo,ScreenChangeEvent event)117 void DisplayManagerAgentProxy::OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
118 {
119 MessageParcel data;
120 MessageParcel reply;
121 MessageOption option(MessageOption::TF_ASYNC);
122 if (!data.WriteInterfaceToken(GetDescriptor())) {
123 WLOGFE("WriteInterfaceToken failed");
124 return;
125 }
126
127 if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
128 WLOGFE("Write screenInfo failed");
129 return;
130 }
131
132 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
133 WLOGFE("Write ScreenChangeEvent failed");
134 return;
135 }
136
137 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
138 WLOGFE("SendRequest failed");
139 }
140 }
141
OnScreenGroupChange(const std::string & trigger,const std::vector<sptr<ScreenInfo>> & screenInfos,ScreenGroupChangeEvent event)142 void DisplayManagerAgentProxy::OnScreenGroupChange(const std::string& trigger,
143 const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent event)
144 {
145 MessageParcel data;
146 MessageParcel reply;
147 MessageOption option(MessageOption::TF_ASYNC);
148 if (!data.WriteInterfaceToken(GetDescriptor())) {
149 WLOGFE("WriteInterfaceToken failed");
150 return;
151 }
152
153 if (!data.WriteString(trigger)) {
154 WLOGFE("Write trigger failed");
155 return;
156 }
157
158 if (!MarshallingHelper::MarshallingVectorParcelableObj<ScreenInfo>(data, screenInfos)) {
159 WLOGFE("Write screenInfos failed");
160 return;
161 }
162
163 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
164 WLOGFE("Write ScreenGroupChangeEvent failed");
165 return;
166 }
167
168 if (Remote()->SendRequest(TRANS_ID_ON_SCREENGROUP_CHANGED, data, reply, option) != ERR_NONE) {
169 WLOGFE("SendRequest failed");
170 }
171 }
172
OnDisplayCreate(sptr<DisplayInfo> displayInfo)173 void DisplayManagerAgentProxy::OnDisplayCreate(sptr<DisplayInfo> displayInfo)
174 {
175 MessageParcel data;
176 MessageParcel reply;
177 MessageOption option(MessageOption::TF_ASYNC);
178 if (!data.WriteInterfaceToken(GetDescriptor())) {
179 WLOGFE("WriteInterfaceToken failed");
180 return;
181 }
182
183 if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
184 WLOGFE("Write DisplayInfo failed");
185 return;
186 }
187
188 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CONNECT, data, reply, option) != ERR_NONE) {
189 WLOGFE("SendRequest failed");
190 }
191 }
192
OnDisplayDestroy(DisplayId displayId)193 void DisplayManagerAgentProxy::OnDisplayDestroy(DisplayId displayId)
194 {
195 MessageParcel data;
196 MessageParcel reply;
197 MessageOption option(MessageOption::TF_ASYNC);
198 if (!data.WriteInterfaceToken(GetDescriptor())) {
199 WLOGFE("WriteInterfaceToken failed");
200 return;
201 }
202
203 if (!data.WriteUint64(displayId)) {
204 WLOGFE("Write DisplayId failed");
205 return;
206 }
207
208 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_DISCONNECT, data, reply, option) != ERR_NONE) {
209 WLOGFE("SendRequest failed");
210 }
211 }
212
OnDisplayChange(sptr<DisplayInfo> displayInfo,DisplayChangeEvent event)213 void DisplayManagerAgentProxy::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event)
214 {
215 MessageParcel data;
216 MessageParcel reply;
217 MessageOption option(MessageOption::TF_ASYNC);
218 if (!data.WriteInterfaceToken(GetDescriptor())) {
219 WLOGFE("WriteInterfaceToken failed");
220 return;
221 }
222
223 if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
224 WLOGFE("Write DisplayInfo failed");
225 return;
226 }
227
228 if (!data.WriteUint32(static_cast<uint32_t>(event))) {
229 WLOGFE("Write DisplayChangeEvent failed");
230 return;
231 }
232
233 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CHANGED, data, reply, option) != ERR_NONE) {
234 WLOGFE("SendRequest failed");
235 }
236 }
237
OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)238 void DisplayManagerAgentProxy::OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)
239 {
240 MessageParcel data;
241 MessageParcel reply;
242 MessageOption option(MessageOption::TF_ASYNC);
243 if (!data.WriteInterfaceToken(GetDescriptor())) {
244 WLOGFE("WriteInterfaceToken failed");
245 return;
246 }
247 if (!data.WriteParcelable(snapshotInfo.GetRefPtr())) {
248 WLOGFE("Write ScreenshotInfo failed");
249 return;
250 }
251 if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_SHOT, data, reply, option) != ERR_NONE) {
252 WLOGFE("SendRequest failed");
253 }
254 }
255
NotifyPrivateWindowStateChanged(bool hasPrivate)256 void DisplayManagerAgentProxy::NotifyPrivateWindowStateChanged(bool hasPrivate)
257 {
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option(MessageOption::TF_ASYNC);
261 if (!data.WriteInterfaceToken(GetDescriptor())) {
262 WLOGFE("WriteInterfaceToken failed");
263 return;
264 }
265 if (!data.WriteBool(hasPrivate)) {
266 WLOGFE("Write private info failed");
267 return;
268 }
269 if (Remote()->SendRequest(TRANS_ID_ON_PRIVATE_WINDOW, data, reply, option) != ERR_NONE) {
270 WLOGFE("SendRequest failed");
271 }
272 }
273
NotifyFoldStatusChanged(FoldStatus foldStatus)274 void DisplayManagerAgentProxy::NotifyFoldStatusChanged(FoldStatus foldStatus)
275 {
276 MessageParcel data;
277 MessageParcel reply;
278 MessageOption option(MessageOption::TF_ASYNC);
279 if (!data.WriteInterfaceToken(GetDescriptor())) {
280 WLOGFE("WriteInterfaceToken failed");
281 return;
282 }
283 if (!data.WriteUint32(static_cast<uint32_t>(foldStatus))) {
284 WLOGFE("Write foldStatus failed");
285 return;
286 }
287 if (Remote()->SendRequest(TRANS_ID_ON_FOLD_STATUS_CHANGED, data, reply, option) != ERR_NONE) {
288 WLOGFE("SendRequest failed");
289 }
290 }
291
NotifyDisplayModeChanged(FoldDisplayMode displayMode)292 void DisplayManagerAgentProxy::NotifyDisplayModeChanged(FoldDisplayMode displayMode)
293 {
294 MessageParcel data;
295 MessageParcel reply;
296 MessageOption option(MessageOption::TF_ASYNC);
297 if (!data.WriteInterfaceToken(GetDescriptor())) {
298 WLOGFE("WriteInterfaceToken failed");
299 return;
300 }
301 if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
302 WLOGFE("Write displayMode failed");
303 return;
304 }
305 if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_MODE_CHANGED, data, reply, option) != ERR_NONE) {
306 WLOGFE("SendRequest failed");
307 }
308 }
309 } // namespace Rosen
310 } // namespace OHOS
311
312