fix: 防止无障碍事件源节点索引越界导致崩溃 - #573
Open
DeanTMaxim wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #572
问题
脚本通过
auto.registerEvent注册窗口变化事件后,AccessibilityService会在调用脚本回调前构造AccessibilityEventWrapper。原
getIndexInParent()会持续递增索引,直到parent.getChild(index)等于事件源节点,但没有按parent.childCount限界。页面切换期间节点树可能变化,事件源节点可能已经从父节点移除;此时循环会访问越界索引,并由 Android 框架抛出ArrayIndexOutOfBoundsException,导致 AutoJs6 进程、无障碍服务和当前脚本一起退出。修改
0 until childCount范围内。RuntimeException时返回安全哨兵-1。findIndexInParent(),以便用本地单元测试稳定复现节点消失和节点失效场景。getDepth()不变:当前崩溃证据只指向getIndexInParent(),本次不加入任意深度上限或扩大重构范围。选择
-1是因为它与UiObject构造器的缺省indexInParent一致,用来表示没有可用的父级索引;本次不改变UiObject的其他导航行为。测试
新增
AccessibilityNodeIndexTest,覆盖:childCount = 1且目标节点已消失时,不读取索引 1,返回-1。RuntimeException时返回-1。TDD 证据:
IndexOutOfBoundsException: Index: 1, Size: 1失败。IllegalStateException: stale node失败。-1时,正常路径用例以expected:<1> but was:<-1>失败。OK (3 tests)。AccessibilityEventWrapper.kt、AccessibilityNodeIndex.kt连同 Android 36android.jar的窄化 Kotlin 编译通过。git diff --check无空白错误。提交前再次运行完整 Gradle 任务
:app:testAppDebugUnitTest --no-daemon --offline:当前
origin/master@ed3eb10e首先存在以下资源链接错误;测试时仅在本地临时补充了两个颜色资源别名:资源链接通过后暴露出同一上游日志面板变更中的第二组既存错误:
测试时仅在本地把其中的
AutoJs.getInstance()调整为项目现有的AutoJs.instance写法,随后完整 Gradle 目标测试通过。上述两项临时基线补丁均已删除,未包含在本 PR 中;本 PR 只包含事件包装修复及其回归测试。