From e333c82da35119cfa25109328c3db98fa84f965e Mon Sep 17 00:00:00 2001 From: Jake Hamby Date: Fri, 13 Jan 2012 13:14:39 -0800 Subject: Convert Arabic phone numbers to ASCII when sending SMS. Modify PhoneNumberUtils to automatically convert non-ASCII digits, such as Arabic-Indic numbers, CJK full-width digits, etc., to ASCII in normalizeNumber(), extractNetworkPortion(), and stripSeparators(). This enables the SMS application to support sending SMS's to phone numbers written with Arabic, or other non-ASCII digits. The number will be converted to ASCII digits and formatted for the user according to the country formatting rules. Bug: 5615791 Change-Id: I42039285db5795b1dda22e4251f54af302e27f13 Signed-off-by: Jake Hamby --- .../java/android/telephony/PhoneNumberUtils.java | 57 +++++++++------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'telephony/java/android') diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 8cfdb794c03d..1d451353d16a 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -64,8 +64,8 @@ public class PhoneNumberUtils /* * Calling Line Identification Restriction (CLIR) */ - private static final String CLIR_ON = "*31#+"; - private static final String CLIR_OFF = "#31#+"; + private static final String CLIR_ON = "*31#"; + private static final String CLIR_OFF = "#31#"; /* * TOA = TON + NPI @@ -213,23 +213,26 @@ public class PhoneNumberUtils int len = phoneNumber.length(); StringBuilder ret = new StringBuilder(len); - boolean firstCharAdded = false; for (int i = 0; i < len; i++) { char c = phoneNumber.charAt(i); - if (isDialable(c) && (c != '+' || !firstCharAdded)) { - firstCharAdded = true; + // Character.digit() supports ASCII and Unicode digits (fullwidth, Arabic-Indic, etc.) + int digit = Character.digit(c, 10); + if (digit != -1) { + ret.append(digit); + } else if (c == '+') { + // Allow '+' as first character or after CLIR MMI prefix + String prefix = ret.toString(); + if (prefix.length() == 0 || prefix.equals(CLIR_ON) || prefix.equals(CLIR_OFF)) { + ret.append(c); + } + } else if (isDialable(c)) { ret.append(c); } else if (isStartsPostDial (c)) { break; } } - int pos = addPlusChar(phoneNumber); - if (pos >= 0 && ret.length() > pos) { - ret.insert(pos, '+'); - } - return ret.toString(); } @@ -283,7 +286,11 @@ public class PhoneNumberUtils for (int i = 0; i < len; i++) { char c = phoneNumber.charAt(i); - if (isNonSeparator(c)) { + // Character.digit() supports ASCII and Unicode digits (fullwidth, Arabic-Indic, etc.) + int digit = Character.digit(c, 10); + if (digit != -1) { + ret.append(digit); + } else if (isNonSeparator(c)) { ret.append(c); } } @@ -371,28 +378,6 @@ public class PhoneNumberUtils } } - /** GSM codes - * Finds if a GSM code includes the international prefix (+). - * - * @param number the number to dial. - * - * @return the position where the + char will be inserted, -1 if the GSM code was not found. - */ - private static int - addPlusChar(String number) { - int pos = -1; - - if (number.startsWith(CLIR_OFF)) { - pos = CLIR_OFF.length() - 1; - } - - if (number.startsWith(CLIR_ON)) { - pos = CLIR_ON.length() - 1; - } - - return pos; - } - /** * Extracts the post-dial sequence of DTMF control digits, pauses, and * waits. Strips separators. This string may be empty, but will not be null @@ -1504,7 +1489,11 @@ public class PhoneNumberUtils int len = phoneNumber.length(); for (int i = 0; i < len; i++) { char c = phoneNumber.charAt(i); - if ((i == 0 && c == '+') || PhoneNumberUtils.isISODigit(c)) { + // Character.digit() supports ASCII and Unicode digits (fullwidth, Arabic-Indic, etc.) + int digit = Character.digit(c, 10); + if (digit != -1) { + sb.append(digit); + } else if (i == 0 && c == '+') { sb.append(c); } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { return normalizeNumber(PhoneNumberUtils.convertKeypadLettersToDigits(phoneNumber)); -- cgit v1.2.3-59-g8ed1b