mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Few tweaks trying to prevent jni global ref table overflow
This commit is contained in:
parent
043ed77c3a
commit
e4570f167d
7 changed files with 45 additions and 69 deletions
|
|
@ -219,14 +219,9 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
}
|
||||
|
||||
if (!number.isNullOrEmpty()) {
|
||||
if (friend.phoneNumbersWithLabel.find {
|
||||
PhoneNumberUtils.arePhoneNumberWeakEqual(it.phoneNumber, number)
|
||||
} == null
|
||||
) {
|
||||
val phoneNumber = Factory.instance()
|
||||
.createFriendPhoneNumber(number, label)
|
||||
friend.addPhoneNumberWithLabel(phoneNumber)
|
||||
}
|
||||
val phoneNumber = Factory.instance()
|
||||
.createFriendPhoneNumber(number, label)
|
||||
friend.addPhoneNumberWithLabel(phoneNumber)
|
||||
}
|
||||
}
|
||||
ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
||||
|
|
@ -250,17 +245,14 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
}
|
||||
}
|
||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
|
||||
val vCard = friend.vcard
|
||||
if (vCard != null) {
|
||||
val givenName: String? = cursor.getString(givenNameColumn)
|
||||
if (!givenName.isNullOrEmpty()) {
|
||||
vCard.givenName = givenName
|
||||
}
|
||||
val givenName: String? = cursor.getString(givenNameColumn)
|
||||
if (!givenName.isNullOrEmpty()) {
|
||||
friend.firstName = givenName
|
||||
}
|
||||
|
||||
val familyName: String? = cursor.getString(familyNameColumn)
|
||||
if (!familyName.isNullOrEmpty()) {
|
||||
vCard.familyName = familyName
|
||||
}
|
||||
val familyName: String? = cursor.getString(familyNameColumn)
|
||||
if (!familyName.isNullOrEmpty()) {
|
||||
friend.lastName = familyName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -291,7 +283,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
|
||||
if (core.globalState == GlobalState.Shutdown || core.globalState == GlobalState.Off) {
|
||||
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!")
|
||||
} else {
|
||||
Log.i("$TAG ${friends.size} friends fetched")
|
||||
|
|
@ -322,7 +314,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
friends.remove(localFriend.refKey)
|
||||
localFriend.nativeUri =
|
||||
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()
|
||||
// Update basic fields that may have changed
|
||||
|
|
|
|||
|
|
@ -304,6 +304,10 @@ class CorePreferences
|
|||
val hideAssistantThirdPartySipAccount: Boolean
|
||||
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
|
||||
val singleSignOnClientId: String
|
||||
get() = config.getString("app", "oidc_client_id", "linphone")!!
|
||||
|
|
|
|||
|
|
@ -97,13 +97,8 @@ class ContactNewOrEditViewModel
|
|||
|
||||
if (exists) {
|
||||
Log.i("$TAG Found friend [${friend.name}] using ref key [$refKey]")
|
||||
val vCard = friend.vcard
|
||||
if (vCard != null) {
|
||||
firstName.postValue(vCard.givenName)
|
||||
lastName.postValue(vCard.familyName)
|
||||
} else {
|
||||
// TODO: What to do if vCard is null?
|
||||
}
|
||||
firstName.postValue(friend.firstName.orEmpty())
|
||||
lastName.postValue(friend.lastName.orEmpty())
|
||||
|
||||
id.postValue(friend.refKey ?: friend.vcard?.uid)
|
||||
|
||||
|
|
@ -169,33 +164,29 @@ class ContactNewOrEditViewModel
|
|||
|
||||
friend.edit()
|
||||
friend.name = name
|
||||
friend.firstName = fn
|
||||
friend.lastName = ln
|
||||
|
||||
val vCard = friend.vcard
|
||||
if (vCard != null) {
|
||||
vCard.givenName = fn
|
||||
vCard.familyName = ln
|
||||
|
||||
val picture = picturePath.value.orEmpty()
|
||||
if (picture.isNotEmpty()) {
|
||||
if (picture.contains(TEMP_PICTURE_NAME)) {
|
||||
val newFile = FileUtils.getFileStoragePath(
|
||||
getPictureFileName(),
|
||||
isImage = true,
|
||||
overrideExisting = true
|
||||
)
|
||||
val oldFile = FileUtils.getProperFilePath(picture).toUri()
|
||||
viewModelScope.launch {
|
||||
FileUtils.copyFile(oldFile, newFile)
|
||||
}
|
||||
val newPicture = FileUtils.getProperFilePath(newFile.absolutePath)
|
||||
Log.i("$TAG Temporary picture [$picture] copied to [$newPicture]")
|
||||
friend.photo = newPicture
|
||||
} else {
|
||||
friend.photo = FileUtils.getProperFilePath(picture)
|
||||
val picture = picturePath.value.orEmpty()
|
||||
if (picture.isNotEmpty()) {
|
||||
if (picture.contains(TEMP_PICTURE_NAME)) {
|
||||
val newFile = FileUtils.getFileStoragePath(
|
||||
getPictureFileName(),
|
||||
isImage = true,
|
||||
overrideExisting = true
|
||||
)
|
||||
val oldFile = FileUtils.getProperFilePath(picture).toUri()
|
||||
viewModelScope.launch {
|
||||
FileUtils.copyFile(oldFile, newFile)
|
||||
}
|
||||
val newPicture = FileUtils.getProperFilePath(newFile.absolutePath)
|
||||
Log.i("$TAG Temporary picture [$picture] copied to [$newPicture]")
|
||||
friend.photo = newPicture
|
||||
} else {
|
||||
friend.photo = null
|
||||
friend.photo = FileUtils.getProperFilePath(picture)
|
||||
}
|
||||
} else {
|
||||
friend.photo = null
|
||||
}
|
||||
|
||||
friend.organization = organization
|
||||
|
|
@ -327,8 +318,8 @@ class ContactNewOrEditViewModel
|
|||
@UiThread
|
||||
fun isPendingChanges(): Boolean {
|
||||
if (isEdit.value == true) {
|
||||
if (firstName.value.orEmpty() != friend.vcard?.givenName.orEmpty()) return true
|
||||
if (lastName.value.orEmpty() != friend.vcard?.familyName.orEmpty()) return true
|
||||
if (firstName.value.orEmpty() != friend.firstName.orEmpty()) return true
|
||||
if (lastName.value.orEmpty() != friend.lastName.orEmpty()) return true
|
||||
if (picturePath.value.orEmpty() != friend.photo.orEmpty()) return true
|
||||
if (company.value.orEmpty() != friend.organization.orEmpty()) return true
|
||||
if (jobTitle.value.orEmpty() != friend.jobTitle.orEmpty()) return true
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ class ContactViewModel
|
|||
fun exportContactAsVCard() {
|
||||
coreContext.postOnCoreThread {
|
||||
if (::friend.isInitialized) {
|
||||
val vCard = friend.vcard?.asVcard4String()
|
||||
val vCard = friend.dumpVcard()
|
||||
if (!vCard.isNullOrEmpty()) {
|
||||
Log.i("$TAG Friend has been successfully dumped as vCard string")
|
||||
val fileName = friend.name.orEmpty().replace(" ", "_").lowercase(
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ class ContactsListViewModel
|
|||
|
||||
coreContext.contactsManager.addListener(contactsListener)
|
||||
magicSearch = core.createMagicSearch()
|
||||
magicSearch.limitedSearch = false
|
||||
magicSearch.limitedSearch = true
|
||||
magicSearch.searchLimit = corePreferences.magicSearchResultsLimit
|
||||
magicSearch.addListener(magicSearchListener)
|
||||
|
||||
coreContext.postOnMainThread {
|
||||
|
|
@ -197,7 +198,7 @@ class ContactsListViewModel
|
|||
@UiThread
|
||||
fun exportContactAsVCard(friend: Friend) {
|
||||
coreContext.postOnCoreThread {
|
||||
val vCard = friend.vcard?.asVcard4String()
|
||||
val vCard = friend.dumpVcard()
|
||||
if (!vCard.isNullOrEmpty()) {
|
||||
Log.i("$TAG Friend has been successfully dumped as vCard string")
|
||||
val fileName = friend.name.orEmpty().replace(" ", "_").lowercase(
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ abstract class AddressSelectionViewModel
|
|||
|
||||
coreContext.contactsManager.addListener(contactsListener)
|
||||
magicSearch = core.createMagicSearch()
|
||||
magicSearch.limitedSearch = false
|
||||
magicSearch.limitedSearch = true
|
||||
magicSearch.searchLimit = corePreferences.magicSearchResultsLimit
|
||||
magicSearch.addListener(magicSearchListener)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,18 +117,5 @@ class PhoneNumberUtils {
|
|||
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(")", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue