feat(android): defer FGS init until foreground - #58
Conversation
Move AppState/FGS cold-start safety into initialize() so consumers can call it from background/headless without string-matching errors. Soft-bind when the service is already up; reject FGS_START_BLOCKED from native; remove no-op boot receivers. Bump to 2.0.0-beta.28. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the React Native Flic2 Android initialization flow to tolerate Android foreground-service start restrictions by deferring native initialization until the app is in the foreground, while also removing unused boot/update receiver plumbing from the library.
Changes:
- Add
initialize(options?: InitializeOptions)on JS side to optionally wait for foreground on Android and retry afterFGS_START_BLOCKED. - Update Android native init to detect “foreground service start not allowed” and reject with a stable
FGS_START_BLOCKEDerror code. - Remove library-provided boot/update receivers and associated manifest entries; bump version to
2.0.0-beta.28.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/index.ts | Adds InitializeOptions and foreground-wait/retry logic when Android blocks starting the foreground service. |
| README.md | Documents the updated initialize() behavior and the new option on Android. |
| package.json | Version bump to 2.0.0-beta.28. |
| package-lock.json | Lockfile version bump to 2.0.0-beta.28. |
| android/src/main/java/nl/xguard/flic2/Flic2Service.kt | Removes unused BootUpReceiver / UpdateReceiver inner classes. |
| android/src/main/java/nl/xguard/flic2/Flic2Module.kt | Adds FGS_START_BLOCKED rejection path when FGS start is blocked; keeps bind-only soft path. |
| android/src/main/java/nl/xguard/flic2/ActivityUtil.kt | Adds detection helper for foreground-service start blocked exceptions/messages. |
| android/src/main/AndroidManifest.xml | Removes boot permission and receiver declarations now that the library doesn’t provide them. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Restore the 0.3.x / master BootUpReceiver and UpdateReceiver so boot and package-replace still wake the process (Application.onCreate). They still do not start the Flic FGS. Co-authored-by: Cursor <cursoragent@cursor.com>
When AppState stays active and FGS_START_BLOCKED persists past the capped retries, reject instead of leaving initialize() hanging with a live subscription. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c4319f3. Configure here.
Co-authored-by: Cursor <cursoragent@cursor.com>

Summary
initialize()rejects with stableFGS_START_BLOCKEDwhenstartForegroundServiceis blocked; bind-only soft path still works whenFlic2Serviceis already running (headless/background).initialize()waits forAppStateactiveand retries (capped 3×500ms when already active) by default;{ waitForForeground: false }fails fast; reject after retry budget instead of hanging.BootUpReceiver/UpdateReceiver; they now try to startFlic2Serviceon boot/update (official flic2lib-android intent), failing soft if blocked.2.0.0-beta.28.Follow-up (apps)
xgac-rn-alarmcurrentlytools:node="remove"sFlic2Service$BootUpReceiver, so it will not get this library boot FGS try until that remove is dropped (keep appOnBootReceiverfor Activity if needed).Test plan
await Flic2.initialize()resolves; buttons APIs workFGS_START_BLOCKEDwhenwaitForForeground: false)startForegroundService(may log failure if blocked); serviceonCreateinits manager when start succeeds