diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-07-29 14:36:03 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-07-29 14:36:03 +0200 |
commit | 3bd81ef7baff1fdc95f0443c0f234864611500c0 (patch) | |
tree | 656b28faeb7622ab415b6e3440b714f1207084f0 | |
parent | 195eb0250eaffee9c928954313b128f057847ec0 (diff) | |
download | packages_apps_ContactsCommon-3bd81ef7baff1fdc95f0443c0f234864611500c0.tar.gz packages_apps_ContactsCommon-3bd81ef7baff1fdc95f0443c0f234864611500c0.tar.bz2 packages_apps_ContactsCommon-3bd81ef7baff1fdc95f0443c0f234864611500c0.zip |
Add utility methods used by the call stats code.
Change-Id: If000c0638af8b50654f2a3637e9a780759710502
-rw-r--r-- | src/com/android/contacts/common/CallUtil.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/com/android/contacts/common/CallUtil.java b/src/com/android/contacts/common/CallUtil.java index d61b700e..435e9868 100644 --- a/src/com/android/contacts/common/CallUtil.java +++ b/src/com/android/contacts/common/CallUtil.java @@ -81,6 +81,45 @@ public class CallUtil { } /** + * Checks whether two phone numbers resolve to the same phone. + */ + public static boolean phoneNumbersEqual(String number1, String number2) { + if (PhoneNumberUtils.isUriNumber(number1) || PhoneNumberUtils.isUriNumber(number2)) { + return sipAddressesEqual(number1, number2); + } else { + return PhoneNumberUtils.compare(number1, number2); + } + } + + private static boolean sipAddressesEqual(String number1, String number2) { + if (number1 == null || number2 == null) return number1 == number2; + + int index1 = number1.indexOf('@'); + final String userinfo1; + final String rest1; + if (index1 != -1) { + userinfo1 = number1.substring(0, index1); + rest1 = number1.substring(index1); + } else { + userinfo1 = number1; + rest1 = ""; + } + + int index2 = number2.indexOf('@'); + final String userinfo2; + final String rest2; + if (index2 != -1) { + userinfo2 = number2.substring(0, index2); + rest2 = number2.substring(index2); + } else { + userinfo2 = number2; + rest2 = ""; + } + + return userinfo1.equals(userinfo2) && rest1.equalsIgnoreCase(rest2); + } + + /** * Return Uri with an appropriate scheme, accepting Voicemail, SIP, and usual phone call * numbers. */ |