1 /*
2  * Copyright (c) 2023 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/screen_session_manager_client_proxy.h"
17 
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS::Rosen {
21 namespace {
22 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenSessionManagerClientProxy" };
23 } // namespace
24 
OnScreenConnectionChanged(ScreenId screenId,ScreenEvent screenEvent,ScreenId rsId,const std::string & name)25 void ScreenSessionManagerClientProxy::OnScreenConnectionChanged(ScreenId screenId, ScreenEvent screenEvent,
26     ScreenId rsId, const std::string& name)
27 {
28     sptr<IRemoteObject> remote = Remote();
29     if (remote == nullptr) {
30         WLOGFE("remote is nullptr");
31         return;
32     }
33 
34     MessageParcel data;
35     MessageParcel reply;
36     MessageOption option(MessageOption::TF_SYNC);
37     if (!data.WriteInterfaceToken(GetDescriptor())) {
38         WLOGFE("WriteInterfaceToken failed");
39         return;
40     }
41     if (!data.WriteUint64(screenId)) {
42         WLOGFE("Write screenId failed");
43         return;
44     }
45     if (!data.WriteUint8(static_cast<uint8_t>(screenEvent))) {
46         WLOGFE("Write screenEvent failed");
47         return;
48     }
49     if (!data.WriteUint64(rsId)) {
50         WLOGFE("Write rsId failed");
51         return;
52     }
53     if (!data.WriteString(name)) {
54         WLOGFE("Write name failed");
55         return;
56     }
57     if (remote->SendRequest(
58         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CONNECTION_CHANGED),
59         data, reply, option) != ERR_NONE) {
60         WLOGFE("SendRequest failed");
61         return;
62     }
63 }
64 
SwitchUserCallback(std::vector<int32_t> oldScbPids,int32_t currentScbPid)65 void ScreenSessionManagerClientProxy::SwitchUserCallback(std::vector<int32_t> oldScbPids, int32_t currentScbPid)
66 {
67     sptr<IRemoteObject> remote = Remote();
68     if (remote == nullptr) {
69         WLOGFE("remote is nullptr");
70         return;
71     }
72 
73     MessageParcel data;
74     MessageParcel reply;
75     MessageOption option(MessageOption::TF_SYNC);
76     if (!data.WriteInterfaceToken(GetDescriptor())) {
77         WLOGFE("WriteInterfaceToken failed");
78         return;
79     }
80     if (!data.WriteInt32Vector(oldScbPids)) {
81         WLOGFE("Write oldScbPids failed");
82         return;
83     }
84     if (!data.WriteInt32(currentScbPid)) {
85         WLOGFE("Write currentScbPid failed");
86         return;
87     }
88     if (remote->SendRequest(
89         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SWITCH_USER_CMD),
90         data, reply, option) != ERR_NONE) {
91         WLOGFE("SendRequest failed");
92         return;
93     }
94 }
95 
OnPropertyChanged(ScreenId screenId,const ScreenProperty & property,ScreenPropertyChangeReason reason)96 void ScreenSessionManagerClientProxy::OnPropertyChanged(ScreenId screenId,
97     const ScreenProperty& property, ScreenPropertyChangeReason reason)
98 {
99     sptr<IRemoteObject> remote = Remote();
100     if (remote == nullptr) {
101         WLOGFE("remote is nullptr");
102         return;
103     }
104 
105     MessageParcel data;
106     MessageParcel reply;
107     MessageOption option(MessageOption::TF_SYNC);
108     if (!data.WriteInterfaceToken(GetDescriptor())) {
109         WLOGFE("WriteInterfaceToken failed");
110         return;
111     }
112     if (!data.WriteUint64(screenId)) {
113         WLOGFE("Write screenId failed");
114         return;
115     }
116     if (!RSMarshallingHelper::Marshalling(data, property)) {
117         WLOGFE("Write property failed");
118         return;
119     }
120     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
121         WLOGFE("Write reason failed");
122         return;
123     }
124     if (remote->SendRequest(
125         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_PROPERTY_CHANGED),
126         data, reply, option) != ERR_NONE) {
127         WLOGFE("SendRequest failed");
128         return;
129     }
130 }
131 
OnPowerStatusChanged(DisplayPowerEvent event,EventStatus status,PowerStateChangeReason reason)132 void ScreenSessionManagerClientProxy::OnPowerStatusChanged(DisplayPowerEvent event, EventStatus status,
133     PowerStateChangeReason reason)
134 {
135     MessageParcel data;
136     MessageParcel reply;
137     MessageOption option(MessageOption::TF_ASYNC);
138     if (!data.WriteInterfaceToken(GetDescriptor())) {
139         WLOGFE("WriteInterfaceToken failed");
140         return;
141     }
142     if (!data.WriteUint32(static_cast<uint32_t>(event))) {
143         WLOGFE("Write event failed");
144         return;
145     }
146     if (!data.WriteUint32(static_cast<uint32_t>(status))) {
147         WLOGFE("Write status failed");
148         return;
149     }
150     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
151         WLOGFE("Write reason failed");
152         return;
153     }
154     auto remote = Remote();
155     if (remote == nullptr) {
156         WLOGFE("SendRequest failed, Remote is nullptr");
157         return;
158     }
159     if (remote->SendRequest(
160         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_POWER_STATUS_CHANGED),
161         data, reply, option) != ERR_NONE) {
162         WLOGFE("SendRequest failed");
163         return;
164     }
165 }
166 
OnSensorRotationChanged(ScreenId screenId,float sensorRotation)167 void ScreenSessionManagerClientProxy::OnSensorRotationChanged(ScreenId screenId, float sensorRotation)
168 {
169     sptr<IRemoteObject> remote = Remote();
170     if (remote == nullptr) {
171         WLOGFE("remote is nullptr");
172         return;
173     }
174 
175     MessageParcel data;
176     MessageParcel reply;
177     MessageOption option(MessageOption::TF_SYNC);
178     if (!data.WriteInterfaceToken(GetDescriptor())) {
179         WLOGFE("WriteInterfaceToken failed");
180         return;
181     }
182     if (!data.WriteUint64(screenId)) {
183         WLOGFE("Write screenId failed");
184         return;
185     }
186     if (!data.WriteFloat(sensorRotation)) {
187         WLOGFE("Write sensorRotation failed");
188         return;
189     }
190     if (remote->SendRequest(
191         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SENSOR_ROTATION_CHANGED),
192         data, reply, option) != ERR_NONE) {
193         WLOGFE("SendRequest failed");
194         return;
195     }
196 }
197 
OnHoverStatusChanged(ScreenId screenId,int32_t hoverStatus)198 void ScreenSessionManagerClientProxy::OnHoverStatusChanged(ScreenId screenId, int32_t hoverStatus)
199 {
200     sptr<IRemoteObject> remote = Remote();
201     if (remote == nullptr) {
202         WLOGFE("remote is nullptr");
203         return;
204     }
205 
206     MessageParcel data;
207     MessageParcel reply;
208     MessageOption option(MessageOption::TF_SYNC);
209     if (!data.WriteInterfaceToken(GetDescriptor())) {
210         WLOGFE("WriteInterfaceToken failed");
211         return;
212     }
213     if (!data.WriteUint64(screenId)) {
214         WLOGFE("Write screenId failed");
215         return;
216     }
217     if (!data.WriteInt32(hoverStatus)) {
218         WLOGFE("Write hoverStatus failed");
219         return;
220     }
221     if (remote->SendRequest(
222         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_HOVER_STATUS_CHANGED),
223         data, reply, option) != ERR_NONE) {
224         WLOGFE("SendRequest failed");
225         return;
226     }
227 }
228 
OnScreenOrientationChanged(ScreenId screenId,float screenOrientation)229 void ScreenSessionManagerClientProxy::OnScreenOrientationChanged(ScreenId screenId, float screenOrientation)
230 {
231     sptr<IRemoteObject> remote = Remote();
232     if (remote == nullptr) {
233         WLOGE("remote is nullptr");
234         return;
235     }
236 
237     MessageParcel data;
238     MessageParcel reply;
239     MessageOption option(MessageOption::TF_SYNC);
240     if (!data.WriteInterfaceToken(GetDescriptor())) {
241         WLOGFE("WriteInterfaceToken failed");
242         return;
243     }
244     if (!data.WriteUint64(screenId)) {
245         WLOGFE("Write screenId failed");
246         return;
247     }
248     if (!data.WriteFloat(screenOrientation)) {
249         WLOGFE("Write screenOrientation failed");
250         return;
251     }
252     if (remote->SendRequest(
253         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ORIENTATION_CHANGED),
254         data, reply, option) != ERR_NONE) {
255         WLOGFE("SendRequest failed");
256         return;
257     }
258 }
259 
OnScreenRotationLockedChanged(ScreenId screenId,bool isLocked)260 void ScreenSessionManagerClientProxy::OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked)
261 {
262     sptr<IRemoteObject> remote = Remote();
263     if (remote == nullptr) {
264         WLOGE("remote is nullptr");
265         return;
266     }
267 
268     MessageParcel data;
269     MessageParcel reply;
270     MessageOption option(MessageOption::TF_SYNC);
271     if (!data.WriteInterfaceToken(GetDescriptor())) {
272         WLOGFE("WriteInterfaceToken failed");
273         return;
274     }
275     if (!data.WriteUint64(screenId)) {
276         WLOGFE("Write screenId failed");
277         return;
278     }
279     if (!data.WriteBool(isLocked)) {
280         WLOGFE("Write isLocked failed");
281         return;
282     }
283     if (remote->SendRequest(
284         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ROTATION_LOCKED_CHANGED),
285         data, reply, option) != ERR_NONE) {
286         WLOGFE("SendRequest failed");
287         return;
288     }
289 }
290 
OnDisplayStateChanged(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)291 void ScreenSessionManagerClientProxy::OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
292     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
293 {
294     sptr<IRemoteObject> remote = Remote();
295     if (remote == nullptr) {
296         WLOGE("remote is nullptr");
297         return;
298     }
299 
300     MessageParcel data;
301     MessageParcel reply;
302     MessageOption option(MessageOption::TF_SYNC);
303     if (!data.WriteInterfaceToken(GetDescriptor())) {
304         WLOGFE("WriteInterfaceToken failed");
305         return;
306     }
307     if (!data.WriteUint64(defaultDisplayId)) {
308         WLOGFE("Write defaultDisplayId failed");
309         return;
310     }
311     if (!data.WriteStrongParcelable(displayInfo)) {
312         WLOGFE("Write displayInfo failed");
313         return;
314     }
315     auto mapSize = static_cast<uint32_t>(displayInfoMap.size());
316     if (!data.WriteUint32(mapSize)) {
317         WLOGFE("Write mapSize failed");
318         return;
319     }
320     for (auto [id, info] : displayInfoMap) {
321         if (!data.WriteUint64(id)) {
322             WLOGFE("Write id failed");
323             return;
324         }
325         if (!data.WriteStrongParcelable(info)) {
326             WLOGFE("Write info failed");
327             return;
328         }
329     }
330     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
331         WLOGFE("Write type failed");
332         return;
333     }
334     if (remote->SendRequest(
335         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_DISPLAY_STATE_CHANGED),
336         data, reply, option) != ERR_NONE) {
337         WLOGFE("SendRequest failed");
338         return;
339     }
340 }
341 
OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t> & missionIds,std::vector<uint64_t> & surfaceNodeIds,bool isBlackList)342 void ScreenSessionManagerClientProxy::OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds,
343     std::vector<uint64_t>& surfaceNodeIds, bool isBlackList)
344 {
345     sptr<IRemoteObject> remote = Remote();
346     if (remote == nullptr) {
347         WLOGE("remote is nullptr");
348         return;
349     }
350 
351     MessageParcel data;
352     MessageParcel reply;
353     MessageOption option(MessageOption::TF_SYNC);
354     if (!data.WriteInterfaceToken(GetDescriptor())) {
355         WLOGFE("WriteInterfaceToken failed");
356         return;
357     }
358     if (!data.WriteUInt64Vector(missionIds)) {
359         WLOGFE("Write missionIds failed");
360         return;
361     }
362     if (!data.WriteUInt64Vector(surfaceNodeIds)) {
363         WLOGFE("Write surfaceNodeIds failed");
364         return;
365     }
366     if (!data.WriteBool(isBlackList)) {
367         WLOGFE("Write isBlackList failed");
368         return;
369     }
370     if (remote->SendRequest(static_cast<uint32_t>(
371         ScreenSessionManagerClientMessage::TRANS_ID_GET_SURFACENODEID_FROM_MISSIONID),
372         data, reply, option) != ERR_NONE) {
373         WLOGFE("SendRequest failed");
374         return;
375     }
376     reply.ReadUInt64Vector(&surfaceNodeIds);
377 }
378 
OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)379 void ScreenSessionManagerClientProxy::OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)
380 {
381     sptr<IRemoteObject> remote = Remote();
382     if (remote == nullptr) {
383         WLOGE("remote is nullptr");
384         return;
385     }
386 
387     MessageParcel data;
388     MessageParcel reply;
389     MessageOption option(MessageOption::TF_ASYNC);
390     if (!data.WriteInterfaceToken(GetDescriptor())) {
391         WLOGFE("WriteInterfaceToken failed");
392         return;
393     }
394     if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
395         WLOGFE("Write displayMode failed");
396         return;
397     }
398     if (remote->SendRequest(
399         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_FOLD_DISPLAY_MODE),
400         data, reply, option) != ERR_NONE) {
401         WLOGFE("SendRequest failed");
402         return;
403     }
404 }
405 
OnScreenshot(DisplayId displayId)406 void ScreenSessionManagerClientProxy::OnScreenshot(DisplayId displayId)
407 {
408     MessageParcel data;
409     MessageParcel reply;
410     MessageOption option(MessageOption::TF_ASYNC);
411     if (!data.WriteInterfaceToken(GetDescriptor())) {
412         WLOGFE("WriteInterfaceToken failed");
413         return;
414     }
415     if (!data.WriteUint64(displayId)) {
416         WLOGFE("Write displayId failed");
417         return;
418     }
419     auto remote = Remote();
420     if (remote == nullptr) {
421         WLOGFE("SendRequest failed, Remote is nullptr");
422         return;
423     }
424     if (remote->SendRequest(
425         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_SHOT),
426         data, reply, option) != ERR_NONE) {
427         WLOGFE("SendRequest failed");
428         return;
429     }
430 }
431 
OnImmersiveStateChanged(bool & immersive)432 void ScreenSessionManagerClientProxy::OnImmersiveStateChanged(bool& immersive)
433 {
434     sptr<IRemoteObject> remote = Remote();
435     if (remote == nullptr) {
436         WLOGE("remote is nullptr");
437         return;
438     }
439 
440     MessageParcel data;
441     MessageParcel reply;
442     MessageOption option(MessageOption::TF_SYNC);
443     if (!data.WriteInterfaceToken(GetDescriptor())) {
444         WLOGFE("WriteInterfaceToken failed");
445         return;
446     }
447     if (remote->SendRequest(
448         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_IMMERSIVE_STATE_CHANGED),
449         data, reply, option) != ERR_NONE) {
450         WLOGFE("SendRequest failed");
451         return;
452     }
453     immersive = reply.ReadBool();
454 }
455 
SetDisplayNodeScreenId(ScreenId screenId,ScreenId displayNodeScreenId)456 void ScreenSessionManagerClientProxy::SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId)
457 {
458     sptr<IRemoteObject> remote = Remote();
459     if (remote == nullptr) {
460         WLOGE("remote is nullptr");
461         return;
462     }
463 
464     MessageParcel data;
465     MessageParcel reply;
466     MessageOption option(MessageOption::TF_ASYNC);
467     if (!data.WriteInterfaceToken(GetDescriptor())) {
468         WLOGFE("WriteInterfaceToken failed");
469         return;
470     }
471     if (!data.WriteUint64(screenId)) {
472         WLOGFE("Write screenId failed");
473         return;
474     }
475     if (!data.WriteUint64(displayNodeScreenId)) {
476         WLOGFE("Write displayNodeScreenId failed");
477         return;
478     }
479     if (remote->SendRequest(
480         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_DISPLAY_NODE_SCREEN_ID),
481         data, reply, option) != ERR_NONE) {
482         WLOGFE("SendRequest failed");
483         return;
484     }
485 }
486 
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)487 void ScreenSessionManagerClientProxy::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
488 {
489     sptr<IRemoteObject> remote = Remote();
490     if (remote == nullptr) {
491         WLOGE("remote is nullptr");
492         return;
493     }
494 
495     MessageParcel data;
496     MessageParcel reply;
497     MessageOption option(MessageOption::TF_SYNC);
498     if (!data.WriteInterfaceToken(GetDescriptor())) {
499         WLOGFE("WriteInterfaceToken failed");
500         return;
501     }
502     if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) {
503         WLOGFE("Write screenId/virtualPixelRatio failed");
504         return;
505     }
506     if (remote->SendRequest(
507         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO_SYSTEM),
508         data, reply, option) != ERR_NONE) {
509         WLOGFE("SendRequest failed");
510         return;
511     }
512 }
513 
OnFoldStatusChangedReportUE(const std::vector<std::string> & screenFoldInfo)514 void ScreenSessionManagerClientProxy::OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo)
515 {
516     sptr<IRemoteObject> remote = Remote();
517     if (remote == nullptr) {
518         WLOGE("remote is nullptr");
519         return;
520     }
521 
522     MessageParcel data;
523     MessageParcel reply;
524     MessageOption option(MessageOption::TF_ASYNC);
525     if (!data.WriteInterfaceToken(GetDescriptor())) {
526         WLOGFE("WriteInterfaceToken failed");
527         return;
528     }
529     if (!data.WriteStringVector(screenFoldInfo)) {
530         WLOGFE("Write screenFoldInfo failed");
531         return;
532     }
533     if (remote->SendRequest(static_cast<uint32_t>(
534         ScreenSessionManagerClientMessage::TRANS_ID_ON_FOLDSTATUS_CHANGED_REPORT_UE),
535         data, reply, option) != ERR_NONE) {
536         WLOGFE("SendRequest failed");
537         return;
538     }
539 }
ScreenCaptureNotify(ScreenId mainScreenId,int32_t uid,const std::string & clientName)540 void ScreenSessionManagerClientProxy::ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid,
541     const std::string& clientName)
542 {
543     sptr<IRemoteObject> remote = Remote();
544     if (remote == nullptr) {
545         WLOGE("remote is nullptr");
546         return;
547     }
548     MessageParcel data;
549     MessageParcel reply;
550     MessageOption option(MessageOption::TF_SYNC);
551     if (!data.WriteInterfaceToken(GetDescriptor())) {
552         WLOGFE("WriteInterfaceToken failed");
553         return;
554     }
555     if (!data.WriteUint64(mainScreenId) || !data.WriteInt32(uid) || !data.WriteString(clientName)) {
556         WLOGFE("Write screenId or uid or client failed");
557         return;
558     }
559     if (remote->SendRequest(
560         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CAPTURE_NOTIFY),
561         data, reply, option) != ERR_NONE) {
562         WLOGFE("SendRequest failed");
563         return;
564     }
565 }
566 } // namespace OHOS::Rosen
567