summaryrefslogtreecommitdiff
path: root/telephony/java/android
diff options
context:
space:
mode:
author Jake Hamby <jhamby@google.com> 2012-01-13 13:14:39 -0800
committer Jake Hamby <jhamby@google.com> 2012-04-16 15:06:40 -0700
commite333c82da35119cfa25109328c3db98fa84f965e (patch)
tree0ba163773a2b6b101de187ba828b7bdef0deab46 /telephony/java/android
parent70544533aec6b318ff1687c9eec0cb9e86ce1b1a (diff)
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 <jhamby@google.com>
Diffstat (limited to 'telephony/java/android')
-rw-r--r--telephony/java/android/telephony/PhoneNumberUtils.java57
1 files changed, 23 insertions, 34 deletions
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));