快照json文件相关api参考信息 #101
cjy0812
started this conversation in
Show and tell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
GKD 快照数据 API 文档
1. 概述
GKD(自动跳过广告工具)在运行过程中会通过无障碍服务捕获当前界面的视图树快照(Snapshot),并以 JSON 格式存储。该快照包含了应用信息、设备信息、GKD 自身状态以及完整的视图节点树,可用于离线分析、规则编写与调试。
本文档定义了 GKD 快照的数据结构、字段含义以及基于快照进行节点匹配时需遵循的规则,特别是针对 快速查询(fastQuery) 优化的支持。
2. 快照根对象
快照 JSON 的顶层是一个对象,包含以下字段:
idappIdactivityIdscreenHeightscreenWidthisLandscapeappInfoappName等互斥appNameappVersionCodeappVersionNamegkdAppInfogkdVersionCode等互斥gkdVersionCodegkdVersionNamedevicenodes2.1
appInfo对象(完整模式)idappId)nameversionCodeversionNameisSystemmtimehiddenenableduserId2.2
gkdAppInfo对象(完整模式)idli.songe.gkd)nameversionCodeversionNameisSystemmtimehiddenenableduserId2.3
device对象devicePD2445)modelmanufacturerbrandsdkIntrelease3. 节点对象(
nodes数组元素)每个节点代表视图树中的一个视图(View)或视图组(ViewGroup)。
idpidid,根节点为-1idQfattr.id是否稳定且可用于快速查询(见第 5 节)textQfattr.text是否静态稳定且可用于快速查询(见第 5 节)attr4. 属性对象(
attr)描述视图的具体布局、内容及交互属性。
idandroid:id/content)vidnameandroid.widget.TextView)textdescclickablefocusablecheckablecheckededitablelongClickablevisibleToUserlefttoprightbottomwidthright - left)heightbottom - top)childCountindexdepth5. 合格标志(
idQf/textQf)与快速查询5.1 定义
idQf(ID Qualified):若为true,表示attr.id是稳定的、来自 Android 资源的视图 ID,可通过findAccessibilityNodeInfosByViewId快速定位。textQf(Text Qualified):若为true,表示attr.text是静态固定文本(不是时间、计数器等动态内容),可通过findAccessibilityNodeInfosByText快速定位。5.2 快速查询优化
GKD 在匹配规则时,如果选择器使用了
[vid="..."]或[text="..."],且对应节点的idQf或textQf为true,则会调用 Android 系统的快速查找 API,避免手动遍历整个视图树,极大提升匹配效率。idQf === true或textQf === true),否则快速查询 API 可能返回空或错误结果。[vid="com.example:id/confirm_button"]→ 依赖idQf[text="确定"]→ 依赖textQf5.3 匹配规则
在编写或解析规则时,必须遵守以下约束:
idQf === trueattr.id进行精确匹配,并可启用快速查询idQf === false或nullattr.id作为匹配条件(ID 可能动态变化或不可靠)textQf === trueattr.text进行完全匹配,并可启用快速查询textQf === false或nullattr.text作为固定文本匹配(例如倒计时“03:59:45”应忽略)6. 示例
6.1 快照根对象(精简模式)
{ "id": 1711547793221, "appId": "com.miHoYo.cloudgames.ys", "activityId": "com.mihoyo.cloudgame.main.MiHoYoCloudMainActivity", "appName": "云·原神", "appVersionCode": 400000014, "appVersionName": "4.5.0", "screenHeight": 1080, "screenWidth": 2400, "isLandscape": true, "gkdVersionCode": 27, "gkdVersionName": "1.7.2", "device": { ... }, "nodes": [ ... ] }6.2 节点对象(含合格标志)
{ "id": 5, "pid": 3, "idQf": true, "textQf": true, "attr": { "id": "com.ss.android.article.lite:id/dcw", "vid": "dcw", "name": "android.widget.TextView", "text": "领取成功!继续观看视频领取更多时长", "clickable": false, "visibleToUser": true, "left": 107, "top": 1470, "right": 974, "bottom": 1538, "width": 867, "height": 68, "childCount": 0, "index": 1, "depth": 4 } }6.3 节点对象(动态文本,不可用于匹配)
{ "id": 9, "pid": 7, "idQf": true, "textQf": false, "attr": { "id": "com.ss.android.article.lite:id/dcs", "text": "03:59:45", ... } }7. 错误处理与兼容性
7.1 缺失字段
idQf或textQf缺失(undefined),解析时应视为null,按“不合格”处理。appInfo缺失,应回退读取appName、appVersionCode等顶层字段。gkdAppInfo缺失,应回退读取gkdVersionCode、gkdVersionName。7.2 树结构异常
pid指向不存在的id→ 将该节点视为根节点。id:nodes数组中id必须唯一,若重复则后者覆盖前者(或报错)。7.3 快速查询失败回退
idQf === true,系统 API 也可能因节点未附加到窗口而返回空。解析器应实现回退策略:快速查询失败后,自动切换为手动遍历。7.4 版本兼容
idQf/textQf,此时默认所有节点的这两个标志均为null,即无法使用快速查询,需完全遍历。8. 相关资源
文档版本:1.0
最后更新:2026-04-06
author:DeepSeek
'内容由AI生成,请仔细甄别'
Beta Was this translation helpful? Give feedback.
All reactions