Merge "Fix a crash caused by SIP addresses containing "%40" instead of "@"" into ics-mr1
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java
index 56a0a2c..07afe30 100644
--- a/telephony/java/android/telephony/PhoneNumberUtils.java
+++ b/telephony/java/android/telephony/PhoneNumberUtils.java
@@ -2118,6 +2118,31 @@
}
/**
+ * @return the "username" part of the specified SIP address,
+ * i.e. the part before the "@" character (or "%40").
+ *
+ * @param number SIP address of the form "username@domainname"
+ * (or the URI-escaped equivalent "username%40domainname")
+ * @see isUriNumber
+ *
+ * @hide
+ */
+ public static String getUsernameFromUriNumber(String number) {
+ // The delimiter between username and domain name can be
+ // either "@" or "%40" (the URI-escaped equivalent.)
+ int delimiterIndex = number.indexOf('@');
+ if (delimiterIndex < 0) {
+ delimiterIndex = number.indexOf("%40");
+ }
+ if (delimiterIndex < 0) {
+ Log.w(LOG_TAG,
+ "getUsernameFromUriNumber: no delimiter found in SIP addr '" + number + "'");
+ delimiterIndex = number.length();
+ }
+ return number.substring(0, delimiterIndex);
+ }
+
+ /**
* This function handles the plus code conversion within NANP CDMA network
* If the number format is
* 1)+1NANP,remove +,
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index 6324550..5d1f758 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -288,7 +288,7 @@
String number, CallerInfo previousResult) {
if (!previousResult.contactExists
&& PhoneNumberUtils.isUriNumber(number)) {
- String username = number.substring(0, number.indexOf('@'));
+ String username = PhoneNumberUtils.getUsernameFromUriNumber(number);
if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
previousResult = getCallerInfo(context,
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,