contacts: fix: don't crash if device doesn't properly support contacts
- Commit
ad18b395ab961ee180f14644c7202f65f82b2283- Author
- Vayun Mathur <[email protected]>
- When
- 2026-02-10 22:44 UTC (9 months ago)
- Parents
05eb71b
Diff
contacts/src/main/java/com/vayunmathur/contacts/Contact.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/Contact.kt b/contacts/src/main/java/com/vayunmathur/contacts/Contact.ktindex ee107d01c2..8ce638322f 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/Contact.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/Contact.kt@@ -428,28 +428,33 @@ data class Contact( } private fun tryGetProfile(context: Context): Contact? {- val contentResolver = context.contentResolver- val uri = Profile.CONTENT_URI- val projection = arrayOf(- Profile._ID,- Profile.DISPLAY_NAME_PRIMARY,- Profile.STARRED,- )- val cursor = contentResolver.query(uri, projection, null, null, null)-- cursor?.use {- while (it.moveToNext()) {- val id = it.getLong(it.getColumnIndexOrThrow(Profile._ID))- val displayName = it.getString(it.getColumnIndexOrThrow(Profile.DISPLAY_NAME_PRIMARY))- val isFavorite = it.getInt(it.getColumnIndexOrThrow(Profile.STARRED)) == 1-- var details = getDetails(context, id, true)- details = processDetails(details, displayName) ?: continue-- return Contact(true, id, isFavorite, details)+ try {+ val contentResolver = context.contentResolver+ val uri = Profile.CONTENT_URI+ val projection = arrayOf(+ Profile._ID,+ Profile.DISPLAY_NAME_PRIMARY,+ Profile.STARRED,+ )+ val cursor = contentResolver.query(uri, projection, null, null, null)++ cursor?.use {+ while (it.moveToNext()) {+ val id = it.getLong(it.getColumnIndexOrThrow(Profile._ID))+ val displayName =+ it.getString(it.getColumnIndexOrThrow(Profile.DISPLAY_NAME_PRIMARY))+ val isFavorite = it.getInt(it.getColumnIndexOrThrow(Profile.STARRED)) == 1++ var details = getDetails(context, id, true)+ details = processDetails(details, displayName) ?: continue++ return Contact(true, id, isFavorite, details)+ } }+ return null+ } catch (e: Exception) {+ return null }- return null } fun getProfile(context: Context): Contact {