[PR #603] [MERGED] feat(mobile): improve Android background service reliability #8692

Closed
opened 2026-02-05 13:51:35 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/603
Author: @fyfrey
Created: 9/7/2022
Status: Merged
Merged: 9/8/2022
Merged by: @alextran1502

Base: mainHead: feature/improveBackgroundJobs


📝 Commits (1)

  • 8f3b1f9 improve Android background service reliability

📊 Changes

9 files changed (+329 additions, -181 deletions)

View changed files

📝 mobile/android/app/src/main/AndroidManifest.xml (+1 -0)
mobile/android/app/src/main/kotlin/com/example/mobile/AppClearedService.kt (+25 -0)
📝 mobile/android/app/src/main/kotlin/com/example/mobile/BackgroundServicePlugin.kt (+14 -19)
📝 mobile/android/app/src/main/kotlin/com/example/mobile/BackupWorker.kt (+92 -109)
mobile/android/app/src/main/kotlin/com/example/mobile/ContentObserverWorker.kt (+137 -0)
📝 mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt (+7 -0)
📝 mobile/lib/modules/backup/background_service/background.service.dart (+47 -49)
📝 mobile/lib/modules/backup/providers/backup.provider.dart (+5 -3)
📝 mobile/lib/modules/home/ui/immich_sliver_appbar.dart (+1 -1)

📄 Description

This change greatly reduces the chance that a backup is not performed when a new photo/video is made.

Instead of combining the change trigger and additonal constraints (wifi or charging) into a single worker, these aspects are now separated. Thus, it is now reliably possible to take pictures while the wifi constraint is not satisfied and upload them hours/days later once connected to wifi without taking a new photo. As a positive side effect, this simplifies the error/retry handling
by directly leveraging Android's WorkManager without workarounds.
The separation also allows to notify the currently running BackupWorker that new assets were added while backing up other assets to also upload those newly added assets.
Further, a new tiny service checks if the app is killed, to reschedule the content change worker and allow to detect the first new photo.
Users that have/can not disable battery optimizations, now also receive silent progress notifications.
Bonus: The home screen now shows backup as enabled if background backup is active.

  • use separate worker/task for listening on changed/added assets
  • use separate worker/task for performing the backup
  • content observer worker enqueues backup worker on each new asset
  • wifi/charging constraints only apply to backup worker
  • backupworker is notified of assets added while running to re-run
  • new service to catch app being killed to workaround WorkManager issue

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/603 **Author:** [@fyfrey](https://github.com/fyfrey) **Created:** 9/7/2022 **Status:** ✅ Merged **Merged:** 9/8/2022 **Merged by:** [@alextran1502](https://github.com/alextran1502) **Base:** `main` ← **Head:** `feature/improveBackgroundJobs` --- ### 📝 Commits (1) - [`8f3b1f9`](https://github.com/immich-app/immich/commit/8f3b1f948bc35adca9dcdf09d00f8a4ce1f51c86) improve Android background service reliability ### 📊 Changes **9 files changed** (+329 additions, -181 deletions) <details> <summary>View changed files</summary> 📝 `mobile/android/app/src/main/AndroidManifest.xml` (+1 -0) ➕ `mobile/android/app/src/main/kotlin/com/example/mobile/AppClearedService.kt` (+25 -0) 📝 `mobile/android/app/src/main/kotlin/com/example/mobile/BackgroundServicePlugin.kt` (+14 -19) 📝 `mobile/android/app/src/main/kotlin/com/example/mobile/BackupWorker.kt` (+92 -109) ➕ `mobile/android/app/src/main/kotlin/com/example/mobile/ContentObserverWorker.kt` (+137 -0) 📝 `mobile/android/app/src/main/kotlin/com/example/mobile/MainActivity.kt` (+7 -0) 📝 `mobile/lib/modules/backup/background_service/background.service.dart` (+47 -49) 📝 `mobile/lib/modules/backup/providers/backup.provider.dart` (+5 -3) 📝 `mobile/lib/modules/home/ui/immich_sliver_appbar.dart` (+1 -1) </details> ### 📄 Description This change greatly reduces the chance that a backup is not performed when a new photo/video is made. Instead of combining the change trigger and additonal constraints (wifi or charging) into a single worker, these aspects are now separated. Thus, it is now reliably possible to take pictures while the wifi constraint is not satisfied and upload them hours/days later once connected to wifi without taking a new photo. As a positive side effect, this simplifies the error/retry handling by directly leveraging Android's WorkManager without workarounds. The separation also allows to notify the currently running BackupWorker that new assets were added while backing up other assets to also upload those newly added assets. Further, a new tiny service checks if the app is killed, to reschedule the content change worker and allow to detect the first new photo. Users that have/can not disable battery optimizations, now also receive silent progress notifications. Bonus: The home screen now shows backup as enabled if background backup is active. * use separate worker/task for listening on changed/added assets * use separate worker/task for performing the backup * content observer worker enqueues backup worker on each new asset * wifi/charging constraints only apply to backup worker * backupworker is notified of assets added while running to re-run * new service to catch app being killed to workaround WorkManager issue --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 13:51:35 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#8692