Added more logs in AsyncContactsLoader
This commit is contained in:
parent
e2e7888292
commit
fdfb66e10c
3 changed files with 50 additions and 21 deletions
|
@ -211,9 +211,9 @@ public final class LinphoneService extends Service {
|
||||||
ContactsContract.Contacts.CONTENT_URI, true, mContactsManager);
|
ContactsContract.Contacts.CONTENT_URI, true, mContactsManager);
|
||||||
}
|
}
|
||||||
if (mContactsManager.hasReadContactsAccess()) {
|
if (mContactsManager.hasReadContactsAccess()) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
mContactsManager.enableContactsAccess();
|
||||||
}
|
}
|
||||||
ContactsManager.getInstance().initializeContactManager();
|
mContactsManager.initializeContactManager();
|
||||||
|
|
||||||
Compatibility.createChatShortcuts(this);
|
Compatibility.createChatShortcuts(this);
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,11 @@ import android.database.Cursor;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.LinphoneService;
|
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.Friend;
|
import org.linphone.core.Friend;
|
||||||
|
@ -53,15 +53,17 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
"data4", // Normalized phone number
|
"data4", // Normalized phone number
|
||||||
};
|
};
|
||||||
|
|
||||||
public AsyncContactsLoader() {}
|
private Context mContext;
|
||||||
|
|
||||||
|
public AsyncContactsLoader(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
Log.i("[Contacts Manager] Synchronization started");
|
Log.i("[Contacts Manager] Synchronization started");
|
||||||
Context context = LinphoneService.instance().getApplicationContext();
|
|
||||||
|
|
||||||
if (LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) {
|
if (LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) {
|
||||||
String rls = context.getString(R.string.rls_uri);
|
String rls = mContext.getString(R.string.rls_uri);
|
||||||
for (FriendList list : LinphoneManager.getCore().getFriendsLists()) {
|
for (FriendList list : LinphoneManager.getCore().getFriendsLists()) {
|
||||||
if (list.getRlsAddress() == null
|
if (list.getRlsAddress() == null
|
||||||
|| !list.getRlsAddress().asStringUriOnly().equals(rls)) {
|
|| !list.getRlsAddress().asStringUriOnly().equals(rls)) {
|
||||||
|
@ -75,9 +77,8 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
@Override
|
@Override
|
||||||
protected AsyncContactsData doInBackground(Void... params) {
|
protected AsyncContactsData doInBackground(Void... params) {
|
||||||
Log.i("[Contacts Manager] Background synchronization started");
|
Log.i("[Contacts Manager] Background synchronization started");
|
||||||
Context context = LinphoneService.instance().getApplicationContext();
|
|
||||||
Cursor c =
|
Cursor c =
|
||||||
context.getContentResolver()
|
mContext.getContentResolver()
|
||||||
.query(
|
.query(
|
||||||
ContactsContract.Data.CONTENT_URI,
|
ContactsContract.Data.CONTENT_URI,
|
||||||
PROJECTION,
|
PROJECTION,
|
||||||
|
@ -91,9 +92,14 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
|
|
||||||
Core core = LinphoneManager.getCore();
|
Core core = LinphoneManager.getCore();
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
for (FriendList list : core.getFriendsLists()) {
|
FriendList[] friendLists = core.getFriendsLists();
|
||||||
for (Friend friend : list.getFriends()) {
|
for (FriendList list : friendLists) {
|
||||||
if (isCancelled()) return data;
|
Friend[] friends = list.getFriends();
|
||||||
|
for (Friend friend : friends) {
|
||||||
|
if (isCancelled()) {
|
||||||
|
Log.w("[Contacts Manager] Task cancelled");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
LinphoneContact contact = (LinphoneContact) friend.getUserData();
|
LinphoneContact contact = (LinphoneContact) friend.getUserData();
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
|
@ -121,8 +127,12 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
Log.i("[Contacts Manager] Found " + c.getCount() + " entries in cursor");
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
if (isCancelled()) return data;
|
if (isCancelled()) {
|
||||||
|
Log.w("[Contacts Manager] Task cancelled");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
String id = c.getString(c.getColumnIndex(ContactsContract.Data.CONTACT_ID));
|
String id = c.getString(c.getColumnIndex(ContactsContract.Data.CONTACT_ID));
|
||||||
boolean starred =
|
boolean starred =
|
||||||
|
@ -141,14 +151,20 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
}
|
}
|
||||||
c.close();
|
c.close();
|
||||||
|
|
||||||
for (FriendList list : core.getFriendsLists()) {
|
FriendList[] friendLists = core.getFriendsLists();
|
||||||
for (Friend friend : list.getFriends()) {
|
for (FriendList list : friendLists) {
|
||||||
if (isCancelled()) return data;
|
Friend[] friends = list.getFriends();
|
||||||
|
for (Friend friend : friends) {
|
||||||
|
if (isCancelled()) {
|
||||||
|
Log.w("[Contacts Manager] Task cancelled");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
LinphoneContact contact = (LinphoneContact) friend.getUserData();
|
LinphoneContact contact = (LinphoneContact) friend.getUserData();
|
||||||
if (contact != null && contact.isAndroidContact()) {
|
if (contact != null && contact.isAndroidContact()) {
|
||||||
String id = contact.getAndroidId();
|
String id = contact.getAndroidId();
|
||||||
if (id != null && !nativeIds.contains(id)) {
|
if (id != null && !nativeIds.contains(id)) {
|
||||||
|
Log.i("[Contacts Manager] Contact removed since last fetch: " + id);
|
||||||
// Has been removed since last fetch
|
// Has been removed since last fetch
|
||||||
androidContactsCache.remove(id);
|
androidContactsCache.remove(id);
|
||||||
}
|
}
|
||||||
|
@ -158,8 +174,13 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
nativeIds.clear();
|
nativeIds.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LinphoneContact contact : androidContactsCache.values()) {
|
Collection<LinphoneContact> contacts = androidContactsCache.values();
|
||||||
if (isCancelled()) return data;
|
Log.i("[Contacts Manager] Found " + contacts.size() + " contacts");
|
||||||
|
for (LinphoneContact contact : contacts) {
|
||||||
|
if (isCancelled()) {
|
||||||
|
Log.w("[Contacts Manager] Task cancelled");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
if (contact.getFullName() == null) {
|
if (contact.getFullName() == null) {
|
||||||
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||||
|
@ -185,7 +206,7 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.getResources().getBoolean(R.bool.hide_sip_contacts_without_presence)) {
|
if (!mContext.getResources().getBoolean(R.bool.hide_sip_contacts_without_presence)) {
|
||||||
if (contact.hasAddress() && !data.sipContacts.contains(contact)) {
|
if (contact.hasAddress() && !data.sipContacts.contains(contact)) {
|
||||||
data.sipContacts.add(contact);
|
data.sipContacts.add(contact);
|
||||||
}
|
}
|
||||||
|
@ -204,6 +225,12 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(AsyncContactsData data) {
|
protected void onPostExecute(AsyncContactsData data) {
|
||||||
|
Log.i(
|
||||||
|
"[Contacts Manager] "
|
||||||
|
+ data.contacts.size()
|
||||||
|
+ " contacts found in which "
|
||||||
|
+ data.sipContacts.size()
|
||||||
|
+ " are SIP");
|
||||||
for (LinphoneContact contact : data.contacts) {
|
for (LinphoneContact contact : data.contacts) {
|
||||||
contact.createOrUpdateFriendFromNativeContact();
|
contact.createOrUpdateFriendFromNativeContact();
|
||||||
}
|
}
|
||||||
|
@ -211,7 +238,9 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
// Now that contact fetching is asynchronous, this is required to ensure
|
// Now that contact fetching is asynchronous, this is required to ensure
|
||||||
// presence subscription event will be sent with all friends
|
// presence subscription event will be sent with all friends
|
||||||
if (LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) {
|
if (LinphonePreferences.instance().isFriendlistsubscriptionEnabled()) {
|
||||||
for (FriendList list : LinphoneManager.getCore().getFriendsLists()) {
|
Log.i("[Contacts Manager] Matching friends created, updating subscription");
|
||||||
|
FriendList[] friendLists = LinphoneManager.getCore().getFriendsLists();
|
||||||
|
for (FriendList list : friendLists) {
|
||||||
list.updateSubscriptions();
|
list.updateSubscriptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
Log.w("[Contacts Manager] Can't fetch contact without READ permission");
|
Log.w("[Contacts Manager] Can't fetch contact without READ permission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mLoadContactTask = new AsyncContactsLoader();
|
mLoadContactTask = new AsyncContactsLoader(mContext);
|
||||||
mContactsFetchedOnce = true;
|
mContactsFetchedOnce = true;
|
||||||
mLoadContactTask.executeOnExecutor(THREAD_POOL_EXECUTOR);
|
mLoadContactTask.executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue