diff --git a/src/org/linphone/DialerFragment.java b/src/org/linphone/DialerFragment.java index 858f7c816..ec0b2f2f1 100644 --- a/src/org/linphone/DialerFragment.java +++ b/src/org/linphone/DialerFragment.java @@ -145,6 +145,7 @@ public class DialerFragment extends Fragment { LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER); LinphoneActivity.instance().updateDialerFragment(this); } + mAddress.setText(""); resetLayout(isCallTransferOngoing); } @@ -167,7 +168,6 @@ public class DialerFragment extends Fragment { mAddContact.setImageResource(R.drawable.cancel); mAddContact.setOnClickListener(cancelListener); } else { - mAddress.setText(""); mCall.setImageResource(R.drawable.call); mAddContact.setEnabled(true); mAddContact.setImageResource(R.drawable.add_contact); diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 36aa56ad1..57b1ada8c 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -1042,33 +1042,42 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } private void prepareContactsInBackground() { + if (contactCursor != null) { + contactCursor.close(); + } + if (sipContactCursor != null) { + sipContactCursor.close(); + } + contactCursor = Compatibility.getContactsCursor(getContentResolver()); sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver()); - contactList = new ArrayList(); - sipContactList = new ArrayList(); - - Thread contactsHandler = new Thread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < contactCursor.getCount(); i++) { - Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i); - contact.refresh(getContentResolver()); - - for (String aon : contact.getNumerosOrAddresses()) { - if (LinphoneUtils.isSipAddress(aon)) { - if (!isContactPresenceDisabled) { - searchFriendAndAddToContact(contact); - } - if (!sipContactList.contains(contact)) { - sipContactList.add(contact); + if (contactCursor != null && sipContactCursor != null) { + contactList = new ArrayList(); + sipContactList = new ArrayList(); + + Thread contactsHandler = new Thread(new Runnable() { + @Override + public void run() { + for (int i = 0; i < contactCursor.getCount(); i++) { + Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i); + contact.refresh(getContentResolver()); + + for (String aon : contact.getNumerosOrAddresses()) { + if (LinphoneUtils.isSipAddress(aon)) { + if (!isContactPresenceDisabled) { + searchFriendAndAddToContact(contact); + } + if (!sipContactList.contains(contact)) { + sipContactList.add(contact); + } } } + contactList.add(contact); } - contactList.add(contact); } - } - }); - contactsHandler.start(); + }); + contactsHandler.start(); + } } private void initInCallMenuLayout(boolean callTransfer) { diff --git a/src/org/linphone/compatibility/ApiFivePlus.java b/src/org/linphone/compatibility/ApiFivePlus.java index 842f6edf1..328292a72 100644 --- a/src/org/linphone/compatibility/ApiFivePlus.java +++ b/src/org/linphone/compatibility/ApiFivePlus.java @@ -136,12 +136,13 @@ public class ApiFivePlus { .toString(); projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS}; Cursor c = cr.query(uri, projection, selection, new String[]{id}, null); - - int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS); - while (c.moveToNext()) { - list.add("sip:" + c.getString(nbId)); + if (c != null) { + int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS); + while (c.moveToNext()) { + list.add("sip:" + c.getString(nbId)); + } + c.close(); } - c.close(); } else { String selection = new StringBuilder() .append(Data.CONTACT_ID).append(" = ? AND ") @@ -152,21 +153,24 @@ public class ApiFivePlus { .append(") = 'sip'") .toString(); Cursor c = cr.query(uri, projection, selection, new String[]{id}, null); - - int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA); - while (c.moveToNext()) { - list.add("sip:" + c.getString(nbId)); + if (c != null) { + int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA); + while (c.moveToNext()) { + list.add("sip:" + c.getString(nbId)); + } + c.close(); } - c.close(); } // Phone Numbers Cursor c = cr.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER }, Phone.CONTACT_ID + " = " + id, null, null); - while (c.moveToNext()) { - String number = c.getString(c.getColumnIndex(Phone.NUMBER)); - list.add(number); - } - c.close(); + if (c != null) { + while (c.moveToNext()) { + String number = c.getString(c.getColumnIndex(Phone.NUMBER)); + list.add(number); + } + c.close(); + } return list; } @@ -220,7 +224,7 @@ public class ApiFivePlus { String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")"; Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, Data.DISPLAY_NAME + " ASC"); - if (!shouldGroupBy) { + if (!shouldGroupBy || cursor == null) { return cursor; } @@ -241,6 +245,7 @@ public class ApiFivePlus { result.addRow(newRow); } } + cursor.close(); return result; } @@ -305,7 +310,7 @@ public class ApiFivePlus { public static String refreshContactName(ContentResolver cr, String id) { Cursor c = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false); - if (c.moveToFirst()) { + if (c != null && c.moveToFirst()) { return getContactDisplayName(c); } return null;