Skip to content

Commit 87dedce

Browse files
committed
feat: added some logs when AutomaticUploadsWorker is cancelled
1 parent 727a5d4 commit 87dedce

1 file changed

Lines changed: 40 additions & 29 deletions

File tree

owncloudApp/src/main/java/com/owncloud/android/workers/AutomaticUploadsWorker.kt

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package com.owncloud.android.workers
2323

2424
import android.content.Context
2525
import android.net.Uri
26+
import android.os.Build
2627
import androidx.core.net.toUri
2728
import androidx.documentfile.provider.DocumentFile
2829
import androidx.work.CoroutineWorker
@@ -50,6 +51,7 @@ import org.koin.core.component.inject
5051
import timber.log.Timber
5152
import java.io.File
5253
import java.util.Date
54+
import java.util.concurrent.CancellationException
5355
import java.util.concurrent.TimeUnit
5456

5557
class AutomaticUploadsWorker(
@@ -75,41 +77,50 @@ class AutomaticUploadsWorker(
7577
private val transferRepository: TransferRepository by inject()
7678

7779
override suspend fun doWork(): Result {
78-
Timber.i("Starting AutomaticUploadsWorker with UUID ${this.id}")
79-
when (val useCaseResult = getAutomaticUploadsConfigurationUseCase(Unit)) {
80-
is UseCaseResult.Success -> {
81-
val cameraUploadsConfiguration = useCaseResult.data
82-
if (cameraUploadsConfiguration == null || cameraUploadsConfiguration.areAutomaticUploadsDisabled()) {
83-
cancelWorker()
84-
return Result.success()
85-
}
86-
cameraUploadsConfiguration.pictureUploadsConfiguration?.let { pictureUploadsConfiguration ->
87-
try {
88-
checkSourcePathIsAValidUriOrThrowException(pictureUploadsConfiguration.sourcePath)
89-
syncFolder(pictureUploadsConfiguration)
90-
} catch (illegalArgumentException: IllegalArgumentException) {
91-
Timber.e(illegalArgumentException, "Source path for picture uploads is not valid")
92-
showNotificationToUpdateUri(SyncType.PICTURE_UPLOADS)
93-
return Result.failure()
80+
try {
81+
Timber.i("Starting AutomaticUploadsWorker with UUID ${this.id}")
82+
when (val useCaseResult = getAutomaticUploadsConfigurationUseCase(Unit)) {
83+
is UseCaseResult.Success -> {
84+
val cameraUploadsConfiguration = useCaseResult.data
85+
if (cameraUploadsConfiguration == null || cameraUploadsConfiguration.areAutomaticUploadsDisabled()) {
86+
cancelWorker()
87+
return Result.success()
9488
}
95-
}
96-
cameraUploadsConfiguration.videoUploadsConfiguration?.let { videoUploadsConfiguration ->
97-
try {
98-
checkSourcePathIsAValidUriOrThrowException(videoUploadsConfiguration.sourcePath)
99-
syncFolder(videoUploadsConfiguration)
100-
} catch (illegalArgumentException: IllegalArgumentException) {
101-
Timber.e(illegalArgumentException, "Source path for video uploads is not valid")
102-
showNotificationToUpdateUri(SyncType.VIDEO_UPLOADS)
103-
return Result.failure()
89+
cameraUploadsConfiguration.pictureUploadsConfiguration?.let { pictureUploadsConfiguration ->
90+
try {
91+
checkSourcePathIsAValidUriOrThrowException(pictureUploadsConfiguration.sourcePath)
92+
syncFolder(pictureUploadsConfiguration)
93+
} catch (illegalArgumentException: IllegalArgumentException) {
94+
Timber.e(illegalArgumentException, "Source path for picture uploads is not valid")
95+
showNotificationToUpdateUri(SyncType.PICTURE_UPLOADS)
96+
return Result.failure()
97+
}
10498
}
99+
cameraUploadsConfiguration.videoUploadsConfiguration?.let { videoUploadsConfiguration ->
100+
try {
101+
checkSourcePathIsAValidUriOrThrowException(videoUploadsConfiguration.sourcePath)
102+
syncFolder(videoUploadsConfiguration)
103+
} catch (illegalArgumentException: IllegalArgumentException) {
104+
Timber.e(illegalArgumentException, "Source path for video uploads is not valid")
105+
showNotificationToUpdateUri(SyncType.VIDEO_UPLOADS)
106+
return Result.failure()
107+
}
108+
}
109+
}
110+
is UseCaseResult.Error -> {
111+
Timber.e(useCaseResult.throwable, "Worker ${useCaseResult.throwable}")
105112
}
106113
}
107-
is UseCaseResult.Error -> {
108-
Timber.e(useCaseResult.throwable, "Worker ${useCaseResult.throwable}")
114+
Timber.i("Finishing CameraUploadsWorker with UUID ${this.id}")
115+
return Result.success()
116+
} catch (e: CancellationException) {
117+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
118+
Timber.i("AutomaticUploadsWorker with UUID ${this.id} was cancelled. Error: $stopReason")
119+
} else {
120+
Timber.i("AutomaticUploadsWorker with UUID ${this.id} was cancelled.")
109121
}
122+
return Result.failure()
110123
}
111-
Timber.i("Finishing CameraUploadsWorker with UUID ${this.id}")
112-
return Result.success()
113124
}
114125

115126
@Throws(IllegalArgumentException::class)

0 commit comments

Comments
 (0)