Skip to content

fix: promote StreamingService to foreground immediately on Android 8+#408

Open
7MS8 wants to merge 1 commit into
newhinton:masterfrom
7MS8:fix/grapheneos-streaming-foreground
Open

fix: promote StreamingService to foreground immediately on Android 8+#408
7MS8 wants to merge 1 commit into
newhinton:masterfrom
7MS8:fix/grapheneos-streaming-foreground

Conversation

@7MS8

@7MS8 7MS8 commented Jul 8, 2026

Copy link
Copy Markdown

Split out of #406 per reviewer request (separate unrelated fixes into their own PRs).

Bug

On GrapheneOS (and strictly enforced Android 12+), streaming/opening a file could silently fail. StreamingService extended IntentService, which runs startForeground() on a background worker thread with non-deterministic scheduling delay. If that delay exceeds the ~5s the platform allows before killing the process, GrapheneOS kills the service before it ever reaches the foreground.

Fix

Convert StreamingService from the deprecated IntentService to a plain Service:

  • Call startForeground() in onStartCommand() on the main thread, guaranteeing foreground promotion before any background-process limits can apply.
  • Run the blocking waitFor() in a dedicated thread instead.
  • Return START_NOT_STICKY (user-initiated serve, no auto-restart).
  • Add tryStartForegroundService() to ActivityHelper and use it for all StreamingService start calls.

Reproduction

  • Device: Pixel 7a, GrapheneOS.
  • App version: build from master prior to this fix (versionCode 410/417).
  • Steps: open the file browser on any remote, tap a file to stream/preview it.
  • Observed: streaming silently fails / file never opens; GrapheneOS kills the service before foreground promotion completes.
  • After this fix: file opens/streams correctly, verified on the same device.

Test plan

  • Verified on a physical Pixel 7a running GrapheneOS: streaming a remote file now works reliably.
  • Local build compiles (./gradlew :app:compileOssDebugSources).

On GrapheneOS (and strictly enforced Android 12+), the 5-second window
for calling startForeground() was being missed because StreamingService
extended IntentService, which ran startForeground() on a background
worker thread with non-deterministic scheduling delay.

Convert StreamingService from deprecated IntentService to Service:
- Call startForeground() in onStartCommand() on the main thread,
  guaranteeing foreground promotion before any background-process
  limits can apply
- Run the blocking waitFor() in a dedicated thread
- Return START_NOT_STICKY (user-initiated serve, no auto-restart)
- Add tryStartForegroundService() to ActivityHelper and use it for
  all StreamingService start calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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