fix: match Brazilian caller IDs to contacts regardless of country/operator code prefix - #899
Closed
brunogamacatao wants to merge 1 commit into
Closed
brunogamacatao wants to merge 1 commit into
brunogamacatao wants to merge 1 commit into
Conversation
…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>
Contributor
|
Fossify accepts code contributions only for open issues labeled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.015for Vivo)<DDD><number>(no country code)<number>(no DDD at all)Because
SimpleCallScreeningServicerelies on the exact/native contact lookup (SimpleContactsHelper.existsSync, which in turn uses the OSPhoneLookupprovider andPhoneNumberUtils.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
BrazilianPhoneNumberMatcher, a small pure-Kotlin utility that parses a raw number intoDDD + subscriber number, discarding country code and operator code (which are never a stable part of the number). It disambiguates mobile (9 digits, always starting with9) 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.SimpleCallScreeningServicenow 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).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🤖 Generated with Claude Code