Skip to content

Migrate to Android Contact Picker and remove READ_CONTACTS - #102928

Merged
AndrewGable merged 8 commits into
Expensify:mainfrom
situchan:feat-102920
Oct 12, 2026
Merged

AndrewGable merged 8 commits into
Expensify:mainfrom
situchan:feat-102920

Conversation

@situchan

@situchan situchan commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Google Play's Contacts Permission policy takes effect on January 27, 2027. It covers apps targeting SDK 37+ that use READ_CONTACTS without a declaration. This PR removes the permission from Android and switches to the system Contact Picker, so the user picks contacts instead of the app reading the whole address book.

Android

  • Removed READ_CONTACTS from the manifest. A tools:node="remove" entry stops any dependency from adding it back.
  • Added pick() to the Nitro contacts module.
    • Android 17+ (API 37): ACTION_PICK_CONTACTS, the new system picker. It returns emails, phone numbers and names, and allows several contacts. Because we still target SDK 36, the intent sets EXTRA_USE_SYSTEM_CONTACTS_PICKER. Without it, the picker forwards the request to a contacts app and the user sees "No apps can perform this action".
    • Android 16 and lower: ACTION_PICK on email rows. One contact per pick. This is the only picker that works without a permission on these versions.
  • The session URI carries a user prefix (content://0@com.android.contacts.picker.sessions/...), so the reader is chosen by API level, not by URI authority.
  • getAll() now returns an empty list on Android. The bulk import, the focus and foreground refreshes, and the permission soft-prompt are gone on Android.
  • "Import contacts" now opens the picker:
    • Expense participant picker: the "Import contacts" row and the "Import your contacts" link.
    • New chat: a new "Import contacts" row. Production had no entry point here; it only showed contacts once the permission was granted.
  • Picked contacts are added to the list the same way production's bulk import adds them: same dedupe, same filtering of invalid emails and phones, same sorting. The search box isn't touched.
  • compileSdk is now 37, which ContactsPickerSessionContract needs. targetSdk stays at 36.

iOS: no change. It still imports the address book after the user grants permission.

HybridApp: Mobile-Expensify also declared READ_CONTACTS and has its own contact flows. Both are handled in Expensify/Mobile-Expensify#14154. Both PRs must ship together, or the shipped app still declares the permission.

Behavior vs production

Production (Android, all versions) This PR, Android 17+ This PR, Android 16 and lower iOS (production = this PR)
Contacts permission READ_CONTACTS requested, with a soft-prompt first Not declared Not declared Contacts permission, unchanged
How contacts get in Whole address book, refreshed on focus and foreground User picks in the system Contact Picker User picks in the contacts app's email picker Whole address book
Several at once All contacts Yes, multi-select No, one per pick (tap again for more) All contacts
Contact with an email Listed Listed Listed Listed
Contact with a phone only Listed Listed Can't be picked (the picker shows email rows only) Listed
Contact with a name only Not listed (filtered out) Shown in the picker, nothing added when picked Not shown in the picker Not listed
Contact that is already an Expensify user Existing user row only, no duplicate Same Same Same
Name shown First and last name First and last name, or the display name if there's no structured name Display name First and last name
Contact photo Yes No, the picker doesn't grant photo access No Yes
"Import contacts" in the participant picker Opens Settings Opens the picker Opens the picker Opens Settings, unchanged
"Import contacts" in New chat Not present Opens the picker Opens the picker Not present

Fixed Issues

$ #102920
MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14154

Tests

Setup: add these device contacts.

  • A: name and email
  • B: email only
  • C: name and a valid phone number only
  • D: name only
  • E: the email of an existing Expensify account

Android 17+ (API 37)

  1. FAB > Start chat > tap "Import contacts".
  2. Verify the system Contact Picker opens, with no permission prompt and no "No apps can perform this action".
  3. Select A, B and C, then confirm.
  4. Verify all three appear in the Contacts list. Scroll or search by name if needed.
  5. Import E. Verify no duplicate row appears; only the existing user's row is shown.
  6. Import D. Verify nothing is added and no error appears.
  7. Open the picker and press Back. Verify nothing changes.
  8. FAB > Create expense > Manual > enter an amount > Next. Tap the "Import contacts" row and verify the picker opens. Pick A and verify A appears and can be selected as a participant.
  9. Device Settings > Apps > Expensify > Permissions: verify Contacts isn't listed.

Android 16 or lower

  1. FAB > Start chat > Import contacts. Verify the contacts app's email picker opens, with no permission prompt.
  2. Pick A's email. Verify A appears in the list.
  3. Repeat for B. Verify both are listed.

Known limitations

  • Phone-only contacts can't be picked on Android 16 and lower.

  • On Android 17+, contacts with only a name are listed in the picker and nothing happens when one is picked.

  • Picked contacts aren't kept after leaving the screen. Production re-reads the address book each time, so its contacts are always listed.

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.mov
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 95.90% <ø> (ø)
src/hooks/useSearchSelector/base.ts 87.80% <ø> (ø)
src/hooks/useSearchSelector/index.native.ts 100.00% <100.00%> (ø)
src/pages/NewChatPage/index.tsx 82.57% <100.00%> (+0.26%) ⬆️
...rc/pages/iou/request/ImportContactButton/index.tsx 0.00% <ø> (ø)
...ContactPermission/useContactPermissions.android.ts 0.00% <0.00%> (ø)
...s/iou/request/ImportContactButton/index.native.tsx 0.00% <0.00%> (ø)
src/pages/iou/request/ParticipantSearchResults.tsx 0.60% <0.00%> (-0.01%) ⬇️
src/libs/ContactImport/index.android.tsx 0.00% <0.00%> (ø)
src/libs/ContactPicker/index.ts 33.33% <33.33%> (ø)
... and 3 more
... and 12 files with indirect coverage changes

@melvin-bot
melvin-bot Bot requested review from garrettmknight and mkhutornyi and removed request for a team October 7, 2026 11:24
@melvin-bot

melvin-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team October 7, 2026 11:24
@garrettmknight
garrettmknight removed their request for review October 7, 2026 11:41
@AndrewGable
AndrewGable self-requested a review October 7, 2026 14:45
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🚧 AndrewGable has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@mkhutornyi

mkhutornyi commented Oct 9, 2026 •

Copy link
Copy Markdown

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
newdot.mov
newdot-lower.mp4
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

Comment thread src/hooks/useContactImport.ts Resolved
Comment thread src/hooks/useContactImport.ts Resolved
@mkhutornyi

Copy link
Copy Markdown

@codex review

@mkhutornyi

Copy link
Copy Markdown

@MelvinBot review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T18:40:42.545787Z 580d361 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

I found no blocking bugs. The Android flow holds together: the soft-prompt modal stays hidden because getContactPermission() now returns UNAVAILABLE, not DENIED. The focus and foreground refreshes no longer clear picked contacts. The only failing checks are the checklist and approval checks. I have four suggestions, from most to least important.

  1. Opening the picker can fail with no feedback. If no activity handles the intent, HybridContactsModule.kt:83 returns an empty list. To the user, tapping "Import contacts" does nothing. Two cases can trigger this:

    • An Android 17+ device without the system picker. The module doesn't fall back to ACTION_PICK (L94-L116).
    • An older device with no contacts app.

    Consider retrying with ACTION_PICK on API 37+, and showing an error or rejecting the promise when nothing can handle the intent.

  2. A picked contact can stay hidden behind the search term. The "Import your contacts" link in the no-results state now opens the picker (ParticipantSearchResults.tsx:589). That state only shows while a search term is entered. If the picked contact doesn't match the term, it's added but not shown. Consider clearing the search, or selecting the picked contact automatically.

  3. The user must find the picked contact. useSearchSelector/index.native.ts:42-46 ignores the contacts that pickContact returns. The user then has to scroll to the new row (test step 4). Selecting the picked contacts automatically would save that step. This matters most on Android 16 and lower, where each pick returns one contact.

  4. No tests cover the new merge logic. Codecov reports lower coverage. A Jest test for pickContact in useContactImport.ts:53-61 should cover replacing an earlier copy of the same login and ignoring an empty pick. Mock @libs/ContactPicker for the test.

Also checked, no change needed
  • The request code 0xC047 fits in the 16 bits that startActivityForResult allows.
  • After the picker closes, the app returns to the foreground. The Android useContactPermissions hook does nothing, so picked contacts aren't reset.
  • On native, useSearchSelector replaces the contactOptions from ParticipantSearchResults. The second useContactImport instance there doesn't hide picked contacts.
  • iOS and web use ContactPicker/index.ts (canPickContacts = false), so they keep their current behavior.
  • Nit: addActivityEventListener is never removed. This is harmless while the module is a singleton.

I reviewed the code only. I didn't run the Android flows because this run only has a web environment.


view run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 580d3617b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@situchan

Copy link
Copy Markdown
Contributor Author
  1. Opening the picker can fail with no feedback. If no activity handles the intent, HybridContactsModule.kt:83 returns an empty list. To the user, tapping "Import contacts" does nothing. Two cases can trigger this:

    • An Android 17+ device without the system picker. The module doesn't fall back to ACTION_PICK (L94-L116).
    • An older device with no contacts app.

    Consider retrying with ACTION_PICK on API 37+, and showing an error or rejecting the promise when nothing can handle the intent.

On Android 17 the picker is handled by a system app, per the ACTION_PICK_CONTACTS docs, so that case shouldn't happen there.
Before 17, a device with no contacts app is an edge case we accept.
I can add a fallback in a follow-up if it shows up in practice.

  1. A picked contact can stay hidden behind the search term. The "Import your contacts" link in the no-results state now opens the picker (ParticipantSearchResults.tsx:589). That state only shows while a search term is entered. If the picked contact doesn't match the term, it's added but not shown. Consider clearing the search, or selecting the picked contact automatically.

By design, picking only adds the contact to the list, like the bulk import on iOS. I'll look at clearing the search together with point 3 in a follow-up if needed.

  1. The user must find the picked contact. useSearchSelector/index.native.ts:42-46 ignores the contacts that pickContact returns. The user then has to scroll to the new row (test step 4). Selecting the picked contacts automatically would save that step. This matters most on Android 16 and lower, where each pick returns one contact.

Not in this PR. Selection works differently on each screen: single-select expense flows go straight to the next step, and New chat has its own group selection.
A picked contact that's already an Expensify user would also need mapping to that user's row.
Follow-up if needed.

  1. No tests cover the new merge logic. Codecov reports lower coverage. A Jest test for pickContact in useContactImport.ts:53-61 should cover replacing an earlier copy of the same login and ignoring an empty pick. Mock @libs/ContactPicker for the test.

Also checked, no change needed

  • The request code 0xC047 fits in the 16 bits that startActivityForResult allows.
  • After the picker closes, the app returns to the foreground. The Android useContactPermissions hook does nothing, so picked contacts aren't reset.
  • On native, useSearchSelector replaces the contactOptions from ParticipantSearchResults. The second useContactImport instance there doesn't hide picked contacts.
  • iOS and web use ContactPicker/index.ts (canPickContacts = false), so they keep their current behavior.
  • Nit: addActivityEventListener is never removed. This is harmless while the module is a singleton.

I reviewed the code only. I didn't run the Android flows because this run only has a web environment.

view run

The new logic is mostly native picker code that Jest can't exercise. A useContactImport test for the merge step can come in a follow-up.

@situchan

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All comments were addressed.

@AndrewGable
AndrewGable merged commit 56f24d3 into Expensify:main Oct 12, 2026
49 of 58 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 AndrewGable has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/AndrewGable in version: 9.5.8-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR changes how Android brings in device contacts (the system Contact Picker instead of the contacts permission), and no article under docs/articles describes device contact import or the contacts permission, so no existing sentence is now wrong.

What I checked
  • Searched docs/articles for "import contacts", "contacts permission", "access to contacts", "phone/device contacts", "address book", and Android permission wording. The only matches are unrelated, such as Xero contacts, support contacts, and Recents / Contacts in attendee selection.
  • Sentences like "Select attendees from Recents, Contacts, or enter a name, email, or phone number" in Adding-Attendees.md:24 are still accurate.
  • Contact import already existed. This PR changes how it works on Android, not what users can do, and iOS doesn't change.

view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.8-5 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants