• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
OnScreenOrientationChanged(ScreenId screenId,float screenOrientation)198 void ScreenSessionManagerClientProxy::OnScreenOrientationChanged(ScreenId screenId, float screenOrientation)
199 {
200     sptr<IRemoteObject> remote = Remote();
201     if (remote == nullptr) {
202         WLOGE("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.WriteFloat(screenOrientation)) {
218         WLOGFE("Write screenOrientation failed");
219         return;
220     }
221     if (remote->SendRequest(
222         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ORIENTATION_CHANGED),
223         data, reply, option) != ERR_NONE) {
224         WLOGFE("SendRequest failed");
225         return;
226     }
227 }
228 
OnScreenRotationLockedChanged(ScreenId screenId,bool isLocked)229 void ScreenSessionManagerClientProxy::OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked)
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.WriteBool(isLocked)) {
249         WLOGFE("Write isLocked failed");
250         return;
251     }
252     if (remote->SendRequest(
253         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ROTATION_LOCKED_CHANGED),
254         data, reply, option) != ERR_NONE) {
255         WLOGFE("SendRequest failed");
256         return;
257     }
258 }
259 
OnDisplayStateChanged(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)260 void ScreenSessionManagerClientProxy::OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
261     const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
262 {
263     sptr<IRemoteObject> remote = Remote();
264     if (remote == nullptr) {
265         WLOGE("remote is nullptr");
266         return;
267     }
268 
269     MessageParcel data;
270     MessageParcel reply;
271     MessageOption option(MessageOption::TF_SYNC);
272     if (!data.WriteInterfaceToken(GetDescriptor())) {
273         WLOGFE("WriteInterfaceToken failed");
274         return;
275     }
276     if (!data.WriteUint64(defaultDisplayId)) {
277         WLOGFE("Write defaultDisplayId failed");
278         return;
279     }
280     if (!data.WriteStrongParcelable(displayInfo)) {
281         WLOGFE("Write displayInfo failed");
282         return;
283     }
284     auto mapSize = static_cast<uint32_t>(displayInfoMap.size());
285     if (!data.WriteUint32(mapSize)) {
286         WLOGFE("Write mapSize failed");
287         return;
288     }
289     for (auto [id, info] : displayInfoMap) {
290         if (!data.WriteUint64(id)) {
291             WLOGFE("Write id failed");
292             return;
293         }
294         if (!data.WriteStrongParcelable(info)) {
295             WLOGFE("Write info failed");
296             return;
297         }
298     }
299     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
300         WLOGFE("Write type failed");
301         return;
302     }
303     if (remote->SendRequest(
304         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_DISPLAY_STATE_CHANGED),
305         data, reply, option) != ERR_NONE) {
306         WLOGFE("SendRequest failed");
307         return;
308     }
309 }
310 
OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t> & missionIds,std::vector<uint64_t> & surfaceNodeIds,bool isBlackList)311 void ScreenSessionManagerClientProxy::OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds,
312     std::vector<uint64_t>& surfaceNodeIds, bool isBlackList)
313 {
314     sptr<IRemoteObject> remote = Remote();
315     if (remote == nullptr) {
316         WLOGE("remote is nullptr");
317         return;
318     }
319 
320     MessageParcel data;
321     MessageParcel reply;
322     MessageOption option(MessageOption::TF_SYNC);
323     if (!data.WriteInterfaceToken(GetDescriptor())) {
324         WLOGFE("WriteInterfaceToken failed");
325         return;
326     }
327     if (!data.WriteUInt64Vector(missionIds)) {
328         WLOGFE("Write missionIds failed");
329         return;
330     }
331     if (!data.WriteUInt64Vector(surfaceNodeIds)) {
332         WLOGFE("Write surfaceNodeIds failed");
333         return;
334     }
335     if (!data.WriteBool(isBlackList)) {
336         WLOGFE("Write isBlackList failed");
337         return;
338     }
339     if (remote->SendRequest(static_cast<uint32_t>(
340         ScreenSessionManagerClientMessage::TRANS_ID_GET_SURFACENODEID_FROM_MISSIONID),
341         data, reply, option) != ERR_NONE) {
342         WLOGFE("SendRequest failed");
343         return;
344     }
345     reply.ReadUInt64Vector(&surfaceNodeIds);
346 }
347 
OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)348 void ScreenSessionManagerClientProxy::OnUpdateFoldDisplayMode(FoldDisplayMode displayMode)
349 {
350     sptr<IRemoteObject> remote = Remote();
351     if (remote == nullptr) {
352         WLOGE("remote is nullptr");
353         return;
354     }
355 
356     MessageParcel data;
357     MessageParcel reply;
358     MessageOption option(MessageOption::TF_ASYNC);
359     if (!data.WriteInterfaceToken(GetDescriptor())) {
360         WLOGFE("WriteInterfaceToken failed");
361         return;
362     }
363     if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
364         WLOGFE("Write displayMode failed");
365         return;
366     }
367     if (remote->SendRequest(
368         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_FOLD_DISPLAY_MODE),
369         data, reply, option) != ERR_NONE) {
370         WLOGFE("SendRequest failed");
371         return;
372     }
373 }
374 
OnScreenshot(DisplayId displayId)375 void ScreenSessionManagerClientProxy::OnScreenshot(DisplayId displayId)
376 {
377     MessageParcel data;
378     MessageParcel reply;
379     MessageOption option(MessageOption::TF_ASYNC);
380     if (!data.WriteInterfaceToken(GetDescriptor())) {
381         WLOGFE("WriteInterfaceToken failed");
382         return;
383     }
384     if (!data.WriteUint64(displayId)) {
385         WLOGFE("Write displayId failed");
386         return;
387     }
388     auto remote = Remote();
389     if (remote == nullptr) {
390         WLOGFE("SendRequest failed, Remote is nullptr");
391         return;
392     }
393     if (remote->SendRequest(
394         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_SHOT),
395         data, reply, option) != ERR_NONE) {
396         WLOGFE("SendRequest failed");
397         return;
398     }
399 }
400 
OnImmersiveStateChanged(bool & immersive)401 void ScreenSessionManagerClientProxy::OnImmersiveStateChanged(bool& immersive)
402 {
403     sptr<IRemoteObject> remote = Remote();
404     if (remote == nullptr) {
405         WLOGE("remote is nullptr");
406         return;
407     }
408 
409     MessageParcel data;
410     MessageParcel reply;
411     MessageOption option(MessageOption::TF_SYNC);
412     if (!data.WriteInterfaceToken(GetDescriptor())) {
413         WLOGFE("WriteInterfaceToken failed");
414         return;
415     }
416     if (remote->SendRequest(
417         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_IMMERSIVE_STATE_CHANGED),
418         data, reply, option) != ERR_NONE) {
419         WLOGFE("SendRequest failed");
420         return;
421     }
422     immersive = reply.ReadBool();
423 }
424 
SetDisplayNodeScreenId(ScreenId screenId,ScreenId displayNodeScreenId)425 void ScreenSessionManagerClientProxy::SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId)
426 {
427     sptr<IRemoteObject> remote = Remote();
428     if (remote == nullptr) {
429         WLOGE("remote is nullptr");
430         return;
431     }
432 
433     MessageParcel data;
434     MessageParcel reply;
435     MessageOption option(MessageOption::TF_ASYNC);
436     if (!data.WriteInterfaceToken(GetDescriptor())) {
437         WLOGFE("WriteInterfaceToken failed");
438         return;
439     }
440     if (!data.WriteUint64(screenId)) {
441         WLOGFE("Write screenId failed");
442         return;
443     }
444     if (!data.WriteUint64(displayNodeScreenId)) {
445         WLOGFE("Write displayNodeScreenId failed");
446         return;
447     }
448     if (remote->SendRequest(
449         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_DISPLAY_NODE_SCREEN_ID),
450         data, reply, option) != ERR_NONE) {
451         WLOGFE("SendRequest failed");
452         return;
453     }
454 }
455 
SetVirtualPixelRatioSystem(ScreenId screenId,float virtualPixelRatio)456 void ScreenSessionManagerClientProxy::SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio)
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_SYNC);
467     if (!data.WriteInterfaceToken(GetDescriptor())) {
468         WLOGFE("WriteInterfaceToken failed");
469         return;
470     }
471     if (!data.WriteUint64(screenId) || !data.WriteFloat(virtualPixelRatio)) {
472         WLOGFE("Write screenId/virtualPixelRatio failed");
473         return;
474     }
475     if (remote->SendRequest(
476         static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO_SYSTEM),
477         data, reply, option) != ERR_NONE) {
478         WLOGFE("SendRequest failed");
479         return;
480     }
481 }
482 
OnFoldStatusChangedReportUE(const std::vector<std::string> & screenFoldInfo)483 void ScreenSessionManagerClientProxy::OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo)
484 {
485     sptr<IRemoteObject> remote = Remote();
486     if (remote == nullptr) {
487         WLOGE("remote is nullptr");
488         return;
489     }
490 
491     MessageParcel data;
492     MessageParcel reply;
493     MessageOption option(MessageOption::TF_ASYNC);
494     if (!data.WriteInterfaceToken(GetDescriptor())) {
495         WLOGFE("WriteInterfaceToken failed");
496         return;
497     }
498     if (!data.WriteStringVector(screenFoldInfo)) {
499         WLOGFE("Write screenFoldInfo failed");
500         return;
501     }
502     if (remote->SendRequest(static_cast<uint32_t>(
503         ScreenSessionManagerClientMessage::TRANS_ID_ON_FOLDSTATUS_CHANGED_REPORT_UE),
504         data, reply, option) != ERR_NONE) {
505         WLOGFE("SendRequest failed");
506         return;
507     }
508 }
509 } // namespace OHOS::Rosen
510