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

remove LocalService

Tuleap: #1367
Change-Id: Ib31f7211ece23f18e2dc1553d807c7eca65bd593
parent 4592e84b
Branches
Tags
No related merge requests found
...@@ -245,13 +245,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -245,13 +245,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:theme="@style/zxing_CaptureTheme" android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden" /> android:windowSoftInputMode="stateAlwaysHidden" />
<service
android:name=".service.LocalService"
android:exported="false">
<intent-filter>
<action android:name=".service.LocalService" />
</intent-filter>
</service>
<service <service
android:name=".service.DRingService" android:name=".service.DRingService"
android:exported="false"> android:exported="false">
......
...@@ -52,7 +52,7 @@ import cx.ring.dependencyinjection.RingInjectionModule; ...@@ -52,7 +52,7 @@ import cx.ring.dependencyinjection.RingInjectionModule;
import cx.ring.dependencyinjection.ServiceInjectionModule; import cx.ring.dependencyinjection.ServiceInjectionModule;
import cx.ring.service.CallManagerCallBack; import cx.ring.service.CallManagerCallBack;
import cx.ring.service.ConfigurationManagerCallback; import cx.ring.service.ConfigurationManagerCallback;
import cx.ring.service.LocalService; import cx.ring.service.DRingService;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.CallService; import cx.ring.services.CallService;
import cx.ring.services.ConferenceService; import cx.ring.services.ConferenceService;
...@@ -62,7 +62,6 @@ import cx.ring.services.DeviceRuntimeService; ...@@ -62,7 +62,6 @@ import cx.ring.services.DeviceRuntimeService;
import cx.ring.services.HardwareService; import cx.ring.services.HardwareService;
import cx.ring.services.PreferencesService; import cx.ring.services.PreferencesService;
import cx.ring.services.PresenceService; import cx.ring.services.PresenceService;
import cx.ring.utils.FutureUtils;
import cx.ring.utils.Log; import cx.ring.utils.Log;
public class RingApplication extends Application { public class RingApplication extends Application {
...@@ -267,7 +266,7 @@ public class RingApplication extends Application { ...@@ -267,7 +266,7 @@ public class RingApplication extends Application {
mRingInjectionComponent.inject(this); mRingInjectionComponent.inject(this);
// to bootstrap the daemon // to bootstrap the daemon
Intent intent = new Intent(this, LocalService.class); Intent intent = new Intent(this, DRingService.class);
startService(intent); startService(intent);
bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT); bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT);
} }
......
...@@ -72,7 +72,6 @@ import cx.ring.model.ServiceEvent; ...@@ -72,7 +72,6 @@ import cx.ring.model.ServiceEvent;
import cx.ring.model.Settings; import cx.ring.model.Settings;
import cx.ring.navigation.RingNavigationFragment; import cx.ring.navigation.RingNavigationFragment;
import cx.ring.service.DRingService; import cx.ring.service.DRingService;
import cx.ring.service.LocalService;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.DeviceRuntimeService; import cx.ring.services.DeviceRuntimeService;
import cx.ring.services.HardwareService; import cx.ring.services.HardwareService;
......
...@@ -48,7 +48,6 @@ import cx.ring.navigation.RingNavigationFragment; ...@@ -48,7 +48,6 @@ import cx.ring.navigation.RingNavigationFragment;
import cx.ring.navigation.RingNavigationPresenter; import cx.ring.navigation.RingNavigationPresenter;
import cx.ring.service.BootReceiver; import cx.ring.service.BootReceiver;
import cx.ring.service.DRingService; import cx.ring.service.DRingService;
import cx.ring.service.LocalService;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.CallService; import cx.ring.services.CallService;
import cx.ring.services.ConferenceService; import cx.ring.services.ConferenceService;
...@@ -113,8 +112,6 @@ public interface RingInjectionComponent { ...@@ -113,8 +112,6 @@ public interface RingInjectionComponent {
void inject(BlackListFragment fragment); void inject(BlackListFragment fragment);
void inject(LocalService service);
void inject(DRingService service); void inject(DRingService service);
void inject(DeviceRuntimeServiceImpl service); void inject(DeviceRuntimeServiceImpl service);
......
...@@ -67,7 +67,6 @@ import cx.ring.model.SipCall; ...@@ -67,7 +67,6 @@ import cx.ring.model.SipCall;
import cx.ring.model.Uri; import cx.ring.model.Uri;
import cx.ring.mvp.BaseFragment; import cx.ring.mvp.BaseFragment;
import cx.ring.service.DRingService; import cx.ring.service.DRingService;
import cx.ring.service.LocalService;
import cx.ring.utils.ActionHelper; import cx.ring.utils.ActionHelper;
import cx.ring.utils.CircleTransform; import cx.ring.utils.CircleTransform;
import cx.ring.utils.ContentUriHandler; import cx.ring.utils.ContentUriHandler;
......
...@@ -29,7 +29,7 @@ public class BootReceiver extends BroadcastReceiver { ...@@ -29,7 +29,7 @@ public class BootReceiver extends BroadcastReceiver {
if (isAllowRingOnStartup) { if (isAllowRingOnStartup) {
Log.w(TAG, "Starting Ring on boot"); Log.w(TAG, "Starting Ring on boot");
Intent serviceIntent = new Intent(context, LocalService.class); Intent serviceIntent = new Intent(context, DRingService.class);
context.startService(serviceIntent); context.startService(serviceIntent);
} }
} }
......
/** /*
* Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr)
* Copyright (C) 2004-2016 Savoir-faire Linux Inc. Copyright (C) 2004-2016 Savoir-faire Linux Inc.
* <p> <p>
* Author: Regis Montoya <r3gis.3R@gmail.com> Author: Regis Montoya <r3gis.3R@gmail.com>
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
* Alexandre Lision <alexandre.lision@savoirfairelinux.com> Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Adrien Béraud <adrien.beraud@savoirfairelinux.com> Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* <p> <p>
* This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. (at your option) any later version.
* If you own a pjsip commercial license you can also redistribute it If you own a pjsip commercial license you can also redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License and/or modify it under the terms of the GNU Lesser General Public License
* as an android library. as an android library.
* <p> <p>
* This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. GNU General Public License for more details.
* <p> <p>
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package cx.ring.service; package cx.ring.service;
...@@ -30,11 +30,13 @@ import android.content.BroadcastReceiver; ...@@ -30,11 +30,13 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.util.Log; import android.util.Log;
...@@ -54,6 +56,7 @@ import cx.ring.client.CallActivity; ...@@ -54,6 +56,7 @@ import cx.ring.client.CallActivity;
import cx.ring.facades.ConversationFacade; import cx.ring.facades.ConversationFacade;
import cx.ring.model.Codec; import cx.ring.model.Codec;
import cx.ring.model.Conversation; import cx.ring.model.Conversation;
import cx.ring.model.ServiceEvent;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.CallService; import cx.ring.services.CallService;
import cx.ring.services.ConferenceService; import cx.ring.services.ConferenceService;
...@@ -64,9 +67,10 @@ import cx.ring.services.HardwareService; ...@@ -64,9 +67,10 @@ import cx.ring.services.HardwareService;
import cx.ring.services.NotificationService; import cx.ring.services.NotificationService;
import cx.ring.services.NotificationServiceImpl; import cx.ring.services.NotificationServiceImpl;
import cx.ring.services.PreferencesService; import cx.ring.services.PreferencesService;
import cx.ring.utils.Observable;
import cx.ring.utils.Observer;
public class DRingService extends Service implements Observer<ServiceEvent> {
public class DRingService extends Service {
public static final String ACTION_TRUST_REQUEST_ACCEPT = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_ACCEPT"; public static final String ACTION_TRUST_REQUEST_ACCEPT = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_ACCEPT";
public static final String ACTION_TRUST_REQUEST_REFUSE = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_REFUSE"; public static final String ACTION_TRUST_REQUEST_REFUSE = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_REFUSE";
...@@ -127,6 +131,11 @@ public class DRingService extends Service { ...@@ -127,6 +131,11 @@ public class DRingService extends Service {
((RingApplication) getApplication()).getRingInjectionComponent().inject(this); ((RingApplication) getApplication()).getRingInjectionComponent().inject(this);
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactContentObserver); getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactContentObserver);
mPreferencesService.addObserver(this);
mAccountService.addObserver(this);
mContactService.addObserver(this);
mConversationFacade.addObserver(this);
} }
@Override @Override
...@@ -134,6 +143,11 @@ public class DRingService extends Service { ...@@ -134,6 +143,11 @@ public class DRingService extends Service {
super.onDestroy(); super.onDestroy();
unregisterReceiver(receiver); unregisterReceiver(receiver);
getContentResolver().unregisterContentObserver(contactContentObserver); getContentResolver().unregisterContentObserver(contactContentObserver);
mPreferencesService.removeObserver(this);
mAccountService.removeObserver(this);
mContactService.removeObserver(this);
mConversationFacade.removeObserver(this);
} }
@Override @Override
...@@ -665,4 +679,43 @@ public class DRingService extends Service { ...@@ -665,4 +679,43 @@ public class DRingService extends Service {
mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID()); mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID());
} }
} }
public void refreshContacts() {
Log.d(TAG, "refreshContacts");
mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID());
}
@Override
public void update(Observable observable, ServiceEvent arg) {
if (observable instanceof PreferencesService) {
refreshContacts();
updateConnectivityState();
}
if (observable instanceof AccountService && arg != null) {
switch (arg.getEventType()) {
case ACCOUNTS_CHANGED:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(DRingService.this);
sharedPreferences.edit()
.putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_RINGACCOUNT, mAccountService.hasRingAccount())
.putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_SIPACCOUNT, mAccountService.hasSipAccount()).apply();
refreshContacts();
return;
}
}
if (observable instanceof ContactService && arg != null) {
switch (arg.getEventType()) {
case CONTACTS_CHANGED:
mConversationFacade.refreshConversations();
return;
case CONTACT_ADDED:
case CONTACT_REMOVED:
refreshContacts();
break;
}
}
}
} }
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cx.ring.service;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.util.Log;
import javax.inject.Inject;
import cx.ring.application.RingApplication;
import cx.ring.facades.ConversationFacade;
import cx.ring.model.ServiceEvent;
import cx.ring.services.AccountService;
import cx.ring.services.ContactService;
import cx.ring.services.DeviceRuntimeService;
import cx.ring.services.NotificationService;
import cx.ring.services.PreferencesService;
import cx.ring.utils.Observable;
import cx.ring.utils.Observer;
public class LocalService extends Service implements Observer<ServiceEvent> {
static final String TAG = LocalService.class.getSimpleName();
@Inject
PreferencesService mPreferencesService;
@Inject
AccountService mAccountService;
@Inject
ContactService mContactService;
@Inject
NotificationService mNotificationService;
@Inject
ConversationFacade mConversationFacade;
@Inject
DeviceRuntimeService mDeviceRuntimeService;
private IDRingService mService = null;
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate");
// dependency injection
((RingApplication) getApplication()).getRingInjectionComponent().inject(this);
// todo
// temporary listen for history modifications
// When MVP/DI injection will be done, only the concerned presenters should listen
// for model modifications
mPreferencesService.addObserver(this);
mAccountService.addObserver(this);
mContactService.addObserver(this);
mConversationFacade.addObserver(this);
// Clear any notifications from a previous app instance
mNotificationService.cancelAll();
startDRingService();
}
private void startDRingService() {
Intent intent = new Intent(this, DRingService.class);
startService(intent);
bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e(TAG, "onDestroy");
mPreferencesService.removeObserver(this);
mAccountService.removeObserver(this);
mContactService.removeObserver(this);
mConversationFacade.removeObserver(this);
}
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Log.w(TAG, "onServiceConnected " + className.getClassName());
mService = IDRingService.Stub.asInterface(service);
mConversationFacade.refreshConversations();
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
Log.d(TAG, "onServiceDisconnected " + arg0.getClassName());
mService = null;
}
};
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
*/
public class LocalBinder extends Binder {
public LocalService getService() {
// Return this instance of LocalService so clients can call public methods
return LocalService.this;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public boolean onUnbind(Intent intent) {
Log.d(TAG, "onUnbind");
if (mConnection != null) {
unbindService(mConnection);
mConnection = null;
}
return super.onUnbind(intent);
}
private void updateConnectivityState() {
if (mService == null) {
return;
}
try {
mService.setAccountsActive(mPreferencesService.isConnectedWifiAndMobile());
mService.connectivityChanged();
} catch (RemoteException e) {
Log.e(TAG, "updateConnectivityState", e);
}
}
public void refreshContacts() {
Log.d(TAG, "refreshContacts");
mContactService.loadContacts(mAccountService.hasRingAccount(), mAccountService.hasSipAccount(), mAccountService.getCurrentAccount().getAccountID());
}
@Override
public void update(Observable observable, ServiceEvent arg) {
if (observable instanceof PreferencesService) {
refreshContacts();
updateConnectivityState();
}
if (observable instanceof AccountService && arg != null) {
switch (arg.getEventType()) {
case ACCOUNTS_CHANGED:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LocalService.this);
sharedPreferences.edit()
.putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_RINGACCOUNT, mAccountService.hasRingAccount())
.putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_SIPACCOUNT, mAccountService.hasSipAccount()).apply();
refreshContacts();
return;
}
}
if (observable instanceof ContactService && arg != null) {
switch (arg.getEventType()) {
case CONTACTS_CHANGED:
mConversationFacade.refreshConversations();
return;
case CONTACT_ADDED:
case CONTACT_REMOVED:
refreshContacts();
return;
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment