Fixed ANR because of presence check in async task
This commit is contained in:
parent
265b000758
commit
de7a2877c8
3 changed files with 36 additions and 30 deletions
|
@ -24,9 +24,11 @@ import android.os.AsyncTask;
|
||||||
public class AsyncContactPresence extends AsyncTask<Void, AndroidContact, Void> {
|
public class AsyncContactPresence extends AsyncTask<Void, AndroidContact, Void> {
|
||||||
|
|
||||||
private LinphoneContact mLinphoneContact;
|
private LinphoneContact mLinphoneContact;
|
||||||
|
private String mAlias;
|
||||||
|
|
||||||
public AsyncContactPresence(LinphoneContact linphoneContact) {
|
public AsyncContactPresence(LinphoneContact linphoneContact, String alias) {
|
||||||
mLinphoneContact = linphoneContact;
|
mLinphoneContact = linphoneContact;
|
||||||
|
mAlias = alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,7 +38,7 @@ public class AsyncContactPresence extends AsyncTask<Void, AndroidContact, Void>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
mLinphoneContact.updateNativeContactWithPresenceInfo();
|
mLinphoneContact.addPresenceInfoToNativeContact(mAlias);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ import org.linphone.core.Friend;
|
||||||
import org.linphone.core.FriendList;
|
import org.linphone.core.FriendList;
|
||||||
import org.linphone.core.FriendListListener;
|
import org.linphone.core.FriendListListener;
|
||||||
import org.linphone.core.MagicSearch;
|
import org.linphone.core.MagicSearch;
|
||||||
|
import org.linphone.core.PresenceBasicStatus;
|
||||||
|
import org.linphone.core.PresenceModel;
|
||||||
import org.linphone.core.ProxyConfig;
|
import org.linphone.core.ProxyConfig;
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
|
@ -485,14 +487,33 @@ public class ContactsManager extends ContentObserver
|
||||||
.getApplicationContext()
|
.getApplicationContext()
|
||||||
.getResources()
|
.getResources()
|
||||||
.getBoolean(R.bool.use_linphone_tag)) {
|
.getBoolean(R.bool.use_linphone_tag)) {
|
||||||
// Inserting Linphone information in Android contact if the parameter is enabled
|
|
||||||
if (LinphonePreferences.instance()
|
if (LinphonePreferences.instance()
|
||||||
.isPresenceStorageInNativeAndroidContactEnabled()) {
|
.isPresenceStorageInNativeAndroidContactEnabled()) {
|
||||||
// add presence to native contact
|
// Inserting information in Android contact if the parameter is enabled
|
||||||
AsyncContactPresence asyncContactPresence = new AsyncContactPresence(contact);
|
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||||
|
if (noa.isSIPAddress()) {
|
||||||
|
// We are only interested in phone numbers
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String value = noa.getValue();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test presence of the value
|
||||||
|
PresenceModel pm = contact.getFriend().getPresenceModelForUriOrTel(value);
|
||||||
|
// If presence is not null
|
||||||
|
if (pm != null
|
||||||
|
&& pm.getBasicStatus() != null
|
||||||
|
&& pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
|
||||||
|
// Add presence to native contact
|
||||||
|
AsyncContactPresence asyncContactPresence =
|
||||||
|
new AsyncContactPresence(contact, value);
|
||||||
asyncContactPresence.execute();
|
asyncContactPresence.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!mSipContacts.contains(contact)) {
|
if (!mSipContacts.contains(contact)) {
|
||||||
mSipContacts.add(contact);
|
mSipContacts.add(contact);
|
||||||
|
|
|
@ -618,35 +618,18 @@ public class LinphoneContact extends AndroidContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateNativeContactWithPresenceInfo() {
|
public synchronized void addPresenceInfoToNativeContact(String value) {
|
||||||
Log.d("[Contact] Trying to update native contact with presence information");
|
Log.d(
|
||||||
|
"[Contact] Trying to update native contact with presence information for phone number ",
|
||||||
|
value);
|
||||||
|
|
||||||
// Creation of the raw contact with the presence information (tablet)
|
// Creation of the raw contact with the presence information (tablet)
|
||||||
createRawLinphoneContactFromExistingAndroidContactIfNeeded();
|
createRawLinphoneContactFromExistingAndroidContactIfNeeded();
|
||||||
|
|
||||||
for (LinphoneNumberOrAddress noa : getNumbersOrAddresses()) {
|
|
||||||
if (noa.isSIPAddress()) {
|
|
||||||
// We are only interested in SIP addresses
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String value = noa.getValue();
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test presence of the value
|
|
||||||
PresenceModel pm = getFriend().getPresenceModelForUriOrTel(value);
|
|
||||||
// If presence is not null
|
|
||||||
if (pm != null
|
|
||||||
&& pm.getBasicStatus() != null
|
|
||||||
&& pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
|
|
||||||
Log.d("[Contact] Found presence information for phone number " + value);
|
|
||||||
if (!isLinphoneAddressMimeEntryAlreadyExisting(value)) {
|
if (!isLinphoneAddressMimeEntryAlreadyExisting(value)) {
|
||||||
// Do the action on the contact only once if it has not been done yet
|
// Do the action on the contact only once if it has not been done yet
|
||||||
updateNativeContactWithPresenceInfo(value);
|
updateNativeContactWithPresenceInfo(value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
saveChangesCommited();
|
saveChangesCommited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue