From 8c6b34303e9962b92c1541e4c20268645aef405a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 28 Jul 2016 16:43:00 +0200 Subject: [PATCH] This should prevent contactFetcherTask to run when LinphoneService is not running --- src/org/linphone/ContactsManager.java | 53 ++++++++++++++------------- src/org/linphone/LinphoneService.java | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/org/linphone/ContactsManager.java b/src/org/linphone/ContactsManager.java index d28183ce9..4cbcdd7eb 100644 --- a/src/org/linphone/ContactsManager.java +++ b/src/org/linphone/ContactsManager.java @@ -247,34 +247,37 @@ public class ContactsManager extends ContentObserver { } } - for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) { - String refkey = friend.getRefKey(); - if (refkey != null) { - boolean found = false; - for (LinphoneContact contact : contacts) { - if (refkey.equals(contact.getAndroidId())) { - // Native matching contact found, link the friend to it - contact.setFriend(friend); - found = true; - break; + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + for (LinphoneFriend friend : lc.getFriendList()) { + String refkey = friend.getRefKey(); + if (refkey != null) { + boolean found = false; + for (LinphoneContact contact : contacts) { + if (refkey.equals(contact.getAndroidId())) { + // Native matching contact found, link the friend to it + contact.setFriend(friend); + found = true; + break; + } } - } - if (!found) { - if (hasContactAccess) { - // If refkey != null and hasContactAccess but there isn't a native contact with this value, then this contact has been deleted. Let's do the same with the LinphoneFriend - LinphoneManager.getLc().removeFriend(friend); - } else { - // Refkey not null but no contact access => can't link it to native contact so display it on is own - LinphoneContact contact = new LinphoneContact(); - contact.setFriend(friend); - contacts.add(contact); + if (!found) { + if (hasContactAccess) { + // If refkey != null and hasContactAccess but there isn't a native contact with this value, then this contact has been deleted. Let's do the same with the LinphoneFriend + lc.removeFriend(friend); + } else { + // Refkey not null but no contact access => can't link it to native contact so display it on is own + LinphoneContact contact = new LinphoneContact(); + contact.setFriend(friend); + contacts.add(contact); + } } + } else { + // No refkey so it's a standalone contact + LinphoneContact contact = new LinphoneContact(); + contact.setFriend(friend); + contacts.add(contact); } - } else { - // No refkey so it's a standalone contact - LinphoneContact contact = new LinphoneContact(); - contact.setFriend(friend); - contacts.add(contact); } } diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 46c5fd742..402e29fde 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -622,6 +622,7 @@ public final class LinphoneService extends Service { } instance = null; + getContentResolver().unregisterContentObserver(ContactsManager.getInstance()); LinphoneManager.destroy(); // Make sure our notification is gone. @@ -630,7 +631,6 @@ public final class LinphoneService extends Service { mNM.cancel(MESSAGE_NOTIF_ID); ((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAlivePendingIntent); - getContentResolver().unregisterContentObserver(ContactsManager.getInstance()); super.onDestroy(); }