1 /*
2 * Copyright (C) 2022 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 "accessibility_element_operator_proxy.h"
17 #include "hilog_wrapper.h"
18 #include "ipc_types.h"
19 #include "iremote_object.h"
20
21 namespace OHOS {
22 namespace Accessibility {
AccessibilityElementOperatorProxy(const sptr<IRemoteObject> & impl)23 AccessibilityElementOperatorProxy::AccessibilityElementOperatorProxy(
24 const sptr<IRemoteObject> &impl) : IRemoteProxy<IAccessibilityElementOperator>(impl)
25 {}
26
~AccessibilityElementOperatorProxy()27 AccessibilityElementOperatorProxy::~AccessibilityElementOperatorProxy()
28 {}
29
WriteInterfaceToken(MessageParcel & data)30 bool AccessibilityElementOperatorProxy::WriteInterfaceToken(MessageParcel &data)
31 {
32 HILOG_DEBUG("start");
33
34 if (!data.WriteInterfaceToken(AccessibilityElementOperatorProxy::GetDescriptor())) {
35 HILOG_ERROR("write interface token failed");
36 return false;
37 }
38 return true;
39 }
40
SearchElementInfoByAccessibilityId(const long elementId,const int requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int mode)41 void AccessibilityElementOperatorProxy::SearchElementInfoByAccessibilityId(const long elementId,
42 const int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback, const int mode)
43 {
44 HILOG_DEBUG("start");
45
46 int error = NO_ERROR;
47 MessageParcel data;
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_ASYNC);
50
51 if (!WriteInterfaceToken(data)) {
52 HILOG_ERROR("fail, connection write Token");
53 return;
54 }
55
56 if (!data.WriteInt32(elementId)) {
57 HILOG_ERROR("fail, connection write parcelable elementId error");
58 return;
59 }
60
61 if (!data.WriteInt32(requestId)) {
62 HILOG_ERROR("fail, connection write parcelable requestId error");
63 return;
64 }
65
66 if (!data.WriteRemoteObject(callback->AsObject())) {
67 HILOG_ERROR("fail, connection write parcelable callback error");
68 return;
69 }
70
71 if (!data.WriteInt32(mode)) {
72 HILOG_ERROR("fail, connection write parcelable mode error");
73 return;
74 }
75
76 error = Remote()->SendRequest(
77 static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::SEARCH_BY_ACCESSIBILITY_ID),
78 data, reply, option);
79 if (error != NO_ERROR) {
80 HILOG_ERROR("SearchAccessibilityInfo fail, error: %d", error);
81 return;
82 }
83 }
84
SearchElementInfosByText(const long elementId,const std::string & text,const int requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)85 void AccessibilityElementOperatorProxy::SearchElementInfosByText(const long elementId,
86 const std::string &text,
87 const int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
88 {
89 HILOG_DEBUG("start");
90
91 int error = NO_ERROR;
92 MessageParcel data;
93 MessageParcel reply;
94 MessageOption option(MessageOption::TF_ASYNC);
95
96 if (!WriteInterfaceToken(data)) {
97 HILOG_ERROR("fail, connection write Token");
98 return;
99 }
100
101 if (!data.WriteInt32(elementId)) {
102 HILOG_ERROR("fail, connection write parcelable elementId error");
103 return;
104 }
105 if (!data.WriteString(text)) {
106 HILOG_ERROR("fail, connection write text error");
107 return;
108 }
109
110 if (!data.WriteInt32(requestId)) {
111 HILOG_ERROR("fail, connection write requestId error");
112 return;
113 }
114
115 if (!data.WriteRemoteObject(callback->AsObject())) {
116 HILOG_ERROR("fail, connection write callback error");
117 return;
118 }
119
120 error = Remote()->SendRequest(
121 static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::SEARCH_BY_TEXT),
122 data, reply, option);
123 if (error != NO_ERROR) {
124 HILOG_ERROR("SearchElementInfosByText fail, error: %d", error);
125 return;
126 }
127 }
128
FindFocusedElementInfo(const long elementId,const int focusType,const int requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)129 void AccessibilityElementOperatorProxy::FindFocusedElementInfo(const long elementId,
130 const int focusType, const int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
131 {
132 HILOG_DEBUG("start");
133
134 int error = NO_ERROR;
135 MessageParcel data;
136 MessageParcel reply;
137 MessageOption option(MessageOption::TF_ASYNC);
138
139 if (!WriteInterfaceToken(data)) {
140 HILOG_ERROR("fail, connection write Token");
141 return;
142 }
143
144 if (!data.WriteInt32(elementId)) {
145 HILOG_ERROR("fail, connection write elementId error");
146 return;
147 }
148
149 if (!data.WriteInt32(focusType)) {
150 HILOG_ERROR("fail, connection write focusType error");
151 return;
152 }
153
154 if (!data.WriteInt32(requestId)) {
155 HILOG_ERROR("fail, connection write requestId error");
156 return;
157 }
158
159 if (!data.WriteRemoteObject(callback->AsObject())) {
160 HILOG_ERROR("fail, connection write callback error");
161 return;
162 }
163
164 error = Remote()->SendRequest(
165 static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::FIND_FOCUSED_INFO),
166 data, reply, option);
167 if (error != NO_ERROR) {
168 HILOG_ERROR("FindFocusedElementInfo fail, error: %d", error);
169 return;
170 }
171 }
172
FocusMoveSearch(const long elementId,const int direction,const int requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)173 void AccessibilityElementOperatorProxy::FocusMoveSearch(const long elementId,
174 const int direction, const int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
175 {
176 HILOG_DEBUG("start");
177
178 int error = NO_ERROR;
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option(MessageOption::TF_ASYNC);
182
183 if (!WriteInterfaceToken(data)) {
184 HILOG_ERROR("fail, connection write Token");
185 return;
186 }
187
188 if (!data.WriteInt32(elementId)) {
189 HILOG_ERROR("fail, connection write elementId error");
190 return;
191 }
192
193 if (!data.WriteInt32(direction)) {
194 HILOG_ERROR("fail, connection write focusType error");
195 return;
196 }
197
198 if (!data.WriteInt32(requestId)) {
199 HILOG_ERROR("fail, connection write requestId error");
200 return;
201 }
202
203 if (!data.WriteRemoteObject(callback->AsObject())) {
204 HILOG_ERROR("fail, connection write callback error");
205 return;
206 }
207
208 error = Remote()->SendRequest(static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::FOCUS_FIND),
209 data, reply, option);
210 if (error != NO_ERROR) {
211 HILOG_ERROR("FindFocusedElementInfo fail, error: %d", error);
212 return;
213 }
214 }
215
ExecuteAction(const long elementId,const int action,const std::map<std::string,std::string> arguments,const int requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)216 void AccessibilityElementOperatorProxy::ExecuteAction(const long elementId, const int action,
217 const std::map<std::string, std::string> arguments, const int requestId,
218 const sptr<IAccessibilityElementOperatorCallback> &callback)
219 {
220 HILOG_DEBUG("start");
221
222 int error = NO_ERROR;
223 MessageParcel data;
224 MessageParcel reply;
225 MessageOption option(MessageOption::TF_ASYNC);
226
227 if (!WriteInterfaceToken(data)) {
228 HILOG_ERROR("fail, connection write Token");
229 return;
230 }
231
232 if (!data.WriteInt32(elementId)) {
233 HILOG_ERROR("fail, connection write elementId error");
234 return;
235 }
236
237 if (!data.WriteInt32(action)) {
238 HILOG_ERROR("fail, connection write focusType error");
239 return;
240 }
241
242 auto iter = arguments.begin();
243 std::vector<std::string> argumentKey;
244 std::vector<std::string> argumentValue;
245 while (iter != arguments.end()) {
246 argumentKey.push_back(iter->first);
247 argumentValue.push_back(iter->second);
248 iter++;
249 }
250
251 if (!data.WriteStringVector(argumentKey)) {
252 HILOG_ERROR("fail, connection write argumentKey error");
253 return;
254 }
255
256 if (!data.WriteStringVector(argumentValue)) {
257 HILOG_ERROR("fail, connection write argumentValue error");
258 return;
259 }
260
261 if (!data.WriteInt32(requestId)) {
262 HILOG_ERROR("fail, connection write requestId error");
263 return;
264 }
265
266 if (!data.WriteRemoteObject(callback->AsObject())) {
267 HILOG_ERROR("fail, connection write callback error");
268 return;
269 }
270
271 error = Remote()->SendRequest(static_cast<uint32_t>(
272 AccessibilityElementOperatorProxy::Message::PERFORM_ACTION),
273 data, reply, option);
274 if (error != NO_ERROR) {
275 HILOG_ERROR("ExecuteAction fail, error: %d", error);
276 return;
277 }
278 }
279
ClearFocus()280 void AccessibilityElementOperatorProxy::ClearFocus()
281 {
282 HILOG_DEBUG("start");
283
284 int error = NO_ERROR;
285 MessageParcel data;
286 MessageParcel reply;
287 MessageOption option;
288 if (!WriteInterfaceToken(data)) {
289 HILOG_ERROR("fail, connection write Token");
290 return;
291 }
292
293 error = Remote()->SendRequest(static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::CLEAR_FOCUS),
294 data, reply, option);
295 if (error != NO_ERROR) {
296 HILOG_ERROR("ExecuteAction fail, error: %d", error);
297 return;
298 }
299 }
300
OutsideTouch()301 void AccessibilityElementOperatorProxy::OutsideTouch()
302 {
303 HILOG_DEBUG("start");
304
305 int error = NO_ERROR;
306 MessageParcel data;
307 MessageParcel reply;
308 MessageOption option;
309 if (!WriteInterfaceToken(data)) {
310 HILOG_ERROR("fail, connection write Token");
311 return;
312 }
313
314 error = Remote()->SendRequest(
315 static_cast<uint32_t>(AccessibilityElementOperatorProxy::Message::OUTSIDE_TOUCH),
316 data, reply, option);
317 if (error != NO_ERROR) {
318 HILOG_ERROR("ExecuteAction fail, error: %d", error);
319 return;
320 }
321 }
322 } // namespace Accessibility
323 } // namespace OHOS