Modern Apps git

← Modern-Apps.git

contacts: open details for phone_lookup intents

Commit
74dc87d11874e9d5913fb0c241d37e85aec9a2d7
Author
Vayun Mathur <[email protected]>
When
2026-11-07 15:23 UTC (28 days ago)
Parents
a39abec
A phone_lookup URI identifies a contact by number, but the intent
routing only extracted a numeric ID from the URI, so these intents
opened nothing. Resolve the number through PhoneLookup and convert
the aggregated contact ID to a raw contact ID before falling
through to the generic extraction.

Found by a second-pass coverage test of MainActivity intent routing.

(cherry picked from commit 505a9eebad452ad4ce686a2f1d508a23bd6413f2)

Diff

contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt b/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.ktindex ea2c191669..8b3ea721c7 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt@@ -418,6 +418,39 @@ class MainActivity : MaActivity() {             return uri.lastPathSegment?.toLongOrNull()         } +        // A phone_lookup URI identifies a contact by number, not by ID: resolve+        // the number through PhoneLookup before the generic ID extraction below.+        if (path.contains("/phone_lookup/")) {+            val number = uri.lastPathSegment?.takeIf { it.isNotBlank() } ?: return null+            val filterUri = Uri.withAppendedPath(+                ContactsContract.PhoneLookup.CONTENT_FILTER_URI,+                Uri.encode(number),+            )+            contentResolver.query(+                filterUri,+                arrayOf(ContactsContract.PhoneLookup._ID),+                null,+                null,+                null,+            )?.use { cursor ->+                if (!cursor.moveToFirst()) return null+                val phoneLookupId = cursor.getLong(0)+                // Convert aggregated contact ID to raw contact ID (same as below).+                contentResolver.query(+                    ContactsContract.RawContacts.CONTENT_URI,+                    arrayOf(ContactsContract.RawContacts._ID),+                    "${ContactsContract.RawContacts.CONTACT_ID} = ? AND ${ContactsContract.RawContacts.DELETED} = 0",+                    arrayOf(phoneLookupId.toString()),+                    "${ContactsContract.RawContacts.STARRED} DESC, ${ContactsContract.RawContacts._ID} ASC"+                )?.use { rawCursor ->+                    if (rawCursor.moveToFirst()) {+                        return rawCursor.getLong(0)+                    }+                }+            }+            return null+        }+         // For contacts/lookup or contacts/<id> URIs, extract the aggregated contact ID         val aggregatedId: Long? = when {             path.contains("/lookup/") -> {