-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
auto.registerEvent 包装无障碍事件时可能因子节点索引越界导致应用崩溃 #572
Copy link
Copy link
Open
Labels
Accepted 🌱 受理Maintainer may be busy resolving or fixing the labeled issuesMaintainer may be busy resolving or fixing the labeled issuesBug 🐞 故障Confirmed bugs or reports that are very likely to be bugsConfirmed bugs or reports that are very likely to be bugsProposal 💡 方案Issue creater's own proposal which may be really helpfulIssue creater's own proposal which may be really helpful
Description
Activity
Metadata
Metadata
Assignees
Labels
Accepted 🌱 受理Maintainer may be busy resolving or fixing the labeled issuesMaintainer may be busy resolving or fixing the labeled issuesBug 🐞 故障Confirmed bugs or reports that are very likely to be bugsConfirmed bugs or reports that are very likely to be bugsProposal 💡 方案Issue creater's own proposal which may be really helpfulIssue creater's own proposal which may be really helpful
问题描述
在 AutoJs6 6.7.0 (3804) 中,脚本通过
auto.registerEvent('window_content_changed', ...)监听无障碍事件时,在微信小程序页面切换过程中偶发进程崩溃。AutoJs6 应用进程、无障碍服务和当前运行脚本会一起退出。异常发生在
AccessibilityService构造AccessibilityEventWrapper的阶段,早于脚本回调,因此脚本层的try/catch无法捕获或规避。环境
master,ed3eb10e88db5a8425fd94bdddefa4176e5e1c94最小复现脚本
复现步骤
该问题具有竞态特征,可能需要多次切换页面才能触发。
实际结果
期望结果
事件源节点在包装期间失效或已不再属于原父节点时,应返回安全的
indexInParent哨兵值并继续处理后续事件,不应导致 AutoJs6 进程退出。根因分析
AccessibilityEventWrapper.getIndexInParent()当前从索引 0 开始查找事件源节点,但循环没有按parent.childCount限界:微信页面切换时无障碍节点树会发生竞态变化。如果事件源节点已从父节点移除,循环不会找到目标,并继续调用越界的
getChild(index)。Android 12 上最终由LongArray.get()抛出ArrayIndexOutOfBoundsException。建议将查找范围限制为父节点的
childCount,并对节点失效期间的运行时异常做防护;父节点为空、目标未找到或节点访问失败时返回-1。该值与UiObject构造器的缺省indexInParent一致,用来表示没有可用的父级索引;本次不改变UiObject的其他导航行为。