mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Prevent crash for call notification due to empty person name, using all identification fields from vCard (first & last names, organization, job title)
This commit is contained in:
parent
9e1d358f4e
commit
dfdc26a575
2 changed files with 27 additions and 11 deletions
|
|
@ -683,7 +683,7 @@ fun Friend.getAvatarBitmap(round: Boolean = false): Bitmap? {
|
|||
photo ?: getNativeContactPictureUri()?.toString(),
|
||||
round
|
||||
)
|
||||
} catch (numberFormatException: NumberFormatException) {
|
||||
} catch (_: NumberFormatException) {
|
||||
// Expected for contacts created by Linphone
|
||||
}
|
||||
return null
|
||||
|
|
@ -720,7 +720,7 @@ fun Friend.getNativeContactPictureUri(): Uri? {
|
|||
lookupUri,
|
||||
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY
|
||||
)
|
||||
} catch (numberFormatException: NumberFormatException) {
|
||||
} catch (_: NumberFormatException) {
|
||||
// Expected for contacts created by Linphone
|
||||
}
|
||||
}
|
||||
|
|
@ -729,7 +729,25 @@ fun Friend.getNativeContactPictureUri(): Uri? {
|
|||
|
||||
@WorkerThread
|
||||
fun Friend.getPerson(): Person {
|
||||
val personBuilder = Person.Builder().setName(name)
|
||||
val personBuilder = Person.Builder()
|
||||
val personName = if (name.orEmpty().isNotEmpty()) {
|
||||
name
|
||||
} else {
|
||||
if (!lastName.isNullOrEmpty() || !firstName.isNullOrEmpty()) {
|
||||
Log.w("[Friend] Name is null or empty, using first and last name")
|
||||
"$firstName $lastName".trim()
|
||||
} else if (!organization.isNullOrEmpty()) {
|
||||
Log.w("[Friend] Name, first name & last name are null or empty, using organization instead")
|
||||
organization
|
||||
} else if (!jobTitle.isNullOrEmpty()) {
|
||||
Log.w("[Friend] Name, first and last names & organization are null or empty, using job title instead")
|
||||
jobTitle
|
||||
} else {
|
||||
Log.e("[Friend] No identification field filled for this friend!")
|
||||
"Unknown"
|
||||
}
|
||||
}
|
||||
personBuilder.setName(personName)
|
||||
|
||||
val bm: Bitmap? = getAvatarBitmap()
|
||||
personBuilder.setIcon(
|
||||
|
|
@ -737,7 +755,7 @@ fun Friend.getPerson(): Person {
|
|||
Log.i(
|
||||
"[Friend] Can't use friend [$name] picture path, generating avatar based on initials"
|
||||
)
|
||||
AvatarGenerator(coreContext.context).setInitials(AppUtils.getInitials(name.orEmpty())).buildIcon()
|
||||
AvatarGenerator(coreContext.context).setInitials(AppUtils.getInitials(personName.orEmpty())).buildIcon()
|
||||
} else {
|
||||
IconCompat.createWithAdaptiveBitmap(bm)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1220,9 +1220,7 @@ class NotificationsManager
|
|||
} else {
|
||||
val contact = friend
|
||||
?: coreContext.contactsManager.findContactByAddress(remoteAddress)
|
||||
val displayName = contact?.name ?: LinphoneUtils.getDisplayName(remoteAddress)
|
||||
|
||||
getPerson(contact, displayName)
|
||||
getPerson(contact, LinphoneUtils.getDisplayName(remoteAddress))
|
||||
}
|
||||
|
||||
val isVideo = LinphoneUtils.isVideoEnabled(call)
|
||||
|
|
@ -1588,14 +1586,14 @@ class NotificationsManager
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun getPerson(friend: Friend?, displayName: String): Person {
|
||||
private fun getPerson(friend: Friend?, fallbackDisplayName: String): Person {
|
||||
return friend?.getPerson()
|
||||
?: Person.Builder()
|
||||
.setName(displayName)
|
||||
.setName(if (fallbackDisplayName.isEmpty()) "Unknown" else fallbackDisplayName)
|
||||
.setIcon(
|
||||
AvatarGenerator(context).setInitials(AppUtils.getInitials(displayName)).buildIcon()
|
||||
AvatarGenerator(context).setInitials(AppUtils.getInitials(fallbackDisplayName)).buildIcon()
|
||||
)
|
||||
.setKey(displayName)
|
||||
.setKey(fallbackDisplayName)
|
||||
.setImportant(false)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue