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 #include "form_renderer_dispatcher_proxy.h"
16
17 #include "appexecfwk_errors.h"
18 #include "errors.h"
19 #include "form_renderer_hilog.h"
20
21 #include "core/event/touch_event.h"
22
23 namespace OHOS {
24 namespace Ace {
FormRendererDispatcherProxy(const sptr<IRemoteObject> & impl)25 FormRendererDispatcherProxy::FormRendererDispatcherProxy(const sptr<IRemoteObject>& impl)
26 : IRemoteProxy<IFormRendererDispatcher>(impl) {}
27
DispatchPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent> & pointerEvent,SerializedGesture & serializedGesture)28 void FormRendererDispatcherProxy::DispatchPointerEvent(
29 const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent,
30 SerializedGesture& serializedGesture)
31 {
32 if (pointerEvent == nullptr) {
33 HILOG_ERROR("%{public}s, pointerEvent is null", __func__);
34 return;
35 }
36
37 MessageParcel data;
38 if (!WriteInterfaceToken(data)) {
39 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
40 return;
41 }
42
43 if (!pointerEvent->WriteToParcel(data)) {
44 HILOG_ERROR("Failed to write pointer event");
45 return;
46 }
47
48 MessageParcel reply;
49 MessageOption option;
50 int error = Remote()->SendRequest(
51 static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_POINTER_EVENT),
52 data, reply, option);
53
54 int32_t size = 0;
55 reply.ReadInt32(size);
56 if (size < 0) {
57 HILOG_ERROR("Serialized gesture size is not valid!");
58 } else {
59 auto buffer = static_cast<const char*>(reply.ReadRawData(size));
60 if (buffer == nullptr) {
61 return;
62 }
63 serializedGesture.data = std::vector<char>(buffer, buffer + size);
64 }
65
66 if (error != ERR_OK) {
67 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
68 }
69 }
70
SetAllowUpdate(bool allowUpdate)71 void FormRendererDispatcherProxy::SetAllowUpdate(bool allowUpdate)
72 {
73 MessageParcel data;
74 if (!WriteInterfaceToken(data)) {
75 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
76 return;
77 }
78
79 if (!data.WriteBool(allowUpdate)) {
80 HILOG_ERROR("write allowUpdate fail, action error");
81 return;
82 }
83
84 MessageParcel reply;
85 MessageOption option;
86 int error = Remote()->SendRequest(
87 static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_ALLOW_UPDATE),
88 data, reply, option);
89 if (error != ERR_OK) {
90 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
91 }
92 }
93
DispatchSurfaceChangeEvent(float width,float height,uint32_t reason,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction,float borderWidth)94 void FormRendererDispatcherProxy::DispatchSurfaceChangeEvent(float width, float height, uint32_t reason,
95 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction, float borderWidth)
96 {
97 MessageParcel data;
98 if (!WriteInterfaceToken(data)) {
99 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
100 return;
101 }
102
103 if (!data.WriteFloat(width)) {
104 HILOG_ERROR("write width fail, action error");
105 return;
106 }
107
108 if (!data.WriteFloat(height)) {
109 HILOG_ERROR("write height fail, action error");
110 return;
111 }
112
113 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
114 HILOG_ERROR("Write SessionSizeChangeReason failed");
115 return;
116 }
117
118 bool hasRSTransaction = rsTransaction != nullptr;
119 if (!data.WriteBool(hasRSTransaction)) {
120 HILOG_ERROR("Write has transaction failed");
121 return;
122 }
123 if (hasRSTransaction) {
124 auto pid = rsTransaction->GetParentPid();
125 rsTransaction->SetParentPid(getprocpid());
126 if (!data.WriteParcelable(rsTransaction.get())) {
127 HILOG_ERROR("Write transaction sync Id failed");
128 return;
129 }
130 rsTransaction->SetParentPid(pid);
131 }
132
133 if (!data.WriteFloat(borderWidth)) {
134 HILOG_ERROR("write borderWidth fail, action error");
135 return;
136 }
137
138 MessageParcel reply;
139 MessageOption option;
140 int error = Remote()->SendRequest(
141 static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_SURFACE_CHANGE_EVENT), data, reply, option);
142 if (error != ERR_OK) {
143 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
144 }
145 }
146
WriteInterfaceToken(MessageParcel & data)147 bool FormRendererDispatcherProxy::WriteInterfaceToken(MessageParcel &data)
148 {
149 if (!data.WriteInterfaceToken(FormRendererDispatcherProxy::GetDescriptor())) {
150 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
151 return false;
152 }
153 return true;
154 }
155
SetObscured(bool isObscured)156 void FormRendererDispatcherProxy::SetObscured(bool isObscured)
157 {
158 MessageParcel data;
159 if (!WriteInterfaceToken(data)) {
160 HILOG_ERROR("failed to write interface token");
161 return;
162 }
163
164 if (!data.WriteBool(isObscured)) {
165 HILOG_ERROR("write isObscured fail, action error");
166 return;
167 }
168
169 MessageParcel reply;
170 MessageOption option;
171 int error = Remote()->SendRequest(
172 static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_OBSCURED),
173 data, reply, option);
174 if (error != ERR_OK) {
175 HILOG_ERROR("failed to SendRequest: %{public}d", error);
176 }
177 }
178
OnAccessibilityChildTreeRegister(uint32_t windowId,int32_t treeId,int64_t accessibilityId)179 void FormRendererDispatcherProxy::OnAccessibilityChildTreeRegister(
180 uint32_t windowId, int32_t treeId, int64_t accessibilityId)
181 {
182 MessageParcel data;
183 if (!WriteInterfaceToken(data)) {
184 HILOG_ERROR("failed to write interface token");
185 return;
186 }
187 if (!data.WriteUint32(windowId)) {
188 HILOG_ERROR("write windowId fail, action error");
189 return;
190 }
191 if (!data.WriteInt32(treeId)) {
192 HILOG_ERROR("write treeId fail, action error");
193 return;
194 }
195 if (!data.WriteInt64(accessibilityId)) {
196 HILOG_ERROR("write accessibilityId fail, action error");
197 return;
198 }
199
200 MessageParcel reply;
201 MessageOption option(MessageOption::TF_ASYNC);
202 int error = Remote()->SendRequest(
203 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_REGISTER),
204 data, reply, option);
205 if (error != ERR_OK) {
206 HILOG_ERROR("failed to SendRequest: %{public}d", error);
207 }
208 }
209
OnAccessibilityChildTreeDeregister()210 void FormRendererDispatcherProxy::OnAccessibilityChildTreeDeregister()
211 {
212 MessageParcel data;
213 if (!WriteInterfaceToken(data)) {
214 HILOG_ERROR("failed to write interface token");
215 return;
216 }
217
218 MessageParcel reply;
219 MessageOption option(MessageOption::TF_ASYNC);
220 int error = Remote()->SendRequest(
221 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_DEREGISTER),
222 data, reply, option);
223 if (error != ERR_OK) {
224 HILOG_ERROR("failed to SendRequest: %{public}d", error);
225 }
226 }
227
OnAccessibilityDumpChildInfo(const std::vector<std::string> & params,std::vector<std::string> & info)228 void FormRendererDispatcherProxy::OnAccessibilityDumpChildInfo(
229 const std::vector<std::string>& params, std::vector<std::string>& info)
230 {
231 MessageParcel data;
232 if (!WriteInterfaceToken(data)) {
233 HILOG_ERROR("failed to write interface token");
234 return;
235 }
236 if (!data.WriteStringVector(params)) {
237 HILOG_ERROR("failed to write params");
238 return;
239 }
240
241 MessageParcel reply;
242 MessageOption option;
243 int error = Remote()->SendRequest(
244 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_DUMP_CHILD_INFO),
245 data, reply, option);
246 if (error != ERR_OK) {
247 HILOG_ERROR("failed to SendRequest: %{public}d", error);
248 return;
249 }
250 if (!reply.ReadStringVector(&info)) {
251 HILOG_ERROR("%{public}s, Read reply info failed.", __func__);
252 }
253 }
254
OnAccessibilityTransferHoverEvent(float pointX,float pointY,int32_t sourceType,int32_t eventType,int64_t timeMs)255 void FormRendererDispatcherProxy::OnAccessibilityTransferHoverEvent(float pointX, float pointY, int32_t sourceType,
256 int32_t eventType, int64_t timeMs)
257 {
258 MessageParcel data;
259 if (!WriteInterfaceToken(data)) {
260 HILOG_ERROR("failed to write interface token");
261 return;
262 }
263 if (!data.WriteFloat(pointX) ||
264 !data.WriteFloat(pointY) ||
265 !data.WriteInt32(sourceType) ||
266 !data.WriteInt32(eventType) ||
267 !data.WriteInt64(timeMs)) {
268 HILOG_ERROR("Write TransferAccessibilityHoverEvent data failed");
269 return;
270 }
271
272 MessageParcel reply;
273 MessageOption option(MessageOption::TF_ASYNC);
274 int error = Remote()->SendRequest(
275 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_TRANSFER_HOVER_EVENT),
276 data, reply, option);
277 if (error != ERR_OK) {
278 HILOG_ERROR("failed to SendRequest: %{public}d", error);
279 }
280 }
281 } // namespace Ace
282 } // namespace OHOS
283