Skip to content

fix(auto-upload): calls#16393

Merged
alperozturk96 merged 7 commits into
masterfrom
fix/auto-upload-background-call
Feb 6, 2026
Merged

fix(auto-upload): calls#16393
alperozturk96 merged 7 commits into
masterfrom
fix/auto-upload-background-call

Conversation

@alperozturk96

@alperozturk96 alperozturk96 commented Jan 28, 2026

Copy link
Copy Markdown
Collaborator
  • Tests written, or not not needed

Issue

On Android, long-running foreground jobs cannot be started while the app is in the background. Attempting to do so results in the following exception:

E  ❌ Exception in ContentObserverWork: startForegroundService() not allowed due to mAllowStartForeground false: service com.nextcloud.client/androidx.work.impl.foreground.SystemForegroundService
android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.nextcloud.client/androidx.work.impl.foreground.SystemForegroundService
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)

ContentObserverWork triggers AutoUploadWorker to upload files. When this happens while the app is in the background, the foreground service cannot be started, causing the auto-upload process to fail.

Additionally, when the app is removed from recent apps, ContentObserverWork may not be triggered at all. In that case, changed content URIs are never passed to AutoUploadWorker, which can cause auto-upload to not work.

Changes

Remove duplicated and repeated worker-trigger logic, keeping only the required and correct trigger points.

Make AutoUploadWorker a long-running foreground worker, as required for upload operations.

Trigger AutoUploadWorker again when the app returns to the foreground. This ensures pending uploads resume in cases where the user previously killed the app and the scheduled execution of ContentObserverWork did not occur.

}

fun insertEntries(folder: SyncedFolder, repository: FileSystemRepository) {
val enabledTimestampMs = folder.enabledTimestampMs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun SyncedFolder.shouldSkipFile already checking and isExisting is not representing existence of the sync folder it means "Also upload existing files". Function name will be change in different PR.

.addContentUriTrigger(MediaStore.Video.Media.INTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true)
.setTriggerContentMaxDelay(MAX_CONTENT_TRIGGER_DELAY_MS, TimeUnit.MILLISECONDS)
.setTriggerContentUpdateDelay(Duration.ofSeconds(5))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating 5, 10 as a const value to fix MagicNumber is not good for this use case. Duration.ofSeconds(5) clearly indicates what it is.

}
}

private suspend fun updateForegroundInfo(notification: Notification) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentObserverWork should be background job.

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@alperozturk96 alperozturk96 force-pushed the fix/auto-upload-background-call branch from 8179bba to 7d13475 Compare January 29, 2026 08:02
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown

Codacy

SpotBugs

CategoryBaseNew
Bad practice4343
Correctness7474
Dodgy code259259
Experimental11
Internationalization77
Malicious code vulnerability33
Multithreaded correctness3434
Performance4343
Security1818
Total482482

@github-actions

Copy link
Copy Markdown

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/16393.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@github-actions

Copy link
Copy Markdown

blue-Light-Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

Comment thread app/src/main/java/com/owncloud/android/MainApp.java
@alperozturk96 alperozturk96 merged commit 6ab7325 into master Feb 6, 2026
18 of 22 checks passed
@alperozturk96 alperozturk96 deleted the fix/auto-upload-background-call branch February 6, 2026 09:51
@alperozturk96

Copy link
Copy Markdown
Collaborator Author

/backport to stable-3.36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants