DownloadWorkerUtil: Cancel download regardless of status when requested

This is useful when an active download is stuck which could happen if the app
was force stopped by user or killed by Android.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-02-19 18:11:28 +05:30
parent b3cada603c
commit 45b1fdf44b

View File

@@ -84,8 +84,8 @@ class DownloadWorkerUtil @Inject constructor(
Log.i(TAG, "Cancelling download for $packageName")
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
downloadsList.filter { it.isNotEmpty() }.firstOrNull()
?.find { it.packageName == packageName && it.downloadStatus == DownloadStatus.QUEUED }
?.let { downloadDao.update(it.copy(downloadStatus = DownloadStatus.CANCELLED)) }
?.find { it.packageName == packageName }
?.let { downloadDao.updateStatus(packageName, DownloadStatus.CANCELLED) }
}
suspend fun clearDownload(packageName: String, versionCode: Int) {