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 "accessible_ability_channel.h"
17 #include "accessible_ability_manager_service.h"
18 #include "accessibility_window_connection.h"
19 #include "accessibility_window_manager.h"
20 #include "accessible_ability_connection.h"
21 #include "hilog_wrapper.h"
22
23 namespace OHOS {
24 namespace Accessibility {
25 namespace {
26 constexpr uint32_t TIME_OUT_OPERATOR = 5000;
27 } // namespace
28
AccessibleAbilityChannel(const int32_t accountId,const std::string & clientName)29 AccessibleAbilityChannel::AccessibleAbilityChannel(const int32_t accountId, const std::string &clientName)
30 : clientName_(clientName), accountId_(accountId)
31 {
32 eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(
33 Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner());
34 }
35
SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId,const int32_t elementId,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int32_t mode)36 RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId,
37 const int32_t elementId, const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
38 const int32_t mode)
39 {
40 HILOG_DEBUG();
41
42 if (!eventHandler_) {
43 HILOG_ERROR("eventHandler_ is nullptr.");
44 return RET_ERR_NULLPTR;
45 }
46
47 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
48 std::future syncFuture = syncPromise->get_future();
49 eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId, elementId, requestId, callback, mode](
50 int32_t accountId, const std::string &name) -> void {
51 HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str());
52 sptr<IAccessibilityElementOperator> elementOperator = nullptr;
53 RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator);
54 if (ret != RET_OK) {
55 HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId);
56 syncPromise->set_value(ret);
57 return;
58 }
59
60 auto& awm = Singleton<AccessibilityWindowManager>::GetInstance();
61 int32_t realElementId = awm.GetSceneBoardElementId(accessibilityWindowId, elementId);
62 elementOperator->SearchElementInfoByAccessibilityId(realElementId, requestId, callback, mode);
63 HILOG_DEBUG("AccessibleAbilityChannel::SearchElementInfoByAccessibilityId successfully");
64 syncPromise->set_value(RET_OK);
65 }, accountId_, clientName_), "SearchElementInfoByAccessibilityId");
66
67 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
68 if (wait != std::future_status::ready) {
69 HILOG_ERROR("Failed to wait SearchElementInfoByAccessibilityId result");
70 return RET_ERR_TIME_OUT;
71 }
72 return syncFuture.get();
73 }
74
SearchElementInfosByText(const int32_t accessibilityWindowId,const int32_t elementId,const std::string & text,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)75 RetError AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId,
76 const int32_t elementId, const std::string &text, const int32_t requestId,
77 const sptr<IAccessibilityElementOperatorCallback> &callback)
78 {
79 HILOG_DEBUG();
80
81 if (!eventHandler_) {
82 HILOG_ERROR("eventHandler_ is nullptr.");
83 return RET_ERR_NULLPTR;
84 }
85
86 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
87 std::future syncFuture = syncPromise->get_future();
88 eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId, elementId, text, requestId, callback](
89 int32_t accountId, const std::string &name) -> void {
90 HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str());
91 sptr<IAccessibilityElementOperator> elementOperator = nullptr;
92 RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator);
93 if (ret != RET_OK) {
94 HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId);
95 syncPromise->set_value(ret);
96 return;
97 }
98
99 auto& awm = Singleton<AccessibilityWindowManager>::GetInstance();
100 int32_t realElementId = awm.GetSceneBoardElementId(accessibilityWindowId, elementId);
101 elementOperator->SearchElementInfosByText(realElementId, text, requestId, callback);
102 syncPromise->set_value(RET_OK);
103 }, accountId_, clientName_), "SearchElementInfosByText");
104
105 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
106 if (wait != std::future_status::ready) {
107 HILOG_ERROR("Failed to wait SearchElementInfosByText result");
108 return RET_ERR_TIME_OUT;
109 }
110 return syncFuture.get();
111 }
112
FindFocusedElementInfo(const int32_t accessibilityWindowId,const int32_t elementId,const int32_t focusType,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)113 RetError AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId,
114 const int32_t elementId, const int32_t focusType, const int32_t requestId,
115 const sptr<IAccessibilityElementOperatorCallback> &callback)
116 {
117 HILOG_DEBUG();
118
119 if (!eventHandler_) {
120 HILOG_ERROR("eventHandler_ is nullptr.");
121 return RET_ERR_NULLPTR;
122 }
123
124 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
125 std::future syncFuture = syncPromise->get_future();
126 eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId, elementId,
127 focusType, requestId, callback](int32_t accountId, const std::string &name) -> void {
128 HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str());
129 sptr<IAccessibilityElementOperator> elementOperator = nullptr;
130 RetError ret = GetElementOperator(accountId, accessibilityWindowId, focusType, name, elementOperator);
131 if (ret != RET_OK) {
132 HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId);
133 syncPromise->set_value(ret);
134 return;
135 }
136
137 auto& awm = Singleton<AccessibilityWindowManager>::GetInstance();
138 int32_t realElementId = awm.GetSceneBoardElementId(accessibilityWindowId, elementId);
139 elementOperator->FindFocusedElementInfo(realElementId, focusType, requestId, callback);
140 syncPromise->set_value(RET_OK);
141 }, accountId_, clientName_), "FindFocusedElementInfo");
142
143 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
144 if (wait != std::future_status::ready) {
145 HILOG_ERROR("Failed to wait FindFocusedElementInfo result");
146 return RET_ERR_TIME_OUT;
147 }
148 return syncFuture.get();
149 }
150
FocusMoveSearch(const int32_t accessibilityWindowId,const int32_t elementId,const int32_t direction,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)151 RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId,
152 const int32_t direction, const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
153 {
154 HILOG_DEBUG();
155
156 if (!eventHandler_) {
157 HILOG_ERROR("eventHandler_ is nullptr.");
158 return RET_ERR_NULLPTR;
159 }
160
161 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
162 std::future syncFuture = syncPromise->get_future();
163 eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId,
164 elementId, direction, requestId, callback](int32_t accountId, const std::string &name) -> void {
165 HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str());
166 sptr<IAccessibilityElementOperator> elementOperator = nullptr;
167 RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator);
168 if (ret != RET_OK) {
169 HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId);
170 syncPromise->set_value(ret);
171 return;
172 }
173
174 auto& awm = Singleton<AccessibilityWindowManager>::GetInstance();
175 int32_t realElementId = awm.GetSceneBoardElementId(accessibilityWindowId, elementId);
176 elementOperator->FocusMoveSearch(realElementId, direction, requestId, callback);
177 syncPromise->set_value(RET_OK);
178 }, accountId_, clientName_), "FocusMoveSearch");
179
180 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
181 if (wait != std::future_status::ready) {
182 HILOG_ERROR("Failed to wait FocusMoveSearch result");
183 return RET_ERR_TIME_OUT;
184 }
185 return syncFuture.get();
186 }
187
ExecuteAction(const int32_t accessibilityWindowId,const int32_t elementId,const int32_t action,const std::map<std::string,std::string> & actionArguments,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)188 RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId,
189 const int32_t action, const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
190 const sptr<IAccessibilityElementOperatorCallback> &callback)
191 {
192 HILOG_DEBUG();
193
194 if (!eventHandler_) {
195 HILOG_ERROR("eventHandler_ is nullptr.");
196 return RET_ERR_NULLPTR;
197 }
198
199 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
200 std::future syncFuture = syncPromise->get_future();
201 eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId, elementId, action,
202 actionArguments, requestId, callback](int32_t accountId, const std::string &name) -> void {
203 HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str());
204 sptr<IAccessibilityElementOperator> elementOperator = nullptr;
205 RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator);
206 if (ret != RET_OK) {
207 HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId);
208 syncPromise->set_value(ret);
209 return;
210 }
211
212 auto& awm = Singleton<AccessibilityWindowManager>::GetInstance();
213 int32_t realElementId = awm.GetSceneBoardElementId(accessibilityWindowId, elementId);
214 elementOperator->ExecuteAction(realElementId, action, actionArguments, requestId, callback);
215 syncPromise->set_value(RET_OK);
216 }, accountId_, clientName_), "ExecuteAction");
217
218 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
219 if (wait != std::future_status::ready) {
220 HILOG_ERROR("Failed to wait ExecuteAction result");
221 return RET_ERR_TIME_OUT;
222 }
223 return syncFuture.get();
224 }
225
GetWindow(const int32_t windowId,AccessibilityWindowInfo & windowInfo)226 RetError AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo)
227 {
228 HILOG_DEBUG("windowId:%{public}d", windowId);
229
230 if (!eventHandler_) {
231 HILOG_ERROR("eventHandler_ is nullptr.");
232 return RET_ERR_NULLPTR;
233 }
234
235 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
236 std::shared_ptr<AccessibilityWindowInfo> tmpWindowInfo = std::make_shared<AccessibilityWindowInfo>(windowInfo);
237 std::future syncFuture = syncPromise->get_future();
238 eventHandler_->PostTask(std::bind([windowId, tmpWindowInfo, syncPromise](
239 int32_t accountId, const std::string &name) -> void {
240 HILOG_DEBUG("windowId:%{public}d", windowId);
241 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
242 if (!clientConnection) {
243 HILOG_ERROR("There is no client connection");
244 syncPromise->set_value(RET_ERR_NO_CONNECTION);
245 return;
246 }
247 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) {
248 HILOG_ERROR("AccessibleAbilityChannel::GetWindow failed: no capability");
249 syncPromise->set_value(RET_ERR_NO_CAPABILITY);
250 return;
251 }
252
253 if (Singleton<AccessibilityWindowManager>::GetInstance().GetAccessibilityWindow(windowId, *tmpWindowInfo)) {
254 syncPromise->set_value(RET_OK);
255 } else {
256 syncPromise->set_value(RET_ERR_NO_WINDOW_CONNECTION);
257 }
258 }, accountId_, clientName_), "GetWindow");
259
260 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
261 if (wait != std::future_status::ready) {
262 HILOG_ERROR("Failed to wait GetWindow result");
263 return RET_ERR_TIME_OUT;
264 }
265
266 windowInfo = *tmpWindowInfo;
267 return syncFuture.get();
268 }
269
GetWindows(std::vector<AccessibilityWindowInfo> & windows)270 RetError AccessibleAbilityChannel::GetWindows(std::vector<AccessibilityWindowInfo> &windows)
271 {
272 HILOG_DEBUG();
273 uint64_t displayId = Singleton<AccessibilityDisplayManager>::GetInstance().GetDefaultDisplayId();
274 HILOG_DEBUG("default display id is %{public}" PRIu64 "", displayId);
275 return GetWindows(displayId, windows);
276 }
277
GetWindowsByDisplayId(const uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows)278 RetError AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId,
279 std::vector<AccessibilityWindowInfo> &windows)
280 {
281 HILOG_DEBUG();
282 return GetWindows(displayId, windows);
283 }
284
GetWindows(uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows) const285 RetError AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const
286 {
287 if (!eventHandler_) {
288 HILOG_ERROR("eventHandler_ is nullptr.");
289 return RET_ERR_NULLPTR;
290 }
291
292 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
293 auto tmpWindows = std::make_shared<std::vector<AccessibilityWindowInfo>>(windows);
294 std::future syncFuture = syncPromise->get_future();
295 eventHandler_->PostTask(std::bind([displayId, tmpWindows, syncPromise](
296 int32_t accountId, const std::string &name) -> void {
297 HILOG_DEBUG();
298 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
299 if (!clientConnection) {
300 HILOG_ERROR("There is no client connection");
301 syncPromise->set_value(RET_ERR_NO_CONNECTION);
302 return;
303 }
304
305 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) {
306 HILOG_ERROR("GetWindows failed: no capability");
307 syncPromise->set_value(RET_ERR_NO_CAPABILITY);
308 return;
309 }
310
311 std::vector<AccessibilityWindowInfo> windowInfos =
312 Singleton<AccessibilityWindowManager>::GetInstance().GetAccessibilityWindows();
313 for (auto &window : windowInfos) {
314 if (window.GetDisplayId() == displayId) {
315 tmpWindows->emplace_back(window);
316 }
317 }
318 syncPromise->set_value(RET_OK);
319 }, accountId_, clientName_), "GetWindows");
320
321 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
322 if (wait != std::future_status::ready) {
323 HILOG_ERROR("Failed to wait GetWindows result");
324 return RET_ERR_TIME_OUT;
325 }
326
327 windows = *tmpWindows;
328 return syncFuture.get();
329 }
330
SetOnKeyPressEventResult(const bool handled,const int32_t sequence)331 void AccessibleAbilityChannel::SetOnKeyPressEventResult(const bool handled, const int32_t sequence)
332 {
333 HILOG_DEBUG();
334
335 if (!eventHandler_) {
336 HILOG_ERROR("eventHandler_ is nullptr.");
337 return;
338 }
339
340 eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void {
341 sptr<KeyEventFilter> keyEventFilter =
342 Singleton<AccessibleAbilityManagerService>::GetInstance().GetKeyEventFilter();
343 if (!keyEventFilter) {
344 return;
345 }
346
347 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
348 if (!clientConnection) {
349 HILOG_ERROR("There is no client connection");
350 return;
351 }
352 keyEventFilter->SetServiceOnKeyEventResult(*clientConnection, handled, sequence);
353 }, accountId_, clientName_), "SetOnKeyPressEventResult");
354 }
355
SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath> & gesturePath)356 RetError AccessibleAbilityChannel::SendSimulateGesture(
357 const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath)
358 {
359 HILOG_INFO();
360 if (!eventHandler_) {
361 HILOG_ERROR("eventHandler_ is nullptr");
362 return RET_ERR_NULLPTR;
363 }
364
365 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
366 std::future syncFuture = syncPromise->get_future();
367 eventHandler_->PostTask(std::bind([gesturePath, syncPromise](int32_t accountId, const std::string &name) -> void {
368 HILOG_DEBUG();
369 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
370 if (!clientConnection) {
371 HILOG_ERROR("There is no client connection");
372 syncPromise->set_value(RET_ERR_NO_CONNECTION);
373 return;
374 }
375
376 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_GESTURE)) {
377 HILOG_ERROR("AccessibleAbilityChannel::SendSimulateGesture failed: no capability");
378 syncPromise->set_value(RET_ERR_NO_CAPABILITY);
379 return;
380 }
381
382 sptr<TouchEventInjector> touchEventInjector =
383 Singleton<AccessibleAbilityManagerService>::GetInstance().GetTouchEventInjector();
384 if (!touchEventInjector) {
385 HILOG_ERROR("touchEventInjector is null");
386 syncPromise->set_value(RET_ERR_NO_INJECTOR);
387 return;
388 }
389 touchEventInjector->InjectEvents(gesturePath);
390 syncPromise->set_value(RET_OK);
391 }, accountId_, clientName_), "SendSimulateGesture");
392
393 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
394 if (wait != std::future_status::ready) {
395 HILOG_ERROR("Failed to wait SendSimulateGesture result");
396 return RET_ERR_TIME_OUT;
397 }
398 return syncFuture.get();
399 }
400
SetTargetBundleName(const std::vector<std::string> & targetBundleNames)401 RetError AccessibleAbilityChannel::SetTargetBundleName(const std::vector<std::string> &targetBundleNames)
402 {
403 HILOG_DEBUG();
404 if (!eventHandler_) {
405 HILOG_ERROR("eventHandler_ is nullptr");
406 return RET_ERR_NULLPTR;
407 }
408
409 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
410 std::future syncFuture = syncPromise->get_future();
411 eventHandler_->PostTask(std::bind([targetBundleNames, syncPromise](
412 int32_t accountId, const std::string &name) -> void {
413 HILOG_DEBUG();
414 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
415 if (!clientConnection) {
416 HILOG_ERROR("There is no client connection");
417 syncPromise->set_value(RET_ERR_NO_CONNECTION);
418 return;
419 }
420
421 clientConnection->SetAbilityInfoTargetBundleName(targetBundleNames);
422 syncPromise->set_value(RET_OK);
423 }, accountId_, clientName_), "SetTargetBundleName");
424
425 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
426 if (wait != std::future_status::ready) {
427 HILOG_ERROR("Failed to wait SetTargetBundleName result");
428 return RET_ERR_TIME_OUT;
429 }
430 return syncFuture.get();
431 }
432
GetConnection(int32_t accountId,const std::string & clientName)433 sptr<AccessibleAbilityConnection> AccessibleAbilityChannel::GetConnection(
434 int32_t accountId, const std::string &clientName)
435 {
436 HILOG_DEBUG();
437 sptr<AccessibilityAccountData> accountData =
438 Singleton<AccessibleAbilityManagerService>::GetInstance().GetAccountData(accountId);
439 if (!accountData) {
440 HILOG_ERROR("accountData is nullptr");
441 return nullptr;
442 }
443
444 HILOG_DEBUG("accountId[%{public}d] clientName[%{public}s]", accountId, clientName.c_str());
445 return accountData->GetAccessibleAbilityConnection(clientName);
446 }
447
GetElementOperator(int32_t accountId,int32_t windowId,int32_t focusType,const std::string & clientName,sptr<IAccessibilityElementOperator> & elementOperator)448 RetError AccessibleAbilityChannel::GetElementOperator(
449 int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName,
450 sptr<IAccessibilityElementOperator> &elementOperator)
451 {
452 HILOG_DEBUG();
453 elementOperator = nullptr;
454 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, clientName);
455 if (!clientConnection) {
456 HILOG_ERROR("There is no client connection");
457 return RET_ERR_NO_CONNECTION;
458 }
459 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) {
460 HILOG_ERROR("the client has no retieve capability");
461 return RET_ERR_NO_CAPABILITY;
462 }
463
464 sptr<AccessibilityAccountData> accountData =
465 Singleton<AccessibleAbilityManagerService>::GetInstance().GetAccountData(accountId);
466 if (!accountData) {
467 HILOG_ERROR("accountData is nullptr");
468 return RET_ERR_NULLPTR;
469 }
470 int32_t realId = Singleton<AccessibilityWindowManager>::GetInstance().ConvertToRealWindowId(windowId, focusType);
471 sptr<AccessibilityWindowConnection> connection = accountData->GetAccessibilityWindowConnection(realId);
472 if (!connection) {
473 HILOG_ERROR("windowId[%{public}d] has no connection", realId);
474 return RET_ERR_NO_WINDOW_CONNECTION;
475 }
476 elementOperator = connection->GetProxy();
477 if (!elementOperator) {
478 HILOG_ERROR("The proxy of window connection is nullptr");
479 return RET_ERR_NULLPTR;
480 }
481 return RET_OK;
482 }
483 } // namespace Accessibility
484 } // namespace OHOS