Commit 752cc402 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Prevent android platform helper from doing code outside of main thread

parent 7557a041
......@@ -48,45 +48,75 @@ public class NetworkManagerAbove21 implements NetworkManagerInterface {
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 21] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 21] Network isn't wifi and wifi only mode is enabled");
}
public void onAvailable(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 21] Network isn't wifi and wifi only mode is enabled");
}
}
});
}
@Override
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 21] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
public void onLost(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
Log.i("[Platform Helper] [Network Manager 21] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
public void onCapabilitiesChanged(final Network network, final NetworkCapabilities networkCapabilities) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 21] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
public void onLinkPropertiesChanged(final Network network, final LinkProperties linkProperties) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
});
}
@Override
public void onLosing(Network network, int maxMsToLive) {
Log.i("[Platform Helper] [Network Manager 21] onLosing " + network.toString());
public void onLosing(final Network network, final int maxMsToLive) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] onLosing " + network.toString());
}
});
}
@Override
public void onUnavailable() {
Log.i("[Platform Helper] [Network Manager 21] onUnavailable");
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 21] onUnavailable");
}
});
}
};
}
......
......@@ -48,45 +48,75 @@ public class NetworkManagerAbove23 implements NetworkManagerInterface {
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 23] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 23] Network isn't wifi and wifi only mode is enabled");
}
public void onAvailable(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 23] Network isn't wifi and wifi only mode is enabled");
}
}
});
}
@Override
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 23] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
public void onLost(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
Log.i("[Platform Helper] [Network Manager 23] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
public void onCapabilitiesChanged(final Network network, final NetworkCapabilities networkCapabilities) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 23] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
public void onLinkPropertiesChanged(final Network network, final LinkProperties linkProperties) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
});
}
@Override
public void onLosing(Network network, int maxMsToLive) {
Log.i("[Platform Helper] [Network Manager 23] onLosing " + network.toString());
public void onLosing(final Network network, final int maxMsToLive) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] onLosing " + network.toString());
}
});
}
@Override
public void onUnavailable() {
Log.i("[Platform Helper] [Network Manager 23] onUnavailable");
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 23] onUnavailable");
}
});
}
};
}
......
......@@ -51,45 +51,75 @@ public class NetworkManagerAbove24 implements NetworkManagerInterface {
mNetworkAvailable = null;
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
Log.i("[Platform Helper] [Network Manager 24] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 24] Network isn't wifi and wifi only mode is enabled");
}
public void onAvailable(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] A network is available: " + mConnectivityManager.getNetworkInfo(network).getType() + ", wifi only is " + (mWifiOnly ? "enabled" : "disabled"));
if (!mWifiOnly || mConnectivityManager.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_WIFI) {
mNetworkAvailable = network;
mHelper.updateNetworkReachability();
} else {
Log.i("[Platform Helper] [Network Manager 24] Network isn't wifi and wifi only mode is enabled");
}
}
});
}
@Override
public void onLost(Network network) {
Log.i("[Platform Helper] [Network Manager 24] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
public void onLost(final Network network) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] A network has been lost");
if (mNetworkAvailable != null && mNetworkAvailable.equals(network)) {
mNetworkAvailable = null;
}
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
Log.i("[Platform Helper] [Network Manager 24] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
public void onCapabilitiesChanged(final Network network, final NetworkCapabilities networkCapabilities) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] onCapabilitiesChanged " + network.toString() + ", " + networkCapabilities.toString());
mHelper.updateNetworkReachability();
}
});
}
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
Log.i("[Platform Helper] [Network Manager 24] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
public void onLinkPropertiesChanged(final Network network, final LinkProperties linkProperties) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] onLinkPropertiesChanged " + network.toString() + ", " + linkProperties.toString());
mHelper.updateDnsServers(linkProperties.getDnsServers());
}
});
}
@Override
public void onLosing(Network network, int maxMsToLive) {
Log.i("[Platform Helper] [Network Manager 24] onLosing " + network.toString());
public void onLosing(final Network network, final int maxMsToLive) {
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] onLosing " + network.toString());
}
});
}
@Override
public void onUnavailable() {
Log.i("[Platform Helper] [Network Manager 24] onUnavailable");
mHelper.getHandler().post(new Runnable() {
@Override
public void run() {
Log.i("[Platform Helper] [Network Manager 24] onUnavailable");
}
});
}
};
}
......
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