mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Delay heavy tasks to prevent ServiceDidNotStartInTimeException (for example)
This commit is contained in:
parent
5b5d6c4abb
commit
8a7709cd47
2 changed files with 20 additions and 4 deletions
|
|
@ -107,9 +107,9 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
}
|
||||
Log.i("$TAG Load finished, found ${cursor.count} entries in cursor")
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
coreContext.postOnCoreThreadWhenAvailableForHeavyTask({
|
||||
parseFriends(cursor)
|
||||
}
|
||||
}, "parse friends")
|
||||
}
|
||||
|
||||
@MainThread
|
||||
|
|
@ -265,9 +265,9 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
|
||||
Log.i("$TAG Contacts parsed, posting another task to handle adding them (or not)")
|
||||
// Re-post another task to allow other tasks on Core thread
|
||||
coreContext.postOnCoreThread {
|
||||
coreContext.postOnCoreThreadWhenAvailableForHeavyTask({
|
||||
addFriendsIfNeeded()
|
||||
}
|
||||
}, "add friends to Core")
|
||||
} catch (sde: StaleDataException) {
|
||||
Log.e("$TAG State Data Exception: $sde")
|
||||
} catch (ise: IllegalStateException) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import kotlin.system.exitProcess
|
||||
import org.linphone.BuildConfig
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.contacts.ContactsManager
|
||||
import org.linphone.core.tools.Log
|
||||
|
|
@ -653,6 +654,21 @@ class CoreContext
|
|||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun postOnCoreThreadWhenAvailableForHeavyTask(@WorkerThread lambda: (core: Core) -> Unit, name: String) {
|
||||
postOnCoreThread {
|
||||
if (core.callsNb >= 1) {
|
||||
Log.i("$TAG At least one call is active, wait until there is no more call before executing lambda [$name] (checking again in 1 sec)")
|
||||
coreContext.postOnCoreThreadDelayed({
|
||||
postOnCoreThreadWhenAvailableForHeavyTask(lambda, name)
|
||||
}, 1000)
|
||||
} else {
|
||||
Log.i("$TAG No active call at the moment, executing lambda [$name] right now")
|
||||
lambda.invoke(core)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun postOnMainThread(
|
||||
@UiThread lambda: () -> Unit
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue