Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANR During Uploads #13578

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutionException
import java.util.concurrent.Semaphore
import javax.inject.Inject

Expand All @@ -57,6 +59,8 @@ class FileUploadHelper {
@Inject
lateinit var fileStorageManager: FileDataStorageManager

private val ioScope = CoroutineScope(Dispatchers.IO)

init {
MainApp.getAppComponent().inject(this)
}
Expand Down Expand Up @@ -231,11 +235,13 @@ class FileUploadHelper {
}

fun cancelFileUpload(remotePath: String, accountName: String) {
val upload = uploadsStorageManager.getUploadByRemotePath(remotePath)
if (upload != null) {
cancelFileUploads(listOf(upload), accountName)
} else {
Log_OC.e(TAG, "Error cancelling current upload because upload does not exist!")
ioScope.launch {
val upload = uploadsStorageManager.getUploadByRemotePath(remotePath)
if (upload != null) {
cancelFileUploads(listOf(upload), accountName)
} else {
Log_OC.e(TAG, "Error cancelling current upload because upload does not exist!")
}
}
}

Expand Down Expand Up @@ -266,8 +272,21 @@ class FileUploadHelper {
return false
}

val upload: OCUpload = uploadsStorageManager.getUploadByRemotePath(file.remotePath) ?: return false
return upload.uploadStatus == UploadStatus.UPLOAD_IN_PROGRESS
val uploadCompletableFuture = CompletableFuture.supplyAsync {
uploadsStorageManager.getUploadByRemotePath(file.remotePath)
}
return try {
val upload = uploadCompletableFuture.get()
if (upload != null) {
upload.uploadStatus == UploadStatus.UPLOAD_IN_PROGRESS
} else {
false
}
} catch (e: ExecutionException) {
false
} catch (e: InterruptedException) {
false
}
}

private fun checkConnectivity(connectivityService: ConnectivityService): Boolean {
Expand Down
Loading