mirror of
https://gitee.com/openharmony/accessibility
synced 2025-02-18 18:07:36 +00:00
取得控件信息速度优化
Signed-off-by: Mupceet <laiguizhong@huawei.com>
This commit is contained in:
parent
4e9e5e498a
commit
33de3437af
@ -232,6 +232,19 @@ public:
|
||||
*/
|
||||
virtual bool SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override;
|
||||
|
||||
/**
|
||||
* @brief Set cache mode.
|
||||
* The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
|
||||
* GetChildren, GetAnchor, GetSource, GetParentElementInfo.
|
||||
* @param cacheMode The cache mode. It includes:
|
||||
* PREFETCH_PREDECESSORS: cache the parent node info also.
|
||||
* PREFETCH_SIBLINGS: cache the sister/brothers node info also.
|
||||
* PREFETCH_CHILDREN: cache the child node info also.
|
||||
* otherwise: no cache.
|
||||
* @return -
|
||||
*/
|
||||
virtual void SetCacheMode(const int32_t cacheMode) override;
|
||||
|
||||
private:
|
||||
sptr<AccessibleAbilityManagerServiceProxy> serviceProxy_ = nullptr;
|
||||
};
|
||||
|
@ -263,6 +263,19 @@ public:
|
||||
*/
|
||||
virtual bool SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override;
|
||||
|
||||
/**
|
||||
* @brief Set cache mode.
|
||||
* The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
|
||||
* GetChildren, GetAnchor, GetSource, GetParentElementInfo.
|
||||
* @param cacheMode The cache mode. It includes:
|
||||
* PREFETCH_PREDECESSORS: cache the parent node info also.
|
||||
* PREFETCH_SIBLINGS: cache the sister/brothers node info also.
|
||||
* PREFETCH_CHILDREN: cache the child node info also.
|
||||
* otherwise: no cache.
|
||||
* @return Return true if sets target bundle names successfully, else return false.
|
||||
*/
|
||||
virtual void SetCacheMode(const int32_t cacheMode) override;
|
||||
|
||||
/**
|
||||
* @brief Clean data.
|
||||
* @param remote The object access to AAMS.
|
||||
@ -289,12 +302,18 @@ private:
|
||||
* @return
|
||||
*/
|
||||
void DispatchGestureInjectResult(uint32_t sequence, bool result);
|
||||
bool GetCacheElementInfo(const int32_t windowId, const int32_t elementId, AccessibilityElementInfo &elementInfo);
|
||||
void SetCacheElementInfo(const int32_t windowId,
|
||||
std::vector<OHOS::Accessibility::AccessibilityElementInfo> &elementInfos);
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
|
||||
sptr<IAccessibleAbilityManagerService> serviceProxy_ = nullptr;
|
||||
std::shared_ptr<AccessibleAbilityListener> listener_ = nullptr;
|
||||
std::shared_ptr<AccessibleAbilityChannelClient> channelClient_ = nullptr;
|
||||
std::map<uint32_t, std::shared_ptr<AccessibilityGestureResultListener>> gestureResultListenerInfos_;
|
||||
int32_t cacheMode_ = 0;
|
||||
int32_t cacheWindowId_ = -1;
|
||||
std::map<int32_t, AccessibilityElementInfo> cacheElementInfos_;
|
||||
};
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
||||
|
@ -322,5 +322,11 @@ bool AccessibilityUITestAbilityImpl::GetChildren(const AccessibilityElementInfo
|
||||
HILOG_INFO();
|
||||
return AccessibleAbilityClient::GetInstance()->GetChildren(parent, children);
|
||||
}
|
||||
|
||||
void AccessibilityUITestAbilityImpl::SetCacheMode(const int32_t cacheMode)
|
||||
{
|
||||
HILOG_INFO();
|
||||
return AccessibleAbilityClient::GetInstance()->SetCacheMode(cacheMode);
|
||||
}
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
@ -30,7 +30,7 @@ namespace Accessibility {
|
||||
// tmp: wait for window registing when client connect done
|
||||
constexpr int WAIT_WINDOW_REGIST = 500;
|
||||
namespace {
|
||||
constexpr int32_t NONE_ID = -1;
|
||||
constexpr int32_t ROOT_NONE_ID = -1;
|
||||
std::mutex g_Mutex;
|
||||
sptr<AccessibleAbilityClientImpl> g_Instance = nullptr;
|
||||
} // namespace
|
||||
@ -260,13 +260,18 @@ bool AccessibleAbilityClientImpl::GetRoot(AccessibilityElementInfo &elementInfo)
|
||||
|
||||
int32_t activeWindow = serviceProxy_->GetActiveWindow();
|
||||
HILOG_INFO("activeWindow[%{public}d]", activeWindow);
|
||||
if (GetCacheElementInfo(activeWindow, ROOT_NONE_ID, elementInfo)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = channelClient_->SearchElementInfosByAccessibilityId(activeWindow, NONE_ID, 0, elementInfos);
|
||||
if (!result) {
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(activeWindow, ROOT_NONE_ID, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(activeWindow, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
elementInfo = elementInfos[0];
|
||||
}
|
||||
@ -282,17 +287,25 @@ bool AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t channelId = windowInfo.GetChannelId();
|
||||
int32_t windowId = windowInfo.GetWindowId();
|
||||
HILOG_INFO("channelId[%{public}d], windowId[%{public}d]", channelId, windowId);
|
||||
HILOG_INFO("windowId[%{public}d]", windowId);
|
||||
if (GetCacheElementInfo(windowId, ROOT_NONE_ID, elementInfo)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = false;
|
||||
result = channelClient_->SearchElementInfosByAccessibilityId(windowId, -1, 0, elementInfos);
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, ROOT_NONE_ID, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("GetRootByWindow OK.");
|
||||
elementInfo = elementInfos.front();
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo)
|
||||
@ -360,22 +373,31 @@ bool AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const
|
||||
HILOG_ERROR("The channel is invalid.");
|
||||
return false;
|
||||
}
|
||||
int32_t channelId = parent.GetChannelId();
|
||||
|
||||
int32_t windowId = parent.GetWindowId();
|
||||
int32_t childId = parent.GetChildId(index);
|
||||
HILOG_INFO("channelId[%{public}d], windowId[%{public}d], childId[%{public}d]", channelId, windowId, childId);
|
||||
HILOG_INFO("windowId[%{public}d], childId[%{public}d]", windowId, childId);
|
||||
if (childId == -1) {
|
||||
HILOG_ERROR("childId[%{public}d] is invalid", childId);
|
||||
return false;
|
||||
}
|
||||
bool result = false;
|
||||
if (GetCacheElementInfo(windowId, childId, child)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
result = channelClient_->SearchElementInfosByAccessibilityId(windowId, childId, 0, elementInfos);
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, childId, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("GetChildElementInfo OK");
|
||||
child = elementInfos.front();
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &parent,
|
||||
@ -397,13 +419,21 @@ bool AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &pa
|
||||
return false;
|
||||
}
|
||||
|
||||
AccessibilityElementInfo child;
|
||||
if (GetCacheElementInfo(windowId, childId, child)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
children.emplace_back(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = channelClient_->SearchElementInfosByAccessibilityId(windowId, childId, 0, elementInfos);
|
||||
if (!result) {
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, childId, cacheMode_, elementInfos)) {
|
||||
HILOG_ERROR("Search elementInfos by AccessibilityId failed. windowId[%{public}d], childId[%{public}d]",
|
||||
windowId, childId);
|
||||
return false;
|
||||
} else {
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("Get child elementInfo OK. windowId[%{public}d], childId[%{public}d]", windowId, childId);
|
||||
children.emplace_back(elementInfos.front());
|
||||
@ -437,19 +467,26 @@ bool AccessibleAbilityClientImpl::GetAnchor(const AccessibilityWindowInfo &windo
|
||||
HILOG_ERROR("The channel is invalid.");
|
||||
return false;
|
||||
}
|
||||
int32_t channelId = windowInfo.GetChannelId();
|
||||
int32_t windowId = windowInfo.GetWindowId();
|
||||
int32_t anchorId = windowInfo.GetAnchorId();
|
||||
HILOG_INFO("channelId[%{public}d], windowId[%{public}d], anchorId[%{public}d]",
|
||||
channelId, windowId, anchorId);
|
||||
HILOG_INFO("windowId[%{public}d], anchorId[%{public}d]", windowId, anchorId);
|
||||
if (GetCacheElementInfo(windowId, anchorId, elementInfo)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = false;
|
||||
result = channelClient_->SearchElementInfosByAccessibilityId(windowId, anchorId, 0, elementInfos);
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, anchorId, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("GetAnchor OK");
|
||||
elementInfo = elementInfos.front();
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::GetSource(const AccessibilityEventInfo &eventInfo,
|
||||
@ -460,18 +497,26 @@ bool AccessibleAbilityClientImpl::GetSource(const AccessibilityEventInfo &eventI
|
||||
HILOG_ERROR("The channel is invalid.");
|
||||
return false;
|
||||
}
|
||||
int32_t channelId = eventInfo.GetChannelId();
|
||||
int32_t windowId = eventInfo.GetWindowId();
|
||||
int32_t elementId = eventInfo.GetAccessibilityId();
|
||||
HILOG_INFO("channelId[%{public}d], windowId[%{public}d], elementId[%{public}d]", channelId, windowId, elementId);
|
||||
HILOG_INFO("windowId[%{public}d], elementId[%{public}d]", windowId, elementId);
|
||||
if (GetCacheElementInfo(windowId, elementId, elementInfo)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = false;
|
||||
result = channelClient_->SearchElementInfosByAccessibilityId(windowId, elementId, 0, elementInfos);
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, elementId, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("GetSource OK");
|
||||
elementInfo = elementInfos.front();
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityElementInfo &child,
|
||||
@ -482,18 +527,26 @@ bool AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityElemen
|
||||
HILOG_ERROR("The channel is invalid.");
|
||||
return false;
|
||||
}
|
||||
int32_t channelId = child.GetChannelId();
|
||||
int32_t windowId = child.GetWindowId();
|
||||
int32_t elementId = child.GetParentNodeId();
|
||||
HILOG_INFO("channelId[%{public}d], windowId[%{public}d], parentId[%{public}d]", channelId, windowId, elementId);
|
||||
HILOG_INFO("windowId[%{public}d], parentId[%{public}d]", windowId, elementId);
|
||||
if (GetCacheElementInfo(windowId, elementId, parent)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<AccessibilityElementInfo> elementInfos {};
|
||||
bool result = false;
|
||||
result = channelClient_->SearchElementInfosByAccessibilityId(windowId, elementId, 0, elementInfos);
|
||||
if (!channelClient_->SearchElementInfosByAccessibilityId(windowId, elementId, cacheMode_, elementInfos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size());
|
||||
SetCacheElementInfo(windowId, elementInfos);
|
||||
if (!elementInfos.empty()) {
|
||||
HILOG_DEBUG("GetParentElementInfo OK");
|
||||
parent = elementInfos.front();
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action,
|
||||
@ -577,5 +630,45 @@ void AccessibleAbilityClientImpl::DispatchGestureInjectResult(uint32_t sequence,
|
||||
HILOG_INFO("sequence[%{public}d] result[%{public}d]", sequence, result);
|
||||
gestureResultListener->OnGestureInjectResult(sequence, result);
|
||||
}
|
||||
|
||||
void AccessibleAbilityClientImpl::SetCacheMode(const int32_t cacheMode)
|
||||
{
|
||||
HILOG_INFO("set cache mode: [%{public}d]", cacheMode);
|
||||
cacheMode_ = cacheMode & GET_SOURCE_PREFETCH_MODE;
|
||||
}
|
||||
|
||||
bool AccessibleAbilityClientImpl::GetCacheElementInfo(const int32_t windowId,
|
||||
const int32_t elementId, AccessibilityElementInfo &elementInfo)
|
||||
{
|
||||
HILOG_DEBUG();
|
||||
if (cacheWindowId_ == -1 || cacheWindowId_ != windowId) {
|
||||
HILOG_ERROR("cacheWindowId[%{public}d], windowId[%{public}d]", cacheWindowId_, windowId);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter = cacheElementInfos_.find(elementId);
|
||||
if (iter == cacheElementInfos_.end()) {
|
||||
HILOG_ERROR("the element id[%{public}d] is not in cache", elementId);
|
||||
return false;
|
||||
}
|
||||
|
||||
elementInfo = iter->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AccessibleAbilityClientImpl::SetCacheElementInfo(const int32_t windowId,
|
||||
std::vector<OHOS::Accessibility::AccessibilityElementInfo> &elementInfos)
|
||||
{
|
||||
HILOG_DEBUG("windowId[%{public}d], elementInfos size[%{public}zu]", windowId, elementInfos.size());
|
||||
if (elementInfos.empty()) {
|
||||
HILOG_ERROR("elementInfos is empty");
|
||||
return;
|
||||
}
|
||||
cacheElementInfos_.clear();
|
||||
cacheWindowId_ = windowId;
|
||||
for (auto &elementInfo : elementInfos) {
|
||||
cacheElementInfos_.insert(std::make_pair(elementInfo.GetAccessibilityId(), elementInfo));
|
||||
}
|
||||
}
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
@ -234,6 +234,19 @@ public:
|
||||
* @return Return true if sets target bundle names successfully, else return false.
|
||||
*/
|
||||
virtual bool SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set cache mode.
|
||||
* The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
|
||||
* GetChildren, GetAnchor, GetSource, GetParentElementInfo.
|
||||
* @param cacheMode The cache mode. It includes:
|
||||
* PREFETCH_PREDECESSORS: cache the parent node info also.
|
||||
* PREFETCH_SIBLINGS: cache the sister/brothers node info also.
|
||||
* PREFETCH_CHILDREN: cache the child node info also.
|
||||
* otherwise: no cache.
|
||||
* @return Return true if sets target bundle names successfully, else return false.
|
||||
*/
|
||||
virtual void SetCacheMode(const int32_t cacheMode) = 0;
|
||||
};
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
||||
|
@ -232,6 +232,19 @@ public:
|
||||
* @return Return true if sets target bundle names successfully, else return false.
|
||||
*/
|
||||
virtual bool SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set cache mode.
|
||||
* The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
|
||||
* GetChildren, GetAnchor, GetSource, GetParentElementInfo.
|
||||
* @param cacheMode The cache mode. It includes:
|
||||
* PREFETCH_PREDECESSORS: cache the parent node info also.
|
||||
* PREFETCH_SIBLINGS: cache the sister/brothers node info also.
|
||||
* PREFETCH_CHILDREN: cache the child node info also.
|
||||
* otherwise: no cache.
|
||||
* @return Return true if sets target bundle names successfully, else return false.
|
||||
*/
|
||||
virtual void SetCacheMode(const int32_t cacheMode) = 0;
|
||||
};
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
||||
|
Loading…
x
Reference in New Issue
Block a user