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 int64_t elementId,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int32_t mode)36 RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId,
37 const int64_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("search element 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 int64_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 int64_t elementId,const std::string & text,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)75 RetError AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId,
76 const int64_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 int64_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 int64_t elementId,const int32_t focusType,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)113 RetError AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId,
114 const int64_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 int64_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 int64_t elementId,const int32_t direction,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)151 RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int64_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 int64_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 int64_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 int64_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 int64_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 #ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
274 uint64_t displayId = Singleton<AccessibilityDisplayManager>::GetInstance().GetDefaultDisplayId();
275 HILOG_DEBUG("default display id is %{public}" PRIu64 "", displayId);
276 return GetWindows(displayId, windows);
277 #else
278 HILOG_DEBUG("not support display manager");
279 return GetWindows(0, windows);
280 #endif
281 }
282
GetWindowsByDisplayId(const uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows)283 RetError AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId,
284 std::vector<AccessibilityWindowInfo> &windows)
285 {
286 HILOG_DEBUG();
287 return GetWindows(displayId, windows);
288 }
289
GetWindows(uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows) const290 RetError AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const
291 {
292 if (!eventHandler_) {
293 HILOG_ERROR("eventHandler_ is nullptr.");
294 return RET_ERR_NULLPTR;
295 }
296
297 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
298 auto tmpWindows = std::make_shared<std::vector<AccessibilityWindowInfo>>(windows);
299 std::future syncFuture = syncPromise->get_future();
300 eventHandler_->PostTask(std::bind([displayId, tmpWindows, syncPromise](
301 int32_t accountId, const std::string &name) -> void {
302 HILOG_DEBUG();
303 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
304 if (!clientConnection) {
305 HILOG_ERROR("There is no client connection");
306 syncPromise->set_value(RET_ERR_NO_CONNECTION);
307 return;
308 }
309
310 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) {
311 HILOG_ERROR("GetWindows failed: no capability");
312 syncPromise->set_value(RET_ERR_NO_CAPABILITY);
313 return;
314 }
315
316 std::vector<AccessibilityWindowInfo> windowInfos =
317 Singleton<AccessibilityWindowManager>::GetInstance().GetAccessibilityWindows();
318 #ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
319 for (auto &window : windowInfos) {
320 if (window.GetDisplayId() == displayId) {
321 tmpWindows->emplace_back(window);
322 }
323 }
324 #else
325 for (auto &window : windowInfos) {
326 tmpWindows->emplace_back(window);
327 }
328 #endif
329 syncPromise->set_value(RET_OK);
330 }, accountId_, clientName_), "GetWindows");
331
332 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
333 if (wait != std::future_status::ready) {
334 HILOG_ERROR("Failed to wait GetWindows result");
335 return RET_ERR_TIME_OUT;
336 }
337
338 windows = *tmpWindows;
339 return syncFuture.get();
340 }
341
SetOnKeyPressEventResult(const bool handled,const int32_t sequence)342 void AccessibleAbilityChannel::SetOnKeyPressEventResult(const bool handled, const int32_t sequence)
343 {
344 HILOG_DEBUG();
345
346 if (!eventHandler_) {
347 HILOG_ERROR("eventHandler_ is nullptr.");
348 return;
349 }
350
351 eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void {
352 sptr<KeyEventFilter> keyEventFilter =
353 Singleton<AccessibleAbilityManagerService>::GetInstance().GetKeyEventFilter();
354 if (!keyEventFilter) {
355 return;
356 }
357
358 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
359 if (!clientConnection) {
360 HILOG_ERROR("There is no client connection");
361 return;
362 }
363 keyEventFilter->SetServiceOnKeyEventResult(*clientConnection, handled, sequence);
364 }, accountId_, clientName_), "SetOnKeyPressEventResult");
365 }
366
SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath> & gesturePath)367 RetError AccessibleAbilityChannel::SendSimulateGesture(
368 const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath)
369 {
370 HILOG_INFO();
371 if (!eventHandler_) {
372 HILOG_ERROR("eventHandler_ is nullptr");
373 return RET_ERR_NULLPTR;
374 }
375
376 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
377 std::future syncFuture = syncPromise->get_future();
378 eventHandler_->PostTask(std::bind([gesturePath, syncPromise](int32_t accountId, const std::string &name) -> void {
379 HILOG_DEBUG();
380 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
381 if (!clientConnection) {
382 HILOG_ERROR("There is no client connection");
383 syncPromise->set_value(RET_ERR_NO_CONNECTION);
384 return;
385 }
386
387 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_GESTURE)) {
388 HILOG_ERROR("AccessibleAbilityChannel::SendSimulateGesture failed: no capability");
389 syncPromise->set_value(RET_ERR_NO_CAPABILITY);
390 return;
391 }
392
393 sptr<TouchEventInjector> touchEventInjector =
394 Singleton<AccessibleAbilityManagerService>::GetInstance().GetTouchEventInjector();
395 if (!touchEventInjector) {
396 HILOG_ERROR("touchEventInjector is null");
397 syncPromise->set_value(RET_ERR_NO_INJECTOR);
398 return;
399 }
400 touchEventInjector->InjectEvents(gesturePath);
401 syncPromise->set_value(RET_OK);
402 }, accountId_, clientName_), "SendSimulateGesture");
403
404 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
405 if (wait != std::future_status::ready) {
406 HILOG_ERROR("Failed to wait SendSimulateGesture result");
407 return RET_ERR_TIME_OUT;
408 }
409 return syncFuture.get();
410 }
411
SetTargetBundleName(const std::vector<std::string> & targetBundleNames)412 RetError AccessibleAbilityChannel::SetTargetBundleName(const std::vector<std::string> &targetBundleNames)
413 {
414 HILOG_DEBUG();
415 if (!eventHandler_) {
416 HILOG_ERROR("eventHandler_ is nullptr");
417 return RET_ERR_NULLPTR;
418 }
419
420 std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
421 std::future syncFuture = syncPromise->get_future();
422 eventHandler_->PostTask(std::bind([targetBundleNames, syncPromise](
423 int32_t accountId, const std::string &name) -> void {
424 HILOG_DEBUG();
425 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, name);
426 if (!clientConnection) {
427 HILOG_ERROR("There is no client connection");
428 syncPromise->set_value(RET_ERR_NO_CONNECTION);
429 return;
430 }
431
432 clientConnection->SetAbilityInfoTargetBundleName(targetBundleNames);
433 syncPromise->set_value(RET_OK);
434 }, accountId_, clientName_), "SetTargetBundleName");
435
436 std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR));
437 if (wait != std::future_status::ready) {
438 HILOG_ERROR("Failed to wait SetTargetBundleName result");
439 return RET_ERR_TIME_OUT;
440 }
441 return syncFuture.get();
442 }
443
GetConnection(int32_t accountId,const std::string & clientName)444 sptr<AccessibleAbilityConnection> AccessibleAbilityChannel::GetConnection(
445 int32_t accountId, const std::string &clientName)
446 {
447 HILOG_DEBUG();
448 sptr<AccessibilityAccountData> accountData =
449 Singleton<AccessibleAbilityManagerService>::GetInstance().GetAccountData(accountId);
450 if (!accountData) {
451 HILOG_ERROR("accountData is nullptr");
452 return nullptr;
453 }
454
455 HILOG_DEBUG("accountId[%{public}d] clientName[%{public}s]", accountId, clientName.c_str());
456 return accountData->GetAccessibleAbilityConnection(clientName);
457 }
458
GetElementOperator(int32_t accountId,int32_t windowId,int32_t focusType,const std::string & clientName,sptr<IAccessibilityElementOperator> & elementOperator)459 RetError AccessibleAbilityChannel::GetElementOperator(
460 int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName,
461 sptr<IAccessibilityElementOperator> &elementOperator)
462 {
463 HILOG_DEBUG();
464 elementOperator = nullptr;
465 sptr<AccessibleAbilityConnection> clientConnection = GetConnection(accountId, clientName);
466 if (!clientConnection) {
467 HILOG_ERROR("There is no client connection");
468 return RET_ERR_NO_CONNECTION;
469 }
470 if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) {
471 HILOG_ERROR("the client has no retieve capability");
472 return RET_ERR_NO_CAPABILITY;
473 }
474
475 sptr<AccessibilityAccountData> accountData =
476 Singleton<AccessibleAbilityManagerService>::GetInstance().GetAccountData(accountId);
477 if (!accountData) {
478 HILOG_ERROR("accountData is nullptr");
479 return RET_ERR_NULLPTR;
480 }
481 int32_t realId = Singleton<AccessibilityWindowManager>::GetInstance().ConvertToRealWindowId(windowId, focusType);
482 sptr<AccessibilityWindowConnection> connection = accountData->GetAccessibilityWindowConnection(realId);
483 if (!connection) {
484 HILOG_ERROR("windowId[%{public}d] has no connection", realId);
485 return RET_ERR_NO_WINDOW_CONNECTION;
486 }
487 elementOperator = connection->GetProxy();
488 if (!elementOperator) {
489 HILOG_ERROR("The proxy of window connection is nullptr");
490 return RET_ERR_NULLPTR;
491 }
492 return RET_OK;
493 }
494 } // namespace Accessibility
495 } // namespace OHOS