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:
2026-11-09 00:25:56 +01:00
parent 4739069737
commit 6d031082a3
9 changed files with 336 additions and 57 deletions
+2 -2
View File
@@ -89,8 +89,8 @@ android {
applicationId = "de.softwareapp_hb.fotodup.finder.free"
minSdk = 26
targetSdk = 36
versionCode = 6
versionName = "1.1.1"
versionCode = 7
versionName = "1.1.2"
// AdMob reads its application id from the manifest, so it has to be a placeholder:
// the value differs between a developer machine, CI and a release build.