Skip to content

fix: prevent delayed accessibility events from overwriting foreground cache - #571

Open
DeanTMaxim wants to merge 1 commit into
SuperMonster003:masterfrom
DeanTMaxim:fix/current-package-cache
Open

fix: prevent delayed accessibility events from overwriting foreground cache#571
DeanTMaxim wants to merge 1 commit into
SuperMonster003:masterfrom
DeanTMaxim:fix/current-package-cache

Conversation

@DeanTMaxim

Copy link
Copy Markdown

Summary / 变更概述

Prevent delayed accessibility window-state events from overwriting the cached foreground package/activity when their original window no longer exists.

避免原窗口已经消失的延迟无障碍窗口状态事件覆盖当前前台包名/Activity 缓存。

Closes #570. Related symptom report: #529.

Root cause / 根因

Both ActivityInfoProvider implementations used:

if (window?.isFocused != false)

If getWindow(event.windowId) returns null, Kotlin evaluates null != false as true. A delayed event from a disappeared SystemUI/launcher/app window could therefore be accepted as if it were focused and replace mLatestPackage/mLatestActivity.

两个 ActivityInfoProvider 实现都使用了上述判断。当 getWindow(event.windowId) 返回 null 时,Kotlin 中 null != false 的结果为 true,所以来自已消失窗口的延迟事件可能被当作聚焦事件接纳,并覆盖 mLatestPackage/mLatestActivity

Fix / 修复方式

Apply the following policy consistently to both maintained namespaces:

  • Existing focused event window: accept.
  • Existing unfocused event window: reject.
  • Missing event window: accept only if both the event window ID and package match rootInActiveWindow.
  • Otherwise, preserve the previous cache.

在两个维护中的命名空间内统一应用以下策略:

  • 事件窗口存在且聚焦:接纳。
  • 事件窗口存在但未聚焦:拒绝。
  • 事件窗口不存在:仅当事件窗口 ID 和包名都与 rootInActiveWindow 一致时接纳。
  • 其他情况保留原缓存。

Changed namespaces / 修改的命名空间:

  • org.autojs.autojs.core.activity
  • com.stardust.autojs.core.activity

Tests / 测试

Added six policy cases for each namespace (12 tests total):

  • focused event window;
  • unfocused event window;
  • missing window with mismatched active-root window ID;
  • missing window with mismatched active-root package;
  • missing window confirmed by the active root;
  • missing package evidence.

两个命名空间各增加 6 个策略用例,共 12 个测试,覆盖聚焦、未聚焦、活动根窗口 ID 不匹配、活动根包名不匹配、活动根确认以及缺少包名证据。

TDD evidence / TDD 证据:

  • With the old eventWindowFocused != false policy, all six missing-window regression cases failed across the two namespaces.
  • With this fix, both test classes report tests="6", failures="0", errors="0" (12/12 passed).

Full verification command / 完整验证命令:

gradle :app:testAppDebugUnitTest --rerun-tasks --no-daemon --stacktrace

Result / 结果:

BUILD SUCCESSFUL in 1m 24s
217 actionable tasks: 217 executed

Verification note / 验证说明

Current master has unrelated compilation errors introduced with the bottom log sheet (console_debug/console_verbose resource references and obsolete AutoJs.getInstance() calls). They are already covered by #556. To run the full unit-test task, equivalent corrections were applied locally only, the full task was rerun, and those corrections were then reverted. This PR does not contain the unrelated bottom-sheet changes.

当前 master 的底部日志面板存在与本修复无关的编译错误(console_debug/console_verbose 资源引用以及过时的 AutoJs.getInstance() 调用),#556 已处理这些问题。为执行完整单元测试,本地仅临时应用了等效修正;测试完成后已恢复。本 PR 不包含这些无关的底部日志面板改动。

The original symptom and event/window mismatch were also reproduced on an OPPO Android test device using ADB and accessibility-window inspection. Device identifiers, accounts, and application data are omitted.

原始现象及事件/窗口不匹配也已在一台 OPPO Android 测试机上通过 ADB 和无障碍窗口检查复现;设备标识、账号和应用数据均已省略。

Prevent delayed window-state events from replacing the foreground package cache unless the active root confirms both the event window and package. Add policy tests for both maintained namespaces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: delayed accessibility events can overwrite the foreground cache / 延迟无障碍事件会覆盖前台缓存

1 participant