• 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 "session_manager/include/zidl/scene_session_manager_proxy.h"
17 
18 #include <ipc_types.h>
19 #include <message_option.h>
20 #include <message_parcel.h>
21 #include <ui/rs_surface_node.h>
22 
23 #include "marshalling_helper.h"
24 #include "permission.h"
25 #include "window_manager.h"
26 #include "window_manager_hilog.h"
27 
28 namespace OHOS::Rosen {
29 namespace {
30 constexpr int32_t CYCLE_LIMIT = 1000;
31 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerProxy"};
32 }
CreateAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,int32_t & persistentId,sptr<ISession> & session,SystemSessionConfig & systemConfig,sptr<IRemoteObject> token)33 WSError SceneSessionManagerProxy::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
34     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
35     sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
36     SystemSessionConfig& systemConfig, sptr<IRemoteObject> token)
37 {
38     MessageOption option(MessageOption::TF_SYNC);
39     MessageParcel data;
40     MessageParcel reply;
41     if (!data.WriteInterfaceToken(GetDescriptor())) {
42         WLOGFE("Write InterfaceToken failed!");
43         return WSError::WS_ERROR_IPC_FAILED;
44     }
45     if (!data.WriteRemoteObject(sessionStage->AsObject())) {
46         WLOGFE("Write ISessionStage failed!");
47         return WSError::WS_ERROR_IPC_FAILED;
48     }
49     if (!data.WriteRemoteObject(eventChannel->AsObject())) {
50         WLOGFE("Write IWindowEventChannel failed!");
51         return WSError::WS_ERROR_IPC_FAILED;
52     }
53     if (!surfaceNode || !surfaceNode->Marshalling(data)) {
54         WLOGFE("Write surfaceNode failed");
55         return WSError::WS_ERROR_IPC_FAILED;
56     }
57 
58     if (property) {
59         if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
60             return WSError::WS_ERROR_IPC_FAILED;
61         }
62     } else {
63         if (!data.WriteBool(false)) {
64             return WSError::WS_ERROR_IPC_FAILED;
65         }
66     }
67     if (token != nullptr) {
68         if (!data.WriteRemoteObject(token)) {
69             return WSError::WS_ERROR_IPC_FAILED;
70         }
71     }
72 
73     sptr<IRemoteObject> remote = Remote();
74     if (remote == nullptr) {
75         WLOGFE("remote is null");
76         return WSError::WS_ERROR_IPC_FAILED;
77     }
78     if (remote->SendRequest(static_cast<uint32_t>(
79         SceneSessionManagerMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), data, reply, option) != ERR_NONE) {
80         WLOGFE("SendRequest failed");
81         return WSError::WS_ERROR_IPC_FAILED;
82     }
83     persistentId = reply.ReadInt32();
84     sptr<IRemoteObject> sessionObject = reply.ReadRemoteObject();
85     if (sessionObject == nullptr) {
86         WLOGFE("ReadRemoteObject failed");
87         return WSError::WS_ERROR_IPC_FAILED;
88     }
89     session = iface_cast<ISession>(sessionObject);
90     sptr<SystemSessionConfig> config = reply.ReadParcelable<SystemSessionConfig>();
91     if (config) {
92         systemConfig = *config;
93     }
94     int32_t ret = reply.ReadInt32();
95     return static_cast<WSError>(ret);
96 }
97 
RecoverAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,sptr<ISession> & session,sptr<IRemoteObject> token)98 WSError SceneSessionManagerProxy::RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
99     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
100     sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token)
101 {
102     MessageParcel data;
103     MessageParcel reply;
104     MessageOption option;
105     if (!data.WriteInterfaceToken(GetDescriptor())) {
106         WLOGFE("Write InterfaceToken failed!");
107         return WSError::WS_ERROR_IPC_FAILED;
108     }
109     if (!sessionStage || !data.WriteRemoteObject(sessionStage->AsObject())) {
110         WLOGFE("Write ISessionStage failed!");
111         return WSError::WS_ERROR_IPC_FAILED;
112     }
113     if (!eventChannel || !data.WriteRemoteObject(eventChannel->AsObject())) {
114         WLOGFE("Write IWindowEventChannel failed!");
115         return WSError::WS_ERROR_IPC_FAILED;
116     }
117     if (!surfaceNode || !surfaceNode->Marshalling(data)) {
118         WLOGFE("Write surfaceNode failed");
119         return WSError::WS_ERROR_IPC_FAILED;
120     }
121 
122     if (property) {
123         if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
124             return WSError::WS_ERROR_IPC_FAILED;
125         }
126     } else {
127         if (!data.WriteBool(false)) {
128             return WSError::WS_ERROR_IPC_FAILED;
129         }
130     }
131     if (token != nullptr && !data.WriteRemoteObject(token)) {
132         return WSError::WS_ERROR_IPC_FAILED;
133     }
134 
135     sptr<IRemoteObject> remote = Remote();
136     if (remote == nullptr) {
137         WLOGFE("remote is null");
138         return WSError::WS_ERROR_IPC_FAILED;
139     }
140     if (remote->SendRequest(static_cast<uint32_t>(
141         SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_CONNECT_SPECIFIC_SESSION),
142         data, reply, option) != ERR_NONE) {
143         WLOGFE("SendRequest failed");
144         return WSError::WS_ERROR_IPC_FAILED;
145     }
146     sptr<IRemoteObject> sessionObject = reply.ReadRemoteObject();
147     if (sessionObject == nullptr) {
148         WLOGFE("ReadRemoteObject failed");
149         return WSError::WS_ERROR_IPC_FAILED;
150     }
151     session = iface_cast<ISession>(sessionObject);
152     int32_t ret = reply.ReadInt32();
153     return static_cast<WSError>(ret);
154 }
RecoverAndReconnectSceneSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<ISession> & session,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)155 WSError SceneSessionManagerProxy::RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
156     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
157     sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
158 {
159     MessageOption option(MessageOption::TF_SYNC);
160     MessageParcel data;
161     MessageParcel reply;
162     if (!data.WriteInterfaceToken(GetDescriptor())) {
163         WLOGFE("Write InterfaceToken failed!");
164         return WSError::WS_ERROR_IPC_FAILED;
165     }
166     if (!sessionStage || !data.WriteRemoteObject(sessionStage->AsObject())) {
167         WLOGFE("Write ISessionStage failed!");
168         return WSError::WS_ERROR_IPC_FAILED;
169     }
170     if (!eventChannel || !data.WriteRemoteObject(eventChannel->AsObject())) {
171         WLOGFE("Write IWindowEventChannel failed!");
172         return WSError::WS_ERROR_IPC_FAILED;
173     }
174     if (!surfaceNode || !surfaceNode->Marshalling(data)) {
175         WLOGFE("Write surfaceNode failed");
176         return WSError::WS_ERROR_IPC_FAILED;
177     }
178 
179     if (property) {
180         if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
181             return WSError::WS_ERROR_IPC_FAILED;
182         }
183     } else {
184         if (!data.WriteBool(false)) {
185             return WSError::WS_ERROR_IPC_FAILED;
186         }
187     }
188     if (token != nullptr && !data.WriteRemoteObject(token)) {
189         return WSError::WS_ERROR_IPC_FAILED;
190     }
191 
192     sptr<IRemoteObject> remote = Remote();
193     if (remote == nullptr) {
194         WLOGFE("remote is null");
195         return WSError::WS_ERROR_IPC_FAILED;
196     }
197     if (remote->SendRequest(
198         static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_RECONNECT_SCENE_SESSION), data, reply,
199         option) != ERR_NONE) {
200         WLOGFE("SendRequest failed");
201         return WSError::WS_ERROR_IPC_FAILED;
202     }
203     sptr<IRemoteObject> sessionObject = reply.ReadRemoteObject();
204     if (sessionObject == nullptr) {
205         WLOGFE("ReadRemoteObject failed");
206         return WSError::WS_ERROR_IPC_FAILED;
207     }
208     session = iface_cast<ISession>(sessionObject);
209     int32_t ret = reply.ReadInt32();
210     return static_cast<WSError>(ret);
211 }
212 
GetSessionSnapshotById(int32_t persistentId,SessionSnapshot & snapshot)213 WMError SceneSessionManagerProxy::GetSessionSnapshotById(int32_t persistentId, SessionSnapshot& snapshot)
214 {
215     MessageParcel data;
216     MessageParcel reply;
217     MessageOption option;
218     if (!data.WriteInterfaceToken(GetDescriptor())) {
219         TLOGE(WmsLogTag::WMS_SYSTEM, "WriteInterfaceToken failed");
220         return WMError::WM_ERROR_IPC_FAILED;
221     }
222     if (!data.WriteInt32(persistentId)) {
223         TLOGE(WmsLogTag::WMS_SYSTEM, "Write persistentId failed");
224         return WMError::WM_ERROR_IPC_FAILED;
225     }
226 
227     sptr<IRemoteObject> remote = Remote();
228     if (remote == nullptr) {
229         TLOGE(WmsLogTag::WMS_SYSTEM, "remote is null");
230         return WMError::WM_ERROR_IPC_FAILED;
231     }
232     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT_BY_ID),
233         data, reply, option) != ERR_NONE) {
234         TLOGE(WmsLogTag::WMS_SYSTEM, "SendRequest failed");
235         return WMError::WM_ERROR_IPC_FAILED;
236     }
237     sptr<SessionSnapshot> info(reply.ReadParcelable<SessionSnapshot>());
238     if (info) {
239         snapshot = *info;
240     } else {
241         TLOGE(WmsLogTag::WMS_SYSTEM, "Read snapshot is null.");
242     }
243     return static_cast<WMError>(reply.ReadInt32());
244 }
245 
GetSnapshotByWindowId(int32_t persistentId,std::shared_ptr<Media::PixelMap> & pixelMap)246 WMError SceneSessionManagerProxy::GetSnapshotByWindowId(int32_t persistentId,
247     std::shared_ptr<Media::PixelMap>& pixelMap)
248 {
249     SessionSnapshot snapshot;
250     WMError ret = GetSessionSnapshotById(persistentId, snapshot);
251     if (ret == WMError::WM_OK) {
252         pixelMap = snapshot.snapshot;
253     }
254     return ret;
255 }
256 
DestroyAndDisconnectSpecificSession(const int32_t persistentId)257 WSError SceneSessionManagerProxy::DestroyAndDisconnectSpecificSession(const int32_t persistentId)
258 {
259     MessageParcel data;
260     MessageParcel reply;
261     MessageOption option(MessageOption::TF_SYNC);
262     if (!data.WriteInterfaceToken(GetDescriptor())) {
263         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
264         return WSError::WS_ERROR_IPC_FAILED;
265     }
266     if (!data.WriteInt32(persistentId)) {
267         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentId failed");
268         return WSError::WS_ERROR_IPC_FAILED;
269     }
270     sptr<IRemoteObject> remote = Remote();
271     if (remote == nullptr) {
272         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
273         return WSError::WS_ERROR_IPC_FAILED;
274     }
275     if (remote->SendRequest(static_cast<uint32_t>(
276         SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION),
277         data, reply, option) != ERR_NONE) {
278         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
279         return WSError::WS_ERROR_IPC_FAILED;
280     }
281     int32_t ret = reply.ReadInt32();
282     return static_cast<WSError>(ret);
283 }
284 
DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,const sptr<IRemoteObject> & callback)285 WSError SceneSessionManagerProxy::DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,
286     const sptr<IRemoteObject>& callback)
287 {
288     MessageParcel data;
289     MessageParcel reply;
290     MessageOption option(MessageOption::TF_SYNC);
291     if (!data.WriteInterfaceToken(GetDescriptor())) {
292         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
293         return WSError::WS_ERROR_IPC_FAILED;
294     }
295     if (!data.WriteInt32(persistentId)) {
296         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentId failed");
297         return WSError::WS_ERROR_IPC_FAILED;
298     }
299     if (callback == nullptr || !data.WriteRemoteObject(callback)) {
300         TLOGE(WmsLogTag::WMS_LIFE, "Write callback failed");
301         return WSError::WS_ERROR_IPC_FAILED;
302     }
303     sptr<IRemoteObject> remote = Remote();
304     if (remote == nullptr) {
305         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
306         return WSError::WS_ERROR_IPC_FAILED;
307     }
308     if (remote->SendRequest(static_cast<uint32_t>(
309         SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION_WITH_DETACH_CALLBACK),
310         data, reply, option) != ERR_NONE) {
311         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
312         return WSError::WS_ERROR_IPC_FAILED;
313     }
314     int32_t ret = reply.ReadInt32();
315     return static_cast<WSError>(ret);
316 }
317 
RequestFocusStatus(int32_t persistentId,bool isFocused,bool byForeground,FocusChangeReason reason)318 WMError SceneSessionManagerProxy::RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground,
319     FocusChangeReason reason)
320 {
321     TLOGI(WmsLogTag::WMS_FOCUS, "SceneSessionManagerProxy::RequestFocusStatus id: %{public}d, focusState:\
322         %{public}u, byForeground: %{public}d, reason: %{public}d", persistentId, isFocused, byForeground, reason);
323     MessageParcel data;
324     MessageParcel reply;
325     MessageOption option(MessageOption::TF_SYNC);
326     if (!data.WriteInterfaceToken(GetDescriptor())) {
327         WLOGFE("WriteInterfaceToken failed");
328         return WMError::WM_ERROR_IPC_FAILED;
329     }
330     if (!data.WriteInt32(persistentId)) {
331         WLOGFE("Write persistentId failed");
332         return WMError::WM_ERROR_IPC_FAILED;
333     }
334     if (!data.WriteBool(isFocused)) {
335         WLOGFE("Write isFocused failed");
336         return WMError::WM_ERROR_IPC_FAILED;
337     }
338 
339     sptr<IRemoteObject> remote = Remote();
340     if (remote == nullptr) {
341         WLOGFE("remote is null");
342         return WMError::WM_ERROR_IPC_FAILED;
343     }
344     if (remote->SendRequest(static_cast<uint32_t>(
345         SceneSessionManagerMessage::TRANS_ID_REQUEST_FOCUS),
346         data, reply, option) != ERR_NONE) {
347         WLOGFE("SendRequest failed");
348         return WMError::WM_ERROR_IPC_FAILED;
349     }
350     int32_t ret = reply.ReadInt32();
351     return static_cast<WMError>(ret);
352 }
353 
RaiseWindowToTop(int32_t persistentId)354 WSError SceneSessionManagerProxy::RaiseWindowToTop(int32_t persistentId)
355 {
356     MessageParcel data;
357     MessageParcel reply;
358     MessageOption option(MessageOption::TF_SYNC);
359     if (!data.WriteInterfaceToken(GetDescriptor())) {
360         WLOGFE("WriteInterfaceToken failed");
361         return WSError::WS_ERROR_IPC_FAILED;
362     }
363     if (!data.WriteInt32(persistentId)) {
364         WLOGFE("Write persistentId failed");
365         return WSError::WS_ERROR_IPC_FAILED;
366     }
367 
368     sptr<IRemoteObject> remote = Remote();
369     if (remote == nullptr) {
370         WLOGFE("remote is null");
371         return WSError::WS_ERROR_IPC_FAILED;
372     }
373     if (remote->SendRequest(static_cast<uint32_t>(
374         SceneSessionManagerMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
375         data, reply, option) != ERR_NONE) {
376         WLOGFE("SendRequest failed");
377         return WSError::WS_ERROR_IPC_FAILED;
378     }
379     int32_t ret = reply.ReadInt32();
380     return static_cast<WSError>(ret);
381 }
382 
BindDialogSessionTarget(uint64_t persistentId,sptr<IRemoteObject> targetToken)383 WSError SceneSessionManagerProxy::BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken)
384 {
385     MessageParcel data;
386     MessageParcel reply;
387     MessageOption option(MessageOption::TF_SYNC);
388     if (!data.WriteInterfaceToken(GetDescriptor())) {
389         WLOGFE("WriteInterfaceToken failed");
390         return WSError::WS_ERROR_IPC_FAILED;
391     }
392     if (!data.WriteUint64(persistentId)) {
393         WLOGFE("Write PropertyChangeAction failed");
394         return WSError::WS_ERROR_IPC_FAILED;
395     }
396     if (targetToken != nullptr) {
397         if (!data.WriteRemoteObject(targetToken)) {
398             WLOGFE("Write targetToken failed");
399             return WSError::WS_ERROR_IPC_FAILED;
400         }
401     }
402 
403     sptr<IRemoteObject> remote = Remote();
404     if (remote == nullptr) {
405         WLOGFE("remote is null");
406         return WSError::WS_ERROR_IPC_FAILED;
407     }
408     if (remote->SendRequest(static_cast<uint32_t>(
409         SceneSessionManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
410         data, reply, option) != ERR_NONE) {
411         WLOGFE("SendRequest failed");
412         return WSError::WS_ERROR_IPC_FAILED;
413     }
414     int32_t ret = reply.ReadInt32();
415     return static_cast<WSError>(ret);
416 }
417 
UpdateSessionAvoidAreaListener(int32_t & persistentId,bool haveListener)418 WSError SceneSessionManagerProxy::UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener)
419 {
420     MessageParcel data;
421     MessageParcel reply;
422     MessageOption option(MessageOption::TF_SYNC);
423 
424     if (!data.WriteInterfaceToken(GetDescriptor())) {
425         WLOGFE("WriteInterfaceToken failed");
426         return WSError::WS_ERROR_IPC_FAILED;
427     }
428     if (!data.WriteInt32(persistentId)) {
429         WLOGFE("Write persistentId failed");
430         return WSError::WS_ERROR_IPC_FAILED;
431     }
432     if (!data.WriteBool(haveListener)) {
433         WLOGFE("Write avoid area listener failed");
434         return WSError::WS_ERROR_IPC_FAILED;
435     }
436     sptr<IRemoteObject> remote = Remote();
437     if (remote == nullptr) {
438         WLOGFE("remote is null");
439         return WSError::WS_ERROR_IPC_FAILED;
440     }
441     if (remote->SendRequest(static_cast<uint32_t>(
442         SceneSessionManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
443         data, reply, option) != ERR_NONE) {
444         return WSError::WS_ERROR_IPC_FAILED;
445     }
446     return static_cast<WSError>(reply.ReadInt32());
447 }
448 
UpdateSessionTouchOutsideListener(int32_t & persistentId,bool haveListener)449 WSError SceneSessionManagerProxy::UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener)
450 {
451     MessageParcel data;
452     MessageParcel reply;
453     MessageOption option(MessageOption::TF_SYNC);
454 
455     if (!data.WriteInterfaceToken(GetDescriptor())) {
456         WLOGFE("WriteInterfaceToken failed");
457         return WSError::WS_ERROR_IPC_FAILED;
458     }
459     if (!data.WriteInt32(persistentId)) {
460         WLOGFE("Write persistentId failed");
461         return WSError::WS_ERROR_IPC_FAILED;
462     }
463     if (!data.WriteBool(haveListener)) {
464         WLOGFE("Write avoid area listener failed");
465         return WSError::WS_ERROR_IPC_FAILED;
466     }
467     sptr<IRemoteObject> remote = Remote();
468     if (remote == nullptr) {
469         WLOGFE("remote is null");
470         return WSError::WS_ERROR_IPC_FAILED;
471     }
472     if (remote->SendRequest(static_cast<uint32_t>(
473         SceneSessionManagerMessage::TRANS_ID_UPDATE_TOUCHOUTSIDE_LISTENER),
474         data, reply, option) != ERR_NONE) {
475         return WSError::WS_ERROR_IPC_FAILED;
476     }
477     return static_cast<WSError>(reply.ReadInt32());
478 }
479 
UpdateSessionWindowVisibilityListener(int32_t persistentId,bool haveListener)480 WSError SceneSessionManagerProxy::UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener)
481 {
482     MessageParcel data;
483     MessageParcel reply;
484     MessageOption option(MessageOption::TF_SYNC);
485 
486     if (!data.WriteInterfaceToken(GetDescriptor())) {
487         WLOGFE("WriteInterfaceToken failed");
488         return WSError::WS_ERROR_IPC_FAILED;
489     }
490     if (!data.WriteInt32(persistentId)) {
491         WLOGFE("Write persistentId failed");
492         return WSError::WS_ERROR_IPC_FAILED;
493     }
494     if (!data.WriteBool(haveListener)) {
495         WLOGFE("Write avoid area listener failed");
496         return WSError::WS_ERROR_IPC_FAILED;
497     }
498     sptr<IRemoteObject> remote = Remote();
499     if (remote == nullptr) {
500         WLOGFE("remote is null");
501         return WSError::WS_ERROR_IPC_FAILED;
502     }
503     if (remote->SendRequest(static_cast<uint32_t>(
504         SceneSessionManagerMessage::TRANS_ID_UPDATE_WINDOW_VISIBILITY_LISTENER),
505         data, reply, option) != ERR_NONE) {
506         return WSError::WS_ERROR_IPC_FAILED;
507     }
508     return static_cast<WSError>(reply.ReadInt32());
509 }
510 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)511 WMError SceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
512     const sptr<IWindowManagerAgent>& windowManagerAgent)
513 {
514     MessageOption option;
515     MessageParcel reply;
516     MessageParcel data;
517     if (!data.WriteInterfaceToken(GetDescriptor())) {
518         WLOGFE("Write InterfaceToken failed");
519         return WMError::WM_ERROR_IPC_FAILED;
520     }
521 
522     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
523         WLOGFE("Write type failed");
524         return WMError::WM_ERROR_IPC_FAILED;
525     }
526 
527     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
528         WLOGFE("Write IWindowManagerAgent failed");
529         return WMError::WM_ERROR_IPC_FAILED;
530     }
531 
532     sptr<IRemoteObject> remote = Remote();
533     if (remote == nullptr) {
534         WLOGFE("remote is null");
535         return WMError::WM_ERROR_IPC_FAILED;
536     }
537     if (remote->SendRequest(static_cast<uint32_t>(
538         SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
539         data, reply, option) != ERR_NONE) {
540         WLOGFE("SendRequest failed");
541         return WMError::WM_ERROR_IPC_FAILED;
542     }
543 
544     return static_cast<WMError>(reply.ReadInt32());
545 }
546 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)547 WMError SceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
548     const sptr<IWindowManagerAgent>& windowManagerAgent)
549 {
550     MessageParcel reply;
551     MessageOption option;
552     MessageParcel data;
553     if (!data.WriteInterfaceToken(GetDescriptor())) {
554         WLOGFE("Write InterfaceToken failed");
555         return WMError::WM_ERROR_IPC_FAILED;
556     }
557 
558     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
559         WLOGFE("Write type failed");
560         return WMError::WM_ERROR_IPC_FAILED;
561     }
562 
563     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
564         WLOGFE("Write IWindowManagerAgent failed");
565         return WMError::WM_ERROR_IPC_FAILED;
566     }
567 
568     sptr<IRemoteObject> remote = Remote();
569     if (remote == nullptr) {
570         WLOGFE("remote is null");
571         return WMError::WM_ERROR_IPC_FAILED;
572     }
573     if (remote->SendRequest(static_cast<uint32_t>(
574         SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
575         data, reply, option) != ERR_NONE) {
576         WLOGFE("SendRequest failed");
577         return WMError::WM_ERROR_IPC_FAILED;
578     }
579 
580     return static_cast<WMError>(reply.ReadInt32());
581 }
582 
SetGestureNavigaionEnabled(bool enable)583 WMError SceneSessionManagerProxy::SetGestureNavigaionEnabled(bool enable)
584 {
585     MessageParcel data;
586     MessageParcel reply;
587     MessageOption option(MessageOption::TF_SYNC);
588     if (!data.WriteInterfaceToken(GetDescriptor())) {
589         WLOGFE("Write InterfaceToken failed");
590         return WMError::WM_ERROR_IPC_FAILED;
591     }
592 
593     if (!data.WriteBool(enable)) {
594         WLOGFE("Write enable failed");
595         return WMError::WM_ERROR_IPC_FAILED;
596     }
597 
598     sptr<IRemoteObject> remote = Remote();
599     if (remote == nullptr) {
600         WLOGFE("remote is null");
601         return WMError::WM_ERROR_IPC_FAILED;
602     }
603     if (remote->SendRequest(static_cast<uint32_t>(
604         SceneSessionManagerMessage::TRANS_ID_SET_GESTURE_NAVIGATION_ENABLED), data, reply, option) != ERR_NONE) {
605         WLOGFE("SendRequest failed");
606         return WMError::WM_ERROR_IPC_FAILED;
607     }
608     int32_t ret = reply.ReadInt32();
609     return static_cast<WMError>(ret);
610 }
611 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)612 void SceneSessionManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
613 {
614     MessageParcel data;
615     MessageParcel reply;
616     MessageOption option;
617     if (!data.WriteInterfaceToken(GetDescriptor())) {
618         WLOGFE("WriteInterfaceToken failed");
619         return;
620     }
621 
622     sptr<IRemoteObject> remote = Remote();
623     if (remote == nullptr) {
624         WLOGFE("remote is null");
625         return;
626     }
627     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
628         data, reply, option) != ERR_NONE) {
629         WLOGFE("SendRequest failed");
630         return;
631     }
632     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
633     if (info) {
634         focusInfo = *info;
635     } else {
636         WLOGFE("info is null.");
637     }
638 }
639 
SetSessionLabel(const sptr<IRemoteObject> & token,const std::string & label)640 WSError SceneSessionManagerProxy::SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label)
641 {
642     WLOGFI("run SceneSessionManagerProxy::SetSessionLabel");
643     MessageParcel data;
644     MessageParcel reply;
645     MessageOption option;
646     if (!data.WriteInterfaceToken(GetDescriptor())) {
647         WLOGFE("WriteInterfaceToken failed");
648         return WSError::WS_ERROR_IPC_FAILED;
649     }
650     if (!data.WriteRemoteObject(token)) {
651         WLOGFE("Write token failed");
652         return WSError::WS_ERROR_IPC_FAILED;
653     }
654     if (!data.WriteString(label)) {
655         WLOGFE("Write label failed");
656         return WSError::WS_ERROR_IPC_FAILED;
657     }
658 
659     sptr<IRemoteObject> remote = Remote();
660     if (remote == nullptr) {
661         WLOGFE("remote is null");
662         return WSError::WS_ERROR_IPC_FAILED;
663     }
664     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_LABEL),
665         data, reply, option) != ERR_NONE) {
666         WLOGFE("SendRequest failed");
667         return WSError::WS_ERROR_IPC_FAILED;
668     }
669     return static_cast<WSError>(reply.ReadInt32());
670 }
671 
SetSessionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & icon)672 WSError SceneSessionManagerProxy::SetSessionIcon(const sptr<IRemoteObject>& token,
673     const std::shared_ptr<Media::PixelMap>& icon)
674 {
675     WLOGFI("run SceneSessionManagerProxy::SetSessionIcon");
676     MessageParcel data;
677     MessageParcel reply;
678     MessageOption option;
679     if (!data.WriteInterfaceToken(GetDescriptor())) {
680         WLOGFE("WriteInterfaceToken failed");
681         return WSError::WS_ERROR_IPC_FAILED;
682     }
683     if (!data.WriteRemoteObject(token)) {
684         WLOGFE("Write token failed");
685         return WSError::WS_ERROR_IPC_FAILED;
686     }
687     if (!data.WriteParcelable(icon.get())) {
688         WLOGFE("Write icon failed");
689         return WSError::WS_ERROR_IPC_FAILED;
690     }
691 
692     sptr<IRemoteObject> remote = Remote();
693     if (remote == nullptr) {
694         WLOGFE("remote is null");
695         return WSError::WS_ERROR_IPC_FAILED;
696     }
697     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_ICON),
698         data, reply, option) != ERR_NONE) {
699         WLOGFE("SendRequest failed");
700         return WSError::WS_ERROR_IPC_FAILED;
701     }
702     return static_cast<WSError>(reply.ReadInt32());
703 }
704 
IsValidSessionIds(const std::vector<int32_t> & sessionIds,std::vector<bool> & results)705 WSError SceneSessionManagerProxy::IsValidSessionIds(
706     const std::vector<int32_t>& sessionIds, std::vector<bool>& results)
707 {
708     WLOGFI("run SceneSessionManagerProxy::IsValidSessionIds");
709     MessageParcel data;
710     MessageParcel reply;
711     MessageOption option;
712     if (!data.WriteInterfaceToken(GetDescriptor())) {
713         WLOGFE("WriteInterfaceToken failed");
714         return WSError::WS_ERROR_IPC_FAILED;
715     }
716     if (!data.WriteInt32Vector(sessionIds)) {
717         WLOGFE("Write sessionIds failed");
718         return WSError::WS_ERROR_IPC_FAILED;
719     }
720 
721     sptr<IRemoteObject> remote = Remote();
722     if (remote == nullptr) {
723         WLOGFE("remote is null");
724         return WSError::WS_ERROR_IPC_FAILED;
725     }
726     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_VALID_SESSION_IDS),
727         data, reply, option) != ERR_NONE) {
728         WLOGFE("SendRequest failed");
729         return WSError::WS_ERROR_IPC_FAILED;
730     }
731 
732     reply.ReadBoolVector(&results);
733     return static_cast<WSError>(reply.ReadInt32());
734 }
735 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)736 WMError SceneSessionManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
737 {
738     MessageOption option;
739     MessageParcel reply;
740     MessageParcel data;
741     if (!data.WriteInterfaceToken(GetDescriptor())) {
742         WLOGFE("Write InterfaceToken failed");
743         return WMError::WM_ERROR_IPC_FAILED;
744     }
745 
746     sptr<IRemoteObject> remote = Remote();
747     if (remote == nullptr) {
748         WLOGFE("remote is null");
749         return WMError::WM_ERROR_IPC_FAILED;
750     }
751     if (remote->SendRequest(static_cast<uint32_t>(
752         SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_INFO),
753         data, reply, option) != ERR_NONE) {
754         WLOGFE("SendRequest failed");
755         return WMError::WM_ERROR_IPC_FAILED;
756     }
757 
758     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
759         WLOGFE("read window info failed.");
760         return WMError::WM_ERROR_IPC_FAILED;
761     }
762     return static_cast<WMError>(reply.ReadUint32());
763 }
764 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)765 WMError SceneSessionManagerProxy::GetUnreliableWindowInfo(int32_t windowId,
766     std::vector<sptr<UnreliableWindowInfo>>& infos)
767 {
768     TLOGD(WmsLogTag::DEFAULT, "run!");
769     MessageOption option;
770     MessageParcel reply;
771     MessageParcel data;
772     if (!data.WriteInterfaceToken(GetDescriptor())) {
773         TLOGE(WmsLogTag::DEFAULT, "Write InterfaceToken failed");
774         return WMError::WM_ERROR_IPC_FAILED;
775     }
776 
777     if (!data.WriteInt32(windowId)) {
778         TLOGE(WmsLogTag::DEFAULT, "Write windowId failed");
779         return WMError::WM_ERROR_IPC_FAILED;
780     }
781 
782     sptr<IRemoteObject> remote = Remote();
783     if (remote == nullptr) {
784         TLOGE(WmsLogTag::DEFAULT, "remote is null");
785         return WMError::WM_ERROR_IPC_FAILED;
786     }
787     if (remote->SendRequest(static_cast<uint32_t>(
788         SceneSessionManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO),
789         data, reply, option) != ERR_NONE) {
790         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
791         return WMError::WM_ERROR_IPC_FAILED;
792     }
793 
794     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<UnreliableWindowInfo>(reply, infos)) {
795         TLOGE(WmsLogTag::DEFAULT, "read window info failed.");
796         return WMError::WM_ERROR_IPC_FAILED;
797     }
798     return static_cast<WMError>(reply.ReadInt32());
799 }
800 
PendingSessionToForeground(const sptr<IRemoteObject> & token)801 WSError SceneSessionManagerProxy::PendingSessionToForeground(const sptr<IRemoteObject>& token)
802 {
803     WLOGFI("run SceneSessionManagerProxy::PendingSessionToForeground");
804     MessageParcel data;
805     MessageParcel reply;
806     MessageOption option;
807     if (!data.WriteInterfaceToken(GetDescriptor())) {
808         WLOGFE("Write interfaceToken failed");
809         return WSError::WS_ERROR_IPC_FAILED;
810     }
811 
812     if (!data.WriteRemoteObject(token)) {
813         WLOGFE("Write token failed");
814         return WSError::WS_ERROR_IPC_FAILED;
815     }
816 
817     sptr<IRemoteObject> remote = Remote();
818     if (remote == nullptr) {
819         WLOGFE("remote is null");
820         return WSError::WS_ERROR_IPC_FAILED;
821     }
822     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND),
823         data, reply, option) != ERR_NONE) {
824         WLOGFE("SendRequest failed");
825         return WSError::WS_ERROR_IPC_FAILED;
826     }
827     return static_cast<WSError>(reply.ReadInt32());
828 }
829 
PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> & token,bool shouldBackToCaller)830 WSError SceneSessionManagerProxy::PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject>& token,
831     bool shouldBackToCaller)
832 {
833     TLOGD(WmsLogTag::WMS_LIFE, "run");
834     MessageParcel data;
835     MessageParcel reply;
836     MessageOption option;
837     if (!data.WriteInterfaceToken(GetDescriptor())) {
838         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
839         return WSError::WS_ERROR_IPC_FAILED;
840     }
841 
842     if (!data.WriteRemoteObject(token)) {
843         TLOGE(WmsLogTag::WMS_LIFE, "Write token failed");
844         return WSError::WS_ERROR_IPC_FAILED;
845     }
846 
847     if (!data.WriteBool(shouldBackToCaller)) {
848         TLOGE(WmsLogTag::WMS_LIFE, "Write shouldBackToCaller failed");
849         return WSError::WS_ERROR_IPC_FAILED;
850     }
851 
852     sptr<IRemoteObject> remote = Remote();
853     if (remote == nullptr) {
854         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
855         return WSError::WS_ERROR_IPC_FAILED;
856     }
857     if (remote->SendRequest(static_cast<uint32_t>(
858         SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR),
859         data, reply, option) != ERR_NONE) {
860         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
861         return WSError::WS_ERROR_IPC_FAILED;
862     }
863     return static_cast<WSError>(reply.ReadInt32());
864 }
865 
RegisterSessionListener(const sptr<ISessionListener> & listener)866 WSError SceneSessionManagerProxy::RegisterSessionListener(const sptr<ISessionListener>& listener)
867 {
868     WLOGFI("run SceneSessionManagerProxy::RegisterSessionListener");
869     MessageParcel data;
870     MessageParcel reply;
871     MessageOption option(MessageOption::TF_SYNC);
872     if (listener == nullptr) {
873         WLOGFE("register mission listener, listener is nullptr");
874         return WSError::WS_ERROR_INVALID_PARAM;
875     }
876     if (!data.WriteInterfaceToken(GetDescriptor())) {
877         WLOGFE("WriteInterfaceToken failed");
878         return WSError::WS_ERROR_IPC_FAILED;
879     }
880     if (!data.WriteRemoteObject(listener->AsObject())) {
881         WLOGFE("write mission listener failed when register mission listener.");
882         return WSError::WS_ERROR_IPC_FAILED;
883     }
884     sptr<IRemoteObject> remote = Remote();
885     if (remote == nullptr) {
886         WLOGFE("remote is null");
887         return WSError::WS_ERROR_IPC_FAILED;
888     }
889     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_LISTENER),
890         data, reply, option) != ERR_NONE) {
891         WLOGFE("SendRequest failed");
892         return WSError::WS_ERROR_IPC_FAILED;
893     }
894     return static_cast<WSError>(reply.ReadInt32());
895 }
896 
UnRegisterSessionListener(const sptr<ISessionListener> & listener)897 WSError SceneSessionManagerProxy::UnRegisterSessionListener(const sptr<ISessionListener>& listener)
898 {
899     WLOGFI("run SceneSessionManagerProxy::UnRegisterSessionListener");
900     if (listener == nullptr) {
901         WLOGFE("unregister mission listener, listener is nullptr");
902         return WSError::WS_ERROR_INVALID_PARAM;
903     }
904     MessageParcel data;
905     MessageParcel reply;
906     MessageOption option(MessageOption::TF_SYNC);
907     if (!data.WriteInterfaceToken(GetDescriptor())) {
908         WLOGFE("WriteInterfaceToken failed");
909         return WSError::WS_ERROR_IPC_FAILED;
910     }
911     if (!data.WriteRemoteObject(listener->AsObject())) {
912         WLOGFE("write mission listener failed when unregister mission listener.");
913         return WSError::WS_ERROR_IPC_FAILED;
914     }
915     sptr<IRemoteObject> remote = Remote();
916     if (remote == nullptr) {
917         WLOGFE("remote is null");
918         return WSError::WS_ERROR_IPC_FAILED;
919     }
920     if (remote->SendRequest(
921         static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER),
922         data, reply, option) != ERR_NONE) {
923         WLOGFE("SendRequest failed");
924         return WSError::WS_ERROR_IPC_FAILED;
925     }
926     return static_cast<WSError>(reply.ReadInt32());
927 }
928 
GetSessionInfos(const std::string & deviceId,int32_t numMax,std::vector<SessionInfoBean> & sessionInfos)929 WSError SceneSessionManagerProxy::GetSessionInfos(const std::string& deviceId, int32_t numMax,
930                                                   std::vector<SessionInfoBean>& sessionInfos)
931 {
932     WLOGFI("run SceneSessionManagerProxy::GetSessionInfos");
933     MessageParcel data;
934     MessageParcel reply;
935     MessageOption option(MessageOption::TF_SYNC);
936     if (!data.WriteInterfaceToken(GetDescriptor())) {
937         WLOGFE("WriteInterfaceToken failed");
938         return WSError::WS_ERROR_IPC_FAILED;
939     }
940     if (!data.WriteString16(Str8ToStr16(deviceId))) {
941         WLOGFE("GetSessionInfos write deviceId failed.");
942         return WSError::WS_ERROR_IPC_FAILED;
943     }
944     if (!data.WriteInt32(numMax)) {
945         WLOGFE("GetSessionInfos numMax write failed.");
946         return WSError::WS_ERROR_IPC_FAILED;
947     }
948     sptr<IRemoteObject> remote = Remote();
949     if (remote == nullptr) {
950         WLOGFE("remote is null");
951         return WSError::WS_ERROR_IPC_FAILED;
952     }
953     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFOS),
954         data, reply, option) != ERR_NONE) {
955         WLOGFE("SendRequest failed");
956         return WSError::WS_ERROR_IPC_FAILED;
957     }
958     WSError error = GetParcelableInfos(reply, sessionInfos);
959     if (error != WSError::WS_OK) {
960         WLOGFE("GetSessionInfos error");
961         return error;
962     }
963     return static_cast<WSError>(reply.ReadInt32());
964 }
965 
GetSessionInfo(const std::string & deviceId,int32_t persistentId,SessionInfoBean & sessionInfo)966 WSError SceneSessionManagerProxy::GetSessionInfo(const std::string& deviceId, int32_t persistentId,
967                                                  SessionInfoBean& sessionInfo)
968 {
969     WLOGFI("run SceneSessionManagerProxy::GetSessionInfo");
970     MessageParcel data;
971     MessageParcel reply;
972     MessageOption option(MessageOption::TF_SYNC);
973     if (!data.WriteInterfaceToken(GetDescriptor())) {
974         WLOGFE("WriteInterfaceToken failed");
975         return WSError::WS_ERROR_IPC_FAILED;
976     }
977     if (!data.WriteString16(Str8ToStr16(deviceId))) {
978         WLOGFE("GetSessionInfo write deviceId failed.");
979         return WSError::WS_ERROR_IPC_FAILED;
980     }
981     if (!data.WriteInt32(persistentId)) {
982         WLOGFE("GetSessionInfo write persistentId failed.");
983         return WSError::WS_ERROR_IPC_FAILED;
984     }
985     sptr<IRemoteObject> remote = Remote();
986     if (remote == nullptr) {
987         WLOGFE("remote is null");
988         return WSError::WS_ERROR_IPC_FAILED;
989     }
990     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFO_BY_ID),
991         data, reply, option) != ERR_NONE) {
992         WLOGFE("SendRequest failed");
993         return WSError::WS_ERROR_IPC_FAILED;
994     }
995     std::unique_ptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
996     if (info == nullptr) {
997         WLOGFE("read missioninfo failed.");
998         return WSError::WS_ERROR_IPC_FAILED;
999     }
1000     sessionInfo = *info;
1001     return static_cast<WSError>(reply.ReadInt32());
1002 }
1003 
GetSessionInfoByContinueSessionId(const std::string & continueSessionId,SessionInfoBean & sessionInfo)1004 WSError SceneSessionManagerProxy::GetSessionInfoByContinueSessionId(
1005     const std::string& continueSessionId, SessionInfoBean& sessionInfo)
1006 {
1007     TLOGD(WmsLogTag::WMS_LIFE, "run query session info");
1008     MessageParcel data;
1009     MessageParcel reply;
1010     MessageOption option(MessageOption::TF_SYNC);
1011     if (!data.WriteInterfaceToken(GetDescriptor())) {
1012         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
1013         return WSError::WS_ERROR_IPC_FAILED;
1014     }
1015     if (!data.WriteString(continueSessionId)) {
1016         TLOGE(WmsLogTag::WMS_LIFE, "GetSessionInfoByContinueSessionId write continueSessionId failed.");
1017         return WSError::WS_ERROR_IPC_FAILED;
1018     }
1019     sptr<IRemoteObject> remote = Remote();
1020     if (remote == nullptr) {
1021         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1022         return WSError::WS_ERROR_IPC_FAILED;
1023     }
1024     if (remote->SendRequest(static_cast<uint32_t>(
1025         SceneSessionManagerMessage::TRANS_ID_GET_SESSION_INFO_BY_CONTINUE_SESSION_ID),
1026         data, reply, option) != ERR_NONE) {
1027         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1028         return WSError::WS_ERROR_IPC_FAILED;
1029     }
1030     sptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
1031     if (info == nullptr) {
1032         TLOGE(WmsLogTag::WMS_LIFE, "read sessioninfo failed.");
1033         return WSError::WS_ERROR_IPC_FAILED;
1034     }
1035     sessionInfo = *info;
1036     return static_cast<WSError>(reply.ReadInt32());
1037 }
1038 
DumpSessionAll(std::vector<std::string> & infos)1039 WSError SceneSessionManagerProxy::DumpSessionAll(std::vector<std::string>& infos)
1040 {
1041     WLOGFI("run SceneSessionManagerProxy::DumpSessionAll");
1042     MessageParcel data;
1043     MessageParcel reply;
1044     MessageOption option(MessageOption::TF_SYNC);
1045     if (!data.WriteInterfaceToken(GetDescriptor())) {
1046         WLOGFE("DumpSessionAll write interface token failed.");
1047         return WSError::WS_ERROR_IPC_FAILED;
1048     }
1049     sptr<IRemoteObject> remote = Remote();
1050     if (remote == nullptr) {
1051         WLOGFE("remote is null");
1052         return WSError::WS_ERROR_IPC_FAILED;
1053     }
1054     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_ALL),
1055         data, reply, option) != ERR_NONE) {
1056         WLOGFE("DumpSessionAll sendRequest failed.");
1057         return WSError::WS_ERROR_IPC_FAILED;
1058     }
1059     if (!reply.ReadStringVector(&infos)) {
1060         WLOGFE("DumpSessionAll read session info failed.");
1061         return WSError::WS_ERROR_IPC_FAILED;
1062     }
1063     return static_cast<WSError>(reply.ReadInt32());
1064 }
1065 
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)1066 WSError SceneSessionManagerProxy::DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos)
1067 {
1068     WLOGFI("run SceneSessionManagerProxy::DumpSessionWithId");
1069     MessageParcel data;
1070     MessageParcel reply;
1071     MessageOption option(MessageOption::TF_SYNC);
1072     if (!data.WriteInterfaceToken(GetDescriptor())) {
1073         WLOGFE("DumpSessionWithId write interface token failed.");
1074         return WSError::WS_ERROR_IPC_FAILED;
1075     }
1076     if (!data.WriteInt32(persistentId)) {
1077         WLOGFE("DumpSessionWithId write persistentId failed.");
1078         return WSError::WS_ERROR_IPC_FAILED;
1079     }
1080     sptr<IRemoteObject> remote = Remote();
1081     if (remote == nullptr) {
1082         WLOGFE("remote is null");
1083         return WSError::WS_ERROR_IPC_FAILED;
1084     }
1085     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_WITH_ID),
1086         data, reply, option) != ERR_NONE) {
1087         WLOGFE("DumpSessionWithId sendRequest failed.");
1088         return WSError::WS_ERROR_IPC_FAILED;
1089     }
1090     if (!reply.ReadStringVector(&infos)) {
1091         WLOGFE("DumpSessionWithId read session info failed.");
1092         return WSError::WS_ERROR_IPC_FAILED;
1093     }
1094     return static_cast<WSError>(reply.ReadInt32());
1095 }
1096 
1097 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)1098 WSError SceneSessionManagerProxy::GetParcelableInfos(MessageParcel& reply, std::vector<T>& parcelableInfos)
1099 {
1100     int32_t infoSize = reply.ReadInt32();
1101     if (infoSize > CYCLE_LIMIT) {
1102         WLOGFE("infoSize is too large");
1103         return WSError::WS_ERROR_IPC_FAILED;
1104     }
1105 
1106     for (int32_t i = 0; i < infoSize; i++) {
1107         std::unique_ptr<T> info(reply.ReadParcelable<T>());
1108         if (!info) {
1109             WLOGFE("Read Parcelable infos failed.");
1110             return WSError::WS_ERROR_IPC_FAILED;
1111         }
1112         parcelableInfos.emplace_back(*info);
1113     }
1114     return WSError::WS_OK;
1115 }
1116 
TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needStartCaller,bool isFromBroker)1117 WSError SceneSessionManagerProxy::TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,
1118     bool needStartCaller, bool isFromBroker)
1119 {
1120     if (abilitySessionInfo == nullptr) {
1121         WLOGFE("abilitySessionInfo is null");
1122         return WSError::WS_ERROR_INVALID_SESSION;
1123     }
1124     MessageParcel data, reply;
1125     MessageOption option(MessageOption::TF_ASYNC);
1126     if (!data.WriteInterfaceToken(GetDescriptor())) {
1127         WLOGFE("WriteInterfaceToken failed");
1128         return WSError::WS_ERROR_IPC_FAILED;
1129     }
1130     if (!data.WriteParcelable(abilitySessionInfo)) {
1131         WLOGFE("write abilitySessionInfo failed");
1132         return WSError::WS_ERROR_IPC_FAILED;
1133     }
1134     if (!data.WriteBool(needStartCaller)) {
1135         WLOGFE("Write needStartCaller failed");
1136         return WSError::WS_ERROR_IPC_FAILED;
1137     }
1138     if (!data.WriteBool(isFromBroker)) {
1139         WLOGFE("Write isFromBroker failed");
1140         return WSError::WS_ERROR_IPC_FAILED;
1141     }
1142     sptr<IRemoteObject> remote = Remote();
1143     if (remote == nullptr) {
1144         WLOGFE("remote is null");
1145         return WSError::WS_ERROR_IPC_FAILED;
1146     }
1147     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_TERMINATE_SESSION_NEW),
1148         data, reply, option) != ERR_NONE) {
1149         WLOGFE("SendRequest failed");
1150         return WSError::WS_ERROR_IPC_FAILED;
1151     }
1152     return static_cast<WSError>(reply.ReadInt32());
1153 }
1154 
GetFocusSessionToken(sptr<IRemoteObject> & token)1155 WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr<IRemoteObject>& token)
1156 {
1157     WLOGFD("run SceneSessionManagerProxy::GetFocusSessionToken");
1158     MessageParcel data;
1159     MessageParcel reply;
1160     MessageOption option;
1161     if (!data.WriteInterfaceToken(GetDescriptor())) {
1162         WLOGFE("Write interfaceToken failed");
1163         return WSError::WS_ERROR_IPC_FAILED;
1164     }
1165 
1166     sptr<IRemoteObject> remote = Remote();
1167     if (remote == nullptr) {
1168         WLOGFE("remote is null");
1169         return WSError::WS_ERROR_IPC_FAILED;
1170     }
1171     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
1172         data, reply, option) != ERR_NONE) {
1173         WLOGFE("SendRequest failed");
1174         return WSError::WS_ERROR_IPC_FAILED;
1175     }
1176     token = reply.ReadRemoteObject();
1177     if (token == nullptr) {
1178         WLOGFD("get token nullptr.");
1179     }
1180     return static_cast<WSError>(reply.ReadInt32());
1181 }
1182 
GetFocusSessionElement(AppExecFwk::ElementName & element)1183 WSError SceneSessionManagerProxy::GetFocusSessionElement(AppExecFwk::ElementName& element)
1184 {
1185     WLOGFD("run SceneSessionManagerProxy::GetFocusSessionElement");
1186     MessageParcel data;
1187     MessageParcel reply;
1188     MessageOption option;
1189     if (!data.WriteInterfaceToken(GetDescriptor())) {
1190         WLOGFE("Write interfaceToken failed");
1191         return WSError::WS_ERROR_IPC_FAILED;
1192     }
1193     sptr<IRemoteObject> remote = Remote();
1194     if (remote == nullptr) {
1195         WLOGFE("remote is null");
1196         return WSError::WS_ERROR_IPC_FAILED;
1197     }
1198     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT),
1199         data, reply, option) != ERR_NONE) {
1200         WLOGFE("SendRequest failed");
1201         return WSError::WS_ERROR_IPC_FAILED;
1202     }
1203     sptr<AppExecFwk::ElementName> ret = reply.ReadParcelable<AppExecFwk::ElementName>();
1204     if (ret) {
1205         element = *ret;
1206     } else {
1207         WLOGFD("get element null.");
1208     }
1209     return static_cast<WSError>(reply.ReadInt32());
1210 }
1211 
CheckWindowId(int32_t windowId,int32_t & pid)1212 WMError SceneSessionManagerProxy::CheckWindowId(int32_t windowId, int32_t& pid)
1213 {
1214     MessageParcel data;
1215     MessageParcel reply;
1216     MessageOption option;
1217     if (!data.WriteInterfaceToken(GetDescriptor())) {
1218         WLOGFE("Failed to write interfaceToken");
1219         return WMError::WM_ERROR_IPC_FAILED;
1220     }
1221     if (!data.WriteInt32(windowId)) {
1222         WLOGFE("Failed to write windowId");
1223         return WMError::WM_ERROR_IPC_FAILED;
1224     }
1225     sptr<IRemoteObject> remote = Remote();
1226     if (remote == nullptr) {
1227         WLOGFE("remote is nullptr");
1228         return WMError::WM_ERROR_NULLPTR;
1229     }
1230     int32_t ret = remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CHECK_WINDOW_ID),
1231         data, reply, option);
1232     if (ret != ERR_NONE) {
1233         WLOGFE("Send request failed, ret:%{public}d", ret);
1234         return WMError::WM_ERROR_IPC_FAILED;
1235     }
1236     if (!reply.ReadInt32(pid)) {
1237         WLOGFE("Failed to read pid");
1238         return WMError::WM_ERROR_IPC_FAILED;
1239     }
1240     return WMError::WM_OK;
1241 }
1242 
GetSessionDumpInfo(const std::vector<std::string> & params,std::string & info)1243 WSError SceneSessionManagerProxy::GetSessionDumpInfo(const std::vector<std::string>& params, std::string& info)
1244 {
1245     MessageParcel data;
1246     MessageParcel reply;
1247     MessageOption option;
1248     if (!data.WriteInterfaceToken(GetDescriptor())) {
1249         WLOGFE("WriteInterfaceToken failed");
1250         return WSError::WS_ERROR_INVALID_PARAM;
1251     }
1252     if (!data.WriteStringVector(params)) {
1253         WLOGFE("Write params failed");
1254         return WSError::WS_ERROR_IPC_FAILED;
1255     }
1256     sptr<IRemoteObject> remote = Remote();
1257     if (remote == nullptr) {
1258         WLOGFE("remote is null");
1259         return WSError::WS_ERROR_IPC_FAILED;
1260     }
1261     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_DUMP_INFO),
1262         data, reply, option) != ERR_NONE) {
1263         WLOGFE("SendRequest failed");
1264         return WSError::WS_ERROR_IPC_FAILED;
1265     }
1266 
1267     auto infoSize = reply.ReadUint32();
1268     if (infoSize != 0) {
1269         const char* infoPtr = nullptr;
1270         infoPtr = reinterpret_cast<const char*>(reply.ReadRawData(infoSize));
1271         info = (infoPtr) ? std::string(infoPtr, infoSize) : "";
1272     }
1273     WLOGFD("GetSessionDumpInfo, infoSize: %{public}d", infoSize);
1274     return static_cast<WSError>(reply.ReadInt32());
1275 }
1276 
GetSessionSnapshot(const std::string & deviceId,int32_t persistentId,SessionSnapshot & snapshot,bool isLowResolution)1277 WSError SceneSessionManagerProxy::GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
1278                                                      SessionSnapshot& snapshot, bool isLowResolution)
1279 {
1280     MessageParcel data;
1281     MessageParcel reply;
1282     MessageOption option;
1283     if (!data.WriteInterfaceToken(GetDescriptor())) {
1284         WLOGFE("WriteInterfaceToken failed");
1285         return WSError::WS_ERROR_INVALID_PARAM;
1286     }
1287     if (!data.WriteString16(Str8ToStr16(deviceId))) {
1288         WLOGFE("Write deviceId failed.");
1289         return WSError::WS_ERROR_IPC_FAILED;
1290     }
1291     if (!data.WriteInt32(persistentId)) {
1292         WLOGFE("Write persistentId failed");
1293         return WSError::WS_ERROR_INVALID_PARAM;
1294     }
1295 
1296     if (!data.WriteBool(isLowResolution)) {
1297         WLOGFE("Write isLowResolution failed");
1298         return WSError::WS_ERROR_INVALID_PARAM;
1299     }
1300 
1301     sptr<IRemoteObject> remote = Remote();
1302     if (remote == nullptr) {
1303         WLOGFE("remote is null");
1304         return WSError::WS_ERROR_IPC_FAILED;
1305     }
1306     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
1307         data, reply, option) != ERR_NONE) {
1308         WLOGFE("SendRequest failed");
1309         return WSError::WS_ERROR_IPC_FAILED;
1310     }
1311     std::unique_ptr<SessionSnapshot> info(reply.ReadParcelable<SessionSnapshot>());
1312     if (info) {
1313         snapshot = *info;
1314     } else {
1315         WLOGFW("Read SessionSnapshot is null.");
1316     }
1317     return static_cast<WSError>(reply.ReadInt32());
1318 }
1319 
GetUIContentRemoteObj(int32_t persistentId,sptr<IRemoteObject> & uiContentRemoteObj)1320 WSError SceneSessionManagerProxy::GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj)
1321 {
1322     MessageParcel data;
1323     MessageParcel reply;
1324     MessageOption option;
1325     if (!data.WriteInterfaceToken(GetDescriptor())) {
1326         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
1327         return WSError::WS_ERROR_INVALID_PARAM;
1328     }
1329     if (!data.WriteInt32(persistentId)) {
1330         TLOGE(WmsLogTag::DEFAULT, "Write persistentId failed");
1331         return WSError::WS_ERROR_INVALID_PARAM;
1332     }
1333 
1334     sptr<IRemoteObject> remote = Remote();
1335     if (remote == nullptr) {
1336         TLOGE(WmsLogTag::DEFAULT, "remote is null");
1337         return WSError::WS_ERROR_IPC_FAILED;
1338     }
1339     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_UI_CONTENT_REMOTE_OBJ),
1340         data, reply, option) != ERR_NONE) {
1341         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
1342         return WSError::WS_ERROR_IPC_FAILED;
1343     }
1344     sptr<IRemoteObject> remoteObj = reply.ReadRemoteObject();
1345     if (remoteObj == nullptr) {
1346         TLOGE(WmsLogTag::DEFAULT, "ReadRemoteObject failed");
1347         return WSError::WS_ERROR_IPC_FAILED;
1348     }
1349     uiContentRemoteObj = remoteObj;
1350     return static_cast<WSError>(reply.ReadUint32());
1351 }
1352 
SetSessionContinueState(const sptr<IRemoteObject> & token,const ContinueState & continueState)1353 WSError SceneSessionManagerProxy::SetSessionContinueState(const sptr<IRemoteObject>& token,
1354     const ContinueState& continueState)
1355 {
1356     MessageParcel data;
1357     MessageParcel reply;
1358     MessageOption option;
1359     if (!data.WriteInterfaceToken(GetDescriptor())) {
1360         WLOGFE("WriteInterfaceToken failed");
1361         return WSError::WS_ERROR_INVALID_PARAM;
1362     }
1363     if (!data.WriteRemoteObject(token)) {
1364         WLOGFE("Write token failed");
1365         return WSError::WS_ERROR_IPC_FAILED;
1366     }
1367     if (!data.WriteInt32(static_cast<int32_t>(continueState))) {
1368         WLOGFE("Write continueState failed");
1369         return WSError::WS_ERROR_IPC_FAILED;
1370     }
1371     sptr<IRemoteObject> remote = Remote();
1372     if (remote == nullptr) {
1373         WLOGFE("remote is null");
1374         return WSError::WS_ERROR_IPC_FAILED;
1375     }
1376     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
1377         data, reply, option) != ERR_NONE) {
1378         WLOGFE("SendRequest failed");
1379         return WSError::WS_ERROR_IPC_FAILED;
1380     }
1381     return static_cast<WSError>(reply.ReadInt32());
1382 }
1383 
NotifyDumpInfoResult(const std::vector<std::string> & info)1384 void SceneSessionManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
1385 {
1386     MessageParcel data;
1387     MessageParcel reply;
1388     MessageOption option(MessageOption::TF_ASYNC);
1389     if (!data.WriteInterfaceToken(GetDescriptor())) {
1390         WLOGFE("WriteInterfaceToken pfailed");
1391         return;
1392     }
1393     uint32_t vectorSize = static_cast<uint32_t>(info.size());
1394     if (!data.WriteUint32(vectorSize)) {
1395         WLOGFE("Write vector size failed");
1396         return;
1397     }
1398     for (const auto& elem : info) {
1399         const char* curInfo = elem.c_str();
1400         uint32_t curSize = static_cast<uint32_t>(strlen(curInfo));
1401         WLOGFD("NotifyDumpInfoResult infoSize: %{public}u", curSize);
1402         if (!data.WriteUint32(curSize)) {
1403             WLOGFE("Write info size failed");
1404             return;
1405         }
1406         if (curSize != 0) {
1407             if (!data.WriteRawData(curInfo, curSize)) {
1408                 WLOGFE("Write info failed");
1409                 return;
1410             }
1411         }
1412     }
1413     sptr<IRemoteObject> remote = Remote();
1414     if (remote == nullptr) {
1415         WLOGFE("remote is null");
1416         return;
1417     }
1418     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
1419         data, reply, option) != ERR_NONE) {
1420         WLOGFE("SendRequest failed");
1421         return;
1422     }
1423 }
1424 
LockSession(int32_t sessionId)1425 WSError SceneSessionManagerProxy::LockSession(int32_t sessionId)
1426 {
1427     WLOGFI("run SceneSessionManagerProxy::LockSession");
1428     MessageParcel data;
1429     MessageParcel reply;
1430     MessageOption option;
1431 
1432     if (!data.WriteInterfaceToken(GetDescriptor())) {
1433         WLOGFE("Write interface token failed.");
1434         return WSError::WS_ERROR_INVALID_PARAM;
1435     }
1436     if (!data.WriteInt32(sessionId)) {
1437         WLOGFE("Write persistentId failed");
1438         return WSError::WS_ERROR_INVALID_PARAM;
1439     }
1440     sptr<IRemoteObject> remote = Remote();
1441     if (remote == nullptr) {
1442         WLOGFE("remote is null");
1443         return WSError::WS_ERROR_IPC_FAILED;
1444     }
1445     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_LOCK_SESSION),
1446         data, reply, option) != ERR_NONE) {
1447         WLOGFE("SendRequest failed");
1448         return WSError::WS_ERROR_IPC_FAILED;
1449     }
1450     return static_cast<WSError>(reply.ReadInt32());
1451 }
1452 
UnlockSession(int32_t sessionId)1453 WSError SceneSessionManagerProxy::UnlockSession(int32_t sessionId)
1454 {
1455     WLOGFI("run SceneSessionManagerProxy::UnlockSession");
1456     MessageParcel data;
1457     MessageParcel reply;
1458     MessageOption option;
1459 
1460     if (!data.WriteInterfaceToken(GetDescriptor())) {
1461         WLOGFE("Write interface token failed.");
1462         return WSError::WS_ERROR_INVALID_PARAM;
1463     }
1464     if (!data.WriteInt32(sessionId)) {
1465         WLOGFE("Write persistentId failed");
1466         return WSError::WS_ERROR_INVALID_PARAM;
1467     }
1468     sptr<IRemoteObject> remote = Remote();
1469     if (remote == nullptr) {
1470         WLOGFE("remote is null");
1471         return WSError::WS_ERROR_IPC_FAILED;
1472     }
1473     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNLOCK_SESSION),
1474         data, reply, option) != ERR_NONE) {
1475         WLOGFE("SendRequest failed");
1476         return WSError::WS_ERROR_IPC_FAILED;
1477     }
1478     return static_cast<WSError>(reply.ReadInt32());
1479 }
1480 
MoveSessionsToForeground(const std::vector<std::int32_t> & sessionIds,int32_t topSessionId)1481 WSError SceneSessionManagerProxy::MoveSessionsToForeground(const std::vector<std::int32_t>& sessionIds,
1482     int32_t topSessionId)
1483 {
1484     WLOGFI("run SceneSessionManagerProxy::MoveSessionsToForeground");
1485     MessageParcel data;
1486     MessageParcel reply;
1487     MessageOption option;
1488     if (!data.WriteInterfaceToken(GetDescriptor())) {
1489         WLOGFE("WriteInterfaceToken failed");
1490         return WSError::WS_ERROR_INVALID_PARAM;
1491     }
1492     if (!data.WriteInt32Vector(sessionIds)) {
1493         WLOGFE("Write sessionIds failed");
1494         return WSError::WS_ERROR_INVALID_PARAM;
1495     }
1496     if (!data.WriteInt32(topSessionId)) {
1497         WLOGFE("Write topSessionId failed");
1498         return WSError::WS_ERROR_INVALID_PARAM;
1499     }
1500     sptr<IRemoteObject> remote = Remote();
1501     if (remote == nullptr) {
1502         WLOGFE("remote is null");
1503         return WSError::WS_ERROR_IPC_FAILED;
1504     }
1505     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND),
1506         data, reply, option) != ERR_NONE) {
1507         WLOGFE("SendRequest failed");
1508         return WSError::WS_ERROR_IPC_FAILED;
1509     }
1510     return static_cast<WSError>(reply.ReadInt32());
1511 }
1512 
MoveSessionsToBackground(const std::vector<std::int32_t> & sessionIds,std::vector<int32_t> & result)1513 WSError SceneSessionManagerProxy::MoveSessionsToBackground(const std::vector<std::int32_t>& sessionIds,
1514     std::vector<int32_t>& result)
1515 {
1516     WLOGFI("run SceneSessionManagerProxy::MoveSessionsToBackground");
1517     MessageParcel data;
1518     MessageParcel reply;
1519     MessageOption option;
1520     if (!data.WriteInterfaceToken(GetDescriptor())) {
1521         WLOGFE("WriteInterfaceToken failed");
1522         return WSError::WS_ERROR_INVALID_PARAM;
1523     }
1524     if (!data.WriteInt32Vector(sessionIds)) {
1525         WLOGFE("Write sessionIds failed");
1526         return WSError::WS_ERROR_INVALID_PARAM;
1527     }
1528     if (!data.WriteInt32Vector(result)) {
1529         WLOGFE("Write result failed");
1530         return WSError::WS_ERROR_INVALID_PARAM;
1531     }
1532     sptr<IRemoteObject> remote = Remote();
1533     if (remote == nullptr) {
1534         WLOGFE("remote is null");
1535         return WSError::WS_ERROR_IPC_FAILED;
1536     }
1537     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND),
1538         data, reply, option) != ERR_NONE) {
1539         WLOGFE("SendRequest failed");
1540         return WSError::WS_ERROR_IPC_FAILED;
1541     }
1542     reply.ReadInt32Vector(&result);
1543     return static_cast<WSError>(reply.ReadInt32());
1544 }
1545 
ClearSession(int32_t persistentId)1546 WSError SceneSessionManagerProxy::ClearSession(int32_t persistentId)
1547 {
1548     WLOGFI("run SceneSessionManagerProxy::ClearSession");
1549     MessageParcel data;
1550     MessageParcel reply;
1551     MessageOption option;
1552     if (!data.WriteInterfaceToken(GetDescriptor())) {
1553         WLOGFE("ClearSession WriteInterfaceToken failed");
1554         return WSError::WS_ERROR_INVALID_PARAM;
1555     }
1556 
1557     if (!data.WriteInt32(persistentId)) {
1558         WLOGFE("Write persistentId failed");
1559         return WSError::WS_ERROR_INVALID_PARAM;
1560     }
1561 
1562     sptr<IRemoteObject> remote = Remote();
1563     if (remote == nullptr) {
1564         WLOGFE("remote is null");
1565         return WSError::WS_ERROR_IPC_FAILED;
1566     }
1567     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_SESSION),
1568         data, reply, option) != ERR_NONE) {
1569         WLOGFE("SendRequest failed");
1570         return WSError::WS_ERROR_IPC_FAILED;
1571     }
1572     return static_cast<WSError>(reply.ReadInt32());
1573 }
1574 
ClearAllSessions()1575 WSError SceneSessionManagerProxy::ClearAllSessions()
1576 {
1577     WLOGFI("run SceneSessionManagerProxy::ClearSession");
1578     MessageParcel data;
1579     MessageParcel reply;
1580     MessageOption option;
1581     if (!data.WriteInterfaceToken(GetDescriptor())) {
1582         WLOGFE("ClearAllSessions WriteInterfaceToken failed");
1583         return WSError::WS_ERROR_INVALID_PARAM;
1584     }
1585 
1586     sptr<IRemoteObject> remote = Remote();
1587     if (remote == nullptr) {
1588         WLOGFE("remote is null");
1589         return WSError::WS_ERROR_IPC_FAILED;
1590     }
1591     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
1592         data, reply, option) != ERR_NONE) {
1593         WLOGFE("SendRequest failed");
1594         return WSError::WS_ERROR_IPC_FAILED;
1595     }
1596     return static_cast<WSError>(reply.ReadInt32());
1597 }
1598 
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)1599 WSError SceneSessionManagerProxy::RegisterIAbilityManagerCollaborator(int32_t type,
1600     const sptr<AAFwk::IAbilityManagerCollaborator>& impl)
1601 {
1602     WLOGFI("run SceneSessionManagerProxy::RegisterIAbilityManagerCollaborator");
1603     if (!impl) {
1604         WLOGFE("impl is nullptr");
1605         return WSError::WS_ERROR_INVALID_PARAM;
1606     }
1607     MessageParcel data;
1608     MessageParcel reply;
1609     MessageOption option;
1610 
1611     if (!data.WriteInterfaceToken(GetDescriptor())) {
1612         WLOGFE("Write interface token failed.");
1613         return WSError::WS_ERROR_INVALID_PARAM;
1614     }
1615     if (!data.WriteInt32(type)) {
1616         WLOGFE("type write failed.");
1617         return WSError::WS_ERROR_INVALID_PARAM;
1618     }
1619     if (!data.WriteRemoteObject(impl->AsObject())) {
1620         WLOGFE("impl write failed.");
1621         return WSError::WS_ERROR_INVALID_PARAM;
1622     }
1623 
1624     sptr<IRemoteObject> remote = Remote();
1625     if (remote == nullptr) {
1626         WLOGFE("remote is null");
1627         return WSError::WS_ERROR_IPC_FAILED;
1628     }
1629     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_COLLABORATOR),
1630         data, reply, option) != ERR_NONE) {
1631         WLOGFE("SendRequest failed");
1632         return WSError::WS_ERROR_IPC_FAILED;
1633     }
1634     return static_cast<WSError>(reply.ReadInt32());
1635 }
1636 
UnregisterIAbilityManagerCollaborator(int32_t type)1637 WSError SceneSessionManagerProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
1638 {
1639     WLOGFI("run SceneSessionManagerProxy::UnregisterIAbilityManagerCollaborator");
1640     MessageParcel data;
1641     MessageParcel reply;
1642     MessageOption option;
1643 
1644     if (!data.WriteInterfaceToken(GetDescriptor())) {
1645         WLOGFE("Write interface token failed.");
1646         return WSError::WS_ERROR_INVALID_PARAM;
1647     }
1648     if (!data.WriteInt32(type)) {
1649         WLOGFE("type write failed.");
1650         return WSError::WS_ERROR_INVALID_PARAM;
1651     }
1652 
1653     sptr<IRemoteObject> remote = Remote();
1654     if (remote == nullptr) {
1655         WLOGFE("remote is null");
1656         return WSError::WS_ERROR_IPC_FAILED;
1657     }
1658     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
1659         data, reply, option) != ERR_NONE) {
1660         WLOGFE("SendRequest failed");
1661         return WSError::WS_ERROR_IPC_FAILED;
1662     }
1663     return static_cast<WSError>(reply.ReadInt32());
1664 }
1665 
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)1666 WSError SceneSessionManagerProxy::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
1667 {
1668     WLOGFI("run SceneSessionManagerProxy::NotifyWindowExtensionVisibilityChange");
1669     MessageParcel data;
1670     MessageParcel reply;
1671     MessageOption option(MessageOption::TF_ASYNC);
1672 
1673     if (!data.WriteInterfaceToken(GetDescriptor())) {
1674         WLOGFE("Write interface token failed.");
1675         return WSError::WS_ERROR_INVALID_PARAM;
1676     }
1677 
1678     if (!data.WriteInt32(pid)) {
1679         WLOGFE("pid write failed.");
1680         return WSError::WS_ERROR_INVALID_PARAM;
1681     }
1682 
1683     if (!data.WriteInt32(uid)) {
1684         WLOGFE("uid write failed.");
1685         return WSError::WS_ERROR_INVALID_PARAM;
1686     }
1687     if (!data.WriteBool(visible)) {
1688         WLOGFE("pid write failed.");
1689         return WSError::WS_ERROR_INVALID_PARAM;
1690     }
1691 
1692     sptr<IRemoteObject> remote = Remote();
1693     if (remote == nullptr) {
1694         WLOGFE("remote is null");
1695         return WSError::WS_ERROR_IPC_FAILED;
1696     }
1697     if (remote->SendRequest(static_cast<uint32_t>(
1698         SceneSessionManagerMessage::TRANS_ID_NOTIFY_WINDOW_EXTENSION_VISIBILITY_CHANGE),
1699         data, reply, option) != ERR_NONE) {
1700         WLOGFE("SendRequest failed");
1701         return WSError::WS_ERROR_IPC_FAILED;
1702     }
1703     return static_cast<WSError>(reply.ReadInt32());
1704 }
1705 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)1706 WMError SceneSessionManagerProxy::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
1707 {
1708     WLOGFD("[GetTopWin] mainId: %{public}d", mainWinId);
1709     MessageParcel data;
1710     MessageParcel reply;
1711     MessageOption option;
1712     if (!data.WriteInterfaceToken(GetDescriptor())) {
1713         WLOGFE("Write interface token failed.");
1714         return WMError::WM_ERROR_IPC_FAILED;
1715     }
1716 
1717     if (!data.WriteUint32(mainWinId)) {
1718         WLOGFE("Write mainWinId failed");
1719         return WMError::WM_ERROR_IPC_FAILED;
1720     }
1721 
1722     sptr<IRemoteObject> remote = Remote();
1723     if (remote == nullptr) {
1724         WLOGFE("remote is null");
1725         return WMError::WM_ERROR_IPC_FAILED;
1726     }
1727     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
1728         data, reply, option) != ERR_NONE) {
1729         WLOGFE("SendRequest failed");
1730         return WMError::WM_ERROR_IPC_FAILED;
1731     }
1732 
1733     topWinId = reply.ReadUint32();
1734     int32_t ret = reply.ReadInt32();
1735     return static_cast<WMError>(ret);
1736 }
1737 
GetParentMainWindowId(int32_t windowId,int32_t & mainWindowId)1738 WMError SceneSessionManagerProxy::GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId)
1739 {
1740     MessageParcel data;
1741     MessageParcel reply;
1742     MessageOption option(MessageOption::TF_SYNC);
1743     if (!data.WriteInterfaceToken(GetDescriptor())) {
1744         TLOGE(WmsLogTag::WMS_SUB, "WriteInterfaceToken failed");
1745         return WMError::WM_ERROR_IPC_FAILED;
1746     }
1747     if (!data.WriteInt32(windowId)) {
1748         TLOGE(WmsLogTag::WMS_SUB, "Write windowId failed");
1749         return WMError::WM_ERROR_IPC_FAILED;
1750     }
1751     sptr<IRemoteObject> remote = Remote();
1752     if (remote == nullptr) {
1753         TLOGE(WmsLogTag::WMS_SUB, "Remote is null");
1754         return WMError::WM_ERROR_IPC_FAILED;
1755     }
1756     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_PARENT_MAIN_WINDOW_ID),
1757         data, reply, option) != ERR_NONE) {
1758         TLOGE(WmsLogTag::WMS_SUB, "SendRequest failed");
1759         return WMError::WM_ERROR_IPC_FAILED;
1760     }
1761     int32_t replyMainWindowId = INVALID_SESSION_ID;
1762     if (!reply.ReadInt32(replyMainWindowId)) {
1763         return WMError::WM_ERROR_IPC_FAILED;
1764     }
1765     int32_t ret = 0;
1766     if (!reply.ReadInt32(ret)) {
1767         return WMError::WM_ERROR_IPC_FAILED;
1768     }
1769     mainWindowId = replyMainWindowId;
1770     return static_cast<WMError>(ret);
1771 }
1772 
GetAllWindowLayoutInfo(DisplayId displayId,std::vector<sptr<WindowLayoutInfo>> & infos)1773 WMError SceneSessionManagerProxy::GetAllWindowLayoutInfo(DisplayId displayId,
1774     std::vector<sptr<WindowLayoutInfo>>& infos)
1775 {
1776     MessageParcel data;
1777     MessageParcel reply;
1778     MessageOption option;
1779     if (!data.WriteInterfaceToken(GetDescriptor())) {
1780         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write interfaceToken failed");
1781         return WMError::WM_ERROR_IPC_FAILED;
1782     }
1783     if (!data.WriteUint64(displayId)) {
1784         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed");
1785         return WMError::WM_ERROR_IPC_FAILED;
1786     }
1787     sptr<IRemoteObject> remote = Remote();
1788     if (remote == nullptr) {
1789         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null");
1790         return WMError::WM_ERROR_IPC_FAILED;
1791     }
1792     if (remote->SendRequest(static_cast<uint32_t>(
1793         SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_LAYOUT_INFO), data, reply, option) != ERR_NONE) {
1794         return WMError::WM_ERROR_IPC_FAILED;
1795     }
1796     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowLayoutInfo>(reply, infos)) {
1797         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read window layout info failed");
1798         return WMError::WM_ERROR_IPC_FAILED;
1799     }
1800     int32_t errCode = 0;
1801     if (!reply.ReadInt32(errCode)) {
1802         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read errcode failed");
1803         return WMError::WM_ERROR_IPC_FAILED;
1804     }
1805     return static_cast<WMError>(errCode);
1806 }
1807 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)1808 WMError SceneSessionManagerProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
1809 {
1810     MessageParcel data;
1811     MessageParcel reply;
1812     MessageOption option;
1813     if (!data.WriteInterfaceToken(GetDescriptor())) {
1814         WLOGFE("GetVisibilityWindowInfo Write interfaceToken failed");
1815         return WMError::WM_ERROR_IPC_FAILED;
1816     }
1817     sptr<IRemoteObject> remote = Remote();
1818     if (remote == nullptr) {
1819         WLOGFE("remote is null");
1820         return WMError::WM_ERROR_IPC_FAILED;
1821     }
1822     if (remote->SendRequest(static_cast<uint32_t>(
1823         SceneSessionManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) {
1824         return WMError::WM_ERROR_IPC_FAILED;
1825     }
1826     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
1827         WLOGFE("read visibility window infos failed");
1828         return WMError::WM_ERROR_IPC_FAILED;
1829     }
1830     return static_cast<WMError>(reply.ReadInt32());
1831 }
1832 
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)1833 WSError SceneSessionManagerProxy::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
1834 {
1835     WLOGFD("run SceneSessionManagerProxy::ShiftAppWindowFocus");
1836     MessageParcel data;
1837     MessageParcel reply;
1838     MessageOption option(MessageOption::TF_SYNC);
1839     if (!data.WriteInterfaceToken(GetDescriptor())) {
1840         WLOGFE("Write interface token failed.");
1841         return WSError::WS_ERROR_INVALID_PARAM;
1842     }
1843 
1844     if (!data.WriteUint32(sourcePersistentId)) {
1845         WLOGFE("Write sourcePersistentId failed");
1846         return WSError::WS_ERROR_INVALID_PARAM;
1847     }
1848 
1849     if (!data.WriteUint32(targetPersistentId)) {
1850         WLOGFE("Write targetPersistentId failed");
1851         return WSError::WS_ERROR_INVALID_PARAM;
1852     }
1853 
1854     sptr<IRemoteObject> remote = Remote();
1855     if (remote == nullptr) {
1856         WLOGFE("remote is null");
1857         return WSError::WS_ERROR_IPC_FAILED;
1858     }
1859     if (remote->SendRequest(static_cast<uint32_t>(
1860         SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_FOCUS),
1861         data, reply, option) != ERR_NONE) {
1862         WLOGFE("SendRequest failed");
1863         return WSError::WS_ERROR_IPC_FAILED;
1864     }
1865     return static_cast<WSError>(reply.ReadInt32());
1866 }
1867 
UpdateModalExtensionRect(const sptr<IRemoteObject> & token,Rect rect)1868 void SceneSessionManagerProxy::UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect)
1869 {
1870     MessageOption option(MessageOption::TF_SYNC);
1871     MessageParcel data;
1872     MessageParcel reply;
1873     if (!data.WriteInterfaceToken(GetDescriptor())) {
1874         TLOGE(WmsLogTag::WMS_UIEXT, "Write interface token failed.");
1875         return;
1876     }
1877     if (!data.WriteRemoteObject(token)) {
1878         TLOGE(WmsLogTag::WMS_UIEXT, "Write token failed");
1879         return;
1880     }
1881     if (!data.WriteInt32(rect.posX_)) {
1882         TLOGE(WmsLogTag::WMS_UIEXT, "Write posX_ failed");
1883         return;
1884     }
1885     if (!data.WriteInt32(rect.posY_)) {
1886         TLOGE(WmsLogTag::WMS_UIEXT, "Write posY_ failed");
1887         return;
1888     }
1889     if (!data.WriteInt32(rect.width_)) {
1890         TLOGE(WmsLogTag::WMS_UIEXT, "Write width_ failed");
1891         return;
1892     }
1893     if (!data.WriteInt32(rect.height_)) {
1894         TLOGE(WmsLogTag::WMS_UIEXT, "Write height_ failed");
1895         return;
1896     }
1897     sptr<IRemoteObject> remote = Remote();
1898     if (remote == nullptr) {
1899         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1900         return;
1901     }
1902     if (remote->SendRequest(static_cast<uint32_t>(
1903                             SceneSessionManagerMessage::TRANS_ID_UPDATE_MODALEXTENSION_RECT_TO_SCB),
1904                             data, reply, option) != ERR_NONE) {
1905         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1906     }
1907 }
1908 
ProcessModalExtensionPointDown(const sptr<IRemoteObject> & token,int32_t posX,int32_t posY)1909 void SceneSessionManagerProxy::ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX,
1910     int32_t posY)
1911 {
1912     MessageOption option(MessageOption::TF_SYNC);
1913     MessageParcel data;
1914     MessageParcel reply;
1915     if (!data.WriteInterfaceToken(GetDescriptor())) {
1916         TLOGE(WmsLogTag::WMS_UIEXT, "Write interface token failed.");
1917         return;
1918     }
1919     if (!data.WriteRemoteObject(token)) {
1920         TLOGE(WmsLogTag::WMS_UIEXT, "Write token failed");
1921         return;
1922     }
1923     if (!data.WriteInt32(posX)) {
1924         TLOGE(WmsLogTag::WMS_UIEXT, "Write posX failed");
1925         return;
1926     }
1927     if (!data.WriteInt32(posY)) {
1928         TLOGE(WmsLogTag::WMS_UIEXT, "Write posY failed");
1929         return;
1930     }
1931     sptr<IRemoteObject> remote = Remote();
1932     if (remote == nullptr) {
1933         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1934         return;
1935     }
1936     if (remote->SendRequest(static_cast<uint32_t>(
1937                             SceneSessionManagerMessage::TRANS_ID_PROCESS_MODALEXTENSION_POINTDOWN_TO_SCB),
1938                             data, reply, option) != ERR_NONE) {
1939         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1940     }
1941 }
1942 
AddExtensionWindowStageToSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,uint64_t surfaceNodeId,bool isConstrainedModal)1943 void SceneSessionManagerProxy::AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage,
1944     const sptr<IRemoteObject>& token, uint64_t surfaceNodeId, bool isConstrainedModal)
1945 {
1946     if (sessionStage == nullptr || token == nullptr) {
1947         TLOGE(WmsLogTag::WMS_UIEXT, "input is nullptr");
1948         return;
1949     }
1950     MessageOption option(MessageOption::TF_SYNC);
1951     MessageParcel data;
1952     MessageParcel reply;
1953     if (!data.WriteInterfaceToken(GetDescriptor())) {
1954         TLOGE(WmsLogTag::WMS_UIEXT, "Write InterfaceToken failed!");
1955         return;
1956     }
1957     if (!data.WriteRemoteObject(sessionStage->AsObject())) {
1958         TLOGE(WmsLogTag::WMS_UIEXT, "Write ISessionStage failed!");
1959         return;
1960     }
1961     if (!data.WriteRemoteObject(token)) {
1962         TLOGE(WmsLogTag::WMS_UIEXT, "Write token failed");
1963         return;
1964     }
1965     if (!data.WriteUint64(static_cast<uint64_t>(surfaceNodeId))) {
1966         TLOGE(WmsLogTag::WMS_UIEXT, "Write surfaceNodeId failed");
1967         return;
1968     }
1969     if (!data.WriteBool(isConstrainedModal)) {
1970         TLOGE(WmsLogTag::WMS_UIEXT, "Write isConstrainedModal failed");
1971         return;
1972     }
1973     sptr<IRemoteObject> remote = Remote();
1974     if (remote == nullptr) {
1975         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1976         return;
1977     }
1978     if (remote->SendRequest(static_cast<uint32_t>(
1979                             SceneSessionManagerMessage::TRANS_ID_ADD_EXTENSION_WINDOW_STAGE_TO_SCB),
1980                             data, reply, option) != ERR_NONE) {
1981         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1982     }
1983 }
1984 
RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,bool isConstrainedModal)1985 void SceneSessionManagerProxy::RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage,
1986     const sptr<IRemoteObject>& token, bool isConstrainedModal)
1987 {
1988     if (sessionStage == nullptr || token == nullptr) {
1989         TLOGE(WmsLogTag::WMS_UIEXT, "input is nullptr");
1990         return;
1991     }
1992     MessageOption option(MessageOption::TF_SYNC);
1993     MessageParcel data;
1994     MessageParcel reply;
1995     if (!data.WriteInterfaceToken(GetDescriptor())) {
1996         TLOGE(WmsLogTag::WMS_UIEXT, "Write InterfaceToken failed!");
1997         return;
1998     }
1999     if (!data.WriteRemoteObject(sessionStage->AsObject())) {
2000         TLOGE(WmsLogTag::WMS_UIEXT, "Write ISessionStage failed!");
2001         return;
2002     }
2003     if (!data.WriteRemoteObject(token)) {
2004         TLOGE(WmsLogTag::WMS_UIEXT, "Write token failed");
2005         return;
2006     }
2007     if (!data.WriteBool(isConstrainedModal)) {
2008         TLOGE(WmsLogTag::WMS_UIEXT, "Write isConstrainedModal failed");
2009         return;
2010     }
2011     sptr<IRemoteObject> remote = Remote();
2012     if (remote == nullptr) {
2013         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
2014         return;
2015     }
2016     if (remote->SendRequest(static_cast<uint32_t>(
2017                             SceneSessionManagerMessage::TRANS_ID_REMOVE_EXTENSION_WINDOW_STAGE_FROM_SCB),
2018                             data, reply, option) != ERR_NONE) {
2019         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
2020     }
2021 }
2022 
AddOrRemoveSecureSession(int32_t persistentId,bool shouldHide)2023 WSError SceneSessionManagerProxy::AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide)
2024 {
2025     MessageParcel data;
2026     MessageParcel reply;
2027     MessageOption option(MessageOption::TF_SYNC);
2028     if (!data.WriteInterfaceToken(GetDescriptor())) {
2029         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
2030         return WSError::WS_ERROR_IPC_FAILED;
2031     }
2032     if (!data.WriteInt32(persistentId)) {
2033         TLOGE(WmsLogTag::WMS_UIEXT, "Write persistentId failed");
2034         return WSError::WS_ERROR_IPC_FAILED;
2035     }
2036     if (!data.WriteBool(shouldHide)) {
2037         TLOGE(WmsLogTag::WMS_UIEXT, "Write shouldHide failed");
2038         return WSError::WS_ERROR_IPC_FAILED;
2039     }
2040     sptr<IRemoteObject> remote = Remote();
2041     if (remote == nullptr) {
2042         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
2043         return WSError::WS_ERROR_IPC_FAILED;
2044     }
2045     if (remote->SendRequest(static_cast<uint32_t>(
2046                             SceneSessionManagerMessage::TRANS_ID_ADD_OR_REMOVE_SECURE_SESSION),
2047                             data, reply, option) != ERR_NONE) {
2048         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
2049         return WSError::WS_ERROR_IPC_FAILED;
2050     }
2051     return static_cast<WSError>(reply.ReadInt32());
2052 }
2053 
UpdateExtWindowFlags(const sptr<IRemoteObject> & token,uint32_t extWindowFlags,uint32_t extWindowActions)2054 WSError SceneSessionManagerProxy::UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags,
2055     uint32_t extWindowActions)
2056 {
2057     TLOGD(WmsLogTag::WMS_UIEXT, "run SceneSessionManagerProxy::UpdateExtWindowFlags");
2058     MessageParcel data;
2059     MessageParcel reply;
2060     MessageOption option(MessageOption::TF_SYNC);
2061     if (!data.WriteInterfaceToken(GetDescriptor())) {
2062         TLOGE(WmsLogTag::WMS_UIEXT, "Write interface token failed.");
2063         return WSError::WS_ERROR_IPC_FAILED;
2064     }
2065     if (!data.WriteRemoteObject(token)) {
2066         TLOGE(WmsLogTag::WMS_UIEXT, "Write token failed");
2067         return WSError::WS_ERROR_IPC_FAILED;
2068     }
2069     if (!data.WriteUint32(extWindowFlags)) {
2070         TLOGE(WmsLogTag::WMS_UIEXT, "Write extWindowFlags failed");
2071         return WSError::WS_ERROR_IPC_FAILED;
2072     }
2073     if (!data.WriteUint32(extWindowActions)) {
2074         TLOGE(WmsLogTag::WMS_UIEXT, "Write extWindowActions failed");
2075         return WSError::WS_ERROR_IPC_FAILED;
2076     }
2077     sptr<IRemoteObject> remote = Remote();
2078     if (remote == nullptr) {
2079         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
2080         return WSError::WS_ERROR_IPC_FAILED;
2081     }
2082     if (remote->SendRequest(
2083         static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_EXTENSION_WINDOW_FLAGS),
2084         data, reply, option) != ERR_NONE) {
2085         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest AddExtensionSessionInfo failed");
2086         return WSError::WS_ERROR_IPC_FAILED;
2087     }
2088     return static_cast<WSError>(reply.ReadInt32());
2089 }
2090 
GetHostWindowRect(int32_t hostWindowId,Rect & rect)2091 WSError SceneSessionManagerProxy::GetHostWindowRect(int32_t hostWindowId, Rect& rect)
2092 {
2093     TLOGD(WmsLogTag::WMS_UIEXT, "run SceneSessionManagerProxy::GetHostWindowRect");
2094     MessageParcel data;
2095     MessageParcel reply;
2096     MessageOption option;
2097     if (!data.WriteInterfaceToken(GetDescriptor())) {
2098         TLOGE(WmsLogTag::WMS_UIEXT, "Write interface token failed.");
2099         return WSError::WS_ERROR_IPC_FAILED;
2100     }
2101     if (!data.WriteInt32(hostWindowId)) {
2102         TLOGE(WmsLogTag::WMS_UIEXT, "Write hostWindowId failed");
2103         return WSError::WS_ERROR_IPC_FAILED;
2104     }
2105     sptr<IRemoteObject> remote = Remote();
2106     if (remote == nullptr) {
2107         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
2108         return WSError::WS_ERROR_IPC_FAILED;
2109     }
2110     if (remote->SendRequest(
2111         static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_HOST_WINDOW_RECT),
2112         data, reply, option) != ERR_NONE) {
2113         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest GetHostWindowRect failed");
2114         return WSError::WS_ERROR_IPC_FAILED;
2115     }
2116     auto posX = reply.ReadInt32();
2117     auto posY = reply.ReadInt32();
2118     auto width = reply.ReadUint32();
2119     auto height = reply.ReadUint32();
2120     rect = {posX, posY, width, height};
2121     return static_cast<WSError>(reply.ReadInt32());
2122 }
2123 
GetFreeMultiWindowEnableState(bool & enable)2124 WSError SceneSessionManagerProxy::GetFreeMultiWindowEnableState(bool& enable)
2125 {
2126     TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "run SceneSessionManagerProxy::GetFreeMultiWindowEnableState");
2127     MessageParcel data;
2128     MessageParcel reply;
2129     MessageOption option;
2130     if (!data.WriteInterfaceToken(GetDescriptor())) {
2131         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write interface token failed.");
2132         return WSError::WS_ERROR_IPC_FAILED;
2133     }
2134     sptr<IRemoteObject> remote = Remote();
2135     if (remote == nullptr) {
2136         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is nullptr");
2137         return WSError::WS_ERROR_NULLPTR;
2138     }
2139     if (remote->SendRequest(
2140         static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FREE_MULTI_WINDOW_ENABLE_STATE),
2141         data, reply, option) != ERR_NONE) {
2142         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "SendRequest GetFreeMultiWindowEnableState failed");
2143         return WSError::WS_ERROR_IPC_FAILED;
2144     }
2145     auto isEnable = reply.ReadBool();
2146     enable = isEnable;
2147     return static_cast<WSError>(reply.ReadInt32());
2148 }
2149 
GetCallingWindowWindowStatus(int32_t persistentId,WindowStatus & windowStatus)2150 WMError SceneSessionManagerProxy::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus)
2151 {
2152     MessageParcel data;
2153     MessageParcel reply;
2154     MessageOption option;
2155 
2156     if (!data.WriteInterfaceToken(GetDescriptor())) {
2157         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
2158         return WMError::WM_ERROR_IPC_FAILED;
2159     }
2160     if (!data.WriteInt32(persistentId)) {
2161         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write windowId failed");
2162         return WMError::WM_ERROR_IPC_FAILED;
2163     }
2164     sptr<IRemoteObject> remote = Remote();
2165     if (remote == nullptr) {
2166         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
2167         return WMError::WM_ERROR_IPC_FAILED;
2168     }
2169     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_STATUS),
2170         data, reply, option) != ERR_NONE) {
2171         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
2172         return WMError::WM_ERROR_IPC_FAILED;
2173     }
2174     auto ret = static_cast<WMError>(reply.ReadInt32());
2175     if (ret == WMError::WM_OK) {
2176         windowStatus = static_cast<WindowStatus>(reply.ReadUint32());
2177     }
2178     return ret;
2179 }
2180 
GetCallingWindowRect(int32_t persistentId,Rect & rect)2181 WMError SceneSessionManagerProxy::GetCallingWindowRect(int32_t persistentId, Rect& rect)
2182 {
2183     MessageParcel data;
2184     MessageParcel reply;
2185     MessageOption option;
2186     if (!data.WriteInterfaceToken(GetDescriptor())) {
2187         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
2188         return WMError::WM_ERROR_IPC_FAILED;
2189     }
2190     if (!data.WriteInt32(persistentId)) {
2191         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write windowId failed");
2192         return WMError::WM_ERROR_IPC_FAILED;
2193     }
2194     sptr<IRemoteObject> remote = Remote();
2195     if (remote == nullptr) {
2196         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
2197         return WMError::WM_ERROR_IPC_FAILED;
2198     }
2199     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_RECT),
2200         data, reply, option) != ERR_NONE) {
2201         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
2202         return WMError::WM_ERROR_IPC_FAILED;
2203     }
2204     auto ret = static_cast<WMError>(reply.ReadInt32());
2205     if (ret == WMError::WM_OK) {
2206         rect.posX_ = reply.ReadInt32();
2207         rect.posY_ = reply.ReadInt32();
2208         rect.width_ = reply.ReadUint32();
2209         rect.height_ = reply.ReadUint32();
2210     }
2211     return ret;
2212 }
2213 
GetWindowModeType(WindowModeType & windowModeType)2214 WMError SceneSessionManagerProxy::GetWindowModeType(WindowModeType& windowModeType)
2215 {
2216     MessageParcel data;
2217     MessageParcel reply;
2218     MessageOption option;
2219     if (!data.WriteInterfaceToken(GetDescriptor())) {
2220         WLOGFE("GetWindowModeType Write interfaceToken failed");
2221         return WMError::WM_ERROR_IPC_FAILED;
2222     }
2223     sptr<IRemoteObject> remote = Remote();
2224     if (remote == nullptr) {
2225         WLOGFE("remote is null");
2226         return WMError::WM_ERROR_IPC_FAILED;
2227     }
2228     if (remote->SendRequest(static_cast<uint32_t>(
2229         SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_MODE_TYPE), data, reply, option) != ERR_NONE) {
2230         return WMError::WM_ERROR_IPC_FAILED;
2231     }
2232     windowModeType = static_cast<WindowModeType>(reply.ReadUint32());
2233     return static_cast<WMError>(reply.ReadInt32());
2234 }
2235 
MinimizeAllAppWindows(DisplayId displayId)2236 WMError SceneSessionManagerProxy::MinimizeAllAppWindows(DisplayId displayId)
2237 {
2238     if (!Permission::IsSystemCallingOrStartByHdcd(true)) {
2239         TLOGE(WmsLogTag::WMS_LIFE, "Not system app, no right, displayId %{public}" PRIu64, displayId);
2240         return WMError::WM_ERROR_NOT_SYSTEM_APP;
2241     }
2242     TLOGE(WmsLogTag::WMS_LIFE, "Not support minimize, displayId %{public}" PRIu64, displayId);
2243     return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
2244 }
2245 
ToggleShownStateForAllAppWindows()2246 WMError SceneSessionManagerProxy::ToggleShownStateForAllAppWindows()
2247 {
2248     if (!Permission::IsSystemCallingOrStartByHdcd(true)) {
2249         TLOGE(WmsLogTag::WMS_LIFE, "Not system app, no right");
2250         return WMError::WM_ERROR_NOT_SYSTEM_APP;
2251     }
2252     TLOGE(WmsLogTag::WMS_LIFE, "Not support call toggleShownState");
2253     return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
2254 }
2255 
GetWindowStyleType(WindowStyleType & windowStyleType)2256 WMError SceneSessionManagerProxy::GetWindowStyleType(WindowStyleType& windowStyleType)
2257 {
2258     MessageParcel data;
2259     MessageParcel reply;
2260     MessageOption option;
2261     if (!data.WriteInterfaceToken(GetDescriptor())) {
2262         TLOGE(WmsLogTag::WMS_LIFE, "GetwindowStyleType Write interfaceToken failed");
2263         return WMError::WM_ERROR_IPC_FAILED;
2264     }
2265     if (Remote()->SendRequest(static_cast<uint32_t>(
2266         SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE), data, reply, option) != ERR_NONE) {
2267         return WMError::WM_ERROR_IPC_FAILED;
2268     }
2269     windowStyleType = static_cast<WindowStyleType>(reply.ReadUint32());
2270     return static_cast<WMError>(reply.ReadInt32());
2271 }
2272 
GetProcessSurfaceNodeIdByPersistentId(const int32_t pid,const std::vector<int32_t> & persistentIds,std::vector<uint64_t> & surfaceNodeIds)2273 WMError SceneSessionManagerProxy::GetProcessSurfaceNodeIdByPersistentId(const int32_t pid,
2274     const std::vector<int32_t>& persistentIds, std::vector<uint64_t>& surfaceNodeIds)
2275 {
2276     MessageParcel data;
2277     MessageParcel reply;
2278     MessageOption option;
2279     if (!data.WriteInterfaceToken(GetDescriptor())) {
2280         TLOGE(WmsLogTag::DEFAULT, "Write interfaceToken failed");
2281         return WMError::WM_ERROR_IPC_FAILED;
2282     }
2283     if (!data.WriteInt32(pid)) {
2284         TLOGE(WmsLogTag::DEFAULT, "Write pid failed");
2285         return WMError::WM_ERROR_IPC_FAILED;
2286     }
2287     if (!data.WriteInt32Vector(persistentIds)) {
2288         TLOGE(WmsLogTag::DEFAULT, "Write persistentIds failed");
2289         return WMError::WM_ERROR_IPC_FAILED;
2290     }
2291     sptr<IRemoteObject> remote = Remote();
2292     if (remote == nullptr) {
2293         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2294         return WMError::WM_ERROR_IPC_FAILED;
2295     }
2296     if (remote->SendRequest(static_cast<uint32_t>(
2297         SceneSessionManagerMessage::TRANS_ID_GET_PROCESS_SURFACENODEID_BY_PERSISTENTID),
2298         data, reply, option) != ERR_NONE) {
2299         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
2300         return WMError::WM_ERROR_IPC_FAILED;
2301     }
2302     reply.ReadUInt64Vector(&surfaceNodeIds);
2303     return static_cast<WMError>(reply.ReadInt32());
2304 }
2305 
GetWindowIdsByCoordinate(DisplayId displayId,int32_t windowNumber,int32_t x,int32_t y,std::vector<int32_t> & windowIds)2306 WMError SceneSessionManagerProxy::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
2307     int32_t x, int32_t y, std::vector<int32_t>& windowIds)
2308 {
2309     MessageParcel data;
2310     MessageParcel reply;
2311     MessageOption option;
2312     if (!data.WriteInterfaceToken(GetDescriptor())) {
2313         TLOGE(WmsLogTag::DEFAULT, "Write interfaceToken failed");
2314         return WMError::WM_ERROR_IPC_FAILED;
2315     }
2316     if (!data.WriteUint64(displayId)) {
2317         TLOGE(WmsLogTag::DEFAULT, "Write displayId failed");
2318         return WMError::WM_ERROR_IPC_FAILED;
2319     }
2320     if (!data.WriteInt32(windowNumber)) {
2321         TLOGE(WmsLogTag::DEFAULT, "Write windowNumber failed");
2322         return WMError::WM_ERROR_IPC_FAILED;
2323     }
2324     if (!data.WriteInt32(x)) {
2325         TLOGE(WmsLogTag::DEFAULT, "Write x failed");
2326         return WMError::WM_ERROR_IPC_FAILED;
2327     }
2328     if (!data.WriteInt32(y)) {
2329         TLOGE(WmsLogTag::DEFAULT, "Write y failed");
2330         return WMError::WM_ERROR_IPC_FAILED;
2331     }
2332     sptr<IRemoteObject> remote = Remote();
2333     if (remote == nullptr) {
2334         TLOGE(WmsLogTag::DEFAULT, "remote is null");
2335         return WMError::WM_ERROR_IPC_FAILED;
2336     }
2337     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_IDS_BY_COORDINATE),
2338         data, reply, option) != ERR_NONE) {
2339         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
2340         return WMError::WM_ERROR_IPC_FAILED;
2341     }
2342     auto ret = static_cast<WMError>(reply.ReadInt32());
2343     if (ret == WMError::WM_OK) {
2344         reply.ReadInt32Vector(&windowIds);
2345     }
2346     return ret;
2347 }
2348 
ReleaseForegroundSessionScreenLock()2349 WMError SceneSessionManagerProxy::ReleaseForegroundSessionScreenLock()
2350 {
2351     MessageParcel data;
2352     MessageParcel reply;
2353     MessageOption option;
2354     if (!data.WriteInterfaceToken(GetDescriptor())) {
2355         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
2356         return WMError::WM_ERROR_IPC_FAILED;
2357     }
2358     if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RELEASE_SESSION_SCREEN_LOCK),
2359         data, reply, option) != ERR_NONE) {
2360         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
2361         return WMError::WM_ERROR_IPC_FAILED;
2362     }
2363     return static_cast<WMError>(reply.ReadInt32());
2364 }
2365 
GetDisplayIdByWindowId(const std::vector<uint64_t> & windowIds,std::unordered_map<uint64_t,DisplayId> & windowDisplayIdMap)2366 WMError SceneSessionManagerProxy::GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
2367     std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap)
2368 {
2369     MessageParcel data;
2370     MessageParcel reply;
2371     MessageOption option;
2372     if (!data.WriteInterfaceToken(GetDescriptor())) {
2373         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
2374         return WMError::WM_ERROR_IPC_FAILED;
2375     }
2376     if (!data.WriteUInt64Vector(windowIds)) {
2377         TLOGE(WmsLogTag::DEFAULT, "Write windowIds failed");
2378         return WMError::WM_ERROR_IPC_FAILED;
2379     }
2380     if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_DISPLAYID_BY_WINDOWID),
2381         data, reply, option) != ERR_NONE) {
2382         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
2383         return WMError::WM_ERROR_IPC_FAILED;
2384     }
2385     int32_t mapSize;
2386     if (!reply.ReadInt32(mapSize)) {
2387         TLOGE(WmsLogTag::DEFAULT, "Fail to read mapSize");
2388         return WMError::WM_ERROR_IPC_FAILED;
2389     }
2390     for (int32_t i = 0; i < mapSize; i++) {
2391         uint64_t windowId;
2392         if (!reply.ReadUint64(windowId)) {
2393             TLOGE(WmsLogTag::DEFAULT, "Fail to read windowId");
2394             return WMError::WM_ERROR_IPC_FAILED;
2395         }
2396         uint64_t displayId;
2397         if (!reply.ReadUint64(displayId)) {
2398             TLOGE(WmsLogTag::DEFAULT, "Fail to read displayId");
2399             return WMError::WM_ERROR_IPC_FAILED;
2400         }
2401         windowDisplayIdMap[windowId] = displayId;
2402     }
2403     return static_cast<WMError>(reply.ReadInt32());
2404 }
2405 
IsPcOrPadFreeMultiWindowMode(bool & isPcOrPadFreeMultiWindowMode)2406 WMError SceneSessionManagerProxy::IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode)
2407 {
2408     MessageParcel data;
2409     MessageParcel reply;
2410     MessageOption option;
2411     if (!data.WriteInterfaceToken(GetDescriptor())) {
2412         TLOGE(WmsLogTag::WMS_SUB, "Write interfaceToken failed");
2413         return WMError::WM_ERROR_IPC_FAILED;
2414     }
2415     sptr<IRemoteObject> remote = Remote();
2416     if (remote == nullptr) {
2417         TLOGE(WmsLogTag::WMS_SUB, "Remote is null");
2418         return WMError::WM_ERROR_IPC_FAILED;
2419     }
2420     if (remote->SendRequest(static_cast<uint32_t>(
2421         SceneSessionManagerMessage::TRANS_ID_IS_PC_OR_PAD_FREE_MULTI_WINDOW_MODE),
2422         data, reply, option) != ERR_NONE) {
2423         TLOGE(WmsLogTag::WMS_SUB, "SendRequest failed");
2424         return WMError::WM_ERROR_IPC_FAILED;
2425     }
2426     bool repliedValue = false;
2427     if (!reply.ReadBool(repliedValue)) {
2428         TLOGE(WmsLogTag::WMS_SUB, "Read isPcOrPadFreeMultiWindowMode failed");
2429         return WMError::WM_ERROR_IPC_FAILED;
2430     }
2431     int32_t ret = 0;
2432     if (!reply.ReadInt32(ret)) {
2433         TLOGE(WmsLogTag::WMS_SUB, "Read ret failed");
2434         return WMError::WM_ERROR_IPC_FAILED;
2435     }
2436     isPcOrPadFreeMultiWindowMode = repliedValue;
2437     return static_cast<WMError>(ret);
2438 }
2439 
IsPcWindow(bool & isPcWindow)2440 WMError SceneSessionManagerProxy::IsPcWindow(bool& isPcWindow)
2441 {
2442     MessageParcel data;
2443     MessageParcel reply;
2444     MessageOption option;
2445     if (!data.WriteInterfaceToken(GetDescriptor())) {
2446         TLOGE(WmsLogTag::WMS_UIEXT, "Write interfaceToken failed");
2447         return WMError::WM_ERROR_IPC_FAILED;
2448     }
2449     sptr<IRemoteObject> remote = Remote();
2450     if (remote == nullptr) {
2451         TLOGE(WmsLogTag::WMS_UIEXT, "Remote is null");
2452         return WMError::WM_ERROR_IPC_FAILED;
2453     }
2454     if (remote->SendRequest(static_cast<uint32_t>(
2455         SceneSessionManagerMessage::TRANS_ID_IS_PC_WINDOW),
2456         data, reply, option) != ERR_NONE) {
2457         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
2458         return WMError::WM_ERROR_IPC_FAILED;
2459     }
2460     bool result = false;
2461     if (!reply.ReadBool(result)) {
2462         TLOGE(WmsLogTag::WMS_UIEXT, "Read isPcWindow failed");
2463         return WMError::WM_ERROR_IPC_FAILED;
2464     }
2465     int32_t ret = 0;
2466     if (!reply.ReadInt32(ret)) {
2467         TLOGE(WmsLogTag::WMS_UIEXT, "Read ret failed");
2468         return WMError::WM_ERROR_IPC_FAILED;
2469     }
2470     isPcWindow = result;
2471     return static_cast<WMError>(ret);
2472 }
2473 
IsWindowRectAutoSave(const std::string & key,bool & enabled)2474 WMError SceneSessionManagerProxy::IsWindowRectAutoSave(const std::string& key, bool& enabled)
2475 {
2476     MessageParcel data;
2477     MessageParcel reply;
2478     MessageOption option;
2479     if (!data.WriteInterfaceToken(GetDescriptor())) {
2480         TLOGE(WmsLogTag::WMS_MAIN, "Write interfaceToken failed");
2481         return WMError::WM_ERROR_IPC_FAILED;
2482     }
2483     if (!data.WriteString(key)) {
2484         TLOGE(WmsLogTag::WMS_MAIN, "Write key failed");
2485         return WMError::WM_ERROR_IPC_FAILED;
2486     }
2487     sptr<IRemoteObject> remote = Remote();
2488     if (remote == nullptr) {
2489         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
2490         return WMError::WM_ERROR_IPC_FAILED;
2491     }
2492     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_WINDOW_RECT_AUTO_SAVE),
2493         data, reply, option) != ERR_NONE) {
2494         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
2495         return WMError::WM_ERROR_IPC_FAILED;
2496     }
2497     if (!reply.ReadBool(enabled)) {
2498         TLOGE(WmsLogTag::WMS_MAIN, "Read enable failed");
2499         return WMError::WM_ERROR_IPC_FAILED;
2500     }
2501     uint32_t ret = 0;
2502     if (!reply.ReadUint32(ret)) {
2503         TLOGE(WmsLogTag::WMS_MAIN, "Read ret failed");
2504         return WMError::WM_ERROR_IPC_FAILED;
2505     }
2506     return static_cast<WMError>(ret);
2507 }
2508 
SetGlobalDragResizeType(DragResizeType dragResizeType)2509 WMError SceneSessionManagerProxy::SetGlobalDragResizeType(DragResizeType dragResizeType)
2510 {
2511     MessageParcel data;
2512     MessageParcel reply;
2513     MessageOption option;
2514     if (!data.WriteInterfaceToken(GetDescriptor())) {
2515         TLOGE(WmsLogTag::WMS_LAYOUT, "Write interfaceToken failed");
2516         return WMError::WM_ERROR_IPC_FAILED;
2517     }
2518     if (!data.WriteUint32(static_cast<uint32_t>(dragResizeType))) {
2519         TLOGE(WmsLogTag::WMS_LAYOUT, "Write dragResizeType failed");
2520         return WMError::WM_ERROR_IPC_FAILED;
2521     }
2522     sptr<IRemoteObject> remote = Remote();
2523     if (remote == nullptr) {
2524         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
2525         return WMError::WM_ERROR_IPC_FAILED;
2526     }
2527     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_GLOBAL_DRAG_RESIZE_TYPE),
2528         data, reply, option) != ERR_NONE) {
2529         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
2530         return WMError::WM_ERROR_IPC_FAILED;
2531     }
2532     uint32_t ret = 0;
2533     if (!reply.ReadUint32(ret)) {
2534         TLOGE(WmsLogTag::WMS_LAYOUT, "Read ret failed");
2535         return WMError::WM_ERROR_IPC_FAILED;
2536     }
2537     return static_cast<WMError>(ret);
2538 }
2539 
GetGlobalDragResizeType(DragResizeType & dragResizeType)2540 WMError SceneSessionManagerProxy::GetGlobalDragResizeType(DragResizeType& dragResizeType)
2541 {
2542     MessageParcel data;
2543     MessageParcel reply;
2544     MessageOption option;
2545     if (!data.WriteInterfaceToken(GetDescriptor())) {
2546         TLOGE(WmsLogTag::WMS_LAYOUT, "Write interfaceToken failed");
2547         return WMError::WM_ERROR_IPC_FAILED;
2548     }
2549     sptr<IRemoteObject> remote = Remote();
2550     if (remote == nullptr) {
2551         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
2552         return WMError::WM_ERROR_IPC_FAILED;
2553     }
2554     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_GLOBAL_DRAG_RESIZE_TYPE),
2555         data, reply, option) != ERR_NONE) {
2556         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
2557         return WMError::WM_ERROR_IPC_FAILED;
2558     }
2559     uint32_t obtainedDragResizeType = 0;
2560     if (!reply.ReadUint32(obtainedDragResizeType)) {
2561         TLOGE(WmsLogTag::WMS_LAYOUT, "Read dragResizeType failed");
2562         return WMError::WM_ERROR_IPC_FAILED;
2563     }
2564     if (obtainedDragResizeType > static_cast<uint32_t>(DragResizeType::RESIZE_WHEN_DRAG_END)) {
2565         TLOGE(WmsLogTag::WMS_LAYOUT, "bad dragResizeType value");
2566         return WMError::WM_ERROR_IPC_FAILED;
2567     }
2568     dragResizeType = static_cast<DragResizeType>(obtainedDragResizeType);
2569     uint32_t ret = 0;
2570     if (!reply.ReadUint32(ret)) {
2571         TLOGE(WmsLogTag::WMS_LAYOUT, "Read ret failed");
2572         return WMError::WM_ERROR_IPC_FAILED;
2573     }
2574     return static_cast<WMError>(ret);
2575 }
2576 
SetAppDragResizeType(const std::string & bundleName,DragResizeType dragResizeType)2577 WMError SceneSessionManagerProxy::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType)
2578 {
2579     MessageParcel data;
2580     MessageParcel reply;
2581     MessageOption option;
2582     if (!data.WriteInterfaceToken(GetDescriptor())) {
2583         TLOGE(WmsLogTag::WMS_LAYOUT, "Write interfaceToken failed");
2584         return WMError::WM_ERROR_IPC_FAILED;
2585     }
2586     if (!data.WriteString(bundleName)) {
2587         TLOGE(WmsLogTag::WMS_LAYOUT, "Write bundleName failed");
2588         return WMError::WM_ERROR_IPC_FAILED;
2589     }
2590     if (!data.WriteUint32(static_cast<uint32_t>(dragResizeType))) {
2591         TLOGE(WmsLogTag::WMS_LAYOUT, "Write dragResizeType failed");
2592         return WMError::WM_ERROR_IPC_FAILED;
2593     }
2594     sptr<IRemoteObject> remote = Remote();
2595     if (remote == nullptr) {
2596         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
2597         return WMError::WM_ERROR_IPC_FAILED;
2598     }
2599     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_APP_DRAG_RESIZE_TYPE),
2600         data, reply, option) != ERR_NONE) {
2601         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
2602         return WMError::WM_ERROR_IPC_FAILED;
2603     }
2604     uint32_t ret = 0;
2605     if (!reply.ReadUint32(ret)) {
2606         TLOGE(WmsLogTag::WMS_LAYOUT, "Read ret failed");
2607         return WMError::WM_ERROR_IPC_FAILED;
2608     }
2609     return static_cast<WMError>(ret);
2610 }
2611 
GetAppDragResizeType(const std::string & bundleName,DragResizeType & dragResizeType)2612 WMError SceneSessionManagerProxy::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType)
2613 {
2614     MessageParcel data;
2615     MessageParcel reply;
2616     MessageOption option;
2617     if (!data.WriteInterfaceToken(GetDescriptor())) {
2618         TLOGE(WmsLogTag::WMS_LAYOUT, "Write interfaceToken failed");
2619         return WMError::WM_ERROR_IPC_FAILED;
2620     }
2621     if (!data.WriteString(bundleName)) {
2622         TLOGE(WmsLogTag::WMS_LAYOUT, "Write bundleName failed");
2623         return WMError::WM_ERROR_IPC_FAILED;
2624     }
2625     sptr<IRemoteObject> remote = Remote();
2626     if (remote == nullptr) {
2627         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
2628         return WMError::WM_ERROR_IPC_FAILED;
2629     }
2630     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_APP_DRAG_RESIZE_TYPE),
2631         data, reply, option) != ERR_NONE) {
2632         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
2633         return WMError::WM_ERROR_IPC_FAILED;
2634     }
2635     uint32_t obtainedDragResizeType = 0;
2636     if (!reply.ReadUint32(obtainedDragResizeType)) {
2637         TLOGE(WmsLogTag::WMS_LAYOUT, "Read dragResizeType failed");
2638         return WMError::WM_ERROR_IPC_FAILED;
2639     }
2640     if (obtainedDragResizeType > static_cast<uint32_t>(DragResizeType::RESIZE_WHEN_DRAG_END)) {
2641         TLOGE(WmsLogTag::WMS_LAYOUT, "bad dragResizeType value");
2642         return WMError::WM_ERROR_IPC_FAILED;
2643     }
2644     dragResizeType = static_cast<DragResizeType>(obtainedDragResizeType);
2645     uint32_t ret = 0;
2646     if (!reply.ReadUint32(ret)) {
2647         TLOGE(WmsLogTag::WMS_LAYOUT, "Read ret failed");
2648         return WMError::WM_ERROR_IPC_FAILED;
2649     }
2650     return static_cast<WMError>(ret);
2651 }
2652 
ShiftAppWindowPointerEvent(int32_t sourcePersistentId,int32_t targetPersistentId)2653 WMError SceneSessionManagerProxy::ShiftAppWindowPointerEvent(int32_t sourcePersistentId, int32_t targetPersistentId)
2654 {
2655     MessageParcel data;
2656     MessageParcel reply;
2657     MessageOption option;
2658     if (!data.WriteInterfaceToken(GetDescriptor())) {
2659         TLOGE(WmsLogTag::WMS_PC, "Write interfaceToken failed");
2660         return WMError::WM_ERROR_IPC_FAILED;
2661     }
2662     if (!data.WriteInt32(sourcePersistentId)) {
2663         TLOGE(WmsLogTag::WMS_PC, "Write sourcePersistentId failed");
2664         return WMError::WM_ERROR_IPC_FAILED;
2665     }
2666     if (!data.WriteInt32(targetPersistentId)) {
2667         TLOGE(WmsLogTag::WMS_PC, "Write targetPersistentId failed");
2668         return WMError::WM_ERROR_IPC_FAILED;
2669     }
2670     sptr<IRemoteObject> remote = Remote();
2671     if (remote == nullptr) {
2672         TLOGE(WmsLogTag::WMS_PC, "remote is null");
2673         return WMError::WM_ERROR_IPC_FAILED;
2674     }
2675     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_POINTER_EVENT),
2676         data, reply, option) != ERR_NONE) {
2677         TLOGE(WmsLogTag::WMS_PC, "SendRequest failed");
2678         return WMError::WM_ERROR_IPC_FAILED;
2679     }
2680     return static_cast<WMError>(reply.ReadInt32());
2681 }
2682 
2683 } // namespace OHOS::Rosen
2684