Fixed: Input dispatching timed out at DownloadMonitorService.cancelDownload.

* Moved the cancel download logic to the IO thread, ensuring that download-related tasks are performed on the IO thread while keeping the main thread free.
* Also moved the functionality to the IO thread for checking the status when we receive the ACTION_DOWNLOAD_COMPLETE broadcast from DownloadManager, to determine if the download was successful or canceled. This ensures it doesn't block the main thread, as cancelDownload is currently causing a blockage.
This commit is contained in:
MohitMaliFtechiz 2024-12-09 18:18:09 +05:30 committed by Kelson
parent 4d3c878aee
commit 7edb65656f

View File

@ -100,7 +100,11 @@ class DownloadMonitorService : Service() {
ACTION_PAUSE -> pauseDownload(downloadId.toLong())
ACTION_RESUME -> resumeDownload(downloadId.toLong())
ACTION_CANCEL -> cancelDownload(downloadId.toLong())
ACTION_QUERY_DOWNLOAD_STATUS -> queryDownloadStatus(downloadId.toLong())
ACTION_QUERY_DOWNLOAD_STATUS -> {
updater.onNext {
queryDownloadStatus(downloadId.toLong())
}
}
}
}
return START_NOT_STICKY
@ -569,10 +573,13 @@ class DownloadMonitorService : Service() {
private fun cancelDownload(downloadId: Long) {
synchronized(lock) {
updater.onNext {
// Remove the download from DownloadManager on IO thread.
downloadManager.remove(downloadId)
handleCancelledDownload(downloadId)
}
}
}
@SuppressLint("Range")
private fun pauseResumeDownloadInDownloadManagerContentResolver(