feat: Add ExternalControlReceiver for silent background automation#644
feat: Add ExternalControlReceiver for silent background automation#644whjstc wants to merge 3 commits intoMetaCubeX:mainfrom
Conversation
个人使用的文档和工具: - BUILD_GUIDE.md - 构建指南 - SUCCESS.md - 构建成功说明 - SETUP_COMPLETE.md - 环境配置记录 - BROADCAST_RECEIVER_WORKING.md - 测试记录 - CLAUDE.md - 项目说明 - PR_GUIDE.md - PR 提交指南 - build.sh, check-env.sh, prepare-pr.sh - 构建脚本 - build.gradle.kts - 支持自定义 keystore 路径 这些文件不会影响上游 PR。
|
我的破澎湃 |
用的是是我这边编译的 apk,还是 MetaCubeX 原仓库发布的版本? |
可以了,太棒了!无感开关。谢谢大佬! |
最近我也发现,后台运行久了,会有自动关不掉的情况,先这样将就了,以后有时间再研究。 |
Merge upstream MetaCubeX/ClashMetaForAndroid up to v2.11.25: - Add dynamic App Shortcuts for Tasker/Samsung Routines (MetaCubeX#676) - Mark MainActivity as singleTask (MetaCubeX#665) - Support hiding app from Recents screen (MetaCubeX#663) - Adapt hidden field for proxy groups (MetaCubeX#685) - Fix seccomp on 32-bit Android <= 10 - Update dependencies and toolchain
Adds a BroadcastReceiver allowing Tasker and other automation tools to control Clash (START/STOP/TOGGLE) without triggering any UI or screen activity, complementing the existing App Shortcuts approach (MetaCubeX#676). Root cause of previous unreliability: the initial implementation checked Remote.broadcasts.clashRunning (in-memory state reset to false when app goes background), so the stop condition always failed in background. Fixed by querying StatusClient.currentProfile() != null for real-time state via ContentProvider IPC, independent of app foreground status. No persistent notification or foreground service required. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
0a227a2 to
18eb3d6
Compare
|
Update: Found and fixed the root cause of the unreliable STOP issue I mentioned earlier. The problem was that Fix: replaced with Also rebased onto current |
Problem
ExternalControlActivitycauses screen flash/popup on some ROMs (Flyme, MIUI, ColorOS) when triggered by automation tools like Tasker, breaking the silent background control experience.Solution
Adds
ExternalControlReceiver— aBroadcastReceiverthat handles START/STOP/TOGGLE actions completely in the background, with no UI triggered.This complements the App Shortcuts approach added in #676 (which targets Samsung Routines and launcher long-press). The BroadcastReceiver approach targets Tasker and other tools that send explicit broadcast intents.
Root cause fix (previously unreliable STOP)
The initial version of this PR checked
Remote.broadcasts.clashRunningto decide whether to callstopClashService(). This is an in-memory value that gets reset tofalseinBroadcasts.unregister()whenever the app goes to the background — so the condition always evaluated tofalsewhen Tasker triggered the receiver, andstopClashService()was never called.Fix: replaced with
StatusClient(context).currentProfile() != null, which queries theStatusProviderContentProvider directly via IPC. This is real-time and independent of whether the app is in the foreground — the same methodBroadcasts.register()uses to initialize state.No
KeepAliveServiceor persistent notification required.Usage (Tasker)
Action: Send Intent
com.github.metacubex.clash.meta.action.STOP_CLASH(or START / TOGGLE)com.github.metacubex.clash.metaFiles changed
app/src/main/java/.../ExternalControlReceiver.kt— BroadcastReceiver implementationapp/src/main/AndroidManifest.xml— register receiverTASKER_GUIDE.md— user guide with examples