Prevent crash when startService is called but service is already running
This commit is contained in:
parent
d092fbbf0f
commit
045f9f50c3
4 changed files with 9 additions and 4 deletions
|
@ -200,8 +200,7 @@
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".LinphoneService"
|
android:name=".LinphoneService"
|
||||||
android:label="@string/service_name"
|
android:label="@string/service_name"/>
|
||||||
android:stopWithTask="false"/>
|
|
||||||
<service
|
<service
|
||||||
android:name=".sync.SyncService"
|
android:name=".sync.SyncService"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|
|
@ -995,9 +995,10 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
|
|
||||||
public static synchronized void destroy() {
|
public static synchronized void destroy() {
|
||||||
if (instance == null) return;
|
if (instance == null) return;
|
||||||
getInstance().changeStatusToOffline();
|
instance.changeStatusToOffline();
|
||||||
sExited = true;
|
sExited = true;
|
||||||
instance.destroyCore();
|
instance.destroyCore();
|
||||||
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getString(int key) {
|
private String getString(int key) {
|
||||||
|
|
|
@ -310,6 +310,11 @@ public final class LinphoneService extends Service {
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
super.onStartCommand(intent, flags, 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);
|
LinphoneManager.createAndStart(LinphoneService.this);
|
||||||
|
|
||||||
instance = this; // instance is ready once linphone manager has been created
|
instance = this; // instance is ready once linphone manager has been created
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||||
} else {
|
} else {
|
||||||
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
|
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
|
||||||
android.util.Log.i("LinphoneBootReceiver", "Device is starting, auto_start is " + autostart);
|
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);
|
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
|
||||||
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
|
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
|
||||||
lLinphoneServiceIntent.putExtra("ForceStartForeground", true);
|
lLinphoneServiceIntent.putExtra("ForceStartForeground", true);
|
||||||
|
|
Loading…
Reference in a new issue