use new hasInternet() API only on Android Q+

some VPN apps are broken on Android 7.1 (and below?)

fixes #4058
This commit is contained in:
Daniel Gultsch 2021-04-18 15:47:28 +02:00
parent 2760f07307
commit ea2acc2963

View file

@ -1079,10 +1079,10 @@ public class XmppConnectionService extends Service {
public boolean hasInternetConnection() {
final ConnectivityManager cm = ContextCompat.getSystemService(this, ConnectivityManager.class);
if (cm == null) {
return false;
return true; //if internet connection can not be checked it is probably best to just try
}
try {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
final Network activeNetwork = cm.getActiveNetwork();
final NetworkCapabilities capabilities = activeNetwork == null ? null : cm.getNetworkCapabilities(activeNetwork);
return capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);