Skip to content

feat: use foreground service to prevent accessibility services from being killed on HyperOS/Redmi#239

Draft
Copilot wants to merge 2 commits into
kt-rewritefrom
copilot/fix-app-killed-hyperos-redmi
Draft

feat: use foreground service to prevent accessibility services from being killed on HyperOS/Redmi#239
Copilot wants to merge 2 commits into
kt-rewritefrom
copilot/fix-app-killed-hyperos-redmi

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

Xiaomi HyperOS/MIUI aggressively kills background processes, causing AppBlockerService and UsageTrackingService to stop functioning. Promoting both to foreground services raises their process priority and prevents this.

Changes

  • Permissions — Added FOREGROUND_SERVICE and FOREGROUND_SERVICE_DATA_SYNC to the manifest
  • Service declarations — Added android:foregroundServiceType="dataSync" to both AppBlockerService and UsageTrackingService
  • BaseBlockingService — Added startForegroundNotification() / stopForegroundNotification() helpers called from onServiceConnected() / onDestroy(); exposed open val foregroundNotificationId so each subclass gets a distinct notification ID
  • UsageTrackingService — Overrides foregroundNotificationId = 9002 (vs. default 9001 used by AppBlockerService in its separate :app_blocker_service process); adds missing super.onServiceConnected() call to trigger the base class foreground promotion
  • Notification — Silent, IMPORTANCE_LOW, ongoing notification on a dedicated curbox_fg_service channel — minimal user-facing footprint while satisfying the foreground service contract
// BaseBlockingService.kt
override fun onServiceConnected() {
    super.onServiceConnected()
    startForegroundNotification()   // elevates process priority
}

override fun onDestroy() {
    stopForegroundNotification()
    super.onDestroy()
}

Copilot AI and others added 2 commits May 3, 2026 18:30
- Add FOREGROUND_SERVICE and FOREGROUND_SERVICE_DATA_SYNC permissions
- Add foregroundServiceType="dataSync" to AppBlockerService and UsageTrackingService manifests
- Add startForegroundNotification/stopForegroundNotification helpers in BaseBlockingService
- AppBlockerService (process :app_blocker_service) uses notification ID 9001
- UsageTrackingService (main process) overrides to use notification ID 9002
- Both services start foreground on connect and stop foreground on destroy
- Add string resources for the foreground notification channel/title/text

Agent-Logs-Url: https://github.com/nethical6/digipaws/sessions/779f9cb6-7eb7-4f21-9dca-4a76a0f2432b

Co-authored-by: nethical6 <79095297+nethical6@users.noreply.github.com>
- Fix indentation of permission declarations in AndroidManifest.xml
- Always attempt to create notification channel (no-op if exists, handles user deletion)
- Remove unnecessary Build.VERSION_CODES.N check since minSdk is 26

Agent-Logs-Url: https://github.com/nethical6/digipaws/sessions/779f9cb6-7eb7-4f21-9dca-4a76a0f2432b

Co-authored-by: nethical6 <79095297+nethical6@users.noreply.github.com>
@RTX3080Ti-Official
Copy link
Copy Markdown

i cn confirm xiaomi being very aggresive

@nethical6
Copy link
Copy Markdown
Owner

i cn confirm xiaomi being very aggresive

wannabe ahh ios 🥀💔✌️

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.

3 participants