Fixed contact lookup

This commit is contained in:
Sylvain Berfini 2016-03-23 15:30:05 +01:00
parent 3e9b5845de
commit 7160756af2
3 changed files with 20 additions and 13 deletions

View file

@ -24,7 +24,9 @@ import java.util.List;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import android.accounts.Account;
@ -166,9 +168,20 @@ public class ContactsManager extends ContentObserver {
String sipUri = address.asStringUriOnly();
String username = address.getUserName();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
LinphoneProxyConfig lpc = null;
if (lc != null) {
lpc = lc.getDefaultProxyConfig();
}
for (LinphoneContact c: getContacts()) {
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
String normalized = null;
if (lpc != null) {
normalized = lpc.normalizePhoneNumber(noa.getValue());
}
if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (normalized != null && !noa.isSIPAddress() && normalized.equals(username)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
return c;
}
}

View file

@ -501,7 +501,12 @@ public class LinphoneContact implements Serializable {
if (found) {
String number = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS)); // PHONE_NUMBER == SIP_ADDRESS == "data1"...
result.add(new LinphoneNumberOrAddress(number, isSIP));
if (number != null && number.length() > 0) {
if (isSIP && !number.startsWith("sip:")) {
number = "sip:" + number;
}
result.add(new LinphoneNumberOrAddress(number, isSIP));
}
}
}
}

View file

@ -39,7 +39,6 @@ import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State;
@ -51,11 +50,9 @@ import org.linphone.mediastream.Log;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
@ -458,13 +455,5 @@ public final class LinphoneUtils {
e.printStackTrace();
}
}
public static List<LinphoneContact> contactCursorToList(ContentResolver cr, Cursor cursor) {
ArrayList<LinphoneContact> list = new ArrayList<LinphoneContact>();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
list.add(Compatibility.getContact(cr, cursor, cursor.getPosition()));
}
return list;
}
}