From 64e05133548f8621c96a7d5a491b5d0561e04372 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 10 Oct 2012 17:41:44 +0200 Subject: [PATCH] Fix some issues --- src/org/linphone/LinphoneActivity.java | 2 +- src/org/linphone/LinphoneUtils.java | 7 +++++-- src/org/linphone/compatibility/ApiFivePlus.java | 14 ++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 05315dea1..eb4a7e6d2 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -1041,7 +1041,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } } - private void prepareContactsInBackground() { + private synchronized void prepareContactsInBackground() { if (contactCursor != null) { contactCursor.close(); } diff --git a/src/org/linphone/LinphoneUtils.java b/src/org/linphone/LinphoneUtils.java index e64e5e905..e969de7fd 100644 --- a/src/org/linphone/LinphoneUtils.java +++ b/src/org/linphone/LinphoneUtils.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; import org.linphone.core.LinphoneAddress; @@ -69,12 +70,14 @@ public final class LinphoneUtils { public static boolean isSipAddress(String numberOrAddress) { Pattern p = Pattern.compile(sipAddressRegExp); - return p.matcher(numberOrAddress).matches(); + Matcher m = p.matcher(numberOrAddress); + return m != null && m.matches(); } public static boolean isStrictSipAddress(String numberOrAddress) { Pattern p = Pattern.compile(strictSipAddressRegExp); - return p.matcher(numberOrAddress).matches(); + Matcher m = p.matcher(numberOrAddress); + return m != null && m.matches(); } public static String getUsernameFromAddress(String address) { diff --git a/src/org/linphone/compatibility/ApiFivePlus.java b/src/org/linphone/compatibility/ApiFivePlus.java index 328292a72..0652d0b8c 100644 --- a/src/org/linphone/compatibility/ApiFivePlus.java +++ b/src/org/linphone/compatibility/ApiFivePlus.java @@ -302,17 +302,23 @@ public class ApiFivePlus { Contact contact = getContact(cr, cursor, 0); if (contact != null && contact.getNumerosOrAddresses().contains(sipUri)) { address.setDisplayName(contact.getName()); + cursor.close(); return contact.getPhotoUri(); } - + + cursor.close(); return null; } public static String refreshContactName(ContentResolver cr, String id) { - Cursor c = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false); - if (c != null && c.moveToFirst()) { - return getContactDisplayName(c); + Cursor cursor = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false); + if (cursor != null && cursor.moveToFirst()) { + String contactDisplayName = getContactDisplayName(cursor); + cursor.close(); + return contactDisplayName; } + + cursor.close(); return null; }