Added logs & fixed some issues in contact removal

This commit is contained in:
Sylvain Berfini 2019-11-19 16:06:38 +01:00
parent 4fd25bb1b0
commit 53a748409d
4 changed files with 23 additions and 8 deletions

View file

@ -146,6 +146,7 @@ class AndroidContact implements Serializable {
}
void deleteAndroidContact() {
Log.i("[Contact] Deleting Android contact ", this);
ContactsManager.getInstance().delete(mAndroidId);
}

View file

@ -95,14 +95,13 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
}
LinphoneContact contact = (LinphoneContact) friend.getUserData();
// A previously fetched friend from rc file will have a user data,
// so the next fetches won't add it in data.contacts
// and thus the "new friends" count in log will be different /!\
if (contact != null) {
if (contact.getAndroidId() != null) {
contact.clearAddresses();
androidContactsCache.put(contact.getAndroidId(), contact);
nativeIds.add(contact.getAndroidId());
} else {
data.contacts.add(contact);
}
} else {
if (friend.getRefKey() != null) {
@ -198,7 +197,7 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
+ contacts.size()
+ " native contacts plus "
+ data.contacts.size()
+ " new friends in the configuration file");
+ " friends in the configuration file");
for (LinphoneContact contact : contacts) {
if (isCancelled()) {
Log.w("[Contacts Manager] Task cancelled");

View file

@ -495,6 +495,7 @@ public class ContactsManager extends ContentObserver
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (String id : ids) {
Log.i("[Contacts Manager] Adding Android contact id ", id, " to batch removal");
String[] args = new String[] {id};
ops.add(
ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)

View file

@ -401,12 +401,23 @@ public class LinphoneContact extends AndroidContact
}
public void deleteFriend() {
if (mFriend == null) return;
Core core = LinphoneManager.getCore();
if (mFriend != null && core != null) {
for (FriendList list : core.getFriendsLists()) {
list.removeFriend(mFriend);
if (core == null) return;
boolean found = false;
Log.i("[Contact] Deleting friend ", mFriend.getName(), " for contact ", this);
for (FriendList list : core.getFriendsLists()) {
FriendList.Status status = list.removeFriend(mFriend);
if (status == FriendList.Status.OK) {
Log.w("[Contact] Friend found in list " + list.getDisplayName());
found = true;
}
}
if (!found) {
Log.w("[Contact] Friend removal failed, friend doesn't belong to any friend list");
}
}
public void createOrUpdateFriendFromNativeContact() {
@ -645,7 +656,10 @@ public class LinphoneContact extends AndroidContact
}
public void delete() {
deleteAndroidContact();
Log.i("[Contact] Deleting contact ", this);
if (isAndroidContact()) {
deleteAndroidContact();
}
if (isFriend()) {
deleteFriend();
}