Added some securities/fixes to cursors
This commit is contained in:
parent
92b53bf73d
commit
83e5533557
3 changed files with 53 additions and 39 deletions
|
@ -145,6 +145,7 @@ public class DialerFragment extends Fragment {
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER);
|
||||||
LinphoneActivity.instance().updateDialerFragment(this);
|
LinphoneActivity.instance().updateDialerFragment(this);
|
||||||
}
|
}
|
||||||
|
mAddress.setText("");
|
||||||
resetLayout(isCallTransferOngoing);
|
resetLayout(isCallTransferOngoing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +168,6 @@ public class DialerFragment extends Fragment {
|
||||||
mAddContact.setImageResource(R.drawable.cancel);
|
mAddContact.setImageResource(R.drawable.cancel);
|
||||||
mAddContact.setOnClickListener(cancelListener);
|
mAddContact.setOnClickListener(cancelListener);
|
||||||
} else {
|
} else {
|
||||||
mAddress.setText("");
|
|
||||||
mCall.setImageResource(R.drawable.call);
|
mCall.setImageResource(R.drawable.call);
|
||||||
mAddContact.setEnabled(true);
|
mAddContact.setEnabled(true);
|
||||||
mAddContact.setImageResource(R.drawable.add_contact);
|
mAddContact.setImageResource(R.drawable.add_contact);
|
||||||
|
|
|
@ -1042,33 +1042,42 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareContactsInBackground() {
|
private void prepareContactsInBackground() {
|
||||||
|
if (contactCursor != null) {
|
||||||
|
contactCursor.close();
|
||||||
|
}
|
||||||
|
if (sipContactCursor != null) {
|
||||||
|
sipContactCursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
contactCursor = Compatibility.getContactsCursor(getContentResolver());
|
contactCursor = Compatibility.getContactsCursor(getContentResolver());
|
||||||
sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver());
|
sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver());
|
||||||
contactList = new ArrayList<Contact>();
|
if (contactCursor != null && sipContactCursor != null) {
|
||||||
sipContactList = new ArrayList<Contact>();
|
contactList = new ArrayList<Contact>();
|
||||||
|
sipContactList = new ArrayList<Contact>();
|
||||||
|
|
||||||
Thread contactsHandler = new Thread(new Runnable() {
|
Thread contactsHandler = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (int i = 0; i < contactCursor.getCount(); i++) {
|
for (int i = 0; i < contactCursor.getCount(); i++) {
|
||||||
Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i);
|
Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i);
|
||||||
contact.refresh(getContentResolver());
|
contact.refresh(getContentResolver());
|
||||||
|
|
||||||
for (String aon : contact.getNumerosOrAddresses()) {
|
for (String aon : contact.getNumerosOrAddresses()) {
|
||||||
if (LinphoneUtils.isSipAddress(aon)) {
|
if (LinphoneUtils.isSipAddress(aon)) {
|
||||||
if (!isContactPresenceDisabled) {
|
if (!isContactPresenceDisabled) {
|
||||||
searchFriendAndAddToContact(contact);
|
searchFriendAndAddToContact(contact);
|
||||||
}
|
}
|
||||||
if (!sipContactList.contains(contact)) {
|
if (!sipContactList.contains(contact)) {
|
||||||
sipContactList.add(contact);
|
sipContactList.add(contact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
contactList.add(contact);
|
||||||
}
|
}
|
||||||
contactList.add(contact);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
contactsHandler.start();
|
||||||
contactsHandler.start();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initInCallMenuLayout(boolean callTransfer) {
|
private void initInCallMenuLayout(boolean callTransfer) {
|
||||||
|
|
|
@ -136,12 +136,13 @@ public class ApiFivePlus {
|
||||||
.toString();
|
.toString();
|
||||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
||||||
Cursor c = cr.query(uri, projection, selection, new String[]{id}, null);
|
Cursor c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||||
|
if (c != null) {
|
||||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
list.add("sip:" + c.getString(nbId));
|
list.add("sip:" + c.getString(nbId));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
}
|
}
|
||||||
c.close();
|
|
||||||
} else {
|
} else {
|
||||||
String selection = new StringBuilder()
|
String selection = new StringBuilder()
|
||||||
.append(Data.CONTACT_ID).append(" = ? AND ")
|
.append(Data.CONTACT_ID).append(" = ? AND ")
|
||||||
|
@ -152,21 +153,24 @@ public class ApiFivePlus {
|
||||||
.append(") = 'sip'")
|
.append(") = 'sip'")
|
||||||
.toString();
|
.toString();
|
||||||
Cursor c = cr.query(uri, projection, selection, new String[]{id}, null);
|
Cursor c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||||
|
if (c != null) {
|
||||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
|
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
list.add("sip:" + c.getString(nbId));
|
list.add("sip:" + c.getString(nbId));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
}
|
}
|
||||||
c.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phone Numbers
|
// Phone Numbers
|
||||||
Cursor c = cr.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER }, Phone.CONTACT_ID + " = " + id, null, null);
|
Cursor c = cr.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER }, Phone.CONTACT_ID + " = " + id, null, null);
|
||||||
while (c.moveToNext()) {
|
if (c != null) {
|
||||||
String number = c.getString(c.getColumnIndex(Phone.NUMBER));
|
while (c.moveToNext()) {
|
||||||
list.add(number);
|
String number = c.getString(c.getColumnIndex(Phone.NUMBER));
|
||||||
}
|
list.add(number);
|
||||||
c.close();
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +224,7 @@ public class ApiFivePlus {
|
||||||
String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";
|
String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";
|
||||||
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, Data.DISPLAY_NAME + " ASC");
|
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, Data.DISPLAY_NAME + " ASC");
|
||||||
|
|
||||||
if (!shouldGroupBy) {
|
if (!shouldGroupBy || cursor == null) {
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +245,7 @@ public class ApiFivePlus {
|
||||||
result.addRow(newRow);
|
result.addRow(newRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +310,7 @@ public class ApiFivePlus {
|
||||||
|
|
||||||
public static String refreshContactName(ContentResolver cr, String id) {
|
public static String refreshContactName(ContentResolver cr, String id) {
|
||||||
Cursor c = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false);
|
Cursor c = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false);
|
||||||
if (c.moveToFirst()) {
|
if (c != null && c.moveToFirst()) {
|
||||||
return getContactDisplayName(c);
|
return getContactDisplayName(c);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue