feat: Add BroadcastReceiver with KeepAliveService for reliable automation #644
+470
−0
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.
🎯 Problem
ExternalControlActivitycauses screen flash/popup on some ROMs (especially Flyme, MIUI, ColorOS) when triggered by automation tools like Tasker, breaking the "background automation" experience.✅ Solution
This PR adds two components for reliable background automation:
1. ExternalControlReceiver (BroadcastReceiver)
2. KeepAliveService (Foreground Service)
Why this is needed: During testing, I discovered that BroadcastReceiver fails when the app enters deep sleep (CACHED_EMPTY state, procState=19). The system freezes the app and blocks broadcasts from third-party apps.
Solution: A lightweight foreground service that:
🧪 Testing
Tested extensively on Flyme with Tasker:
📱 Usage
Tasker Configuration
Action: Send Intent
com.github.metacubex.clash.meta.action.START_CLASH(or STOP/TOGGLE)com.github.metacubex.clash.metaExample Automation Scenarios
📄 Files Changed
app/src/main/java/.../ExternalControlReceiver.kt- BroadcastReceiver implementationapp/src/main/java/.../KeepAliveService.kt- Foreground service for reliabilityapp/src/main/java/.../MainApplication.kt- Auto-start KeepAliveServiceapp/src/main/AndroidManifest.xml- Register receiver and serviceTASKER_GUIDE.md- Complete user guide with examplesapp/src/main/res/values/strings.xml- Notification strings🔧 Technical Details
Why Foreground Service instead of battery optimization whitelist?
Resource usage:
📚 Documentation
Complete Tasker setup guide included in
TASKER_GUIDE.mdwith: