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); mMediaScanner = new MediaScanner(c);
} }
public static synchronized void createAndStart(Context c) { public static synchronized void createAndStart(Context c, boolean isPush) {
if (sInstance != null) { if (sInstance != null) {
Log.e( Log.e(
"[Manager] Linphone Manager is already initialized ! Destroying it and creating a new one..."); "[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 = new LinphoneManager(c);
sInstance.startLibLinphone(c); sInstance.startLibLinphone(c, isPush);
sInstance.initOpenH264DownloadHelper(); sInstance.initOpenH264DownloadHelper();
// H264 codec Management - set to auto mode -> MediaCodec >= android 5.0 >= OpenH264 // 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() { public void restartCore() {
destroyCore(); destroyCore();
startLibLinphone(mServiceContext); startLibLinphone(mServiceContext, false);
sExited = false; sExited = false;
} }
private synchronized void startLibLinphone(Context c) { private synchronized void startLibLinphone(Context c, boolean isPush) {
try { try {
copyAssetsFromPackage(); copyAssetsFromPackage();
// traces alway start with traces enable to not missed first initialization // traces alway start with traces enable to not missed first initialization
mCore = Factory.instance().createCore(configFile, mLinphoneFactoryConfigFile, c); mCore = Factory.instance().createCore(configFile, mLinphoneFactoryConfigFile, c);
mCore.addListener(this); 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(); mCore.start();
TimerTask lTask = TimerTask lTask =
new TimerTask() { new TimerTask() {

View file

@ -177,8 +177,10 @@ 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);
boolean isPush = false;
if (intent.getBooleanExtra("PushNotification", false)) { if (intent.getBooleanExtra("PushNotification", false)) {
Log.i("[Service] [Push Notification] LinphoneService started because of a push"); Log.i("[Service] [Push Notification] LinphoneService started because of a push");
isPush = true;
} }
if (sInstance != null) { if (sInstance != null) {
@ -186,7 +188,7 @@ public final class LinphoneService extends Service {
return START_REDELIVER_INTENT; return START_REDELIVER_INTENT;
} }
LinphoneManager.createAndStart(this); LinphoneManager.createAndStart(this, isPush);
sInstance = this; // sInstance is ready once linphone manager has been created sInstance = this; // sInstance is ready once linphone manager has been created
mNotificationManager = new NotificationsManager(this); mNotificationManager = new NotificationsManager(this);
@ -428,8 +430,8 @@ public final class LinphoneService extends Service {
// We have to so there are no more ref on the native LinphoneCore object and thus call // We have to so there are no more ref on the native LinphoneCore object and thus call
// it's uninit() method which will free the AndroidPlatformHelper resources... // it's uninit() method which will free the AndroidPlatformHelper resources...
// Problem is both the below methods do not guaranty the finalize will be called in time... // Problem is both the below methods do not guaranty the finalize will be called in time...
//System.gc(); // System.gc();
//System.runFinalization(); // System.runFinalization();
// Make sure our notification is gone. // Make sure our notification is gone.
mNotificationManager.destroy(); mNotificationManager.destroy();

View file

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