Skip to content

fix(android): stop the sync keep-alive when its foreground time limit runs out - #20488

Merged
mdmohsin7 merged 2 commits into
mainfrom
fix/sync-fgs-handle-timeout
Oct 3, 2026
Merged

mdmohsin7 merged 2 commits into
mainfrom
fix/sync-fgs-handle-timeout

Conversation

@mdmohsin7

@mdmohsin7 mdmohsin7 commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Android users get "Omi keeps stopping" when a long background recording sync hits Android's foreground-service time limit.

  • Android 15+ caps a dataSync foreground service at about 6 hours a day.
  • Android 14+ caps shortService at about 3 minutes.
  • When a cap is reached, the system calls Service.onTimeout. If the service is still running a few seconds later, Android kills the process with ForegroundServiceDidNotStopInTimeException.
  • SyncTransferForegroundService never overrode onTimeout.

Crashlytics, last 14 days:

  • 31 users, all on 1.0.553+1320, Android 15–17.
  • Every crash happened with the app in the background.
  • The message is "A foreground service of type dataSync did not stop within its timeout: ComponentInfo{com.friend.ios/com.friend.ios.sync.SyncTransferForegroundService}".

Change

  • Both onTimeout overloads now release the wake lock, drop the notification and call stopSelf():
    • onTimeout(startId), Android 14+, for shortService;
    • onTimeout(startId, fgsType), Android 15+, for dataSync.
  • The service uses shortService as its cold-start type, so that limit needs handling too.
  • The Dart transfer continues without the keep-alive, as it already does when Android refuses the start.

Not in this PR

Product invariants affected

none

Failure class

Failure-Class: none

The existing foreground-service classes (FC-foreground-service-promotion-after-startup-work and FC-foreground-start-cancelled-before-delivery) cover promotion at start. This bug is a missing timeout stop.

Verification

  • ./gradlew :app:testDevDebugUnitTest --tests com.friend.ios.sync.SyncTransferForegroundServiceTest (JDK 21): 5 tests pass, including the two new ones:
    • a dataSync timeout stops the service and releases the wake lock;
    • a shortService timeout stops the service.
  • Both new tests fail without the fix.
  • scripts/pr-preflight --pr-body-file <this body>: passes.
  • Not run on a device or emulator. Reaching the real 6-hour limit needs adb shell cmd activity FGS timeout overrides on an Android 15+ device.

🤖 Generated with Claude Code

Review in cubic

… runs out

Android 15+ caps a dataSync foreground service at about 6 hours a day and
Android 14+ caps shortService at about 3 minutes. When a cap is reached
the system calls Service.onTimeout and, if the service is still running a
few seconds later, crashes the process with
ForegroundServiceDidNotStopInTimeException. SyncTransferForegroundService
never overrode onTimeout, so a long background sync took the app down
(Crashlytics: 31 users on 1.0.553+1320, Android 15-17, all background,
"A foreground service of type dataSync did not stop within its timeout").

Both onTimeout overloads now release the wake lock, drop the notification
and stopSelf(). The Dart transfer continues without the keep-alive, as it
already does when a start is refused.

Verification:
- ./gradlew :app:testDevDebugUnitTest --tests
  com.friend.ios.sync.SyncTransferForegroundServiceTest (JDK 21): 5 pass.
- The two new tests fail without the fix.

Failure-Class: none

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@mdmohsin7
mdmohsin7 merged commit 7b40315 into main Oct 3, 2026
47 checks passed
@mdmohsin7
mdmohsin7 deleted the fix/sync-fgs-handle-timeout branch October 3, 2026 17:48
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.

1 participant