Prevent crash when startService is called but service is already running

This commit is contained in:
Sylvain Berfini 2018-09-20 11:28:12 +02:00
parent d092fbbf0f
commit 045f9f50c3
4 changed files with 9 additions and 4 deletions

View file

@ -200,8 +200,7 @@
<service
android:name=".LinphoneService"
android:label="@string/service_name"
android:stopWithTask="false"/>
android:label="@string/service_name"/>
<service
android:name=".sync.SyncService"
android:exported="true">

View file

@ -995,9 +995,10 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
public static synchronized void destroy() {
if (instance == null) return;
getInstance().changeStatusToOffline();
instance.changeStatusToOffline();
sExited = true;
instance.destroyCore();
instance = null;
}
private String getString(int key) {

View file

@ -310,6 +310,11 @@ public final class LinphoneService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (instance != null) {
Log.w("Attempt to start the LinphoneService but it is already running !");
return START_REDELIVER_INTENT;
}
LinphoneManager.createAndStart(LinphoneService.this);
instance = this; // instance is ready once linphone manager has been created

View file

@ -39,7 +39,7 @@ public class BootReceiver extends BroadcastReceiver {
} else {
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
android.util.Log.i("LinphoneBootReceiver", "Device is starting, auto_start is " + autostart);
if (autostart) {
if (autostart && !LinphoneService.isReady()) {
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
lLinphoneServiceIntent.putExtra("ForceStartForeground", true);