mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-03 15:26:27 +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 (!number.isNullOrEmpty()) {
|
||||||
if (friend.phoneNumbersWithLabel.find {
|
val phoneNumber = Factory.instance()
|
||||||
PhoneNumberUtils.arePhoneNumberWeakEqual(it.phoneNumber, number)
|
.createFriendPhoneNumber(number, label)
|
||||||
} == null
|
friend.addPhoneNumberWithLabel(phoneNumber)
|
||||||
) {
|
|
||||||
val phoneNumber = Factory.instance()
|
|
||||||
.createFriendPhoneNumber(number, label)
|
|
||||||
friend.addPhoneNumberWithLabel(phoneNumber)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
||||||
|
|
@ -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
|
val givenName: String? = cursor.getString(givenNameColumn)
|
||||||
if (vCard != null) {
|
if (!givenName.isNullOrEmpty()) {
|
||||||
val givenName: String? = cursor.getString(givenNameColumn)
|
friend.firstName = givenName
|
||||||
if (!givenName.isNullOrEmpty()) {
|
}
|
||||||
vCard.givenName = 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
|
||||||
|
|
|
||||||
|
|
@ -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")!!
|
||||||
|
|
|
||||||
|
|
@ -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,33 +164,29 @@ class ContactNewOrEditViewModel
|
||||||
|
|
||||||
friend.edit()
|
friend.edit()
|
||||||
friend.name = name
|
friend.name = name
|
||||||
|
friend.firstName = fn
|
||||||
|
friend.lastName = ln
|
||||||
|
|
||||||
val vCard = friend.vcard
|
val picture = picturePath.value.orEmpty()
|
||||||
if (vCard != null) {
|
if (picture.isNotEmpty()) {
|
||||||
vCard.givenName = fn
|
if (picture.contains(TEMP_PICTURE_NAME)) {
|
||||||
vCard.familyName = ln
|
val newFile = FileUtils.getFileStoragePath(
|
||||||
|
getPictureFileName(),
|
||||||
val picture = picturePath.value.orEmpty()
|
isImage = true,
|
||||||
if (picture.isNotEmpty()) {
|
overrideExisting = true
|
||||||
if (picture.contains(TEMP_PICTURE_NAME)) {
|
)
|
||||||
val newFile = FileUtils.getFileStoragePath(
|
val oldFile = FileUtils.getProperFilePath(picture).toUri()
|
||||||
getPictureFileName(),
|
viewModelScope.launch {
|
||||||
isImage = true,
|
FileUtils.copyFile(oldFile, newFile)
|
||||||
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 newPicture = FileUtils.getProperFilePath(newFile.absolutePath)
|
||||||
|
Log.i("$TAG Temporary picture [$picture] copied to [$newPicture]")
|
||||||
|
friend.photo = newPicture
|
||||||
} else {
|
} else {
|
||||||
friend.photo = null
|
friend.photo = FileUtils.getProperFilePath(picture)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
friend.photo = null
|
||||||
}
|
}
|
||||||
|
|
||||||
friend.organization = organization
|
friend.organization = organization
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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(")", "")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue