Catch StaleDataException in ContactLoader
This commit is contained in:
parent
ae04a06e42
commit
4d6f614df8
1 changed files with 120 additions and 108 deletions
|
@ -21,6 +21,7 @@ package org.linphone.contact
|
|||
|
||||
import android.content.ContentUris
|
||||
import android.database.Cursor
|
||||
import android.database.StaleDataException
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
|
@ -31,6 +32,7 @@ import androidx.loader.content.CursorLoader
|
|||
import androidx.loader.content.Loader
|
||||
import java.lang.Exception
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
@ -79,6 +81,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
val friends = HashMap<String, Friend>()
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
while (!cursor.isClosed && cursor.moveToNext()) {
|
||||
try {
|
||||
val id: String =
|
||||
|
@ -87,10 +90,14 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Data.DISPLAY_NAME_PRIMARY))
|
||||
val mime: String? =
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Data.MIMETYPE))
|
||||
val data1: String? = cursor.getString(cursor.getColumnIndexOrThrow("data1"))
|
||||
val data2: String? = cursor.getString(cursor.getColumnIndexOrThrow("data2"))
|
||||
val data3: String? = cursor.getString(cursor.getColumnIndexOrThrow("data3"))
|
||||
val data4: String? = cursor.getString(cursor.getColumnIndexOrThrow("data4"))
|
||||
val data1: String? =
|
||||
cursor.getString(cursor.getColumnIndexOrThrow("data1"))
|
||||
val data2: String? =
|
||||
cursor.getString(cursor.getColumnIndexOrThrow("data2"))
|
||||
val data3: String? =
|
||||
cursor.getString(cursor.getColumnIndexOrThrow("data3"))
|
||||
val data4: String? =
|
||||
cursor.getString(cursor.getColumnIndexOrThrow("data4"))
|
||||
val starred =
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.STARRED)) == 1
|
||||
val lookupKey =
|
||||
|
@ -114,7 +121,8 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
|
||||
when (mime) {
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> {
|
||||
val typeLabel = ContactsContract.CommonDataKinds.Phone.getTypeLabel(
|
||||
val typeLabel =
|
||||
ContactsContract.CommonDataKinds.Phone.getTypeLabel(
|
||||
loader.context.resources,
|
||||
data2?.toInt() ?: 0,
|
||||
data3
|
||||
|
@ -201,6 +209,10 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
Log.i("[Contacts Loader] Friends added & subscription updated")
|
||||
coreContext.contactsManager.fetchFinished()
|
||||
}
|
||||
} catch (sde: StaleDataException) {
|
||||
Log.e("[Contacts Loader] State Data Exception: $sde")
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue