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 
18 #include <ipc_types.h>
19 
20 #include "dm_common.h"
21 #include "marshalling_helper.h"
22 #include "window_manager_hilog.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentProxy"};
28 }
29 
NotifyDisplayPowerEvent(DisplayPowerEvent event,EventStatus status)30 void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
31 {
32     sptr<IRemoteObject> remote = Remote();
33     if (remote == nullptr) {
34         WLOGFW("NotifyDisplayPowerEvent: remote is nullptr");
35         return;
36     }
37 
38     MessageParcel data;
39     MessageParcel reply;
40     MessageOption option;
41     if (!data.WriteInterfaceToken(GetDescriptor())) {
42         WLOGFE("WriteInterfaceToken failed");
43         return;
44     }
45 
46     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
47         WLOGFE("Write event failed");
48         return;
49     }
50 
51     if (!data.WriteUint32(static_cast<uint32_t>(status))) {
52         WLOGFE("Write status failed");
53         return;
54     }
55 
56     if (remote->SendRequest(TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT, data, reply, option) != ERR_NONE) {
57         WLOGFE("SendRequest failed");
58     }
59 }
60 
NotifyDisplayStateChanged(DisplayId id,DisplayState state)61 void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
62 {
63     sptr<IRemoteObject> remote = Remote();
64     if (remote == nullptr) {
65         WLOGFW("NotifyDisplayStateChanged: remote is nullptr");
66         return;
67     }
68 
69     MessageParcel data;
70     MessageParcel reply;
71     MessageOption option;
72     if (!data.WriteInterfaceToken(GetDescriptor())) {
73         WLOGFE("WriteInterfaceToken failed");
74         return;
75     }
76 
77     if (!data.WriteUint32(static_cast<uint32_t>(state))) {
78         WLOGFE("Write DisplayState failed");
79         return;
80     }
81 
82     if (!data.WriteUint64(static_cast<uint64_t>(id))) {
83         WLOGFE("Write displayId failed");
84         return;
85     }
86 
87     if (remote->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) {
88         WLOGFE("SendRequest failed");
89     }
90 }
91 
OnScreenConnect(sptr<ScreenInfo> screenInfo)92 void DisplayManagerAgentProxy::OnScreenConnect(sptr<ScreenInfo> screenInfo)
93 {
94     sptr<IRemoteObject> remote = Remote();
95     if (remote == nullptr) {
96         WLOGFW("OnScreenConnect: remote is nullptr");
97         return;
98     }
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.WriteParcelable(screenInfo.GetRefPtr())) {
109         WLOGFE("Write ScreenInfo failed");
110         return;
111     }
112 
113     if (remote->SendRequest(TRANS_ID_ON_SCREEN_CONNECT, data, reply, option) != ERR_NONE) {
114         WLOGFE("SendRequest failed");
115     }
116 }
117 
OnScreenDisconnect(ScreenId screenId)118 void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
119 {
120     sptr<IRemoteObject> remote = Remote();
121     if (remote == nullptr) {
122         WLOGFW("OnScreenDisconnect: remote is nullptr");
123         return;
124     }
125 
126     MessageParcel data;
127     MessageParcel reply;
128     MessageOption option(MessageOption::TF_ASYNC);
129     if (!data.WriteInterfaceToken(GetDescriptor())) {
130         WLOGFE("WriteInterfaceToken failed");
131         return;
132     }
133 
134     if (!data.WriteUint64(screenId)) {
135         WLOGFE("Write ScreenId failed");
136         return;
137     }
138 
139     if (remote->SendRequest(TRANS_ID_ON_SCREEN_DISCONNECT, data, reply, option) != ERR_NONE) {
140         WLOGFE("SendRequest failed");
141     }
142 }
143 
OnScreenChange(const sptr<ScreenInfo> & screenInfo,ScreenChangeEvent event)144 void DisplayManagerAgentProxy::OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
145 {
146     sptr<IRemoteObject> remote = Remote();
147     if (remote == nullptr) {
148         WLOGFW("OnScreenChange: remote is nullptr");
149         return;
150     }
151 
152     MessageParcel data;
153     MessageParcel reply;
154     MessageOption option(MessageOption::TF_ASYNC);
155     if (!data.WriteInterfaceToken(GetDescriptor())) {
156         WLOGFE("WriteInterfaceToken failed");
157         return;
158     }
159 
160     if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
161         WLOGFE("Write screenInfo failed");
162         return;
163     }
164 
165     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
166         WLOGFE("Write ScreenChangeEvent failed");
167         return;
168     }
169 
170     if (remote->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
171         WLOGFE("SendRequest failed");
172     }
173 }
174 
OnScreenGroupChange(const std::string & trigger,const std::vector<sptr<ScreenInfo>> & screenInfos,ScreenGroupChangeEvent event)175 void DisplayManagerAgentProxy::OnScreenGroupChange(const std::string& trigger,
176     const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent event)
177 {
178     sptr<IRemoteObject> remote = Remote();
179     if (remote == nullptr) {
180         WLOGFW("OnScreenGroupChange: remote is nullptr");
181         return;
182     }
183 
184     MessageParcel data;
185     MessageParcel reply;
186     MessageOption option(MessageOption::TF_ASYNC);
187     if (!data.WriteInterfaceToken(GetDescriptor())) {
188         WLOGFE("WriteInterfaceToken failed");
189         return;
190     }
191 
192     if (!data.WriteString(trigger)) {
193         WLOGFE("Write trigger failed");
194         return;
195     }
196 
197     if (!MarshallingHelper::MarshallingVectorParcelableObj<ScreenInfo>(data, screenInfos)) {
198         WLOGFE("Write screenInfos failed");
199         return;
200     }
201 
202     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
203         WLOGFE("Write ScreenGroupChangeEvent failed");
204         return;
205     }
206 
207     if (remote->SendRequest(TRANS_ID_ON_SCREENGROUP_CHANGED, data, reply, option) != ERR_NONE) {
208         WLOGFE("SendRequest failed");
209     }
210 }
211 
OnDisplayCreate(sptr<DisplayInfo> displayInfo)212 void DisplayManagerAgentProxy::OnDisplayCreate(sptr<DisplayInfo> displayInfo)
213 {
214     sptr<IRemoteObject> remote = Remote();
215     if (remote == nullptr) {
216         WLOGFW("OnDisplayCreate: remote is nullptr");
217         return;
218     }
219 
220     MessageParcel data;
221     MessageParcel reply;
222     MessageOption option(MessageOption::TF_ASYNC);
223     if (!data.WriteInterfaceToken(GetDescriptor())) {
224         WLOGFE("WriteInterfaceToken failed");
225         return;
226     }
227 
228     if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
229         WLOGFE("Write DisplayInfo failed");
230         return;
231     }
232 
233     if (remote->SendRequest(TRANS_ID_ON_DISPLAY_CONNECT, data, reply, option) != ERR_NONE) {
234         WLOGFE("SendRequest failed");
235     }
236 }
237 
OnDisplayDestroy(DisplayId displayId)238 void DisplayManagerAgentProxy::OnDisplayDestroy(DisplayId displayId)
239 {
240     sptr<IRemoteObject> remote = Remote();
241     if (remote == nullptr) {
242         WLOGFW("OnDisplayDestroy: remote is nullptr");
243         return;
244     }
245 
246     MessageParcel data;
247     MessageParcel reply;
248     MessageOption option(MessageOption::TF_ASYNC);
249     if (!data.WriteInterfaceToken(GetDescriptor())) {
250         WLOGFE("WriteInterfaceToken failed");
251         return;
252     }
253 
254     if (!data.WriteUint64(displayId)) {
255         WLOGFE("Write DisplayId failed");
256         return;
257     }
258 
259     if (remote->SendRequest(TRANS_ID_ON_DISPLAY_DISCONNECT, data, reply, option) != ERR_NONE) {
260         WLOGFE("SendRequest failed");
261     }
262 }
263 
OnDisplayChange(sptr<DisplayInfo> displayInfo,DisplayChangeEvent event)264 void DisplayManagerAgentProxy::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event)
265 {
266     sptr<IRemoteObject> remote = Remote();
267     if (remote == nullptr) {
268         WLOGFW("OnDisplayChange: remote is nullptr");
269         return;
270     }
271 
272     MessageParcel data;
273     MessageParcel reply;
274     MessageOption option(MessageOption::TF_ASYNC);
275     if (!data.WriteInterfaceToken(GetDescriptor())) {
276         WLOGFE("WriteInterfaceToken failed");
277         return;
278     }
279 
280     if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
281         WLOGFE("Write DisplayInfo failed");
282         return;
283     }
284 
285     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
286         WLOGFE("Write DisplayChangeEvent failed");
287         return;
288     }
289 
290     if (remote->SendRequest(TRANS_ID_ON_DISPLAY_CHANGED, data, reply, option) != ERR_NONE) {
291         WLOGFE("SendRequest failed");
292     }
293 }
294 
OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)295 void DisplayManagerAgentProxy::OnScreenshot(sptr<ScreenshotInfo> snapshotInfo)
296 {
297     sptr<IRemoteObject> remote = Remote();
298     if (remote == nullptr) {
299         WLOGFW("OnScreenshot: remote is nullptr");
300         return;
301     }
302 
303     MessageParcel data;
304     MessageParcel reply;
305     MessageOption option(MessageOption::TF_ASYNC);
306     if (!data.WriteInterfaceToken(GetDescriptor())) {
307         WLOGFE("WriteInterfaceToken failed");
308         return;
309     }
310     if (!data.WriteParcelable(snapshotInfo.GetRefPtr())) {
311         WLOGFE("Write ScreenshotInfo failed");
312         return;
313     }
314     if (remote->SendRequest(TRANS_ID_ON_SCREEN_SHOT, data, reply, option) != ERR_NONE) {
315         WLOGFE("SendRequest failed");
316     }
317 }
318 
NotifyPrivateWindowStateChanged(bool hasPrivate)319 void DisplayManagerAgentProxy::NotifyPrivateWindowStateChanged(bool hasPrivate)
320 {
321     sptr<IRemoteObject> remote = Remote();
322     if (remote == nullptr) {
323         WLOGFW("NotifyPrivateWindowStateChanged: remote is nullptr");
324         return;
325     }
326 
327     MessageParcel data;
328     MessageParcel reply;
329     MessageOption option(MessageOption::TF_ASYNC);
330     if (!data.WriteInterfaceToken(GetDescriptor())) {
331         WLOGFE("WriteInterfaceToken failed");
332         return;
333     }
334     if (!data.WriteBool(hasPrivate)) {
335         WLOGFE("Write private info failed");
336         return;
337     }
338     if (remote->SendRequest(TRANS_ID_ON_PRIVATE_WINDOW, data, reply, option) != ERR_NONE) {
339         WLOGFE("SendRequest failed");
340     }
341 }
342 
NotifyPrivateStateWindowListChanged(DisplayId id,std::vector<std::string> privacyWindowList)343 void DisplayManagerAgentProxy::NotifyPrivateStateWindowListChanged(DisplayId id,
344     std::vector<std::string> privacyWindowList)
345 {
346     sptr<IRemoteObject> remote = Remote();
347     if (remote == nullptr) {
348         WLOGFW("NotifyPrivateStateWindowListChanged: remote is nullptr");
349         return;
350     }
351 
352     MessageParcel data;
353     MessageParcel reply;
354     MessageOption option(MessageOption::TF_ASYNC);
355     if (!data.WriteInterfaceToken(GetDescriptor())) {
356         WLOGFE("WriteInterfaceToken failed");
357         return;
358     }
359     if (!data.WriteUint64(id)) {
360         WLOGFE("Write DisplayId failed");
361         return;
362     }
363     if (!data.WriteStringVector(privacyWindowList)) {
364         WLOGFE("Write privacyWindowList failed");
365         return;
366     }
367     if (remote->SendRequest(TRANS_ID_ON_PRIVATE_WINDOW_LIST, data, reply, option) != ERR_NONE) {
368         WLOGFE("SendRequest failed");
369     }
370 }
371 
NotifyFoldStatusChanged(FoldStatus foldStatus)372 void DisplayManagerAgentProxy::NotifyFoldStatusChanged(FoldStatus foldStatus)
373 {
374     sptr<IRemoteObject> remote = Remote();
375     if (remote == nullptr) {
376         WLOGFW("NotifyFoldStatusChanged: remote is nullptr");
377         return;
378     }
379 
380     MessageParcel data;
381     MessageParcel reply;
382     MessageOption option(MessageOption::TF_ASYNC);
383     if (!data.WriteInterfaceToken(GetDescriptor())) {
384         WLOGFE("WriteInterfaceToken failed");
385         return;
386     }
387     if (!data.WriteUint32(static_cast<uint32_t>(foldStatus))) {
388         WLOGFE("Write foldStatus failed");
389         return;
390     }
391     if (remote->SendRequest(TRANS_ID_ON_FOLD_STATUS_CHANGED, data, reply, option) != ERR_NONE) {
392         WLOGFE("SendRequest failed");
393     }
394 }
395 
NotifyFoldAngleChanged(std::vector<float> foldAngles)396 void DisplayManagerAgentProxy::NotifyFoldAngleChanged(std::vector<float> foldAngles)
397 {
398     sptr<IRemoteObject> remote = Remote();
399     if (remote == nullptr) {
400         WLOGFW("NotifyFoldAngleChanged: remote is nullptr");
401         return;
402     }
403 
404     MessageParcel data;
405     MessageParcel reply;
406     MessageOption option(MessageOption::TF_ASYNC);
407     if (!data.WriteInterfaceToken(GetDescriptor())) {
408         WLOGFE("WriteInterfaceToken failed");
409         return;
410     }
411     if (!data.WriteFloatVector(foldAngles)) {
412         WLOGFE("Write foldAngles failed");
413         return;
414     }
415     if (remote->SendRequest(TRANS_ID_ON_FOLD_ANGLE_CHANGED, data, reply, option) != ERR_NONE) {
416         WLOGFE("SendRequest failed");
417     }
418 }
419 
NotifyCaptureStatusChanged(bool isCapture)420 void DisplayManagerAgentProxy::NotifyCaptureStatusChanged(bool isCapture)
421 {
422     sptr<IRemoteObject> remote = Remote();
423     if (remote == nullptr) {
424         WLOGFW("NotifyCaptureStatusChanged: remote is nullptr");
425         return;
426     }
427 
428     MessageParcel data;
429     MessageParcel reply;
430     MessageOption option(MessageOption::TF_ASYNC);
431     if (!data.WriteInterfaceToken(GetDescriptor())) {
432         WLOGFE("WriteInterfaceToken failed");
433         return;
434     }
435     if (!data.WriteBool(isCapture)) {
436         WLOGFE("Write isCapture failed");
437         return;
438     }
439     if (remote->SendRequest(TRANS_ID_ON_CAPTURE_STATUS_CHANGED, data, reply, option) != ERR_NONE) {
440         WLOGFE("SendRequest failed");
441     }
442 }
443 
NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo> & info)444 void DisplayManagerAgentProxy::NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info)
445 {
446     sptr<IRemoteObject> remote = Remote();
447     if (remote == nullptr) {
448         WLOGFW("NotifyDisplayChangeInfoChanged: remote is nullptr");
449         return;
450     }
451 
452     MessageParcel data;
453     MessageParcel reply;
454     MessageOption option(MessageOption::TF_ASYNC);
455     if (!data.WriteInterfaceToken(GetDescriptor())) {
456         WLOGFE("WriteInterfaceToken failed");
457         return;
458     }
459     if (!info->Marshalling(data)) {
460         WLOGFE("Write display change info failed");
461         return;
462     }
463     if (remote->SendRequest(TRANS_ID_ON_DISPLAY_CHANGE_INFO_CHANGED, data, reply, option) != ERR_NONE) {
464         WLOGFE("SendRequest failed");
465     }
466 }
467 
NotifyDisplayModeChanged(FoldDisplayMode displayMode)468 void DisplayManagerAgentProxy::NotifyDisplayModeChanged(FoldDisplayMode displayMode)
469 {
470     sptr<IRemoteObject> remote = Remote();
471     if (remote == nullptr) {
472         WLOGFW("NotifyDisplayModeChanged: remote is nullptr");
473         return;
474     }
475 
476     MessageParcel data;
477     MessageParcel reply;
478     MessageOption option(MessageOption::TF_ASYNC);
479     if (!data.WriteInterfaceToken(GetDescriptor())) {
480         WLOGFE("WriteInterfaceToken failed");
481         return;
482     }
483     if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
484         WLOGFE("Write displayMode failed");
485         return;
486     }
487     if (remote->SendRequest(TRANS_ID_ON_DISPLAY_MODE_CHANGED, data, reply, option) != ERR_NONE) {
488         WLOGFE("SendRequest failed");
489     }
490 }
491 
NotifyAvailableAreaChanged(DMRect area)492 void DisplayManagerAgentProxy::NotifyAvailableAreaChanged(DMRect area)
493 {
494     sptr<IRemoteObject> remote = Remote();
495     if (remote == nullptr) {
496         WLOGFW("NotifyAvailableAreaChanged: remote is nullptr");
497         return;
498     }
499 
500     MessageParcel data;
501     MessageParcel reply;
502     MessageOption option(MessageOption::TF_ASYNC);
503     if (!data.WriteInterfaceToken(GetDescriptor())) {
504         WLOGFE("WriteInterfaceToken failed");
505         return;
506     }
507     if (!data.WriteInt32(area.posX_) || !data.WriteInt32(area.posY_) || !data.WriteUint32(area.width_)
508         ||!data.WriteUint32(area.height_)) {
509         WLOGFE("Write rect failed");
510         return;
511     }
512     if (remote->SendRequest(TRANS_ID_ON_AVAILABLE_AREA_CHANGED, data, reply, option) != ERR_NONE) {
513         WLOGFE("SendRequest failed");
514     }
515 }
516 
NotifyScreenModeChange(const std::vector<sptr<ScreenInfo>> & screenInfos)517 void DisplayManagerAgentProxy::NotifyScreenModeChange(const std::vector<sptr<ScreenInfo>>& screenInfos)
518 {
519     sptr<IRemoteObject> remote = Remote();
520     if (remote == nullptr) {
521         WLOGFW("NotifyScreenModeChange: remote is nullptr");
522         return;
523     }
524 
525     MessageParcel data;
526     MessageParcel reply;
527     MessageOption option(MessageOption::TF_ASYNC);
528     if (!data.WriteInterfaceToken(GetDescriptor())) {
529         WLOGFE("WriteInterfaceToken failed");
530         return;
531     }
532 
533     if (!MarshallingHelper::MarshallingVectorParcelableObj<ScreenInfo>(data, screenInfos)) {
534         WLOGFE("Write screenInfos failed");
535         return;
536     }
537 
538     if (remote->SendRequest(TRANS_ID_ON_SCREEN_MODE_CHANGED, data, reply, option) != ERR_NONE) {
539         WLOGFE("SendRequest failed");
540     }
541 }
542 } // namespace Rosen
543 } // namespace OHOS
544 
545