Added remarks

pull/214/head
M66B 1 year ago
parent ab764786fe
commit a379a70a51

@ -299,10 +299,13 @@ public class ConnectionHelper {
Log.i("isMetered: active caps=" + caps); Log.i("isMetered: active caps=" + caps);
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) { if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
// Active network is not a VPN
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
Log.i("isMetered: no internet"); Log.i("isMetered: no internet");
return null; return null;
} }
boolean captive = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL); boolean captive = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
if ((require_validated || (require_validated_captive && captive)) && if ((require_validated || (require_validated_captive && captive)) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
@ -325,19 +328,22 @@ public class ConnectionHelper {
if (vpn_only) { if (vpn_only) {
boolean vpn = vpnActive(context); boolean vpn = vpnActive(context);
Log.i("VPN only vpn=" + vpn); Log.i("isMetered: VPN only vpn=" + vpn);
if (!vpn) if (!vpn)
return null; return null;
} }
if (standalone_vpn || if (standalone_vpn ||
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) { caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
// Standalone VPN: internet not checked
// NET_CAPABILITY_NOT_METERED is unreliable on older Android versions // NET_CAPABILITY_NOT_METERED is unreliable on older Android versions
boolean metered = cm.isActiveNetworkMetered(); boolean metered = cm.isActiveNetworkMetered();
Log.i("isMetered: active not VPN metered=" + metered); Log.i("isMetered: active not VPN metered=" + metered);
return metered; return metered;
} }
// Active network is a VPN
Network[] networks = cm.getAllNetworks(); Network[] networks = cm.getAllNetworks();
if (networks != null && networks.length == 1) { if (networks != null && networks.length == 1) {
// Standalone VPN // Standalone VPN
@ -390,8 +396,10 @@ public class ConnectionHelper {
} }
} }
if (!underlying) if (!underlying) {
Log.i("isMetered: no underlying network");
return null; return null;
}
// Assume metered // Assume metered
Log.i("isMetered: underlying assume metered"); Log.i("isMetered: underlying assume metered");

Loading…
Cancel
Save