diff options
author | Shaopeng Jia <shaopengjia@google.com> | 2012-02-02 16:52:26 +0100 |
---|---|---|
committer | Shaopeng Jia <shaopengjia@google.com> | 2012-02-06 15:46:10 +0100 |
commit | 26cd243601fc05c5ed39c2d1e3ab203a8eb97c25 (patch) | |
tree | 89cb552adcb51f93eaeadfd4b3e3ff80ed782205 /telephony/java/android | |
parent | 26daa02bdb0c62f8162ad8d4d771cabce8644b4a (diff) | |
download | frameworks_base-26cd243601fc05c5ed39c2d1e3ab203a8eb97c25.zip frameworks_base-26cd243601fc05c5ed39c2d1e3ab203a8eb97c25.tar.gz frameworks_base-26cd243601fc05c5ed39c2d1e3ab203a8eb97c25.tar.bz2 |
Fix the 3-parameter formatNumber to correctly handle IDDs.
Also added more unittests.
Bug: 5726454
Change-Id: I7fd96b47e7b0c34b66a2fe698308342e125ec0f3
Diffstat (limited to 'telephony/java/android')
-rw-r--r-- | telephony/java/android/telephony/PhoneNumberUtils.java | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 5da3d97..24a4876 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -1438,7 +1438,8 @@ public class PhoneNumberUtils * phoneNumber doesn't have the country code. * @param defaultCountryIso * the ISO 3166-1 two letters country code whose convention will - * be used if the phoneNumberE164 is null or invalid. + * be used if the phoneNumberE164 is null or invalid, or if phoneNumber + * contains IDD. * @return the formatted number if the given number has been formatted, * otherwise, return the given number. * @@ -1457,9 +1458,13 @@ public class PhoneNumberUtils if (phoneNumberE164 != null && phoneNumberE164.length() >= 2 && phoneNumberE164.charAt(0) == '+') { try { - PhoneNumber pn = util.parse(phoneNumberE164, defaultCountryIso); + // The number to be parsed is in E164 format, so the default region used doesn't + // matter. + PhoneNumber pn = util.parse(phoneNumberE164, "ZZ"); String regionCode = util.getRegionCodeForNumber(pn); - if (!TextUtils.isEmpty(regionCode)) { + if (!TextUtils.isEmpty(regionCode) && + // This makes sure phoneNumber doesn't contain an IDD + normalizeNumber(phoneNumber).indexOf(phoneNumberE164.substring(1)) <= 0) { defaultCountryIso = regionCode; } } catch (NumberParseException e) { |