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 <aayushgupta219@gmail.com>
This commit is contained in:
@@ -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<GPlayFile>
|
||||
): 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)
|
||||
|
||||
Reference in New Issue
Block a user