Skip to content

Commit adff0ad

Browse files
Babis TriantafyllouJohan Redestig
authored andcommitted
Makes PhoneNumberUtils support international numbers after a CLIR command.
Makes PhoneNumberUtils.java support numbers in international format (starting with ‘+’ character) after a CLIR command. Previously a plus character would always be removed unless it occupied the first position of the number string. In this case, when the number is preceded by #31# (CLIR), the plus character will be removed as well. This is an error, prohibiting a type approval of the phone. This change will detect the plus character after the CLIR command and will insert it at the right position. Change-Id: Ib220aee7b3eda30cde960db8c7470523dc5fd313
1 parent 2594066 commit adff0ad

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

telephony/java/android/telephony/PhoneNumberUtils.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public class PhoneNumberUtils
5454
public static final char WAIT = ';';
5555
public static final char WILD = 'N';
5656

57+
/*
58+
* Calling Line Identification Restriction (CLIR)
59+
*/
60+
private static final String CLIR_ON = "*31#+";
61+
private static final String CLIR_OFF = "#31#+";
62+
5763
/*
5864
* TOA = TON + NPI
5965
* See TS 24.008 section 10.5.4.7 for details.
@@ -179,8 +185,6 @@ public static String getNumberFromIntent(Intent intent, Context context) {
179185
* Please note that the GSM wild character is allowed in the result.
180186
* This must be resolved before dialing.
181187
*
182-
* Allows + only in the first position in the result string.
183-
*
184188
* Returns null if phoneNumber == null
185189
*/
186190
public static String
@@ -203,6 +207,11 @@ public static String getNumberFromIntent(Intent intent, Context context) {
203207
}
204208
}
205209

210+
int pos = addPlusChar(phoneNumber);
211+
if (pos >= 0 && ret.length() > pos) {
212+
ret.insert(pos, '+');
213+
}
214+
206215
return ret.toString();
207216
}
208217

@@ -304,6 +313,28 @@ private static void log(String msg) {
304313
}
305314
}
306315

316+
/** GSM codes
317+
* Finds if a GSM code includes the international prefix (+).
318+
*
319+
* @param number the number to dial.
320+
*
321+
* @return the position where the + char will be inserted, -1 if the GSM code was not found.
322+
*/
323+
private static int
324+
addPlusChar(String number) {
325+
int pos = -1;
326+
327+
if (number.startsWith(CLIR_OFF)) {
328+
pos = CLIR_OFF.length() - 1;
329+
}
330+
331+
if (number.startsWith(CLIR_ON)) {
332+
pos = CLIR_ON.length() - 1;
333+
}
334+
335+
return pos;
336+
}
337+
307338
/**
308339
* Extracts the post-dial sequence of DTMF control digits, pauses, and
309340
* waits. Strips separators. This string may be empty, but will not be null

0 commit comments

Comments
 (0)