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,float borderWidth)94 void FormRendererDispatcherProxy::DispatchSurfaceChangeEvent(float width, float height, float borderWidth)
95 {
96 MessageParcel data;
97 if (!WriteInterfaceToken(data)) {
98 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
99 return;
100 }
101
102 if (!data.WriteFloat(width)) {
103 HILOG_ERROR("write width fail, action error");
104 return;
105 }
106
107 if (!data.WriteFloat(height)) {
108 HILOG_ERROR("write height fail, action error");
109 return;
110 }
111
112 if (!data.WriteFloat(borderWidth)) {
113 HILOG_ERROR("write borderWidth fail, action error");
114 return;
115 }
116
117 MessageParcel reply;
118 MessageOption option;
119 int error = Remote()->SendRequest(
120 static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_SURFACE_CHANGE_EVENT), data, reply, option);
121 if (error != ERR_OK) {
122 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
123 }
124 }
125
WriteInterfaceToken(MessageParcel & data)126 bool FormRendererDispatcherProxy::WriteInterfaceToken(MessageParcel &data)
127 {
128 if (!data.WriteInterfaceToken(FormRendererDispatcherProxy::GetDescriptor())) {
129 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
130 return false;
131 }
132 return true;
133 }
134
SetObscured(bool isObscured)135 void FormRendererDispatcherProxy::SetObscured(bool isObscured)
136 {
137 MessageParcel data;
138 if (!WriteInterfaceToken(data)) {
139 HILOG_ERROR("failed to write interface token");
140 return;
141 }
142
143 if (!data.WriteBool(isObscured)) {
144 HILOG_ERROR("write isObscured fail, action error");
145 return;
146 }
147
148 MessageParcel reply;
149 MessageOption option;
150 int error = Remote()->SendRequest(
151 static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_OBSCURED),
152 data, reply, option);
153 if (error != ERR_OK) {
154 HILOG_ERROR("failed to SendRequest: %{public}d", error);
155 }
156 }
157
OnAccessibilityChildTreeRegister(uint32_t windowId,int32_t treeId,int64_t accessibilityId)158 void FormRendererDispatcherProxy::OnAccessibilityChildTreeRegister(
159 uint32_t windowId, int32_t treeId, int64_t accessibilityId)
160 {
161 MessageParcel data;
162 if (!WriteInterfaceToken(data)) {
163 HILOG_ERROR("failed to write interface token");
164 return;
165 }
166 if (!data.WriteUint32(windowId)) {
167 HILOG_ERROR("write windowId fail, action error");
168 return;
169 }
170 if (!data.WriteInt32(treeId)) {
171 HILOG_ERROR("write treeId fail, action error");
172 return;
173 }
174 if (!data.WriteInt64(accessibilityId)) {
175 HILOG_ERROR("write accessibilityId fail, action error");
176 return;
177 }
178
179 MessageParcel reply;
180 MessageOption option(MessageOption::TF_ASYNC);
181 int error = Remote()->SendRequest(
182 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_REGISTER),
183 data, reply, option);
184 if (error != ERR_OK) {
185 HILOG_ERROR("failed to SendRequest: %{public}d", error);
186 }
187 }
188
OnAccessibilityChildTreeDeregister()189 void FormRendererDispatcherProxy::OnAccessibilityChildTreeDeregister()
190 {
191 MessageParcel data;
192 if (!WriteInterfaceToken(data)) {
193 HILOG_ERROR("failed to write interface token");
194 return;
195 }
196
197 MessageParcel reply;
198 MessageOption option(MessageOption::TF_ASYNC);
199 int error = Remote()->SendRequest(
200 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_DEREGISTER),
201 data, reply, option);
202 if (error != ERR_OK) {
203 HILOG_ERROR("failed to SendRequest: %{public}d", error);
204 }
205 }
206
OnAccessibilityDumpChildInfo(const std::vector<std::string> & params,std::vector<std::string> & info)207 void FormRendererDispatcherProxy::OnAccessibilityDumpChildInfo(
208 const std::vector<std::string>& params, std::vector<std::string>& info)
209 {
210 MessageParcel data;
211 if (!WriteInterfaceToken(data)) {
212 HILOG_ERROR("failed to write interface token");
213 return;
214 }
215 if (!data.WriteStringVector(params)) {
216 HILOG_ERROR("failed to write params");
217 return;
218 }
219
220 MessageParcel reply;
221 MessageOption option;
222 int error = Remote()->SendRequest(
223 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_DUMP_CHILD_INFO),
224 data, reply, option);
225 if (error != ERR_OK) {
226 HILOG_ERROR("failed to SendRequest: %{public}d", error);
227 return;
228 }
229 if (!reply.ReadStringVector(&info)) {
230 HILOG_ERROR("%{public}s, Read reply info failed.", __func__);
231 }
232 }
233
OnAccessibilityTransferHoverEvent(float pointX,float pointY,int32_t sourceType,int32_t eventType,int64_t timeMs)234 void FormRendererDispatcherProxy::OnAccessibilityTransferHoverEvent(float pointX, float pointY, int32_t sourceType,
235 int32_t eventType, int64_t timeMs)
236 {
237 MessageParcel data;
238 if (!WriteInterfaceToken(data)) {
239 HILOG_ERROR("failed to write interface token");
240 return;
241 }
242 if (!data.WriteFloat(pointX) ||
243 !data.WriteFloat(pointY) ||
244 !data.WriteInt32(sourceType) ||
245 !data.WriteInt32(eventType) ||
246 !data.WriteInt64(timeMs)) {
247 HILOG_ERROR("Write TransferAccessibilityHoverEvent data failed");
248 return;
249 }
250
251 MessageParcel reply;
252 MessageOption option(MessageOption::TF_ASYNC);
253 int error = Remote()->SendRequest(
254 static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_TRANSFER_HOVER_EVENT),
255 data, reply, option);
256 if (error != ERR_OK) {
257 HILOG_ERROR("failed to SendRequest: %{public}d", error);
258 }
259 }
260 } // namespace Ace
261 } // namespace OHOS
262