Skip to content

feat(service): Introduce fallback worker to ensure service stays alive#4295

Merged
jamesarich merged 1 commit into
mainfrom
fix/fb_issues
Jan 25, 2026
Merged

feat(service): Introduce fallback worker to ensure service stays alive#4295
jamesarich merged 1 commit into
mainfrom
fix/fb_issues

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

This commit introduces ServiceKeepAliveWorker, an expedited CoroutineWorker, to ensure the MeshService can be reliably started from the background. This worker acts as a fallback mechanism for Android 14+ devices, which may block startForegroundService calls due to new restrictions.

When a foreground service start is denied, the app now schedules this one-time expedited worker. The worker has temporary permission to start a foreground service, ensuring the MeshService is launched successfully.

Key Changes:

  • ServiceKeepAliveWorker:

    • A new HiltWorker that runs as an expedited task to start MeshService.
    • Displays a temporary "Resuming Mesh Service" notification while active, as required for expedited workers on newer Android versions.
  • MeshServiceStarter.kt:

    • When context.startForegroundService() fails with ForegroundServiceStartNotAllowedException, it now logs a warning and schedules the ServiceKeepAliveWorker as a fallback.
  • AndroidManifest.xml & MeshService.kt:

    • Added FOREGROUND_SERVICE_DATA_SYNC permission and service type to comply with foreground service requirements and align with the worker's function.
  • Crashlytics Logging (GooglePlatformAnalytics.kt):

    • Improved Crashlytics logging to filter out CancellationException and only report genuine errors or exceptions, reducing noise from standard coroutine behavior.
    • Non-fatal exceptions are now only recorded for log severities of Error or higher, unless an explicit Throwable is provided.

This commit introduces `ServiceKeepAliveWorker`, an expedited `CoroutineWorker`, to ensure the `MeshService` can be reliably started from the background. This worker acts as a fallback mechanism for Android 14+ devices, which may block `startForegroundService` calls due to new restrictions.

When a foreground service start is denied, the app now schedules this one-time expedited worker. The worker has temporary permission to start a foreground service, ensuring the `MeshService` is launched successfully.

### Key Changes:

-   **`ServiceKeepAliveWorker`:**
    -   A new `HiltWorker` that runs as an expedited task to start `MeshService`.
    -   Displays a temporary "Resuming Mesh Service" notification while active, as required for expedited workers on newer Android versions.

-   **`MeshServiceStarter.kt`:**
    -   When `context.startForegroundService()` fails with `ForegroundServiceStartNotAllowedException`, it now logs a warning and schedules the `ServiceKeepAliveWorker` as a fallback.

-   **`AndroidManifest.xml` & `MeshService.kt`:**
    -   Added `FOREGROUND_SERVICE_DATA_SYNC` permission and service type to comply with foreground service requirements and align with the worker's function.

-   **Crashlytics Logging (`GooglePlatformAnalytics.kt`):**
    -   Improved Crashlytics logging to filter out `CancellationException` and only report genuine errors or exceptions, reducing noise from standard coroutine behavior.
    -   Non-fatal exceptions are now only recorded for log severities of `Error` or higher, unless an explicit `Throwable` is provided.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@github-actions github-actions Bot added the bugfix PR tag label Jan 24, 2026
@jamesarich jamesarich enabled auto-merge January 24, 2026 16:45
@codecov

codecov Bot commented Jan 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (833f1ca) to head (9ca15c3).
⚠️ Report is 5 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #4295   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files          3       3           
  Lines         23      23           
  Branches       7       7           
=====================================
  Misses        23      23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this pull request to the merge queue Jan 24, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 24, 2026
@jamesarich jamesarich added this pull request to the merge queue Jan 25, 2026
Merged via the queue into main with commit 576ae67 Jan 25, 2026
11 checks passed
@jamesarich jamesarich deleted the fix/fb_issues branch January 25, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant