Trying to fix checkStateLoss crash + Stopping contacts fetch task if we stop linphone

This commit is contained in:
Erwan Croze 2017-01-11 10:43:55 +01:00
parent 49c98c9ebd
commit 81d0a0b21e
3 changed files with 43 additions and 15 deletions

View file

@ -157,7 +157,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
}
if (mCall == null) {
Log.e("Couldn't find outgoing call");
LinphoneActivity.instance().goToDialerFragment();
finish();
return;
}
@ -249,6 +248,8 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
finish();
}
private void checkAndRequestCallPermissions() {
ArrayList<String> permissionsList = new ArrayList<String>();

View file

@ -307,6 +307,11 @@ public class ContactsManager extends ContentObserver {
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
Date contactsTime = new Date();
//We need to check sometimes to know if Linphone was destroyed
if (this.isCancelled()) {
return null;
}
if (hasContactsAccess()) {
Cursor c = getContactsCursor(contentResolver);
if (c != null) {
@ -323,7 +328,10 @@ public class ContactsManager extends ContentObserver {
} else {
Log.w("[Permission] Read contacts permission wasn't granted, only fetch LinphoneFriends");
}
//We need to check sometimes to know if Linphone was destroyed
if (this.isCancelled()) {
return null;
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
for (LinphoneFriend friend : lc.getFriendList()) {
@ -361,6 +369,10 @@ public class ContactsManager extends ContentObserver {
int i = 0;
for (LinphoneContact contact : contacts) {
//We need to check sometimes to know if Linphone was destroyed
if (this.isCancelled()) {
return null;
}
// This will only get name & picture informations to be able to quickly display contacts list
contact.minimalRefresh();
i++;
@ -382,6 +394,10 @@ public class ContactsManager extends ContentObserver {
publishProgress(contacts);
for (LinphoneContact contact : contacts) {
//We need to check sometimes to know if Linphone was destroyed
if (this.isCancelled()) {
return null;
}
// This time fetch all informations including phone numbers and SIP addresses
contact.refresh();
}

View file

@ -671,7 +671,8 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
public synchronized final void destroyLinphoneCore() {
sExited = true;
BluetoothManager.getInstance().destroy();
ContactsManagerDestroy();
BluetoothManagerDestroy();
try {
mTimer.cancel();
mLc.destroy();
@ -936,7 +937,8 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void doDestroy() {
BluetoothManager.getInstance().destroy();
ContactsManagerDestroy();
BluetoothManagerDestroy();
try {
mTimer.cancel();
mLc.destroy();
@ -952,9 +954,18 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
}
}
public static void ContactsManagerDestroy() {
if (ContactsManager.getInstance() != null)
ContactsManager.getInstance().destroy();
}
public static void BluetoothManagerDestroy() {
if (BluetoothManager.getInstance() != null)
BluetoothManager.getInstance().destroy();
}
public static synchronized void destroy() {
if (instance == null) return;
ContactsManager.getInstance().destroy();
getInstance().changeStatusToOffline();
sExited = true;
instance.doDestroy();