Added some securities/fixes to cursors

This commit is contained in:
Sylvain Berfini 2012-10-09 11:11:48 +02:00
parent 92b53bf73d
commit 83e5533557
3 changed files with 53 additions and 39 deletions

View file

@ -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);

View file

@ -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<Contact>();
sipContactList = new ArrayList<Contact>();
if (contactCursor != null && sipContactCursor != null) {
contactList = new ArrayList<Contact>();
sipContactList = new ArrayList<Contact>();
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());
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);
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) {

View file

@ -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;