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/container/include/zidl/session_stage_proxy.h"
17
18 #include <cstdint>
19 #include <ipc_types.h>
20 #include <message_option.h>
21 #include <message_parcel.h>
22
23 #include "window_manager_hilog.h"
24
25 namespace OHOS::Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"};
28 }
29
SetActive(bool active)30 WSError SessionStageProxy::SetActive(bool active)
31 {
32 MessageParcel data;
33 MessageParcel reply;
34 MessageOption option(MessageOption::TF_ASYNC);
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 WLOGFE("WriteInterfaceToken failed");
37 return WSError::WS_ERROR_IPC_FAILED;
38 }
39
40 if (!data.WriteBool(active)) {
41 WLOGFE("Write active failed");
42 return WSError::WS_ERROR_IPC_FAILED;
43 }
44
45 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_SET_ACTIVE),
46 data, reply, option) != ERR_NONE) {
47 WLOGFE("SendRequest failed");
48 return WSError::WS_ERROR_IPC_FAILED;
49 }
50 int32_t ret = reply.ReadInt32();
51 return static_cast<WSError>(ret);
52 }
53
UpdateRect(const WSRect & rect,SizeChangeReason reason)54 WSError SessionStageProxy::UpdateRect(const WSRect& rect, SizeChangeReason reason)
55 {
56 MessageParcel data;
57 MessageParcel reply;
58 MessageOption option(MessageOption::TF_ASYNC);
59 if (!data.WriteInterfaceToken(GetDescriptor())) {
60 WLOGFE("WriteInterfaceToken failed");
61 return WSError::WS_ERROR_IPC_FAILED;
62 }
63
64 if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
65 data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) {
66 WLOGFE("Write WindowRect failed");
67 return WSError::WS_ERROR_IPC_FAILED;
68 }
69
70 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
71 WLOGFE("Write SessionSizeChangeReason failed");
72 return WSError::WS_ERROR_IPC_FAILED;
73 }
74
75 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_SIZE_CHANGE),
76 data, reply, option) != ERR_NONE) {
77 WLOGFE("SendRequest failed");
78 return WSError::WS_ERROR_IPC_FAILED;
79 }
80 int32_t ret = reply.ReadInt32();
81 return static_cast<WSError>(ret);
82 }
83
HandleBackEvent()84 WSError SessionStageProxy::HandleBackEvent()
85 {
86 MessageParcel data;
87 MessageParcel reply;
88 MessageOption option(MessageOption::TF_ASYNC);
89 if (!data.WriteInterfaceToken(GetDescriptor())) {
90 WLOGFE("WriteInterfaceToken failed");
91 return WSError::WS_ERROR_IPC_FAILED;
92 }
93 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_HANDLE_BACK_EVENT),
94 data, reply, option) != ERR_NONE) {
95 WLOGFE("SendRequest failed");
96 return WSError::WS_ERROR_IPC_FAILED;
97 }
98 int32_t ret = reply.ReadInt32();
99 return static_cast<WSError>(ret);
100 }
101
MarkProcessed(int32_t eventId)102 WSError SessionStageProxy::MarkProcessed(int32_t eventId)
103 {
104 return WSError::WS_DO_NOTHING;
105 }
106
UpdateFocus(bool focus)107 WSError SessionStageProxy::UpdateFocus(bool focus)
108 {
109 MessageParcel data;
110 MessageParcel reply;
111 MessageOption option(MessageOption::TF_ASYNC);
112 if (!data.WriteInterfaceToken(GetDescriptor())) {
113 WLOGFE("WriteInterfaceToken failed");
114 return WSError::WS_ERROR_IPC_FAILED;
115 }
116
117 if (!data.WriteBool(focus)) {
118 WLOGFE("Write focus failed");
119 return WSError::WS_ERROR_IPC_FAILED;
120 }
121
122 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_FOCUS_CHANGE),
123 data, reply, option) != ERR_NONE) {
124 WLOGFE("SendRequest failed");
125 return WSError::WS_ERROR_IPC_FAILED;
126 }
127 int32_t ret = reply.ReadInt32();
128 return static_cast<WSError>(ret);
129 }
130
NotifyDestroy()131 WSError SessionStageProxy::NotifyDestroy()
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option(MessageOption::TF_ASYNC);
136 if (!data.WriteInterfaceToken(GetDescriptor())) {
137 WLOGFE("WriteInterfaceToken failed");
138 return WSError::WS_ERROR_IPC_FAILED;
139 }
140
141 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_DESTROY),
142 data, reply, option) != ERR_NONE) {
143 WLOGFE("SendRequest failed");
144 return WSError::WS_ERROR_IPC_FAILED;
145 }
146 int32_t ret = reply.ReadInt32();
147 return static_cast<WSError>(ret);
148 }
149
NotifyTouchDialogTarget()150 void SessionStageProxy::NotifyTouchDialogTarget()
151 {
152 MessageParcel data;
153 MessageParcel reply;
154 MessageOption option(MessageOption::TF_ASYNC);
155 if (!data.WriteInterfaceToken(GetDescriptor())) {
156 WLOGFE("WriteInterfaceToken failed");
157 return;
158 }
159
160 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TOUCH_DIALOG_TARGET),
161 data, reply, option) != ERR_NONE) {
162 WLOGFE("SendRequest failed");
163 return;
164 }
165 }
166
NotifyTransferComponentData(const AAFwk::WantParams & wantParams)167 WSError SessionStageProxy::NotifyTransferComponentData(const AAFwk::WantParams& wantParams)
168 {
169 MessageParcel data;
170 MessageParcel reply;
171 MessageOption option(MessageOption::TF_ASYNC);
172 if (!data.WriteInterfaceToken(GetDescriptor())) {
173 WLOGFE("WriteInterfaceToken failed");
174 return WSError::WS_ERROR_IPC_FAILED;
175 }
176
177 if (!data.WriteParcelable(&wantParams)) {
178 WLOGFE("wantParams write failed.");
179 return WSError::WS_ERROR_IPC_FAILED;
180 }
181
182 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA),
183 data, reply, option) != ERR_NONE) {
184 WLOGFE("SendRequest failed");
185 return WSError::WS_ERROR_IPC_FAILED;
186 }
187 int32_t ret = reply.ReadInt32();
188 return static_cast<WSError>(ret);
189 }
190
NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info)191 void SessionStageProxy::NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info)
192 {
193 MessageParcel data;
194 MessageParcel reply;
195 MessageOption option(MessageOption::TF_ASYNC);
196 if (!data.WriteInterfaceToken(GetDescriptor())) {
197 WLOGFE("WriteInterfaceToken failed");
198 return;
199 }
200
201 if (!data.WriteParcelable(info.GetRefPtr())) {
202 WLOGFE("occupied info write failed.");
203 return;
204 }
205
206 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_OCCUPIED_AREA_CHANGE_INFO),
207 data, reply, option) != ERR_NONE) {
208 WLOGFE("SendRequest failed");
209 return;
210 }
211 return;
212 }
213
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)214 WSError SessionStageProxy::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
215 {
216 MessageParcel data;
217 MessageParcel reply;
218 MessageOption option(MessageOption::TF_ASYNC);
219 if (!data.WriteInterfaceToken(GetDescriptor())) {
220 WLOGFE("WriteInterfaceToken failed");
221 return WSError::WS_ERROR_IPC_FAILED;
222 }
223 if (!data.WriteStrongParcelable(avoidArea)) {
224 WLOGFE("Write AvoidArea failed");
225 return WSError::WS_ERROR_IPC_FAILED;
226 }
227 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
228 WLOGFE("Write AvoidAreaType failed");
229 return WSError::WS_ERROR_IPC_FAILED;
230 }
231 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_UPDATE_AVOID_AREA),
232 data, reply, option) != ERR_NONE) {
233 WLOGFE("SendRequest failed");
234 return WSError::WS_ERROR_IPC_FAILED;
235 }
236 return WSError::WS_OK;
237 }
238
DumpSessionElementInfo(const std::vector<std::string> & params)239 void SessionStageProxy::DumpSessionElementInfo(const std::vector<std::string>& params)
240 {
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option(MessageOption::TF_ASYNC);
244 if (!data.WriteInterfaceToken(GetDescriptor())) {
245 WLOGFE("WriteInterfaceToken failed");
246 return;
247 }
248 if (!data.WriteStringVector(params)) {
249 WLOGFE("Write params failed");
250 return;
251 }
252 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_DUMP_SESSSION_ELEMENT_INFO),
253 data, reply, option) != ERR_NONE) {
254 WLOGFE("SendRequest failed");
255 return;
256 }
257 }
258
NotifyScreenshot()259 void SessionStageProxy::NotifyScreenshot()
260 {
261 MessageParcel data;
262 MessageParcel reply;
263 MessageOption option(MessageOption::TF_ASYNC);
264 if (!data.WriteInterfaceToken(GetDescriptor())) {
265 WLOGFE("WriteInterfaceToken failed");
266 return;
267 }
268
269 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_SCREEN_SHOT),
270 data, reply, option) != ERR_NONE) {
271 WLOGFE("SendRequest failed");
272 return;
273 }
274 }
275
NotifyTouchOutside()276 WSError SessionStageProxy::NotifyTouchOutside()
277 {
278 MessageParcel data;
279 MessageParcel reply;
280 MessageOption option(MessageOption::TF_ASYNC);
281 if (!data.WriteInterfaceToken(GetDescriptor())) {
282 WLOGFE("WriteInterfaceToken failed");
283 return WSError::WS_ERROR_IPC_FAILED;
284 }
285 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TOUCH_OUTSIDE),
286 data, reply, option) != ERR_NONE) {
287 WLOGFE("SendRequest failed");
288 return WSError::WS_ERROR_IPC_FAILED;
289 }
290 return WSError::WS_OK;
291 }
292
UpdateWindowMode(WindowMode mode)293 WSError SessionStageProxy::UpdateWindowMode(WindowMode mode)
294 {
295 MessageParcel data;
296 MessageParcel reply;
297 MessageOption option(MessageOption::TF_ASYNC);
298 if (!data.WriteInterfaceToken(GetDescriptor())) {
299 WLOGFE("WriteInterfaceToken failed");
300 return WSError::WS_ERROR_IPC_FAILED;
301 }
302
303 if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
304 WLOGFE("Write mode failed");
305 return WSError::WS_ERROR_IPC_FAILED;
306 }
307
308 if (Remote()->SendRequest(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_WINDOW_MODE_CHANGE),
309 data, reply, option) != ERR_NONE) {
310 WLOGFE("SendRequest failed");
311 return WSError::WS_ERROR_IPC_FAILED;
312 }
313 int32_t ret = reply.ReadInt32();
314 return static_cast<WSError>(ret);
315 }
316 } // namespace OHOS::Rosen
317