Skip to content

fix(android): call startForeground before blocking Flic2Manager.init - #61

Merged
LuukC merged 1 commit into
developfrom
feature/auto-20260831-140128
Aug 31, 2026
Merged

LuukC merged 1 commit into
developfrom
feature/auto-20260831-140128

Conversation

@jdegger

@jdegger jdegger commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Android 8+ kills Flic2Service when startForeground() is delayed by a
slow init. Promote the FGS first, keep init synchronous so bind and
button listeners still run after the manager is ready.

Co-authored-by: Cursor cursoragent@cursor.com


Note

Low Risk
Small reordering in service onCreate with no auth or data changes; main risk is duplicate or early foreground notification behavior, which onStartCommand already guards.

Overview
Fixes Flic2Service being killed on Android 8+ when Flic2Manager.init() blocks the main thread long enough to miss the ~5s window after startForegroundService().

onCreate now creates the notification channel, builds the notification, and calls startForegroundService() before synchronous Flic2Manager.init(). Init order is unchanged in spirit—still on the main thread in onCreate so bind and button listeners see a ready manager—only foreground promotion is moved earlier.

Package version bumped to 2.0.0-beta.29.

Reviewed by Cursor Bugbot for commit 7f75c21. Bugbot is set up for automated code reviews on this repo. Configure here.

Android 8+ kills Flic2Service when startForeground() is delayed by a
slow init. Promote the FGS first, keep init synchronous so bind and
button listeners still run after the manager is ready.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 31, 2026 12:03
@jdegger

jdegger commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Plain-language overview

Goal: Stop Android from crashing the Flic button service when the app starts that background service.

In simple terms: Android requires a visible “this service is running” notification within a few seconds of starting the Flic service. Setting up the Flic library can take longer than that, so the phone killed the app. This change shows the notification first, then finishes Flic setup on the same startup step so button presses are not skipped.

What changes for users / the system:

  • The Flic service should no longer crash on Android 8+ during startup (Sentry XGAC-RN-ALARM-12H).
  • Button presses are still delivered after setup finishes, including clicks stored on the button while it was disconnected.
  • Version bump to 2.0.0-beta.29 so the alarm app can pick this up after publish (no app-side patch).

High-level picture

flowchart LR
  startService[Android starts Flic service] --> showNotice[Show running notification]
  showNotice --> setupFlic[Finish Flic setup]
  setupFlic --> deliverClicks[Listen and deliver button clicks]
Loading

Last synced to commit 7f75c21.

@LuukC
LuukC merged commit bae240d into develop Aug 31, 2026
4 checks passed

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 addresses Android 8+ foreground-service timing constraints by promoting Flic2Service to the foreground earlier in onCreate(), reducing the chance the OS kills the service when Flic2Manager.init() blocks long enough to miss the ~5s startForegroundService() → startForeground() deadline.

Changes:

  • Reorders Flic2Service.onCreate() to create the notification channel/notification and call startForegroundService() before running synchronous Flic2Manager.init().
  • Bumps the package version to 2.0.0-beta.29 (and updates the lockfile accordingly).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
package.json Bumps library version to 2.0.0-beta.29.
package-lock.json Updates lockfile version fields to match 2.0.0-beta.29.
android/src/main/java/nl/xguard/flic2/Flic2Service.kt Promotes the service to foreground before potentially slow synchronous manager initialization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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