Skip to content

feat(android): defer FGS init until foreground - #58

Merged
wesdewitte merged 4 commits into
developfrom
feature/android-fgs-init-safety-20260717-090214
Jul 17, 2026
Merged

feat(android): defer FGS init until foreground#58
wesdewitte merged 4 commits into
developfrom
feature/android-fgs-init-safety-20260717-090214

Conversation

@jdegger

@jdegger jdegger commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Android cold initialize() rejects with stable FGS_START_BLOCKED when startForegroundService is blocked; bind-only soft path still works when Flic2Service is already running (headless/background).
  • JS initialize() waits for AppState active and retries (capped 3×500ms when already active) by default; { waitForForeground: false } fails fast; reject after retry budget instead of hanging.
  • Keep library BootUpReceiver / UpdateReceiver; they now try to start Flic2Service on boot/update (official flic2lib-android intent), failing soft if blocked.
  • Bump to 2.0.0-beta.28.

Follow-up (apps)

xgac-rn-alarm currently tools:node="remove"s Flic2Service$BootUpReceiver, so it will not get this library boot FGS try until that remove is dropped (keep app OnBootReceiver for Activity if needed).

Test plan

  • Foreground: await Flic2.initialize() resolves; buttons APIs work
  • Background soft-bind: with Flic2Service already up, initialize from headless/background resolves without FGS start
  • Cold start while backgrounded: initialize waits / retries until app becomes active (or rejects with FGS_START_BLOCKED when waitForForeground: false)
  • Boot/update: receivers attempt startForegroundService (may log failure if blocked); service onCreate inits manager when start succeeds
  • iOS initialize unchanged

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>
Copilot AI review requested due to automatic review settings July 17, 2026 07:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 after FGS_START_BLOCKED.
  • Update Android native init to detect “foreground service start not allowed” and reject with a stable FGS_START_BLOCKED error 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.

Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts
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>
Copilot AI review requested due to automatic review settings July 17, 2026 07:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/index.ts
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>
Copilot AI review requested due to automatic review settings July 17, 2026 08:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/index.ts
Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings July 17, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

@wesdewitte
wesdewitte merged commit 3aa604d into develop Jul 17, 2026
4 checks passed
@jdegger
jdegger deleted the feature/android-fgs-init-safety-20260717-090214 branch July 17, 2026 08:35
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.

3 participants