Skip to content
Snippets Groups Projects
Commit eebad40c authored by Alexandre Lision's avatar Alexandre Lision
Browse files

localservice: move contact observer to DRingService


System contacts changes must be listened to from DRingService since we
are getting rid of the LocalService

Tuleap: #1367
Reviewed-by: default avatarHadrien De Sousa <hadrien.desousa@savoirfairelinux.com>
Change-Id: Ica563a56eeddf0c504fbee34828f2894c6efca2c
parent 0b966f7a
No related branches found
No related tags found
No related merge requests found
......@@ -30,10 +30,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.util.Log;
import java.io.File;
......@@ -106,6 +108,8 @@ public class DRingService extends Service {
@Named("DaemonExecutor")
protected ExecutorService mExecutor;
private final ContactsContentObserver contactContentObserver = new ContactsContentObserver();
@Override
public void onCreate() {
Log.i(TAG, "onCreated");
......@@ -113,12 +117,15 @@ public class DRingService extends Service {
// dependency injection
((RingApplication) getApplication()).getRingInjectionComponent().inject(this);
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactContentObserver);
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
getContentResolver().unregisterContentObserver(contactContentObserver);
}
@Override
......@@ -628,4 +635,18 @@ public class DRingService extends Service {
break;
}
}
private class ContactsContentObserver extends ContentObserver {
ContactsContentObserver() {
super(null);
}
@Override
public void onChange(boolean selfChange, android.net.Uri uri) {
super.onChange(selfChange, uri);
Log.d(TAG, "ContactsContentObserver.onChange");
mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID());
}
}
}
......@@ -26,12 +26,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.util.Log;
import javax.inject.Inject;
......@@ -81,8 +79,6 @@ public class LocalService extends Service implements Observer<ServiceEvent> {
private IDRingService mService = null;
private final ContactsContentObserver contactContentObserver = new ContactsContentObserver();
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
......@@ -120,8 +116,6 @@ public class LocalService extends Service implements Observer<ServiceEvent> {
}
private void startDRingService() {
// start Listener
startListener();
Intent intent = new Intent(this, DRingService.class);
startService(intent);
bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT);
......@@ -135,7 +129,6 @@ public class LocalService extends Service implements Observer<ServiceEvent> {
mAccountService.removeObserver(this);
mContactService.removeObserver(this);
mConversationFacade.removeObserver(this);
stopListener();
}
private ServiceConnection mConnection = new ServiceConnection() {
......@@ -221,28 +214,6 @@ public class LocalService extends Service implements Observer<ServiceEvent> {
}
};
public void startListener() {
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactContentObserver);
}
private class ContactsContentObserver extends ContentObserver {
ContactsContentObserver() {
super(null);
}
@Override
public void onChange(boolean selfChange, android.net.Uri uri) {
super.onChange(selfChange, uri);
Log.d(TAG, "ContactsContentObserver.onChange");
refreshContacts();
}
}
public void stopListener() {
getContentResolver().unregisterContentObserver(contactContentObserver);
}
public void refreshContacts() {
Log.d(TAG, "refreshContacts");
mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment