From 7748859290e1c1e64caa6a15906463ae0ba001fd Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 16 Sep 2024 16:57:21 +0200 Subject: [PATCH] fix: Fix ANR spotted by sentry Make sure coroutine is executed on IO thread. https://murena-sas.sentry.io/issues/5845828831/?project=4504355890724864&query=mechanism%3A%5BANR%2CAppExitInfo%5D&referrer=issue-stream&sort=freq&statsPeriod=14d&stream_index=0 --- app/src/main/java/foundation/e/apps/ui/MainActivity.kt | 3 ++- .../main/java/foundation/e/apps/ui/MainActivityViewModel.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt index 65843485c..e3dba9a5b 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt @@ -61,6 +61,7 @@ import foundation.e.apps.ui.setup.signin.SignInViewModel import foundation.e.apps.utils.SystemInfoProvider import foundation.e.apps.utils.eventBus.AppEvent import foundation.e.apps.utils.eventBus.EventBus +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter @@ -547,7 +548,7 @@ class MainActivity : AppCompatActivity() { viewModel: MainActivityViewModel, packageName: String ) { - lifecycleScope.launch { + lifecycleScope.launch(Dispatchers.IO) { val fusedDownload = viewModel.updateAwaitingForPurchasedApp(packageName) if (fusedDownload != null) { ApplicationDialogFragment( diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt index cd54ddf68..030755e7d 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt @@ -50,6 +50,7 @@ import foundation.e.apps.install.pkg.AppLoungePackageManager import foundation.e.apps.install.pkg.PWAManager import foundation.e.apps.install.workmanager.AppInstallProcessor import foundation.e.apps.utils.NetworkStatusManager +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import javax.inject.Inject @@ -190,7 +191,7 @@ class MainActivityViewModel @Inject constructor( } fun getApplication(app: Application) { - viewModelScope.launch { + viewModelScope.launch(Dispatchers.IO) { appInstallProcessor.initAppInstall(app) } } -- GitLab