Commit 153a89ea authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Android network manager DNS improvements

parent 2c96fc29
......@@ -454,18 +454,13 @@ public class AndroidPlatformHelper {
}
}
private synchronized void storeDnsServers(Network activeNetwork) {
mDnsServers = null;
if (activeNetwork == null || mConnectivityManager.getLinkProperties(activeNetwork) == null) {
Log.e("[Platform Helper] Active network is null or we can't get it's link properties");
public synchronized void updateDnsServers(List<InetAddress> inetServers) {
if (inetServers == null) {
Log.e("[Platform Helper] inet servers list is null, don't update DNS servers");
return;
}
int i = 0;
List<InetAddress> inetServers = null;
inetServers = mConnectivityManager.getLinkProperties(activeNetwork).getDnsServers();
String[] servers = new String[inetServers.size()];
for (InetAddress address : inetServers) {
String host = address.getHostAddress();
......@@ -476,6 +471,19 @@ public class AndroidPlatformHelper {
mDnsServers = servers;
}
private synchronized void storeDnsServers(Network activeNetwork) {
mDnsServers = null;
if (activeNetwork == null || mConnectivityManager.getLinkProperties(activeNetwork) == null) {
Log.e("[Platform Helper] Active network is null or we can't get it's link properties");
return;
}
List<InetAddress> inetServers = null;
inetServers = mConnectivityManager.getLinkProperties(activeNetwork).getDnsServers();
updateDnsServers(inetServers);
}
public synchronized void updateNetworkReachability() {
if (mNativePtr == 0) {
Log.w("[Platform Helper] Native pointer has been reset, stopping there");
......
......@@ -38,15 +38,18 @@ public class NetworkManagerAbove21 implements NetworkManagerInterface {
private AndroidPlatformHelper mHelper;
private boolean mIsNetworkAvailable;
private ConnectivityManager.NetworkCallback mNetworkCallback;
private Network mNetworkAvailable;
public NetworkManagerAbove21(final AndroidPlatformHelper helper) {
mHelper = helper;
mIsNetworkAvailable = false;
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 21] A network is available");
mIsNetworkAvailable = true;
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
}
......@@ -54,6 +57,9 @@ public class NetworkManagerAbove21 implements NetworkManagerInterface {
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 21] A network has been lost");
mIsNetworkAvailable = false;
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
......@@ -66,6 +72,7 @@ public class NetworkManagerAbove21 implements NetworkManagerInterface {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 21] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
@Override
......@@ -92,11 +99,15 @@ public class NetworkManagerAbove21 implements NetworkManagerInterface {
}
public NetworkInfo getActiveNetworkInfo(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return connectivityManager.getNetworkInfo(mNetworkAvailable);
}
return connectivityManager.getActiveNetworkInfo();
}
public Network getActiveNetwork(ConnectivityManager connectivityManager) {
return null;
return mNetworkAvailable;
}
public boolean isCurrentlyConnected(Context context, ConnectivityManager connectivityManager, boolean wifiOnly) {
......
......@@ -38,15 +38,18 @@ public class NetworkManagerAbove23 implements NetworkManagerInterface {
private AndroidPlatformHelper mHelper;
private boolean mIsNetworkAvailable;
private ConnectivityManager.NetworkCallback mNetworkCallback;
private Network mNetworkAvailable;
public NetworkManagerAbove23(final AndroidPlatformHelper helper) {
mHelper = helper;
mIsNetworkAvailable = false;
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 23] A network is available");
mIsNetworkAvailable = true;
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
}
......@@ -54,6 +57,9 @@ public class NetworkManagerAbove23 implements NetworkManagerInterface {
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 23] A network has been lost");
mIsNetworkAvailable = false;
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
......@@ -66,6 +72,7 @@ public class NetworkManagerAbove23 implements NetworkManagerInterface {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 23] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
@Override
......@@ -92,15 +99,24 @@ public class NetworkManagerAbove23 implements NetworkManagerInterface {
}
public NetworkInfo getActiveNetworkInfo(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return connectivityManager.getNetworkInfo(mNetworkAvailable);
}
Network network = connectivityManager.getActiveNetwork();
if (network != null) {
return connectivityManager.getNetworkInfo(network);
}
Log.i("[Platform Helper] [Network Manager 23] getActiveNetwork() returned null, using getActiveNetworkInfo() instead");
return connectivityManager.getActiveNetworkInfo();
}
public Network getActiveNetwork(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return mNetworkAvailable;
}
return connectivityManager.getActiveNetwork();
}
......
......@@ -41,15 +41,18 @@ public class NetworkManagerAbove24 implements NetworkManagerInterface {
private AndroidPlatformHelper mHelper;
private boolean mIsNetworkAvailable;
private ConnectivityManager.NetworkCallback mNetworkCallback;
private Network mNetworkAvailable;
public NetworkManagerAbove24(final AndroidPlatformHelper helper) {
mHelper = helper;
mIsNetworkAvailable = false;
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 24] A network is available");
mIsNetworkAvailable = true;
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
}
......@@ -57,6 +60,9 @@ public class NetworkManagerAbove24 implements NetworkManagerInterface {
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 24] A network has been lost");
mIsNetworkAvailable = false;
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
......@@ -69,6 +75,7 @@ public class NetworkManagerAbove24 implements NetworkManagerInterface {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 24] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
@Override
......@@ -96,15 +103,24 @@ public class NetworkManagerAbove24 implements NetworkManagerInterface {
}
public NetworkInfo getActiveNetworkInfo(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return connectivityManager.getNetworkInfo(mNetworkAvailable);
}
Network network = connectivityManager.getActiveNetwork();
if (network != null) {
return connectivityManager.getNetworkInfo(network);
}
Log.i("[Platform Helper] [Network Manager 24] getActiveNetwork() returned null, using getActiveNetworkInfo() instead");
return connectivityManager.getActiveNetworkInfo();
}
public Network getActiveNetwork(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return mNetworkAvailable;
}
return connectivityManager.getActiveNetwork();
}
......
......@@ -41,15 +41,18 @@ public class NetworkManagerAbove26 implements NetworkManagerInterface {
private AndroidPlatformHelper mHelper;
private boolean mIsNetworkAvailable;
private ConnectivityManager.NetworkCallback mNetworkCallback;
private Network mNetworkAvailable;
public NetworkManagerAbove26(final AndroidPlatformHelper helper) {
mHelper = helper;
mIsNetworkAvailable = false;
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 26] A network is available");
mIsNetworkAvailable = true;
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
}
......@@ -57,6 +60,9 @@ public class NetworkManagerAbove26 implements NetworkManagerInterface {
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 26] A network has been lost");
mIsNetworkAvailable = false;
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
......@@ -69,6 +75,7 @@ public class NetworkManagerAbove26 implements NetworkManagerInterface {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 26] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
@Override
......@@ -96,6 +103,10 @@ public class NetworkManagerAbove26 implements NetworkManagerInterface {
}
public NetworkInfo getActiveNetworkInfo(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return connectivityManager.getNetworkInfo(mNetworkAvailable);
}
Network network = connectivityManager.getActiveNetwork();
if (network != null) {
return connectivityManager.getNetworkInfo(network);
......@@ -105,6 +116,10 @@ public class NetworkManagerAbove26 implements NetworkManagerInterface {
}
public Network getActiveNetwork(ConnectivityManager connectivityManager) {
if (mNetworkAvailable != null) {
return mNetworkAvailable;
}
return connectivityManager.getActiveNetwork();
}
......
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