Skip to content

fix(mobile): [WIP] Improve foreground service type handling #19506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yagueto
Copy link

@yagueto yagueto commented Jun 24, 2025

Description

This pull request updates the foreground service type to TYPE_DATA_SYNC. Previously, a TYPE_SHORT_SERVICE was being used, which caused the app to ANR after syncing for more than three minutes. This change allows the service to run for up to six hours without issues

Will fix #17980

How Has This Been Tested?

  • Test A
  • Test B

Screenshots (if appropriate)

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

yagueto added 2 commits June 24, 2025 18:47
Changes foreground service type from SHORT_SERVICE to DATA_SYNC to avoid getting ANR if the service runs for longer than two minutes
Copy link
Contributor

Label error. Requires exactly 1 of: changelog:.*. Found: . A maintainer will add the required label.

@yagueto
Copy link
Author

yagueto commented Jun 24, 2025

This PR is still WIP as the 6-hour limit should be handled. According to the android dev docs :

A foreground service of this type must be stopped within the timeout by Service.stopSelf(), Context.stopService(android.content.Intent) or their overloads). Service.stopForeground(int) will also work, which will demote the service to a "background" service, which will soon be stopped by the system.

If the service isn't stopped within the timeout, Service.onTimeout(int, int) will be called.

This is specially important as I've discovered that the reason the app was crashing for me at #17980 was due to a corrupted video which got stuck trying to be uploaded without any warning - maybe this should be handled on another issue.

@yagueto yagueto changed the title [WIP] Improve foreground service type handling fix(mobile): [WIP] Improve foreground service type handling Jun 24, 2025
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.

Android background service ANRs repeteadly
1 participant