From 483bebfe978903a00731c34d1915ca10f9ce80b1 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Sat, 6 May 2017 17:43:41 -0400 Subject: [PATCH] remove LocalService Tuleap: #1367 Change-Id: Ib31f7211ece23f18e2dc1553d807c7eca65bd593 --- ring-android/app/src/main/AndroidManifest.xml | 7 - .../cx/ring/application/RingApplication.java | 5 +- .../java/cx/ring/client/HomeActivity.java | 1 - .../RingInjectionComponent.java | 3 - .../java/cx/ring/fragments/CallFragment.java | 1 - .../java/cx/ring/service/BootReceiver.java | 2 +- .../java/cx/ring/service/DRingService.java | 105 ++++++--- .../java/cx/ring/service/LocalService.java | 203 ------------------ 8 files changed, 82 insertions(+), 245 deletions(-) delete mode 100644 ring-android/app/src/main/java/cx/ring/service/LocalService.java diff --git a/ring-android/app/src/main/AndroidManifest.xml b/ring-android/app/src/main/AndroidManifest.xml index d795f7a80..c025c4907 100644 --- a/ring-android/app/src/main/AndroidManifest.xml +++ b/ring-android/app/src/main/AndroidManifest.xml @@ -245,13 +245,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. android:theme="@style/zxing_CaptureTheme" android:windowSoftInputMode="stateAlwaysHidden" /> - <service - android:name=".service.LocalService" - android:exported="false"> - <intent-filter> - <action android:name=".service.LocalService" /> - </intent-filter> - </service> <service android:name=".service.DRingService" android:exported="false"> diff --git a/ring-android/app/src/main/java/cx/ring/application/RingApplication.java b/ring-android/app/src/main/java/cx/ring/application/RingApplication.java index 7f766b760..0b5ef6959 100644 --- a/ring-android/app/src/main/java/cx/ring/application/RingApplication.java +++ b/ring-android/app/src/main/java/cx/ring/application/RingApplication.java @@ -52,7 +52,7 @@ import cx.ring.dependencyinjection.RingInjectionModule; import cx.ring.dependencyinjection.ServiceInjectionModule; import cx.ring.service.CallManagerCallBack; import cx.ring.service.ConfigurationManagerCallback; -import cx.ring.service.LocalService; +import cx.ring.service.DRingService; import cx.ring.services.AccountService; import cx.ring.services.CallService; import cx.ring.services.ConferenceService; @@ -62,7 +62,6 @@ import cx.ring.services.DeviceRuntimeService; import cx.ring.services.HardwareService; import cx.ring.services.PreferencesService; import cx.ring.services.PresenceService; -import cx.ring.utils.FutureUtils; import cx.ring.utils.Log; public class RingApplication extends Application { @@ -267,7 +266,7 @@ public class RingApplication extends Application { mRingInjectionComponent.inject(this); // to bootstrap the daemon - Intent intent = new Intent(this, LocalService.class); + Intent intent = new Intent(this, DRingService.class); startService(intent); bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT); } diff --git a/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java b/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java index 7cecf4f02..4a4bccf47 100644 --- a/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java +++ b/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java @@ -72,7 +72,6 @@ import cx.ring.model.ServiceEvent; import cx.ring.model.Settings; import cx.ring.navigation.RingNavigationFragment; import cx.ring.service.DRingService; -import cx.ring.service.LocalService; import cx.ring.services.AccountService; import cx.ring.services.DeviceRuntimeService; import cx.ring.services.HardwareService; diff --git a/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java b/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java index 4a71a6180..67400e056 100755 --- a/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java +++ b/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java @@ -48,7 +48,6 @@ import cx.ring.navigation.RingNavigationFragment; import cx.ring.navigation.RingNavigationPresenter; import cx.ring.service.BootReceiver; import cx.ring.service.DRingService; -import cx.ring.service.LocalService; import cx.ring.services.AccountService; import cx.ring.services.CallService; import cx.ring.services.ConferenceService; @@ -113,8 +112,6 @@ public interface RingInjectionComponent { void inject(BlackListFragment fragment); - void inject(LocalService service); - void inject(DRingService service); void inject(DeviceRuntimeServiceImpl service); diff --git a/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java b/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java index b42eb0ac0..d58fa0771 100644 --- a/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java +++ b/ring-android/app/src/main/java/cx/ring/fragments/CallFragment.java @@ -67,7 +67,6 @@ import cx.ring.model.SipCall; import cx.ring.model.Uri; import cx.ring.mvp.BaseFragment; import cx.ring.service.DRingService; -import cx.ring.service.LocalService; import cx.ring.utils.ActionHelper; import cx.ring.utils.CircleTransform; import cx.ring.utils.ContentUriHandler; diff --git a/ring-android/app/src/main/java/cx/ring/service/BootReceiver.java b/ring-android/app/src/main/java/cx/ring/service/BootReceiver.java index b6a66cba3..36611ef82 100644 --- a/ring-android/app/src/main/java/cx/ring/service/BootReceiver.java +++ b/ring-android/app/src/main/java/cx/ring/service/BootReceiver.java @@ -29,7 +29,7 @@ public class BootReceiver extends BroadcastReceiver { if (isAllowRingOnStartup) { Log.w(TAG, "Starting Ring on boot"); - Intent serviceIntent = new Intent(context, LocalService.class); + Intent serviceIntent = new Intent(context, DRingService.class); context.startService(serviceIntent); } } diff --git a/ring-android/app/src/main/java/cx/ring/service/DRingService.java b/ring-android/app/src/main/java/cx/ring/service/DRingService.java index 4394219d6..bd3c32219 100644 --- a/ring-android/app/src/main/java/cx/ring/service/DRingService.java +++ b/ring-android/app/src/main/java/cx/ring/service/DRingService.java @@ -1,27 +1,27 @@ -/** - * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) - * Copyright (C) 2004-2016 Savoir-faire Linux Inc. - * <p> - * Author: Regis Montoya <r3gis.3R@gmail.com> - * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> - * Alexandre Lision <alexandre.lision@savoirfairelinux.com> - * Adrien Béraud <adrien.beraud@savoirfairelinux.com> - * <p> - * 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. - * 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 - * as an android library. - * <p> - * 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. - * <p> - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. +/* + Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) + Copyright (C) 2004-2016 Savoir-faire Linux Inc. + <p> + Author: Regis Montoya <r3gis.3R@gmail.com> + Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> + Alexandre Lision <alexandre.lision@savoirfairelinux.com> + Adrien Béraud <adrien.beraud@savoirfairelinux.com> + <p> + 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. + 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 + as an android library. + <p> + 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. + <p> + 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; @@ -30,11 +30,13 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.database.ContentObserver; import android.net.ConnectivityManager; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; +import android.preference.PreferenceManager; import android.provider.ContactsContract; import android.util.Log; @@ -54,6 +56,7 @@ import cx.ring.client.CallActivity; import cx.ring.facades.ConversationFacade; import cx.ring.model.Codec; import cx.ring.model.Conversation; +import cx.ring.model.ServiceEvent; import cx.ring.services.AccountService; import cx.ring.services.CallService; import cx.ring.services.ConferenceService; @@ -64,9 +67,10 @@ import cx.ring.services.HardwareService; import cx.ring.services.NotificationService; import cx.ring.services.NotificationServiceImpl; import cx.ring.services.PreferencesService; +import cx.ring.utils.Observable; +import cx.ring.utils.Observer; - -public class DRingService extends Service { +public class DRingService extends Service implements Observer<ServiceEvent> { 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"; @@ -127,6 +131,11 @@ public class DRingService extends Service { ((RingApplication) getApplication()).getRingInjectionComponent().inject(this); getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactContentObserver); + + mPreferencesService.addObserver(this); + mAccountService.addObserver(this); + mContactService.addObserver(this); + mConversationFacade.addObserver(this); } @Override @@ -134,6 +143,11 @@ public class DRingService extends Service { super.onDestroy(); unregisterReceiver(receiver); getContentResolver().unregisterContentObserver(contactContentObserver); + + mPreferencesService.removeObserver(this); + mAccountService.removeObserver(this); + mContactService.removeObserver(this); + mConversationFacade.removeObserver(this); } @Override @@ -665,4 +679,43 @@ public class DRingService extends Service { 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; + } + } + } } diff --git a/ring-android/app/src/main/java/cx/ring/service/LocalService.java b/ring-android/app/src/main/java/cx/ring/service/LocalService.java deleted file mode 100644 index 2cadceb17..000000000 --- a/ring-android/app/src/main/java/cx/ring/service/LocalService.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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 -- GitLab