fix: keep the scan's foreground service inside Android's start budget
ScanController called stopService() from a Dispatchers.Default coroutine right after startForegroundService(), so a scan that finished at once or a Cancel tap could beat the pending foreground start on the main thread. ScanService then never reached startForeground() and Android killed the process a few seconds later with RemoteServiceException$ForegroundServiceDidNotStartInTimeException - a stack with no app frames. - ScanService enters the foreground in onCreate() and at the top of every onStartCommand(), before the Cancel early-return. - A refused startForeground() (start not allowed, missing service type or permission, rejected notification) is logged instead of crashing, and a notification error can no longer kill the state collector. - The service stops itself when it observes scanning == false; nothing outside it calls stopService() any more. - New Robolectric ScanServiceTest covers onCreate, the idle and cancel paths, a failing startForeground() and the Android 15 onTimeout path. - Version 1.1.2 / versionCode 7: versionCode 6 (1.1.1) is already on a Play track. CHANGELOG, AGENTS.md, codemap, ROADMAP and the release checklist (1.1.2 artefact record and paste-ready notes) are updated.
This commit is contained in:
@@ -10,6 +10,27 @@ upload needs a **higher `versionCode`** than every previous upload.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.1.2] — 2026-11-09 · versionCode 7
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`ForegroundServiceDidNotStartInTimeException` when a scan starts or cancels
|
||||
quickly.** `ScanController` called `stopService()` from a background coroutine
|
||||
immediately after `startForegroundService()` (a scan that finished at once, or a
|
||||
Cancel tap). When that stop beat the pending foreground start, `ScanService` never
|
||||
ran `startForeground()` and Android killed the process a few seconds later with
|
||||
`RemoteServiceException$ForegroundServiceDidNotStartInTimeException` — a stack with
|
||||
no app frames. The service now enters the foreground in `onCreate()` *and* at the
|
||||
top of every `onStartCommand()` (before the Cancel early-return), tolerates a
|
||||
`startForeground()` that the system refuses instead of crashing, and stops itself
|
||||
once `ScanState.scanning` goes false; nothing outside it calls `stopService()`
|
||||
anymore. Covered by the new Robolectric `ScanServiceTest`.
|
||||
|
||||
### Changed
|
||||
|
||||
- **`versionName` 1.1.2 / `versionCode` 7.** `versionCode` 6 (1.1.1) is already on a
|
||||
Play track, so the fix needs a new code.
|
||||
|
||||
## [1.1.1] — 2026-10-20 · versionCode 6
|
||||
|
||||
### Fixed
|
||||
|
||||
Reference in New Issue
Block a user