Fixed dual logger + force network reachability and background mode on Core when starting because of a push

This commit is contained in:
Sylvain Berfini 2019-02-27 10:14:15 +01:00
parent e653ce2fe7
commit ef5c88a109
3 changed files with 15 additions and 13 deletions

View file

@ -232,7 +232,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
mMediaScanner = new MediaScanner(c);
}
public static synchronized void createAndStart(Context c) {
public static synchronized void createAndStart(Context c, boolean isPush) {
if (sInstance != null) {
Log.e(
"[Manager] Linphone Manager is already initialized ! Destroying it and creating a new one...");
@ -240,7 +240,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
}
sInstance = new LinphoneManager(c);
sInstance.startLibLinphone(c);
sInstance.startLibLinphone(c, isPush);
sInstance.initOpenH264DownloadHelper();
// H264 codec Management - set to auto mode -> MediaCodec >= android 5.0 >= OpenH264
@ -686,16 +686,22 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
public void restartCore() {
destroyCore();
startLibLinphone(mServiceContext);
startLibLinphone(mServiceContext, false);
sExited = false;
}
private synchronized void startLibLinphone(Context c) {
private synchronized void startLibLinphone(Context c, boolean isPush) {
try {
copyAssetsFromPackage();
// traces alway start with traces enable to not missed first initialization
mCore = Factory.instance().createCore(configFile, mLinphoneFactoryConfigFile, c);
mCore.addListener(this);
if (isPush) {
Log.w(
"[Manager] We are here because of a received push notification, force network reachability and enter background mode before starting the Core");
mCore.setNetworkReachable(true);
mCore.enterBackground();
}
mCore.start();
TimerTask lTask =
new TimerTask() {

View file

@ -177,8 +177,10 @@ public final class LinphoneService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
boolean isPush = false;
if (intent.getBooleanExtra("PushNotification", false)) {
Log.i("[Service] [Push Notification] LinphoneService started because of a push");
isPush = true;
}
if (sInstance != null) {
@ -186,7 +188,7 @@ public final class LinphoneService extends Service {
return START_REDELIVER_INTENT;
}
LinphoneManager.createAndStart(this);
LinphoneManager.createAndStart(this, isPush);
sInstance = this; // sInstance is ready once linphone manager has been created
mNotificationManager = new NotificationsManager(this);

View file

@ -27,11 +27,8 @@ import android.content.Intent;
import android.os.SystemClock;
import org.linphone.LinphoneManager;
import org.linphone.LinphoneService;
import org.linphone.R;
import org.linphone.core.Core;
import org.linphone.core.tools.Log;
import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.LinphoneUtils;
/*
* Purpose of this receiver is to disable keep alives when screen is off
@ -40,9 +37,6 @@ public class KeepAliveReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (LinphoneService.isReady()) {
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
LinphoneUtils.configureLoggingService(
isDebugEnabled, context.getString(R.string.app_name));
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null) return;