Skip to content
Snippets Groups Projects
Commit 0db708e2 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Nicolas Pomepuy
Browse files

Remove thread from app initialization

This was a workaround for a bug in kotlinx.coroutines causing I/O ops in
Dispatchers setup.
We can now call `AppScope.launch` directly.

`AppContextProvider.setLocale` takes less than 1ms (on emulator) so it
has been moved in main thread.

(cherry picked from commit 583944ff)
parent 5ab166e5
No related branches found
No related tags found
1 merge request!782Backport to 3.3.x
......@@ -24,7 +24,6 @@ import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import kotlinx.coroutines.DEBUG_PROPERTY_NAME
import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
import kotlinx.coroutines.Dispatchers
......@@ -45,7 +44,6 @@ import org.videolan.tools.AppScope
import org.videolan.tools.Settings
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.gui.SendCrashActivity
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.NotificationHelper
import org.videolan.vlc.util.DialogDelegate
import org.videolan.vlc.util.SettingsMigration
......@@ -68,7 +66,6 @@ class AppSetupDelegate : AppDelegate,
NotificationHelper.createNotificationChannels(this)
// Service loaders
Log.i("AppSetupDelegate", "Registering factories")
FactoryManager.registerFactory(IMediaFactory.factoryId, MediaFactory())
FactoryManager.registerFactory(ILibVLCFactory.factoryId, LibVLCFactory())
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
......@@ -83,24 +80,21 @@ class AppSetupDelegate : AppDelegate,
setupIndexers()
}
}
AppContextProvider.setLocale(Settings.getInstance(this).getString("set_locale", ""))
//Initiate Kotlinx Dispatchers in a thread to prevent ANR
backgroundInit()
}
// init operations executed in background threads
private fun Context.backgroundInit() {
Thread(Runnable {
AppContextProvider.setLocale(Settings.getInstance(this).getString("set_locale", ""))
AppScope.launch(Dispatchers.IO) {
private fun Context.backgroundInit() = AppScope.launch {
launch(Dispatchers.IO) {
if (!VLCInstance.testCompatibleCPU(AppContextProvider.appContext)) return@launch
Dialog.setCallbacks(VLCInstance.getInstance(this@backgroundInit), DialogDelegate)
}
packageManager.setComponentEnabledSetting(ComponentName(this@backgroundInit, SendCrashActivity::class.java),
if (BuildConfig.BETA) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
SettingsMigration.migrateSettings(this@backgroundInit)
if (!VLCInstance.testCompatibleCPU(AppContextProvider.appContext)) return@launch
Dialog.setCallbacks(VLCInstance.getInstance(this@backgroundInit), DialogDelegate)
}
packageManager.setComponentEnabledSetting(ComponentName(this, SendCrashActivity::class.java),
if (BuildConfig.BETA) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
SettingsMigration.migrateSettings(this)
}).start()
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment