Skip to content

Commit

Permalink
Mark VPN as non-metered
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed May 7, 2024
1 parent 4ce7452 commit c43315e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit c43315e

Please sign in to comment.