Skip to content

fix: match Brazilian caller IDs to contacts regardless of country/operator code prefix - #899

Closed
brunogamacatao wants to merge 1 commit into
FossifyOrg:mainfrom
brunogamacatao:main
Closed

brunogamacatao wants to merge 1 commit into
FossifyOrg:mainfrom
brunogamacatao:main

Conversation

@brunogamacatao

Copy link
Copy Markdown

Summary

In Brazil, carriers deliver caller ID for the very same phone line in several inconsistent formats, e.g.:

  • +55<DDD><number> (with country code)
  • 0<operator code><DDD><number> (with a long-distance carrier/operator selection code, e.g. 015 for Vivo)
  • <DDD><number> (no country code)
  • <number> (no DDD at all)

Because SimpleCallScreeningService relies on the exact/native contact lookup (SimpleContactsHelper.existsSync, which in turn uses the OS PhoneLookup provider and PhoneNumberUtils.compare), these format variations frequently fail to match against a contact saved with a different formatting, even though it's the same physical number. This makes the "only allow calls from contacts" setting unreliable for Brazilian users — legitimate calls from saved contacts get blocked as "unknown".

There's an additional wrinkle: Brazil made a 9th digit mandatory for all mobile numbers starting in 2016. Contacts saved before that migration may still have the old 8-digit format, while an incoming call is reported using the current 9-digit format (or vice versa).

Solution

  • Added BrazilianPhoneNumberMatcher, a small pure-Kotlin utility that parses a raw number into DDD + subscriber number, discarding country code and operator code (which are never a stable part of the number). It disambiguates mobile (9 digits, always starting with 9) vs. landline (8 digits) subscriber numbers, and compares only the last 8 digits when one side is in the old 8-digit mobile format and the other in the current 9-digit format.
  • SimpleCallScreeningService now falls back to this comparison — against both system and private ("my contacts") phone numbers — only when the existing lookup returns a definite "not found", preserving all current behavior (including the "undetermined"/no-permission case, which still allows the call through).
  • Added unit tests (BrazilianPhoneNumberMatcherTest) covering country code, operator code, trunk prefix, formatting characters, DDD/number mismatches, and the 8-digit vs 9-digit mobile format transition.

Test plan

  • ./gradlew :app:testFossDebugUnitTest — all tests pass
  • ./gradlew :app:assembleFossDebug — builds successfully
  • Manually installed on a physical device (Android, foss flavor) with "only allow calls from contacts" enabled, and confirmed a real incoming call from a saved contact — previously misdetected as unknown due to carrier-added prefixes — is now correctly recognized and allowed through

🤖 Generated with Claude Code

…rator code prefix

Carriers deliver the same Brazilian number in inconsistent formats
(+55<ddd><number>, 0<operator><ddd><number>, <ddd><number>, <number>),
which the existing exact/system contact lookup can fail to match,
causing "only allow calls from contacts" to block legitimate callers.

Add a fallback comparison that parses DDD + subscriber number, ignoring
country and operator codes, and also handles the pre-2016 8-digit mobile
format against the current mandatory 9-digit format.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fossifybot

fossifybot Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Fossify accepts code contributions only for open issues labeled help wanted. This pull request does not meet that requirement or one of the documented exceptions, so it is being closed without review. Please read the contribution guidelines before starting work.

@fossifybot fossifybot Bot closed this Sep 18, 2026
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.

1 participant