diff --git a/services/aams/include/accessible_ability_channel.h b/services/aams/include/accessible_ability_channel.h index b17b37ff..2b7e2b68 100644 --- a/services/aams/include/accessible_ability_channel.h +++ b/services/aams/include/accessible_ability_channel.h @@ -72,6 +72,7 @@ private: static sptr GetConnection(int32_t accountId, const std::string &clientName); static RetError GetElementOperator(int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName, sptr &elementOperator, const int32_t treeId); + static bool CheckWinFromAwm(const int32_t windowId); RetError GetWindows(uint64_t displayId, std::vector &windows) const; RetError TransmitActionToMmi(const int32_t action); static void SetKeyCodeToMmi(std::shared_ptr& keyEvent, const bool isPress, diff --git a/services/aams/src/accessible_ability_channel.cpp b/services/aams/src/accessible_ability_channel.cpp index 1576dd5c..d6832db8 100644 --- a/services/aams/src/accessible_ability_channel.cpp +++ b/services/aams/src/accessible_ability_channel.cpp @@ -75,7 +75,7 @@ RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const Elem sptr elementOperator = nullptr; RetError ret = GetElementOperator(accountId_, windowId, FOCUS_TYPE_INVALID, clientName_, elementOperator, treeId); - if (ret != RET_OK) { + if (ret != RET_OK || !CheckWinFromAwm(windowId)) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", windowId); std::vector infos = {}; callback->SetSearchElementInfoByAccessibilityIdResult(infos, requestId); @@ -714,5 +714,19 @@ RetError AccessibleAbilityChannel::GetElementOperator( } return RET_OK; } + +bool AccessibleAbilityChannel::CheckWinFromAwm(const int32_t windowId) +{ + std::vector windowsFromAwm = + Singleton::GetInstance().GetAccessibilityWindows(); + if (!windowsFromAwm.empty()) { + for (const auto& window: windowsFromAwm) { + if (windowId == window.GetWindowId()) { + return true; + } + } + } + return false; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file