From c43315eb1a4ff2257f331bbe6931346982a964c3 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Tue, 7 May 2024 19:34:11 +0200 Subject: [PATCH] Mark VPN as non-metered --- .../tech/httptoolkit/android/ProxyVpnService.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt b/app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt index ed5130f..000824a 100644 --- a/app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt +++ b/app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt @@ -168,6 +168,15 @@ class ProxyVpnService : VpnService(), IProtectSocket { val vpnInterface = Builder() .addAddress(VPN_IP_ADDRESS, 32) .addRoute(ALL_ROUTES, 0) + .apply { + // On Android 10+ VPNs are assumed as metered by default, unless we explicitly + // specify otherwise: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + setMetered(false) + } + } + .setMtu(MAX_PACKET_LEN) // Limit the packet size to the buffer used by ProxyVpnRunnable + .setBlocking(true) // We use a blocking loop to read in ProxyVpnRunnable .apply { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // Where possible, we want to explicitly set the proxy in addition to @@ -177,10 +186,6 @@ class ProxyVpnService : VpnService(), IProtectSocket { setHttpProxy(ProxyInfo.buildDirectProxy(proxyConfig.ip, proxyConfig.port)) } } - - .setMtu(MAX_PACKET_LEN) // Limit the packet size to the buffer used by ProxyVpnRunnable - .setBlocking(true) // We use a blocking loop to read in ProxyVpnRunnable - .apply { // We exclude ourselves from interception, so we can still make network requests // separately, primarily because otherwise pinging with isReachable is recursive.