Modern Apps git

← Modern-Apps.git

maps: drop READ_CONTACTS — read picked address from the Contact Picker's returned URI (temporary per-URI grant), postal single-select

Commit
0d829e6e7435cdbaaef29632e74720f1eadc0d19
Author
vayun-mathur <[email protected]>
When
2026-08-17 22:18 UTC (3 months ago)
Parents
f560b96

Diff

maps/src/main/AndroidManifest.xml
diff --git a/maps/src/main/AndroidManifest.xml b/maps/src/main/AndroidManifest.xmlindex 19ef59f3a3..33defc60bd 100644--- a/maps/src/main/AndroidManifest.xml+++ b/maps/src/main/AndroidManifest.xml@@ -35,10 +35,9 @@          routes to the user-selected recognition service (the MA speech app when          installed). -->     <uses-permission android:name="android.permission.RECORD_AUDIO" />-    <!-- Contact address shortcut (P17): fallback only. The system postal-address-         picker grants an implicit per-row read, so this is requested at runtime-         solely when an OEM refuses that read; the common path needs no grant. -->-    <uses-permission android:name="android.permission.READ_CONTACTS" />+    <!-- Contact address shortcut (P17): NO READ_CONTACTS. The system Contact+         Picker returns a URI with a temporary per-URI read grant, so the picked+         address is read directly from that URI without any contacts permission. -->     <!-- Android 11+ package visibility: needed so SpeechRecognizer can see and          bind the installed on-device recognition service for voice search. -->     <queries>
maps/src/main/java/com/vayunmathur/maps/ui/ContactAddressButton.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/ContactAddressButton.kt b/maps/src/main/java/com/vayunmathur/maps/ui/ContactAddressButton.ktindex 371f85f3e8..b51c6af164 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/ContactAddressButton.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/ContactAddressButton.kt@@ -175,19 +175,24 @@ fun ContactAddressButton(onAddress: (String) -> Unit, modifier: Modifier = Modif      IconButton(         onClick = {-            val launchedNewPicker =-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CINNAMON_BUN) {-                    try {-                        addressPicker.launch(newSystemContactPickerIntent())-                        true-                    } catch (_: ActivityNotFoundException) {-                        // Android 17 image without the system picker — use the old path.-                        false+            // Read the address purely from the picker's returned URI (temporary+            // per-URI read grant) — no READ_CONTACTS. On Android 17 the system+            // Contact Picker returns a session URI we query directly.+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CINNAMON_BUN) {+                try {+                    addressPicker.launch(newSystemContactPickerIntent())+                } catch (_: ActivityNotFoundException) {+                    runCatching {+                        Toast.makeText(+                            context,+                            context.getString(com.vayunmathur.maps.R.string.no_contact_picker),+                            Toast.LENGTH_SHORT,+                        ).show()                     }-                } else {-                    false                 }-            if (!launchedNewPicker) {+            } else {+                // Older devices: the legacy postal-row ACTION_PICK also returns a+                // row URI with an implicit read grant (no READ_CONTACTS).                 launchPostalPicker(context, postalPicker, contactPicker)             }         },@@ -247,14 +252,12 @@ private fun newSystemContactPickerIntent(): Intent =     Intent(ContactsPickerSessionContract.ACTION_PICK_CONTACTS).apply {         // Also engage the system picker when targeting a lower SDK on Android 17.         putExtra(Intent.EXTRA_USE_SYSTEM_CONTACTS_PICKER, true)-        // Ask only for postal-address rows → picker surfaces addresses, not names.+        // Ask only for postal-address rows.         putStringArrayListExtra(             ContactsPickerSessionContract.EXTRA_PICK_CONTACTS_REQUESTED_DATA_FIELDS,             arrayListOf(StructuredPostal.CONTENT_ITEM_TYPE),         )-        // Native single-item selection: the user picks ONE address.         putExtra(ContactsPickerSessionContract.EXTRA_PICK_CONTACTS_SELECTION_LIMIT, 1)-        // Single-select: intentionally do NOT set Intent.EXTRA_ALLOW_MULTIPLE.     }  /** Legacy postal-picker path: try the postal-row picker, then the whole-contact