whalechoi:AsteriskMETA 自动切换下沉至核心,将随 1.2.20-dev 发布

在 AsteriskMETA PR #25 下,whalechoi 说明自动切换功能已通过 rebase 和重构合入 main,并保留贡献者的原始提交与作者信息。检测与切换下沉至 AndroidLibClashLite v1.19.32-android.4,VPN 内嵌核心与 ROOT CLI 共用实现;App 不再需要单独的前台服务,ROOT 模式下即使 App 进程不在也能继续工作。设置写入 asterisk-auto-switch,支持运行时热更新;状态和历史仅保存在内存。新建连接正在使用的节点免额外探测,全部不可用时扫描逐步退避;检测复用连接测试的地址、超时和并发设置,地区匹配按完整词识别,设置纳入备份恢复。使用上传的自定义核心时,关闭功能不写入该字段,开启时提示不支持。作者称已在 AVD 测试 VPN、ROOT 内置核心和 ROOT 官方核心且功能关闭的情况;功能将随 1.2.20-dev 发布。

作者原文

Thanks for this feature! It has been merged into main with a rebase plus a follow-up refactor, so GitHub cannot match the commits and I am closing this PR manually. Your original commit is kept as 2ca0f33 with your authorship.

What changed during the merge:

  • Checks run inside the core. Health checks and switching moved into AndroidLibClashLite (v1.19.32-android.4). The same code runs in the embedded VPN core and the ROOT CLI, so the app no longer needs its own foreground service, and ROOT keeps working even when the app process is gone.
  • Settings reach the core. They are written to the generated profile as the asterisk-auto-switch key. Changes made while running apply immediately through PATCH /asterisk/auto-switch (or the JNI bridge). Status and history come from the core (GET /asterisk/auto-switch) and are kept in memory only.
  • Less probing on mobile. A node that new connections are actively using counts as healthy without a probe. When no node is healthy, later replacement scans back off, so we no longer need an Android network monitor.
  • Uses the Connection test settings (URL, timeout, concurrency) instead of hard-coded values.
  • Region matching is token-aware, so "UK" no longer matches "Ukraine".
  • Settings are included in backup and restore.
  • Uploaded custom cores are handled. When the feature is off, the key is not written, so an uploaded official Mihomo core gets an unchanged configuration. When it is on, the app explains that a custom core does not support it.

Tested on an AVD in VPN mode, in ROOT (BPF2SOCKS) with the built-in core, and in ROOT with an official core and the feature off. It ships in 1.2.20-dev.


感谢贡献!该功能已通过 rebase 加重构的方式合入 main。由于提交哈希发生了变化,GitHub 无法自动识别,因此手动关闭本 PR。你的原始提交以 2ca0f33 保留,作者信息不变。

合入时的主要调整:

  • 检测改在核心内运行。 检测与切换逻辑下沉到 AndroidLibClashLite(v1.19.32-android.4),VPN 内嵌核心与 ROOT CLI 共用同一实现。App 不再需要单独的前台服务;即使 App 进程不在,ROOT 下也能继续工作。
  • 设置写入核心。 设置以 asterisk-auto-switch 字段写入生成的配置;运行中修改会通过 API 或 JNI 热更新。状态与历史从核心读取,只保存在内存中。
  • 移动端减少探测。 新建连接正在使用的节点直接视为可用,不再额外探测;所有节点都不可用时,后续扫描会逐步退避,因此不再需要 Android 网络监听。
  • 改用「连接测试」设置(测试地址、超时、并发数),不再写死。
  • 地区匹配按完整词识别,"UK" 不会再误匹配 "Ukraine"。
  • 设置已纳入备份与恢复。
  • 兼容上传的自定义核心。 功能关闭时不写入该字段,上传的官方核心拿到的配置不受影响;功能开启时,App 会提示自定义核心不支持此功能。

已在 AVD 上实测:VPN 模式、ROOT(BPF2SOCKS)内置核心,以及 ROOT 使用官方核心且功能关闭的情况。将随 1.2.20-dev 发布。