diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 25bee187d..794df768e 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -18,7 +18,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -42,7 +41,6 @@ import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreListenerBase; import org.linphone.mediastream.Log; -import org.linphone.ui.AddressText; import android.Manifest; import android.annotation.SuppressLint; diff --git a/src/org/linphone/ContactsManager.java b/src/org/linphone/ContactsManager.java index 0ea30dc8a..c1a920868 100644 --- a/src/org/linphone/ContactsManager.java +++ b/src/org/linphone/ContactsManager.java @@ -31,6 +31,8 @@ import java.util.concurrent.TimeUnit; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCoreException; +import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneFriend; import org.linphone.core.LinphoneFriendImpl; import org.linphone.core.LinphoneProxyConfig; @@ -65,9 +67,7 @@ public class ContactsManager extends ContentObserver { private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false; private ContentResolver contentResolver; private Context context; - private HashMap contactsCache; private HashMap androidContactsCache; - private LinphoneContact contactNotFound; private Bitmap defaultAvatar; private static ArrayList contactsUpdatedListeners; @@ -88,8 +88,6 @@ public class ContactsManager extends ContentObserver { private ContactsManager(Handler handler) { super(handler); defaultAvatar = BitmapFactory.decodeResource(LinphoneService.instance().getResources(), R.drawable.avatar); - contactNotFound = new LinphoneContact(); - contactsCache = new HashMap(); androidContactsCache = new HashMap(); contactsUpdatedListeners = new ArrayList(); contacts = new ArrayList(); @@ -223,64 +221,34 @@ public class ContactsManager extends ContentObserver { public LinphoneContact findContactFromAddress(LinphoneAddress address) { String sipUri = address.asStringUriOnly(); - String username = address.getUserName(); - - LinphoneContact cache = contactsCache.get(sipUri); - if (cache != null) { - if (cache == contactNotFound) return null; - return cache; - } - LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); - LinphoneProxyConfig lpc = null; - if (lc != null) { - lpc = lc.getDefaultProxyConfig(); + LinphoneFriend lf = lc.findFriendByAddress(sipUri); + if (lf != null) { + LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData(); + return contact; } - - for (LinphoneContact c: getContacts()) { - for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) { - String normalized = null; - if (lpc != null) { - normalized = lpc.normalizePhoneNumber(noa.getValue()); - } - String alias = c.getPresenceModelForUri(noa.getValue()); - - if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (alias != null && alias.equals(sipUri)) || (normalized != null && !noa.isSIPAddress() && normalized.equals(username)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) { - contactsCache.put(sipUri, c); - return c; - } - } - } - contactsCache.put(sipUri, contactNotFound); return null; } public LinphoneContact findContactFromPhoneNumber(String phoneNumber) { - LinphoneContact cache = contactsCache.get(phoneNumber); - if (cache != null) { - if (cache == contactNotFound) return null; - return cache; - } - LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneProxyConfig lpc = null; if (lc != null) { lpc = lc.getDefaultProxyConfig(); } - - for (LinphoneContact c: getContacts()) { - for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) { - String normalized = null; - if (lpc != null) { - normalized = lpc.normalizePhoneNumber(noa.getValue()); - } - if (noa.getValue().equals(phoneNumber) || (normalized != null && normalized.equals(phoneNumber))) { - contactsCache.put(phoneNumber, c); - return c; - } - } + String normalized = lpc.normalizePhoneNumber(phoneNumber); + LinphoneAddress addr = null; + try { + addr = LinphoneCoreFactory.instance().createLinphoneAddress(normalized); + } catch (LinphoneCoreException e) { + return null; + } + + LinphoneFriend lf = lc.findFriendByAddress(addr.asStringUriOnly()); + if (lf != null) { + LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData(); + return contact; } - contactsCache.put(phoneNumber, contactNotFound); return null; } @@ -450,7 +418,6 @@ public class ContactsManager extends ContentObserver { Collections.sort(sipContacts); setContacts(contacts); setSipContacts(sipContacts); - contactsCache.clear(); LinphoneManager.getLc().getFriendLists()[0].updateSubscriptions(); for (ContactsUpdatedListener listener : contactsUpdatedListeners) {