!1525 无障碍elementInfo新增mainWindowId属性

Merge pull request !1525 from qianchuang/master
This commit is contained in:
openharmony_ci 2024-11-08 07:52:23 +00:00 committed by Gitee
commit f43bc6bd51
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 139 additions and 43 deletions

View File

@ -170,6 +170,7 @@ bool AccessibilityElementInfoParcel::ReadFromParcelFourthPart(Parcel &parcel)
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isActive_);
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityVisible_);
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, clip_);
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, mainWindowId_);
return true;
}
@ -290,6 +291,7 @@ bool AccessibilityElementInfoParcel::MarshallingThirdPart(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isActive_);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityVisible_);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, clip_);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, mainWindowId_);
return true;
}

View File

@ -104,6 +104,7 @@ RetError AccessibleAbilityChannelClient::FindFocusedElementInfo(int32_t accessib
HILOG_INFO("Get result successfully from ace.");
elementInfo = elementOperator->accessibilityInfoResult_;
elementInfo.SetMainWindowId(windowId);
return RET_OK;
}
@ -274,6 +275,11 @@ RetError AccessibleAbilityChannelClient::SearchElementInfosByAccessibilityId(int
}
HILOG_DEBUG("Get result successfully from ace. size[%{public}zu]", elementOperator->elementInfosResult_.size());
elementInfos = elementOperator->elementInfosResult_;
if (!elementInfos.empty()) {
for (auto &element : elementInfos) {
element.SetMainWindowId(accessibilityWindowId);
}
}
return RET_OK;
}

View File

@ -405,7 +405,11 @@ RetError AccessibleAbilityClientImpl::GetFocusByElementInfo(const AccessibilityE
HILOG_DEBUG("windowId[%{public}d], elementId[%{public}" PRId64 "], focusType[%{public}d]",
windowId, elementId, focusType);
return channelClient_->FindFocusedElementInfo(windowId, elementId, focusType, elementInfo);
RetError ret = channelClient_->FindFocusedElementInfo(windowId, elementId, focusType, elementInfo);
if (ret == RET_OK) {
elementInfo.SetMainWindowId(sourceInfo.GetMainWindowId());
}
return ret;
}
RetError AccessibleAbilityClientImpl::InjectGesture(const std::shared_ptr<AccessibilityGestureInjectPath> &gesturePath)
@ -463,7 +467,11 @@ RetError AccessibleAbilityClientImpl::GetRoot(AccessibilityElementInfo &elementI
return RET_OK;
}
return SearchElementInfoFromAce(activeWindow, ROOT_NONE_ID, cacheMode_, elementInfo);
RetError ret = SearchElementInfoFromAce(activeWindow, ROOT_NONE_ID, cacheMode_, elementInfo);
if (ret == RET_OK) {
elementInfo.SetMainWindowId(activeWindow);
}
return ret;
}
RetError AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo,
@ -488,7 +496,11 @@ RetError AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowI
return RET_OK;
}
return SearchElementInfoFromAce(windowId, ROOT_NONE_ID, cacheMode_, elementInfo);
RetError ret = SearchElementInfoFromAce(windowId, ROOT_NONE_ID, cacheMode_, elementInfo);
if (ret == RET_OK) {
elementInfo.SetMainWindowId(windowId);
}
return ret;
}
RetError AccessibleAbilityClientImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo)
@ -672,8 +684,12 @@ RetError AccessibleAbilityClientImpl::GetNext(const AccessibilityElementInfo &el
HILOG_ERROR("direction is invalid.");
return RET_ERR_INVALID_PARAM;
}
return channelClient_->FocusMoveSearch(elementInfo.GetWindowId(),
RetError ret = channelClient_->FocusMoveSearch(elementInfo.GetWindowId(),
elementInfo.GetAccessibilityId(), direction, nextElementInfo);
if (ret == RET_OK) {
nextElementInfo.SetMainWindowId(elementInfo.GetMainWindowId());
}
return ret;
}
RetError AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent,
@ -746,6 +762,11 @@ RetError AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo
children.emplace_back(elementInfos.front());
}
ret = GetChildrenWork(windowId, childIds, children);
if (!children.empty()) {
for (auto &child : children) {
child.SetMainWindowId(parent.GetMainWindowId());
}
}
return ret;
}
@ -792,32 +813,24 @@ RetError AccessibleAbilityClientImpl::GetByContent(const AccessibilityElementInf
int32_t windowId = elementInfo.GetWindowId();
int64_t elementId = elementInfo.GetAccessibilityId();
int32_t treeId = (static_cast<uint64_t>(elementId) >> ELEMENT_MOVE_BIT);
HILOG_DEBUG("windowId %{public}d, elementId %{public}" PRId64 ", text %{public}s",
windowId, elementId, text.c_str());
RetError ret = RET_ERR_FAILED;
if (text != "") { // find element condition is null, so we will search all element info
RetError ret = channelClient_->SearchElementInfosByText(windowId, elementId, text, elementInfos);
if (ret != RET_OK) {
HILOG_ERROR("SearchElementInfosByText failed ret:%{public}d, windowId:%{public}d, text:%{public}s",
ret, windowId, text.c_str());
}
ret = channelClient_->SearchElementInfosByText(windowId, elementId, text, elementInfos);
if (elementInfos.empty()) {
HILOG_DEBUG("SearchElementInfosByText get resilt size 0, begin SearchElementInfoRecursiveByWinid");
ret = SearchElementInfoRecursiveByContent(serviceProxy_->GetActiveWindow(),
elementId, GET_SOURCE_MODE, elementInfos, text, ROOT_TREE_ID);
if (ret != RET_OK) {
HILOG_ERROR("get window element info failed ret:%{public}d", ret);
return ret;
}
HILOG_DEBUG("get resilt size:%{public}zu", elementInfos.size());
}
return RET_OK;
} else {
ret = SearchElementInfoRecursiveByWinid(windowId, elementId, GET_SOURCE_MODE, elementInfos, treeId);
}
RetError ret = SearchElementInfoRecursiveByWinid(windowId, elementId, GET_SOURCE_MODE, elementInfos, treeId);
if (ret != RET_OK) {
HILOG_ERROR("get window element info failed");
return ret;
if (!elementInfos.empty()) {
for (auto &element : elementInfos) {
element.SetMainWindowId(elementInfo.GetMainWindowId());
}
}
return RET_OK;
HILOG_INFO("ret:%{public}d, windowId:%{public}d, text:%{public}s", ret, windowId, text.c_str());
return ret;
}
RetError AccessibleAbilityClientImpl::SearchElementInfoRecursiveByContent(const int32_t windowId,
@ -921,20 +934,24 @@ RetError AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityEl
HILOG_DEBUG("get element info from cache");
return RET_OK;
}
RetError ret = RET_ERR_FAILED;
if ((parentElementId == ROOT_PARENT_ELEMENT_ID) && (parentWindowId > 0)) {
parentElementId = serviceProxy_->GetRootParentId(windowId, treeId);
if (parentElementId > 0) {
treeId = (static_cast<uint64_t>(parentElementId) >> ELEMENT_MOVE_BIT);
HILOG_DEBUG("find root parentId and search parentElementId [%{public}" PRId64 "] treeId[%{public}d]",
parentElementId, treeId);
return SearchElementInfoByElementId(child.GetParentWindowId(), parentElementId, cacheMode_, parent, treeId);
ret = SearchElementInfoByElementId(child.GetParentWindowId(), parentElementId, cacheMode_, parent, treeId);
parent.SetMainWindowId(child.GetMainWindowId());
return ret;
} else {
HILOG_DEBUG("GetRootParentId faild, parentElement:%{public}" PRId64 "", parentElementId);
return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE;
}
}
return SearchElementInfoByElementId(windowId, parentElementId, cacheMode_, parent, treeId);
ret = SearchElementInfoByElementId(windowId, parentElementId, cacheMode_, parent, treeId);
parent.SetMainWindowId(child.GetMainWindowId());
return ret;
}
RetError AccessibleAbilityClientImpl::GetByElementId(const int64_t elementId, const int32_t windowId,
@ -1206,6 +1223,7 @@ RetError AccessibleAbilityClientImpl::SearchElementInfoFromAce(const int32_t win
if (!GetCacheElementInfo(windowId, elementId, info)) {
return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE;
}
info.SetMainWindowId(windowId);
HILOG_DEBUG("elementId:%{public}" PRId64 ", windowId:%{public}d, treeId:%{public}d",
info.GetAccessibilityId(), info.GetWindowId(), info.GetBelongTreeId());
return RET_OK;
@ -1257,6 +1275,7 @@ RetError AccessibleAbilityClientImpl::SearchElementInfoByInspectorKey(const std:
if (info.GetInspectorKey() == inspectorKey) {
HILOG_INFO("find elementInfo by inspectorKey success, inspectorKey: %{public}s", inspectorKey.c_str());
elementInfo = info;
elementInfo.SetMainWindowId(windowId);
return RET_OK;
}
}
@ -1504,6 +1523,7 @@ RetError AccessibleAbilityClientImpl::SearchElementInfoByAccessibilityId(const i
SetCacheElementInfo(windowId, elementInfos);
info = elementInfos.front();
info.SetMainWindowId(windowId);
return RET_OK;
}

View File

@ -126,6 +126,16 @@ void AccessibilityElementInfo::SetWindowId(const int32_t windowId)
windowId_ = windowId;
}
int32_t AccessibilityElementInfo::GetMainWindowId() const
{
return mainWindowId_;
}
void AccessibilityElementInfo::SetMainWindowId(const int32_t windowId)
{
mainWindowId_ = windowId;
}
int64_t AccessibilityElementInfo::GetParentNodeId() const
{
return parentId_;

View File

@ -350,5 +350,11 @@ int32_t AccessibilityEventInfo::GetRequestFocusElementId() const
HILOG_DEBUG("requestFocusElementId_[%{public}d]", requestFocusElementId_);
return requestFocusElementId_;
}
void AccessibilityEventInfo::SetElementMainWindowId(const int32_t windowId)
{
HILOG_DEBUG("mainWindowId[%{public}d]", windowId);
elementInfo_.SetMainWindowId(windowId);
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -1751,6 +1751,21 @@ public:
* @sysCap Accessibility
*/
void SetClip(const bool clip);
/**
* @brief Get the windowId to the element info.
* @return mainWindowId.
* @sysCap Accessibility
*/
int32_t GetMainWindowId() const;
/**
* @brief Set the windowId to the element info.
* @param windowId The mainWindowId of node.
* @sysCap Accessibility
*/
void SetMainWindowId(const int32_t windowId);
protected:
int32_t pageId_ = -1;
int32_t windowId_ = -1;
@ -1830,6 +1845,7 @@ protected:
bool accessibilityVisible_ = true;
bool clip_ = false;
static const int backgroundImageMaxLength = 20;
int32_t mainWindowId_ = -1; // same widowId in uiview
};
} // namespace Accessibility
} // namespace OHOS

View File

@ -511,6 +511,8 @@ public:
*/
int32_t GetRequestFocusElementId() const;
void SetElementMainWindowId(const int32_t windowId);
protected:
EventType eventType_ = TYPE_VIEW_INVALID;
std::string bundleName_ = "";

View File

@ -141,7 +141,8 @@ public:
static void GetElementInfoIsActive(NAccessibilityElementData *callbackInfo, napi_value &value);
static void GetElementInfoAccessibilityVisible(NAccessibilityElementData *callbackInfo, napi_value &value);
static void GetElementInfoClip(NAccessibilityElementData *callbackInfo, napi_value &value);
static void GetElementInfoMainWindowId(NAccessibilityElementData *callbackInfo, napi_value &value);
// Window info
static void GetWindowInfoIsActive(NAccessibilityElementData *callbackInfo, napi_value &value);
static void GetWindowInfoScreenRect(NAccessibilityElementData *callbackInfo, napi_value &value);

View File

@ -104,7 +104,7 @@ namespace {
{"span", &NAccessibilityElement::GetElementInfoSpan},
{"isActive", &NAccessibilityElement::GetElementInfoIsActive},
{"accessibilityVisible", &NAccessibilityElement::GetElementInfoAccessibilityVisible},
{"mainWindowId", &NAccessibilityElement::GetElementInfoWindowId},
{"mainWindowId", &NAccessibilityElement::GetElementInfoMainWindowId},
{"allAttribute", &NAccessibilityElement::GetElementInfoAllAttribute},
{"clip", &NAccessibilityElement::GetElementInfoClip},
};
@ -992,6 +992,20 @@ void NAccessibilityElement::GetElementInfoWindowId(NAccessibilityElementData *ca
callbackInfo->accessibilityElement_.elementInfo_->GetWindowId(), &value));
}
void NAccessibilityElement::GetElementInfoMainWindowId(NAccessibilityElementData *callbackInfo, napi_value &value)
{
if (!CheckElementInfoParameter(callbackInfo, value)) {
return;
}
int32_t windowId = callbackInfo->accessibilityElement_.elementInfo_->GetWindowId();
int32_t mainWindowId = callbackInfo->accessibilityElement_.elementInfo_->GetMainWindowId();
if (mainWindowId <= 0) {
mainWindowId = windowId;
HILOG_INFO("mainWindowId <= 0, use windowId");
}
NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_create_int32(callbackInfo->env_, mainWindowId, &value));
}
void NAccessibilityElement::GetElementInfoIsFocused(NAccessibilityElementData *callbackInfo, napi_value &value)
{
if (!CheckElementInfoParameter(callbackInfo, value)) {
@ -1375,7 +1389,7 @@ void NAccessibilityElement::GetElementInfoAllAttribute5(NAccessibilityElementDat
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "clip", clip));
napi_value mainWindowId = nullptr;
GetElementInfoWindowId(callbackInfo, mainWindowId);
GetElementInfoMainWindowId(callbackInfo, mainWindowId);
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "mainWindowId", mainWindowId));
}
@ -2114,6 +2128,22 @@ void NAccessibilityElement::FindElementComplete(napi_env env, napi_status status
}
napi_value result[ARGS_SIZE_TWO] = {0};
// set reslult mainWindowId = param mainWidnowId
int32_t mainWindowId = -1;
if (callbackInfo->accessibilityElement_.elementInfo_ != nullptr) {
mainWindowId = callbackInfo->accessibilityElement_.elementInfo_->GetMainWindowId();
} else if (callbackInfo->accessibilityElement_.windowInfo_ != nullptr) {
mainWindowId = callbackInfo->accessibilityElement_.windowInfo_->GetMainWindowId();
}
if (mainWindowId > 0) {
HILOG_INFO("callbackInfo node set mainWindowId: %{public}d", mainWindowId);
callbackInfo->nodeInfo_.SetMainWindowId(mainWindowId);
for (auto &node : callbackInfo->nodeInfos_) {
node.SetMainWindowId(mainWindowId);
}
}
GetElement(callbackInfo, result[PARAM1]);
result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_);
if (callbackInfo->callback_) {

View File

@ -92,7 +92,6 @@ void AccessibilityWindowManager::WinDeInit()
HILOG_DEBUG();
std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_);
a11yWindows_.clear();
subWindows_.clear();
sceneBoardElementIdMap_.Clear();
activeWindowId_ = INVALID_WINDOW_ID;
}
@ -288,6 +287,7 @@ void AccessibilityWindowManager::UpdateAccessibilityWindowInfo(AccessibilityWind
accWindowInfo.SetInnerWid(windowInfo->innerWid_);
if (accWindowInfo.GetWindowId() == SCENE_BOARD_WINDOW_ID) {
accWindowInfo.SetWindowId(windowInfo->innerWid_);
accWindowInfo.SetMainWindowId(windowInfo->innerWid_);
HILOG_DEBUG("scene board window id 1 convert inner window id[%{public}d]", windowInfo->innerWid_);
}
HILOG_DEBUG("bundle name is [%{public}s] , touchHotAreas size(%{public}zu)",
@ -355,7 +355,7 @@ AccessibilityWindowInfo AccessibilityWindowManager::CreateAccessibilityWindowInf
void AccessibilityWindowManager::SetActiveWindow(int32_t windowId, bool isSendEvent)
{
HILOG_DEBUG("windowId is %{public}d", windowId);
HILOG_INFO("windowId is %{public}d, activeWindowId_: %{public}d", windowId, activeWindowId_);
std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_);
if (windowId == INVALID_WINDOW_ID) {
ClearOldActiveWindow();
@ -812,11 +812,10 @@ void AccessibilityWindowManager::WindowUpdateTypeEvent(const int32_t realWidId,
void AccessibilityWindowManager::WindowUpdateAll(const std::vector<sptr<Rosen::AccessibilityWindowInfo>>& infos)
{
HILOG_DEBUG();
std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_);
auto oldA11yWindows_ = a11yWindows_;
HILOG_DEBUG("WindowUpdateAll info size(%{public}zu), oldA11yWindows_ size(%{public}zu)",
infos.size(), oldA11yWindows_.size());
int32_t oldActiveWindowId = activeWindowId_;
HILOG_INFO("WindowUpdateAll start activeWindowId_: %{public}d", activeWindowId_);
WinDeInit();
for (auto &window : infos) {
if (window == nullptr) {
@ -829,7 +828,7 @@ void AccessibilityWindowManager::WindowUpdateAll(const std::vector<sptr<Rosen::A
if (!a11yWindows_.count(realWid)) {
auto a11yWindowInfo = CreateAccessibilityWindowInfo(window);
a11yWindows_.emplace(realWid, a11yWindowInfo);
HILOG_DEBUG("WindowUpdateAll a11yWindowInfo size(%{public}s)", a11yWindowInfo.GetBundleName().c_str());
HILOG_DEBUG("a11yWindowInfo bundleName(%{public}s)", a11yWindowInfo.GetBundleName().c_str());
}
if (IsSceneBoard(window)) {
subWindows_.insert(realWid);
@ -863,7 +862,7 @@ void AccessibilityWindowManager::WindowUpdateAll(const std::vector<sptr<Rosen::A
for (auto it = oldA11yWindows_.begin(); it != oldA11yWindows_.end(); ++it) {
WindowUpdateTypeEvent(it->first, WINDOW_UPDATE_REMOVED);
}
HILOG_DEBUG("WindowUpdateAll a11yWindowInfo_ size(%{public}zu)", a11yWindows_.size());
HILOG_INFO("WindowUpdateAll end activeWindowId_: %{public}d", activeWindowId_);
}
void AccessibilityWindowManager::ClearOldActiveWindow()

View File

@ -512,7 +512,9 @@ bool AccessibleAbilityManagerService::FindFocusedElement(AccessibilityElementInf
HILOG_ERROR("GetCurrentAccountData failed");
return false;
}
connection = accountData->GetAccessibilityWindowConnection(windowId);
int32_t realId =
Singleton<AccessibilityWindowManager>::GetInstance().ConvertToRealWindowId(windowId, FOCUS_TYPE_INVALID);
connection = accountData->GetAccessibilityWindowConnection(realId);
HILOG_DEBUG("windowId[%{public}d], elementId[%{public}" PRId64 "]", windowId, elementId);
if (connection == nullptr) {
HILOG_ERROR("connection is nullptr");
@ -560,7 +562,6 @@ void AccessibleAbilityManagerService::GetElementOperatorConnection(sptr<Accessib
bool AccessibleAbilityManagerService::ExecuteActionOnAccessibilityFocused(const ActionType &action)
{
HILOG_DEBUG();
int32_t windowId = GetFocusWindowId();
int64_t elementId = GetFocusElementId();
uint32_t timeOut = 5000;
@ -570,9 +571,9 @@ bool AccessibleAbilityManagerService::ExecuteActionOnAccessibilityFocused(const
HILOG_ERROR("GetCurrentAccountData failed");
return false;
}
sptr<AccessibilityWindowConnection> connection = accountData->GetAccessibilityWindowConnection(windowId);
HILOG_DEBUG("windowId[%{public}d], elementId[%{public}" PRId64 "], action[%{public}d", windowId, elementId,
action);
int32_t realId =
Singleton<AccessibilityWindowManager>::GetInstance().ConvertToRealWindowId(windowId, FOCUS_TYPE_INVALID);
sptr<AccessibilityWindowConnection> connection = accountData->GetAccessibilityWindowConnection(realId);
if (connection == nullptr) {
HILOG_ERROR("connection is nullptr");
return false;
@ -606,7 +607,8 @@ bool AccessibleAbilityManagerService::ExecuteActionOnAccessibilityFocused(const
HILOG_ERROR("ExecuteAction Failed to wait result");
return false;
}
HILOG_INFO("windowId[%{public}d], elementId[%{public}" PRId64 "], action[%{public}d, result: %{public}d",
windowId, elementId, action, actionCallback->executeActionResult_);
return actionCallback->executeActionResult_;
}
@ -1971,10 +1973,12 @@ void AccessibleAbilityManagerService::UpdateAccessibilityWindowStateByEvent(cons
EventType evtType = event.GetEventType();
HILOG_DEBUG("windowId is %{public}d", event.GetWindowId());
int32_t windowId = event.GetWindowId();
if (windowId == 1 && (evtType == TYPE_VIEW_HOVER_ENTER_EVENT || evtType == TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT)) {
if (windowId == 1) {
FindInnerWindowId(event, windowId);
}
const_cast<AccessibilityEventInfo&>(event).SetElementMainWindowId(windowId);
switch (evtType) {
case TYPE_VIEW_HOVER_ENTER_EVENT:
Singleton<AccessibilityWindowManager>::GetInstance().SetActiveWindow(windowId, false);