Few tweaks trying to prevent jni global ref table overflow

This commit is contained in:
Sylvain Berfini 2025-03-18 14:00:22 +01:00
parent 043ed77c3a
commit e4570f167d
7 changed files with 45 additions and 69 deletions

View file

@ -219,16 +219,11 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
} }
if (!number.isNullOrEmpty()) { if (!number.isNullOrEmpty()) {
if (friend.phoneNumbersWithLabel.find {
PhoneNumberUtils.arePhoneNumberWeakEqual(it.phoneNumber, number)
} == null
) {
val phoneNumber = Factory.instance() val phoneNumber = Factory.instance()
.createFriendPhoneNumber(number, label) .createFriendPhoneNumber(number, label)
friend.addPhoneNumberWithLabel(phoneNumber) friend.addPhoneNumberWithLabel(phoneNumber)
} }
} }
}
ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> { ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
val sipAddress: String? = cursor.getString(sipAddressColumn) val sipAddress: String? = cursor.getString(sipAddressColumn)
if (!sipAddress.isNullOrEmpty()) { if (!sipAddress.isNullOrEmpty()) {
@ -250,17 +245,14 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
} }
} }
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
val vCard = friend.vcard
if (vCard != null) {
val givenName: String? = cursor.getString(givenNameColumn) val givenName: String? = cursor.getString(givenNameColumn)
if (!givenName.isNullOrEmpty()) { if (!givenName.isNullOrEmpty()) {
vCard.givenName = givenName friend.firstName = givenName
} }
val familyName: String? = cursor.getString(familyNameColumn) val familyName: String? = cursor.getString(familyNameColumn)
if (!familyName.isNullOrEmpty()) { if (!familyName.isNullOrEmpty()) {
vCard.familyName = familyName friend.lastName = familyName
}
} }
} }
} }
@ -291,7 +283,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
if (core.globalState == GlobalState.Shutdown || core.globalState == GlobalState.Off) { if (core.globalState == GlobalState.Shutdown || core.globalState == GlobalState.Off) {
Log.w("$TAG Core is being stopped or already destroyed, abort") Log.w("$TAG Core is being stopped or already destroyed, abort")
} else if (friends.isEmpty) { } else if (friends.isEmpty()) {
Log.w("$TAG No friend created!") Log.w("$TAG No friend created!")
} else { } else {
Log.i("$TAG ${friends.size} friends fetched") Log.i("$TAG ${friends.size} friends fetched")
@ -322,7 +314,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
friends.remove(localFriend.refKey) friends.remove(localFriend.refKey)
localFriend.nativeUri = localFriend.nativeUri =
newlyFetchedFriend.nativeUri // Native URI isn't stored in linphone database, needs to be updated newlyFetchedFriend.nativeUri // Native URI isn't stored in linphone database, needs to be updated
if (newlyFetchedFriend.vcard?.asVcard4String() == localFriend.vcard?.asVcard4String()) continue if (newlyFetchedFriend.dumpVcard() == localFriend.dumpVcard()) continue
localFriend.edit() localFriend.edit()
// Update basic fields that may have changed // Update basic fields that may have changed

View file

@ -304,6 +304,10 @@ class CorePreferences
val hideAssistantThirdPartySipAccount: Boolean val hideAssistantThirdPartySipAccount: Boolean
get() = config.getBool("ui", "assistant_hide_third_party_account", false) get() = config.getBool("ui", "assistant_hide_third_party_account", false)
@get:WorkerThread
val magicSearchResultsLimit: Int
get() = config.getInt("ui", "max_number_of_magic_search_results", 1000)
@get:WorkerThread @get:WorkerThread
val singleSignOnClientId: String val singleSignOnClientId: String
get() = config.getString("app", "oidc_client_id", "linphone")!! get() = config.getString("app", "oidc_client_id", "linphone")!!

View file

@ -97,13 +97,8 @@ class ContactNewOrEditViewModel
if (exists) { if (exists) {
Log.i("$TAG Found friend [${friend.name}] using ref key [$refKey]") Log.i("$TAG Found friend [${friend.name}] using ref key [$refKey]")
val vCard = friend.vcard firstName.postValue(friend.firstName.orEmpty())
if (vCard != null) { lastName.postValue(friend.lastName.orEmpty())
firstName.postValue(vCard.givenName)
lastName.postValue(vCard.familyName)
} else {
// TODO: What to do if vCard is null?
}
id.postValue(friend.refKey ?: friend.vcard?.uid) id.postValue(friend.refKey ?: friend.vcard?.uid)
@ -169,11 +164,8 @@ class ContactNewOrEditViewModel
friend.edit() friend.edit()
friend.name = name friend.name = name
friend.firstName = fn
val vCard = friend.vcard friend.lastName = ln
if (vCard != null) {
vCard.givenName = fn
vCard.familyName = ln
val picture = picturePath.value.orEmpty() val picture = picturePath.value.orEmpty()
if (picture.isNotEmpty()) { if (picture.isNotEmpty()) {
@ -196,7 +188,6 @@ class ContactNewOrEditViewModel
} else { } else {
friend.photo = null friend.photo = null
} }
}
friend.organization = organization friend.organization = organization
friend.jobTitle = jobTitle.value.orEmpty().trim() friend.jobTitle = jobTitle.value.orEmpty().trim()
@ -327,8 +318,8 @@ class ContactNewOrEditViewModel
@UiThread @UiThread
fun isPendingChanges(): Boolean { fun isPendingChanges(): Boolean {
if (isEdit.value == true) { if (isEdit.value == true) {
if (firstName.value.orEmpty() != friend.vcard?.givenName.orEmpty()) return true if (firstName.value.orEmpty() != friend.firstName.orEmpty()) return true
if (lastName.value.orEmpty() != friend.vcard?.familyName.orEmpty()) return true if (lastName.value.orEmpty() != friend.lastName.orEmpty()) return true
if (picturePath.value.orEmpty() != friend.photo.orEmpty()) return true if (picturePath.value.orEmpty() != friend.photo.orEmpty()) return true
if (company.value.orEmpty() != friend.organization.orEmpty()) return true if (company.value.orEmpty() != friend.organization.orEmpty()) return true
if (jobTitle.value.orEmpty() != friend.jobTitle.orEmpty()) return true if (jobTitle.value.orEmpty() != friend.jobTitle.orEmpty()) return true

View file

@ -369,7 +369,7 @@ class ContactViewModel
fun exportContactAsVCard() { fun exportContactAsVCard() {
coreContext.postOnCoreThread { coreContext.postOnCoreThread {
if (::friend.isInitialized) { if (::friend.isInitialized) {
val vCard = friend.vcard?.asVcard4String() val vCard = friend.dumpVcard()
if (!vCard.isNullOrEmpty()) { if (!vCard.isNullOrEmpty()) {
Log.i("$TAG Friend has been successfully dumped as vCard string") Log.i("$TAG Friend has been successfully dumped as vCard string")
val fileName = friend.name.orEmpty().replace(" ", "_").lowercase( val fileName = friend.name.orEmpty().replace(" ", "_").lowercase(

View file

@ -109,7 +109,8 @@ class ContactsListViewModel
coreContext.contactsManager.addListener(contactsListener) coreContext.contactsManager.addListener(contactsListener)
magicSearch = core.createMagicSearch() magicSearch = core.createMagicSearch()
magicSearch.limitedSearch = false magicSearch.limitedSearch = true
magicSearch.searchLimit = corePreferences.magicSearchResultsLimit
magicSearch.addListener(magicSearchListener) magicSearch.addListener(magicSearchListener)
coreContext.postOnMainThread { coreContext.postOnMainThread {
@ -197,7 +198,7 @@ class ContactsListViewModel
@UiThread @UiThread
fun exportContactAsVCard(friend: Friend) { fun exportContactAsVCard(friend: Friend) {
coreContext.postOnCoreThread { coreContext.postOnCoreThread {
val vCard = friend.vcard?.asVcard4String() val vCard = friend.dumpVcard()
if (!vCard.isNullOrEmpty()) { if (!vCard.isNullOrEmpty()) {
Log.i("$TAG Friend has been successfully dumped as vCard string") Log.i("$TAG Friend has been successfully dumped as vCard string")
val fileName = friend.name.orEmpty().replace(" ", "_").lowercase( val fileName = friend.name.orEmpty().replace(" ", "_").lowercase(

View file

@ -104,7 +104,8 @@ abstract class AddressSelectionViewModel
coreContext.contactsManager.addListener(contactsListener) coreContext.contactsManager.addListener(contactsListener)
magicSearch = core.createMagicSearch() magicSearch = core.createMagicSearch()
magicSearch.limitedSearch = false magicSearch.limitedSearch = true
magicSearch.searchLimit = corePreferences.magicSearchResultsLimit
magicSearch.addListener(magicSearchListener) magicSearch.addListener(magicSearchListener)
} }

View file

@ -117,18 +117,5 @@ class PhoneNumberUtils {
else -> ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM else -> ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM
} }
} }
@AnyThread
fun arePhoneNumberWeakEqual(number1: String, number2: String): Boolean {
return trimPhoneNumber(number1) == trimPhoneNumber(number2)
}
@AnyThread
private fun trimPhoneNumber(phoneNumber: String): String {
return phoneNumber.replace(" ", "")
.replace("-", "")
.replace("(", "")
.replace(")", "")
}
} }
} }