Stop contacts loading process if core is being shutdown or is already destroyed
This commit is contained in:
parent
b8685c2dda
commit
4d7ce73422
1 changed files with 35 additions and 25 deletions
|
@ -40,6 +40,7 @@ import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.core.Factory
|
import org.linphone.core.Factory
|
||||||
import org.linphone.core.Friend
|
import org.linphone.core.Friend
|
||||||
|
import org.linphone.core.GlobalState
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
|
@ -88,6 +89,11 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
val core = coreContext.core
|
val core = coreContext.core
|
||||||
val linphoneMime = loader.context.getString(R.string.linphone_address_mime_type)
|
val linphoneMime = loader.context.getString(R.string.linphone_address_mime_type)
|
||||||
|
|
||||||
|
if (core.globalState == GlobalState.Shutdown || core.globalState == GlobalState.Off) {
|
||||||
|
Log.w("[Contacts Loader] Core is being stopped or already destroyed, abort")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
coreContext.lifecycleScope.launch {
|
coreContext.lifecycleScope.launch {
|
||||||
val friends = HashMap<String, Friend>()
|
val friends = HashMap<String, Friend>()
|
||||||
|
|
||||||
|
@ -193,6 +199,9 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
if (core.globalState == GlobalState.Shutdown || core.globalState == GlobalState.Off) {
|
||||||
|
Log.w("[Contacts Loader] Core is being stopped or already destroyed, abort")
|
||||||
|
} else {
|
||||||
Log.i("[Contacts Loader] Friends created")
|
Log.i("[Contacts Loader] Friends created")
|
||||||
val contactId = coreContext.contactsManager.contactIdToWatchFor
|
val contactId = coreContext.contactsManager.contactIdToWatchFor
|
||||||
if (contactId.isNotEmpty()) {
|
if (contactId.isNotEmpty()) {
|
||||||
|
@ -221,6 +230,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
Log.i("[Contacts Loader] Friends added & subscription updated")
|
Log.i("[Contacts Loader] Friends added & subscription updated")
|
||||||
coreContext.contactsManager.fetchFinished()
|
coreContext.contactsManager.fetchFinished()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (sde: StaleDataException) {
|
} catch (sde: StaleDataException) {
|
||||||
Log.e("[Contacts Loader] State Data Exception: $sde")
|
Log.e("[Contacts Loader] State Data Exception: $sde")
|
||||||
} catch (ise: IllegalStateException) {
|
} catch (ise: IllegalStateException) {
|
||||||
|
|
Loading…
Reference in a new issue