From a379a70a5107fbd22b58cbe798912a86521a0c07 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 5 Sep 2023 16:00:44 +0200 Subject: [PATCH] Added remarks --- .../java/eu/faircode/email/ConnectionHelper.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index b89a670903..04bab71ddc 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -299,10 +299,13 @@ public class ConnectionHelper { Log.i("isMetered: active caps=" + caps); if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) { + // Active network is not a VPN + if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { Log.i("isMetered: no internet"); return null; } + boolean captive = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL); if ((require_validated || (require_validated_captive && captive)) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && @@ -325,19 +328,22 @@ public class ConnectionHelper { if (vpn_only) { boolean vpn = vpnActive(context); - Log.i("VPN only vpn=" + vpn); + Log.i("isMetered: VPN only vpn=" + vpn); if (!vpn) return null; } if (standalone_vpn || caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) { + // Standalone VPN: internet not checked // NET_CAPABILITY_NOT_METERED is unreliable on older Android versions boolean metered = cm.isActiveNetworkMetered(); Log.i("isMetered: active not VPN metered=" + metered); return metered; } + // Active network is a VPN + Network[] networks = cm.getAllNetworks(); if (networks != null && networks.length == 1) { // Standalone VPN @@ -390,8 +396,10 @@ public class ConnectionHelper { } } - if (!underlying) + if (!underlying) { + Log.i("isMetered: no underlying network"); return null; + } // Assume metered Log.i("isMetered: underlying assume metered");