0

I have an android app which uses VpnService API to establish a connection to a proxy. My intention is to let DNS queries bypass the proxy and route the rest of the device traffic through it. On SDK 33+ I can do it like this:

Builder builder = new VpnService.Builder();
            ParcelFileDescriptor vpnInterface = builder
                    .setMtu(1500)
                    .addAddress("26.26.26.1", 24)
                    .addRoute("0.0.0.0", 0)
                    .excludeRoute(new IpPrefix(InetAddress.getByName("8.8.8.8"), 32))
                    .addDnsServer("8.8.8.8")
                    .establish();

But the excludeRoute method does not seem to exist on API 32 and lower. Is the only option to add routes like this: 1.0.0.0/8, 2.0.0.0/8, 3.0.0.0/8, 4.0.0.0/6, 8.0.0.0/12... or are there more elegant methods?

Anton2319
  • 83
  • 1
  • 5

0 Answers0