Prevent crash when killing Linphone while contacts fetch task is still running

This commit is contained in:
Sylvain Berfini 2016-07-22 18:07:13 +02:00
parent bc86d3886b
commit 3bb10f26a4
2 changed files with 14 additions and 1 deletions

View file

@ -55,6 +55,7 @@ public class ContactsManager extends ContentObserver {
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false; private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
private ContentResolver contentResolver; private ContentResolver contentResolver;
private Context context; private Context context;
private ContactsFetchTask contactsFetchTask;
private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners; private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners;
public static void addContactsListener(ContactsUpdatedListener listener) { public static void addContactsListener(ContactsUpdatedListener listener) {
@ -78,6 +79,13 @@ public class ContactsManager extends ContentObserver {
sipContacts = new ArrayList<LinphoneContact>(); sipContacts = new ArrayList<LinphoneContact>();
} }
public void destroy() {
if (contactsFetchTask != null && !contactsFetchTask.isCancelled()) {
contactsFetchTask.cancel(true);
}
instance = null;
}
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
onChange(selfChange, null); onChange(selfChange, null);
@ -213,7 +221,11 @@ public class ContactsManager extends ContentObserver {
} }
public synchronized void fetchContactsAsync() { public synchronized void fetchContactsAsync() {
new ContactsFetchTask().execute(); if (contactsFetchTask != null && !contactsFetchTask.isCancelled()) {
contactsFetchTask.cancel(true);
}
contactsFetchTask = new ContactsFetchTask();
contactsFetchTask.execute();
} }

View file

@ -805,6 +805,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
public static synchronized void destroy() { public static synchronized void destroy() {
if (instance == null) return; if (instance == null) return;
ContactsManager.getInstance().destroy();
getInstance().changeStatusToOffline(); getInstance().changeStatusToOffline();
sExited = true; sExited = true;
instance.doDestroy(); instance.doDestroy();