• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "accessibility_system_ability_client.h"
17 
18 #include "adapter/ohos/osal/accessibility/accessibility_hidumper_osal.h"
19 #include "base/log/dump_log.h"
20 #include "core/accessibility/accessibility_utils.h"
21 
22 using namespace OHOS::Accessibility;
23 using namespace OHOS::AccessibilityConfig;
24 
25 namespace OHOS::Ace::Framework {
26 
27 namespace {
BoolToString(bool tag)28 inline std::string BoolToString(bool tag)
29 {
30     return tag ? "true" : "false";
31 }
32 
ChildrenToString(const std::vector<int64_t> & children,int32_t treeId)33 inline std::string ChildrenToString(const std::vector<int64_t>& children, int32_t treeId)
34 {
35     std::string ids;
36     for (auto& child : children) {
37         if (!ids.empty()) {
38             ids.append(",");
39         }
40         int64_t childId = child;
41         AccessibilitySystemAbilityClient::SetSplicElementIdTreeId(treeId, childId);
42         ids.append(std::to_string(childId));
43     }
44     return ids;
45 }
46 
DumpRectNG(const Accessibility::Rect & rect)47 inline void DumpRectNG(const Accessibility::Rect& rect)
48 {
49     DumpLog::GetInstance().AddDesc(
50         "width: ", std::to_string(rect.GetRightBottomXScreenPostion() - rect.GetLeftTopXScreenPostion()));
51     DumpLog::GetInstance().AddDesc(
52         "height: ", std::to_string(rect.GetRightBottomYScreenPostion() - rect.GetLeftTopYScreenPostion()));
53     DumpLog::GetInstance().AddDesc("left: ", std::to_string(rect.GetLeftTopXScreenPostion()));
54     DumpLog::GetInstance().AddDesc("top: ", std::to_string(rect.GetLeftTopYScreenPostion()));
55     DumpLog::GetInstance().AddDesc("right: ", std::to_string(rect.GetRightBottomXScreenPostion()));
56     DumpLog::GetInstance().AddDesc("bottom: ", std::to_string(rect.GetRightBottomYScreenPostion()));
57 }
58 
59 } // namespace
60 
ToCommonInfo(const Accessibility::AccessibilityElementInfo & nodeInfo,int32_t treeId)61 void AccessibilityElementInfoUtils::ToCommonInfo(
62     const Accessibility::AccessibilityElementInfo& nodeInfo,
63     int32_t treeId)
64 {
65     int64_t elementId = nodeInfo.GetAccessibilityId();
66     AccessibilitySystemAbilityClient::SetSplicElementIdTreeId(treeId, elementId);
67     DumpLog::GetInstance().AddDesc("ID: ", elementId);
68     DumpLog::GetInstance().AddDesc("UniqueID: ", nodeInfo.GetUniqueId());
69     int64_t parentId = nodeInfo.GetParentNodeId();
70     AccessibilitySystemAbilityClient::SetSplicElementIdTreeId(treeId, parentId);
71     DumpLog::GetInstance().AddDesc("parent ID: ", parentId);
72     DumpLog::GetInstance().AddDesc("child IDs: ", ChildrenToString(nodeInfo.GetChildIds(), treeId));
73     DumpLog::GetInstance().AddDesc("component type: ", nodeInfo.GetComponentType());
74     DumpLog::GetInstance().AddDesc("accessibilityCustomRole: " + nodeInfo.GetCustomComponentType());
75     DumpLog::GetInstance().AddDesc("text: ", nodeInfo.GetContent());
76     DumpLog::GetInstance().AddDesc("originText: ", nodeInfo.GetOriginalText());
77     DumpLog::GetInstance().AddDesc("window id: " + std::to_string(nodeInfo.GetWindowId()));
78     DumpRectNG(nodeInfo.GetRectInScreen());
79 
80     DumpLog::GetInstance().AddDesc("enabled: ", BoolToString(nodeInfo.IsEnabled()));
81     DumpLog::GetInstance().AddDesc("focusable: ", BoolToString(nodeInfo.IsFocusable()));
82     DumpLog::GetInstance().AddDesc("focused: ", BoolToString(nodeInfo.IsFocused()));
83     DumpLog::GetInstance().AddDesc("visible: ", BoolToString(nodeInfo.IsVisible()));
84     DumpLog::GetInstance().AddDesc("accessibility focused: ", BoolToString(nodeInfo.HasAccessibilityFocus()));
85     DumpLog::GetInstance().AddDesc("accessibilityText: " + nodeInfo.GetAccessibilityText());
86     DumpLog::GetInstance().AddDesc("accessibilityGroup: " + BoolToString(nodeInfo.GetAccessibilityGroup()));
87     DumpLog::GetInstance().AddDesc("accessibilityLevel: " + nodeInfo.GetAccessibilityLevel());
88     DumpLog::GetInstance().AddDesc("accessibilityDescription: " + nodeInfo.GetDescriptionInfo());
89     DumpLog::GetInstance().AddDesc("hitTestBehavior: " + nodeInfo.GetHitTestBehavior());
90 
91     DumpLog::GetInstance().AddDesc("inspector key: ", nodeInfo.GetInspectorKey());
92     DumpLog::GetInstance().AddDesc("bundle name: ", nodeInfo.GetBundleName());
93     DumpLog::GetInstance().AddDesc("page id: " + std::to_string(nodeInfo.GetPageId()));
94     DumpLog::GetInstance().AddDesc("page path: ", nodeInfo.GetPagePath());
95     DumpLog::GetInstance().AddDesc("is valid element: ", BoolToString(nodeInfo.IsValidElement()));
96     DumpLog::GetInstance().AddDesc("resource name: ", nodeInfo.GetComponentResourceId());
97 
98     DumpLog::GetInstance().AddDesc("clickable: ", BoolToString(nodeInfo.IsClickable()));
99     DumpLog::GetInstance().AddDesc("long clickable: ", BoolToString(nodeInfo.IsLongClickable()));
100     DumpLog::GetInstance().AddDesc("popup supported: ", BoolToString(nodeInfo.IsPopupSupported()));
101     DumpLog::GetInstance().AddDesc("zindex: ", std::to_string(nodeInfo.GetZIndex()));
102 }
103 } // namespace OHOS::Ace::Framework
104