diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java index 763f76072..98b1899f3 100644 --- a/app/src/main/java/org/linphone/LinphoneManager.java +++ b/app/src/main/java/org/linphone/LinphoneManager.java @@ -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() { diff --git a/app/src/main/java/org/linphone/LinphoneService.java b/app/src/main/java/org/linphone/LinphoneService.java index ee2e5caeb..89ea219d7 100644 --- a/app/src/main/java/org/linphone/LinphoneService.java +++ b/app/src/main/java/org/linphone/LinphoneService.java @@ -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); @@ -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 // 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... - //System.gc(); - //System.runFinalization(); + // System.gc(); + // System.runFinalization(); // Make sure our notification is gone. mNotificationManager.destroy(); diff --git a/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java b/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java index ff9d11428..0a77b7608 100644 --- a/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/org/linphone/receivers/KeepAliveReceiver.java @@ -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;