Loading telephony/java/android/telephony/PhoneNumberUtils.java +82 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony; import android.util.SparseArray; import com.android.i18n.phonenumbers.NumberParseException; import com.android.i18n.phonenumbers.PhoneNumberUtil; import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; Loading Loading @@ -143,6 +144,54 @@ public class PhoneNumberUtils return !isDialable(ch) && !(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')); } /** * On some CDMA networks +COUNTRYCODE must be rewritten to 0 when making a local * call from within the user's home network. We maintain a white list of * (country code prefix) -> (rewrite rule) to perform this substitution. * * Since country codes are variable length it is easiest to compile a regex */ private static SparseArray<RewriteRule> sCdmaLocalRewriteWhitelist; private static Pattern sCdmaLocalRewritePattern; static { sCdmaLocalRewriteWhitelist = new SparseArray<RewriteRule>(); addRewriteRule(62, "IN", "0"); // indonesia StringBuffer regex = new StringBuffer(); regex.append("[+]("); for (int i=0; i < sCdmaLocalRewriteWhitelist.size(); ++i) { int countryCode = sCdmaLocalRewriteWhitelist.keyAt(i); if (i > 0) { regex.append("|"); } regex.append(countryCode); } regex.append(")"); sCdmaLocalRewritePattern = Pattern.compile(regex.toString()); } private static class RewriteRule { public int countryCodePrefix; public String isoCountryCode; public String replacement; public RewriteRule(int countryCodePrefix, String isoCountryCode, String replacement) { this.countryCodePrefix = countryCodePrefix; this.isoCountryCode = isoCountryCode; this.replacement = replacement; } public String apply(String dialStr) { return dialStr.replaceFirst("[+]" + countryCodePrefix, replacement); } } private static void addRewriteRule(int countryCodePrefix, String isoCountryCode, String replacement) { sCdmaLocalRewriteWhitelist.put(countryCodePrefix, new RewriteRule(countryCodePrefix, isoCountryCode, replacement)); } /** Extracts the phone number from an Intent. * * @param intent the intent to get the number of Loading Loading @@ -2459,6 +2508,29 @@ public class PhoneNumberUtils return retVal; } /** * Returns a rewrite rule for the country code prefix if the dial string matches the * whitelist and the user is in their home network * * @param dialStr number being dialed * @param currIso ISO code of currently attached network * @param defaultIso ISO code of user's sim * @return RewriteRule or null if conditions fail */ private static RewriteRule getCdmaLocalRewriteRule(String dialStr, String currIso, String defaultIso) { Matcher m = sCdmaLocalRewritePattern.matcher(dialStr); if (m.find()) { String dialPrefix = m.group(1); RewriteRule rule = sCdmaLocalRewriteWhitelist.get(Integer.valueOf(dialPrefix)); if (currIso.equalsIgnoreCase(defaultIso) && currIso.equalsIgnoreCase(rule.isoCountryCode)) { return rule; } } return null; } /** * Determines if the specified number is actually a URI * (i.e. a SIP address) rather than a regular PSTN phone number, Loading Loading @@ -2521,11 +2593,19 @@ public class PhoneNumberUtils if (useNanp && isOneNanp(newStr)) { // Remove the leading plus sign retStr = newStr; } else { RewriteRule rewriteRule = getCdmaLocalRewriteRule(networkDialStr, SystemProperties.get(PROPERTY_OPERATOR_ISO_COUNTRY, ""), SystemProperties.get(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, "")); if (rewriteRule != null) { retStr = rewriteRule.apply(networkDialStr); } else { // Replaces the plus sign with the default IDP retStr = networkDialStr.replaceFirst("[+]", getCurrentIdp(useNanp)); } } } if (DBG) log("processPlusCode, retStr=" + retStr); return retStr; } Loading Loading
telephony/java/android/telephony/PhoneNumberUtils.java +82 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony; import android.util.SparseArray; import com.android.i18n.phonenumbers.NumberParseException; import com.android.i18n.phonenumbers.PhoneNumberUtil; import com.android.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; Loading Loading @@ -143,6 +144,54 @@ public class PhoneNumberUtils return !isDialable(ch) && !(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')); } /** * On some CDMA networks +COUNTRYCODE must be rewritten to 0 when making a local * call from within the user's home network. We maintain a white list of * (country code prefix) -> (rewrite rule) to perform this substitution. * * Since country codes are variable length it is easiest to compile a regex */ private static SparseArray<RewriteRule> sCdmaLocalRewriteWhitelist; private static Pattern sCdmaLocalRewritePattern; static { sCdmaLocalRewriteWhitelist = new SparseArray<RewriteRule>(); addRewriteRule(62, "IN", "0"); // indonesia StringBuffer regex = new StringBuffer(); regex.append("[+]("); for (int i=0; i < sCdmaLocalRewriteWhitelist.size(); ++i) { int countryCode = sCdmaLocalRewriteWhitelist.keyAt(i); if (i > 0) { regex.append("|"); } regex.append(countryCode); } regex.append(")"); sCdmaLocalRewritePattern = Pattern.compile(regex.toString()); } private static class RewriteRule { public int countryCodePrefix; public String isoCountryCode; public String replacement; public RewriteRule(int countryCodePrefix, String isoCountryCode, String replacement) { this.countryCodePrefix = countryCodePrefix; this.isoCountryCode = isoCountryCode; this.replacement = replacement; } public String apply(String dialStr) { return dialStr.replaceFirst("[+]" + countryCodePrefix, replacement); } } private static void addRewriteRule(int countryCodePrefix, String isoCountryCode, String replacement) { sCdmaLocalRewriteWhitelist.put(countryCodePrefix, new RewriteRule(countryCodePrefix, isoCountryCode, replacement)); } /** Extracts the phone number from an Intent. * * @param intent the intent to get the number of Loading Loading @@ -2459,6 +2508,29 @@ public class PhoneNumberUtils return retVal; } /** * Returns a rewrite rule for the country code prefix if the dial string matches the * whitelist and the user is in their home network * * @param dialStr number being dialed * @param currIso ISO code of currently attached network * @param defaultIso ISO code of user's sim * @return RewriteRule or null if conditions fail */ private static RewriteRule getCdmaLocalRewriteRule(String dialStr, String currIso, String defaultIso) { Matcher m = sCdmaLocalRewritePattern.matcher(dialStr); if (m.find()) { String dialPrefix = m.group(1); RewriteRule rule = sCdmaLocalRewriteWhitelist.get(Integer.valueOf(dialPrefix)); if (currIso.equalsIgnoreCase(defaultIso) && currIso.equalsIgnoreCase(rule.isoCountryCode)) { return rule; } } return null; } /** * Determines if the specified number is actually a URI * (i.e. a SIP address) rather than a regular PSTN phone number, Loading Loading @@ -2521,11 +2593,19 @@ public class PhoneNumberUtils if (useNanp && isOneNanp(newStr)) { // Remove the leading plus sign retStr = newStr; } else { RewriteRule rewriteRule = getCdmaLocalRewriteRule(networkDialStr, SystemProperties.get(PROPERTY_OPERATOR_ISO_COUNTRY, ""), SystemProperties.get(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, "")); if (rewriteRule != null) { retStr = rewriteRule.apply(networkDialStr); } else { // Replaces the plus sign with the default IDP retStr = networkDialStr.replaceFirst("[+]", getCurrentIdp(useNanp)); } } } if (DBG) log("processPlusCode, retStr=" + retStr); return retStr; } Loading