From bbeb11b8472430f70f670c40a25bdf053fa7064b Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Mon, 17 Mar 2025 13:54:38 +0800 Subject: [PATCH] DownloadWorker: Move back verification to same IO dispatcher NonCancellable dispatcher breaks the parent and child job relation which while ensures the new job is not cancelled when parent fails, the parent job also no longer waits for the child to finish. Signed-off-by: Aayush Gupta --- .../aurora/store/data/work/DownloadWorker.kt | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt b/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt index a9b06a9f6..65dea2763 100644 --- a/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt @@ -183,10 +183,13 @@ class DownloadWorker @AssistedInject constructor( if (isStopped) return onFailure(Exceptions.DownloadFailedException()) // Verify downloaded files - val verifySuccess = verifyFiles(download.packageName, files) - - // Report failure if verification failed - if (!verifySuccess || isStopped) return onFailure(Exceptions.VerificationFailedException()) + try { + notifyStatus(DownloadStatus.VERIFYING) + files.forEach { file -> require(verifyFile(file)) } + } catch (exception: Exception) { + Log.e(TAG, "Failed to verify ${download.packageName}", exception) + onFailure(Exceptions.VerificationFailedException()) + } Log.i(TAG, "Finished downloading & verifying ${download.packageName}") notifyStatus(DownloadStatus.COMPLETED) @@ -194,24 +197,6 @@ class DownloadWorker @AssistedInject constructor( return onSuccess() } - private suspend fun verifyFiles( - packageName: String, - files: List - ): Boolean = withContext(NonCancellable) { - notifyStatus(DownloadStatus.VERIFYING) - - for (file in files) { - try { - verifyFile(file) - } catch (e: Exception) { - Log.e(TAG, "Failed to verify $packageName : ${file.name}", e) - return@withContext false - } - } - - true - } - private suspend fun onSuccess(): Result = withContext(NonCancellable) { return@withContext try { appInstaller.getPreferredInstaller().install(download)