@@ -43,7 +43,6 @@ import com.owncloud.android.lib.common.utils.Log_OC
4343import com.owncloud.android.operations.UploadFileOperation
4444import com.owncloud.android.ui.notifications.NotificationUtils
4545import com.owncloud.android.utils.theme.ViewThemeUtils
46- import kotlinx.coroutines.CoroutineScope
4746import kotlinx.coroutines.Dispatchers
4847import kotlinx.coroutines.cancel
4948import kotlinx.coroutines.coroutineScope
@@ -84,8 +83,7 @@ class FileUploadWorker(
8483 const val TOTAL_UPLOAD_SIZE = " total_upload_size"
8584 const val SHOW_SAME_FILE_ALREADY_EXISTS_NOTIFICATION = " show_same_file_already_exists_notification"
8685
87- private val activeUploadFileOperations = ConcurrentHashMap <String , UploadFileOperation >()
88-
86+ val activeUploadFileOperations = ConcurrentHashMap <String , UploadFileOperation >()
8987 private const val UPLOADS_ADDED_MESSAGE = " UPLOADS_ADDED"
9088 private const val UPLOAD_START_MESSAGE = " UPLOAD_START"
9189 private const val UPLOAD_FINISH_MESSAGE = " UPLOAD_FINISH"
@@ -123,7 +121,7 @@ class FileUploadWorker(
123121 fun isUploading (remotePath : String? , accountName : String? ): Boolean {
124122 return activeUploadFileOperations.values.any {
125123 it.remotePath == remotePath && it.user.accountName == accountName
126- }
124+ }
127125 }
128126
129127 fun getUploadAction (action : String ): Int = when (action) {
@@ -263,10 +261,16 @@ class FileUploadWorker(
263261 val ocAccount = OwnCloudAccount (user.toPlatformAccount(), context)
264262 val client = OwnCloudClientManagerFactory .getDefaultSingleton().getClientFor(ocAccount, context)
265263
266- return @withContext parallelUpload(uploads, user, previouslyUploadedFileSize, totalUploadSize, client, accountName)
264+ return @withContext parallelUpload(
265+ uploads,
266+ user,
267+ previouslyUploadedFileSize,
268+ totalUploadSize,
269+ client,
270+ accountName
271+ )
267272 }
268273
269-
270274 private suspend fun parallelUpload (
271275 uploads : List <OCUpload >? ,
272276 user : User ,
@@ -279,9 +283,10 @@ class FileUploadWorker(
279283 return Result .success()
280284 }
281285
282- val semaphore = Semaphore (5 ) // Limit to 5 parallel uploads
286+ val semaphore = Semaphore (10 ) // Limit to 10 parallel uploads
283287 val quotaExceeded = AtomicBoolean (false )
284288 val completedCount = AtomicInteger (0 )
289+ val storageManager = FileDataStorageManager (user, context.contentResolver)
285290
286291 coroutineScope {
287292 for (upload in uploads) {
@@ -304,7 +309,7 @@ class FileUploadWorker(
304309 }
305310
306311 setWorkerState(user)
307- val operation = createUploadFileOperation(upload, user)
312+ val operation = createUploadFileOperation(upload, user, storageManager )
308313 activeUploadFileOperations[operation.originalStoragePath] = operation
309314
310315 try {
@@ -320,10 +325,10 @@ class FileUploadWorker(
320325 )
321326 }
322327
323- val result = upload(operation, user, client)
328+ val result = upload(operation, user, client)
324329
325- val entity = uploadsStorageManager.uploadDao.getUploadById(upload.uploadId, accountName)
326- uploadsStorageManager.updateStatus(entity, result.isSuccess)
330+ val entity = uploadsStorageManager.uploadDao.getUploadById(upload.uploadId, accountName)
331+ uploadsStorageManager.updateStatus(entity, result.isSuccess)
327332
328333 if (result.code == ResultCode .QUOTA_EXCEEDED ) {
329334 Log_OC .w(TAG , " Quota exceeded, stopping uploads" )
@@ -333,14 +338,13 @@ class FileUploadWorker(
333338 return @launch
334339 }
335340
336- sendUploadFinishEvent(totalUploadSize, currentUploadIndex, operation, result)
337-
341+ sendUploadFinishEvent(totalUploadSize, currentUploadIndex, operation, result)
338342 } finally {
339343 activeUploadFileOperations.remove(operation.originalStoragePath)
340344 lastPercents.remove(operation.originalStoragePath)
341345 lastUpdateTimes.remove(operation.originalStoragePath)
342346 }
343- }
347+ }
344348 }
345349 }
346350 }
@@ -383,7 +387,11 @@ class FileUploadWorker(
383387 return result
384388 }
385389
386- private fun createUploadFileOperation (upload : OCUpload , user : User ): UploadFileOperation = UploadFileOperation (
390+ private fun createUploadFileOperation (
391+ upload : OCUpload ,
392+ user : User ,
393+ storageManager : FileDataStorageManager
394+ ): UploadFileOperation = UploadFileOperation (
387395 uploadsStorageManager,
388396 connectivityService,
389397 powerManagementService,
@@ -396,7 +404,7 @@ class FileUploadWorker(
396404 upload.isUseWifiOnly,
397405 upload.isWhileChargingOnly,
398406 true ,
399- FileDataStorageManager (user, context.contentResolver)
407+ storageManager
400408 ).apply {
401409 addDataTransferProgressListener(this @FileUploadWorker)
402410 }
0 commit comments