From 3402242992143b551d3a52a30cc75d9e2593aff6 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 9 Dec 2024 18:18:09 +0530 Subject: [PATCH] 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. --- .../downloadManager/DownloadMonitorService.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadMonitorService.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadMonitorService.kt index 44fc93ea8c..403db07dfb 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadMonitorService.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadMonitorService.kt @@ -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,8 +573,11 @@ class DownloadMonitorService : Service() { private fun cancelDownload(downloadId: Long) { synchronized(lock) { - downloadManager.remove(downloadId) - handleCancelledDownload(downloadId) + updater.onNext { + // Remove the download from DownloadManager on IO thread. + downloadManager.remove(downloadId) + handleCancelledDownload(downloadId) + } } }