summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2014-11-12 12:30:31 -0800
committerMatt Garnes <matt@cyngn.com>2014-11-12 12:30:31 -0800
commitf138ea681278980a1d37b67e99940eae6cad3cb3 (patch)
tree97099060d481dda88b8fefba5d28ec781298d803
parente4b2b7ef0304be52697591271730eaff8a2b8115 (diff)
downloadandroid_packages_apps_ContactsCommon-f138ea681278980a1d37b67e99940eae6cad3cb3.tar.gz
android_packages_apps_ContactsCommon-f138ea681278980a1d37b67e99940eae6cad3cb3.tar.bz2
android_packages_apps_ContactsCommon-f138ea681278980a1d37b67e99940eae6cad3cb3.zip
Add utility methods used by the call stats code
Change-Id: If000c0638af8b50654f2a3637e9a780759710502
-rw-r--r--src/com/android/contacts/common/CallUtil.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/com/android/contacts/common/CallUtil.java b/src/com/android/contacts/common/CallUtil.java
index 91f59938..9f3084da 100644
--- a/src/com/android/contacts/common/CallUtil.java
+++ b/src/com/android/contacts/common/CallUtil.java
@@ -24,6 +24,7 @@ import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
+import android.telephony.PhoneNumberUtils;
import com.android.contacts.common.util.PhoneNumberHelper;
import com.android.phone.common.PhoneConstants;
@@ -160,6 +161,46 @@ public class CallUtil {
/**
* Return Uri with an appropriate scheme, accepting both SIP and usual phone call
+ * 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.
*/
public static Uri getCallUri(String number) {