Skip to content

Commit

Permalink
Merge branch 'release/8.13.40'
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRocks committed Oct 13, 2024
2 parents 7bcaceb + de70e8c commit 181080c
Show file tree
Hide file tree
Showing 22 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
}
dependencies {
implementation 'io.michaelrocks:libphonenumber-android:8.13.39'
implementation 'io.michaelrocks:libphonenumber-android:8.13.40'
}
```

Expand Down Expand Up @@ -63,5 +63,5 @@ License
limitations under the License.

[1]: https://github.com/googlei18n/libphonenumber
[2]: http://www.methodscount.com/?lib=com.googlecode.libphonenumber%3Alibphonenumber%3A8.13.39
[2]: http://www.methodscount.com/?lib=com.googlecode.libphonenumber%3Alibphonenumber%3A8.13.40
[3]: http://blog.nimbledroid.com/2016/04/06/slow-ClassLoader.getResourceAsStream.html
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
group = 'io.michaelrocks'
version = '8.13.39'
version = '8.13.40'

ext.projectCompileSdkVersion = 35
ext.projectBuildToolsVersion = '35.0.0'
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class PhoneNumberUtil {
// considered to be an area code.
private static final Set<Integer> GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES;

// Set of country codes that doesn't have national prefix, but it has area codes.
private static final Set<Integer> COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES;

// Set of country calling codes that have geographically assigned mobile numbers. This may not be
// complete; we add calling codes case by case, as we find geographical mobile numbers or hear
// from user reports. Note that countries like the US, where we can't distinguish between
Expand Down Expand Up @@ -132,6 +135,11 @@ public class PhoneNumberUtil {
GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES =
Collections.unmodifiableSet(geoMobileCountriesWithoutMobileAreaCodes);

HashSet<Integer> countriesWithoutNationalPrefixWithAreaCodes = new HashSet<>();
countriesWithoutNationalPrefixWithAreaCodes.add(52); // Mexico
COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES =
Collections.unmodifiableSet(countriesWithoutNationalPrefixWithAreaCodes);

HashSet<Integer> geoMobileCountries = new HashSet<>();
geoMobileCountries.add(52); // Mexico
geoMobileCountries.add(54); // Argentina
Expand Down Expand Up @@ -923,14 +931,18 @@ public int getLengthOfGeographicalAreaCode(PhoneNumber number) {
if (metadata == null) {
return 0;
}

PhoneNumberType type = getNumberType(number);
int countryCallingCode = number.getCountryCode();
// If a country doesn't use a national prefix, and this number doesn't have an Italian leading
// zero, we assume it is a closed dialling plan with no area codes.
if (!metadata.hasNationalPrefix() && !number.isItalianLeadingZero()) {
// Note:this is our general assumption, but there are exceptions which are tracked in
// COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
if (!metadata.hasNationalPrefix() && !number.isItalianLeadingZero()
&& !COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.contains(countryCallingCode)) {
return 0;
}

PhoneNumberType type = getNumberType(number);
int countryCallingCode = number.getCountryCode();
if (type == PhoneNumberType.MOBILE
// Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
// codes are present for some mobile phones but not for others. We have no better way of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ public void testGetLengthOfGeographicalAreaCode() {
// Italian numbers - there is no national prefix, but it still has an area code.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(IT_NUMBER));

// Mexico numbers - there is no national prefix, but it still has an area code.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(MX_NUMBER1));

// Google Singapore. Singapore has no area code and no national prefix.
assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(SG_NUMBER));

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 181080c

Please sign in to comment.