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())
|
if (isStopped) return onFailure(Exceptions.DownloadFailedException())
|
||||||
|
|
||||||
// Verify downloaded files
|
// Verify downloaded files
|
||||||
val verifySuccess = verifyFiles(download.packageName, files)
|
try {
|
||||||
|
notifyStatus(DownloadStatus.VERIFYING)
|
||||||
// Report failure if verification failed
|
files.forEach { file -> require(verifyFile(file)) }
|
||||||
if (!verifySuccess || isStopped) return onFailure(Exceptions.VerificationFailedException())
|
} catch (exception: Exception) {
|
||||||
|
Log.e(TAG, "Failed to verify ${download.packageName}", exception)
|
||||||
|
onFailure(Exceptions.VerificationFailedException())
|
||||||
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Finished downloading & verifying ${download.packageName}")
|
Log.i(TAG, "Finished downloading & verifying ${download.packageName}")
|
||||||
notifyStatus(DownloadStatus.COMPLETED)
|
notifyStatus(DownloadStatus.COMPLETED)
|
||||||
@@ -194,24 +197,6 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
return onSuccess()
|
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) {
|
private suspend fun onSuccess(): Result = withContext(NonCancellable) {
|
||||||
return@withContext try {
|
return@withContext try {
|
||||||
appInstaller.getPreferredInstaller().install(download)
|
appInstaller.getPreferredInstaller().install(download)
|
||||||
|
|||||||
Reference in New Issue
Block a user