From 158f116eb7fdc23a12d6822d34a549f33605bc8c Mon Sep 17 00:00:00 2001 From: David Brown Date: Wed, 16 Nov 2011 22:10:56 -0800 Subject: [PATCH] Fix a crash caused by SIP addresses containing "%40" instead of "@" CallerInfo.doSecondaryLookupIfNecessary() was assuming that SIP addresses would always contain the character '@', but that's not always true since the username/domainname delimiter can actually be "%40" (the URI-escaped equivalent.) This would cause the in-call UI to crash if you ever called a SIP address like "xyz%40example.com". TESTED: - Make an outgoing call to the SIP address "xyz%40example.com" ==> The call ultimately fails, but the in-call UI no longer crashes when it first comes up. Bug: 5637074 Change-Id: I62d15a7ccd509924d38b780b92e657b9efa26125 --- .../android/telephony/PhoneNumberUtils.java | 25 +++++++++++++++++++ .../internal/telephony/CallerInfo.java | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 56a0a2c050221..07afe3077ff2b 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -2117,6 +2117,31 @@ public class PhoneNumberUtils return number != null && (number.contains("@") || number.contains("%40")); } + /** + * @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 diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java index 6324550cc1df7..5d1f7588a5848 100644 --- a/telephony/java/com/android/internal/telephony/CallerInfo.java +++ b/telephony/java/com/android/internal/telephony/CallerInfo.java @@ -288,7 +288,7 @@ public class CallerInfo { 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,