DownloadWorker: Always run onSuccess block as NonCancellable

* Change context in SessionInstaller when starting activity instead

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-02-21 20:31:17 +05:30
parent 1108edc303
commit e0d1185f16
2 changed files with 4 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ import android.content.Intent
import android.content.pm.PackageInstaller
import android.util.Log
import androidx.core.content.IntentCompat
import com.aurora.extensions.runOnUiThread
import com.aurora.gplayapi.data.models.App
import com.aurora.store.R
import com.aurora.store.data.event.InstallerEvent
@@ -80,7 +81,7 @@ class InstallerStatusReceiver : BroadcastReceiver() {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
context.startActivity(it)
runOnUiThread { context.startActivity(it) }
} catch (exception: Exception) {
Log.e(TAG, "Failed to trigger installation!", exception)
}

View File

@@ -20,7 +20,6 @@ import com.aurora.extensions.isSAndAbove
import com.aurora.extensions.requiresObbDir
import com.aurora.gplayapi.helpers.PurchaseHelper
import com.aurora.store.data.installer.AppInstaller
import com.aurora.store.data.installer.SessionInstaller
import com.aurora.store.data.model.DownloadInfo
import com.aurora.store.data.model.DownloadStatus
import com.aurora.store.data.model.Request
@@ -166,11 +165,9 @@ class DownloadWorker @AssistedInject constructor(
}
private suspend fun onSuccess() {
val installer = appInstaller.getPreferredInstaller()
val dispatcher = if (installer is SessionInstaller) Dispatchers.Main else NonCancellable
withContext(dispatcher) {
withContext(NonCancellable) {
try {
installer.install(download)
appInstaller.getPreferredInstaller().install(download)
} catch (exception: Exception) {
Log.e(TAG, "Failed to install ${download.packageName}", exception)
}