Commit d4d4c3aa authored by Mickaël Turnel's avatar Mickaël Turnel

Added compatibility for detection of connectivity

parent 08be1ad6
......@@ -21,8 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package org.linphone.core.tools;
import org.linphone.core.Core;
import org.linphone.core.receivers.DozeReceiver;
import org.linphone.core.receivers.NetworkManager;
import org.linphone.core.tools.DozeReceiver;
import org.linphone.core.tools.NetworkManager;
import org.linphone.core.tools.NetworkManagerAbove21;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version;
......@@ -39,7 +40,6 @@ import android.content.pm.ApplicationInfo;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
......@@ -60,8 +60,6 @@ import java.io.InputStream;
**/
public class AndroidPlatformHelper {
private static boolean mIsInstanciated = false;
private static AndroidPlatformHelper instance = null;
private long mNativePtr;
private Context mContext;
private WifiManager.WifiLock mWifiLock;
......@@ -87,6 +85,7 @@ public class AndroidPlatformHelper {
private IntentFilter mNetworkIntentFilter;
private boolean mWifiOnly;
private boolean mUsingHttpProxy;
private NetworkManagerAbove21 mNetworkManagerAbove21;
private native void setNativePreviewWindowId(long nativePtr, Object view);
private native void setNativeVideoWindowId(long nativePtr, Object view);
......@@ -127,47 +126,25 @@ public class AndroidPlatformHelper {
} catch (IOException e) {
Log.e("AndroidPlatformHelper(): failed to install some resources.");
}
mIsInstanciated = true;
instance = this;
}
public static boolean isInstanciated() {
return mIsInstanciated;
}
public static AndroidPlatformHelper getInstance() {
return instance;
}
public void onLinphoneCoreReady(boolean monitoringEnabled) {
if (!monitoringEnabled) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mNetworkReceiver = new NetworkManager();
mNetworkReceiver = new NetworkManager(this);
mNetworkIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
android.util.Log.i("Linphone","NETWORK: registered");
mContext.registerReceiver(mNetworkReceiver, mNetworkIntentFilter);
} else {
mConnectivityManager.registerNetworkCallback(
new NetworkRequest.Builder().build(),
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
updateNetworkReachability();
}
@Override
public void onLost(Network network) {
updateNetworkReachability();
}
}
);
mNetworkManagerAbove21 = new NetworkManagerAbove21(this);
mNetworkManagerAbove21.registerNetworkCallbacks(mConnectivityManager);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mDozeIntentFilter = new IntentFilter();
mDozeIntentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
mDozeReceiver = new DozeReceiver();
mDozeReceiver = new DozeReceiver(this);
dozeModeEnabled = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE)).isDeviceIdleMode();
mContext.registerReceiver(mDozeReceiver, mDozeIntentFilter);
}
......
package org.linphone.core.receivers;
/*
DozeReceiver.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
......@@ -19,6 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
......@@ -30,15 +30,20 @@ import org.linphone.core.tools.AndroidPlatformHelper;
* Purpose of this receiver is to disable keep alives when device is on idle
* */
public class DozeReceiver extends android.content.BroadcastReceiver {
private AndroidPlatformHelper mHelper;
public DozeReceiver(AndroidPlatformHelper helper) {
mHelper = helper;
}
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean dozeM = pm.isDeviceIdleMode();
if (AndroidPlatformHelper.isInstanciated()) {
AndroidPlatformHelper.getInstance().setDozeModeEnabled(dozeM);
AndroidPlatformHelper.getInstance().updateNetworkReachability();
if (mHelper != null) {
mHelper.setDozeModeEnabled(dozeM);
mHelper.updateNetworkReachability();
}
}
}
......
package org.linphone.core.receivers;
/*
ContactPickerActivity.java
NetworkManager.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
......@@ -19,6 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -27,16 +27,23 @@ import android.net.ConnectivityManager;
import org.linphone.core.tools.AndroidPlatformHelper;
/**
* Intercept network state changes and update linphone core through LinphoneManager.
* Intercept network state changes and update linphone core.
*/
public class NetworkManager extends BroadcastReceiver {
private AndroidPlatformHelper mHelper;
public NetworkManager(AndroidPlatformHelper helper) {
mHelper = helper;
android.util.Log.i("Linphone","NETWORK: networkManager created");
}
@Override
public void onReceive(Context context, Intent intent) {
android.util.Log.i("Linphone","NETWORK: Call onReceive");
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (AndroidPlatformHelper.isInstanciated()) {
AndroidPlatformHelper.getInstance().updateNetworkReachability();
if (mHelper != null) {
mHelper.updateNetworkReachability();
}
}
......
/*
NetworkManager.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkRequest;
import android.os.Build;
import org.linphone.core.tools.AndroidPlatformHelper;
/**
* Intercept network state changes and update linphone core.
*/
public class NetworkManagerAbove21 {
private AndroidPlatformHelper mHelper;
public NetworkManagerAbove21(AndroidPlatformHelper helper) {
mHelper = helper;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void registerNetworkCallbacks(ConnectivityManager connectivityManager) {
connectivityManager.registerNetworkCallback(
new NetworkRequest.Builder().build(),
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
mHelper.updateNetworkReachability();
}
@Override
public void onLost(Network network) {
mHelper.updateNetworkReachability();
}
}
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment