Skip to content

Commit 5c1103f

Browse files
committed
fix: remove stale foreground cancellation in upload worker
1 parent e63d0b5 commit 5c1103f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

opencloudApp/src/main/java/eu/opencloud/android/workers/UploadFileFromFileSystemWorker.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ class UploadFileFromFileSystemWorker(
327327
}
328328

329329
private fun updateProgressFromTus(offset: Long, totalSize: Long) {
330+
if (this.isStopped) {
331+
Timber.w("Cancelling TUS upload. The worker is stopped by user or system")
332+
tusUploadHelper.cancel()
333+
}
334+
330335
if (totalSize <= 0) return
331336
val percent: Int = (100.0 * offset.toDouble() / totalSize.toDouble()).toInt()
332337
if (percent == lastPercent) return
@@ -446,6 +451,14 @@ class UploadFileFromFileSystemWorker(
446451
totalToTransfer: Long,
447452
filePath: String
448453
) {
454+
if (this.isStopped) {
455+
Timber.w("Cancelling upload operation. The worker is stopped by user or system")
456+
if (::uploadFileOperation.isInitialized) {
457+
uploadFileOperation.cancel()
458+
uploadFileOperation.removeDataTransferProgressListener(this)
459+
}
460+
}
461+
449462
val percent: Int = (100.0 * totalTransferredSoFar.toDouble() / totalToTransfer.toDouble()).toInt()
450463
if (percent == lastPercent) return
451464

0 commit comments

Comments
 (0)