Skip to content

目标应用同包内切换 Activity 时对新窗口补一次全扫描 - #109

Merged
zfdang merged 1 commit into
masterfrom
perf/rescan-on-activity-change
Sep 22, 2026
Merged

zfdang merged 1 commit into
masterfrom
perf/rescan-on-activity-change

Conversation

@zfdang

@zfdang zfdang commented Sep 22, 2026

Copy link
Copy Markdown
Owner

背景

真机(OPPO PHY110 / Android 16)测试 #108 时发现:美团外卖先进入 MainActivity,约 1 秒后才弹出 SplashAdActivity。原逻辑在"同包内切换 Activity"时只记录 Activity 名就 break,不对新窗口做全窗口扫描,广告页只能靠后续 CONTENT_CHANGED 事件碰巧覆盖到跳过按钮。这是原有行为,不是 #108 引入的。

改动

  • STATE_CHANGED 同包、Activity 变化时,跳过流程继续运行,并像第一个 Activity 一样对新窗口调度一次全窗口扫描(经 rootOfActiveTargetWindow() 校验包名)。流程未运行时不做任何事,白名单 / 桌面 / 输入法不受影响。
  • debug 构建里打印带文字/描述的节点,便于在真机上排查"为什么没命中"。release 不受影响。

验证

  • 新增 2 个 Robolectric 测试:同包切到新 Activity 时扫描新窗口并点击;非目标包切换 Activity 不触发扫描。单元测试共 41 个,全部通过。
  • 真机一轮(知乎、闲鱼、京东、天猫、美团外卖):知乎、京东开屏广告 0.2–0.5s 内命中并点击;新路径触发 4 次,无异常、无误点。

🤖 Generated with Claude Code

Some apps start their main activity first and show the splash-ad
activity on top of it a moment later (seen with Meituan's
SplashAdActivity on a real device). The window-state event for that
second activity used to only record the activity name, so the ad window
was never scanned as a whole and could only be found through later
content-changed events. The skip-ad process now treats an activity
change inside the target package like the first activity: it keeps
running and schedules one full scan of the new window. Nothing happens
while no process is running, so whitelisted or launcher packages are
unaffected.

Also logs labelled nodes in debug builds to make "no keyword matched"
cases diagnosable on a device.
@zfdang
zfdang merged commit b44d60c into master Sep 22, 2026
1 check passed
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.

1 participant