Skip to content

Fix service start crashes (streaming and USB) - #190

Merged
zeevy merged 2 commits into
masterfrom
fix/186-streaming-fgs-start-crash
Oct 10, 2026
Merged

zeevy merged 2 commits into
masterfrom
fix/186-streaming-fgs-start-crash

Conversation

@zeevy

@zeevy zeevy commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Fixes three crashes from the Play Console.

#186 - ForegroundServiceDidNotStartInTimeException after Continue on the start streaming dialog

  • FileStreamerIntentService is started with startForegroundService() but called startForeground() only deep in onHandleIntent, on the worker thread. With no G-code file it returned early without it, the service stopped, and Android killed the app.
  • Now startForeground() runs first in onStartCommand, on every start, with the same notification (checking or streaming, file name). The two later calls and their always-true SDK_INT > N_MR1 checks (minSdk 26) are gone.

RemoteServiceException on Android 10 (no message in the trace)

  • Most likely the Android 11-and-older form of the same "did not call startForeground" crash. Its two known sources are the streaming start (this PR) and the USB screen's old startForegroundService() in onStart (already fixed in v2.61, ed7501f). No extra code.

#189 - BackgroundServiceStartNotAllowedException in UsbConnectionActivity.onStart

  • startService() there throws while Android counts the app as in the background. The bind in onCreate already creates and keeps the service alive (onStartCommand does nothing), so the refusal is now caught and logged.

Checked on the emulator (API 37)

  • No machine can connect to the emulator, so throwaway builds (not committed) skipped the fragment's file and connection checks, and made the USB startService() call 8 s after onStop with am make-uid-idle in between.
  • Old code: both crashes reproduced with the same exceptions.
  • New code: Continue with no file shows "No gcode file selected", no crash, no notification left. The refused USB start logs a warning, no crash.
  • Real build: normal launch starts the USB service as before (startRequested=true).
  • ./gradlew build passes.

FileStreamerIntentService is started with startForegroundService(), but
it called startForeground() only deep in onHandleIntent on the worker
thread. When no G-code file was found it returned early without it, the
service stopped, and Android killed the app with
ForegroundServiceDidNotStartInTimeException (RemoteServiceException on
Android 11 and older).

Call startForeground() first in onStartCommand, on every start, with the
same notification. Drop the later calls and their always-true SDK checks.

Fixes #186
UsbConnectionActivity.onStart() calls startService(), which throws
BackgroundServiceStartNotAllowedException while Android counts the app
as in the background. The bind in onCreate already creates and keeps
the service alive, so catch the refusal and log it.

Fixes #189
@zeevy
zeevy merged commit 6e0438a into master Oct 10, 2026
12 checks passed
@zeevy
zeevy deleted the fix/186-streaming-fgs-start-crash branch October 10, 2026 03:04
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.

2 participants