From 04912777fdbd9799710756c2478f2d5927675e23 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Thu, 24 Nov 2016 20:40:52 +0000 Subject: Use stable API to detect system nameservers Motivation: __system_get_property is a hidden api and has already been removed from the ndk once --- src/main/AndroidManifest.xml | 1 + .../java/org/xapek/andiodine/IodineVpnService.java | 50 +++++++++++++++++++++- src/main/res/values-de/strings.xml | 1 + src/main/res/values/strings.xml | 1 + 4 files changed, 52 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 0bea991..5325d7f 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ android:targetSdkVersion="16"/> + = Build.VERSION_CODES.LOLLIPOP) { + ConnectivityManager cm = + (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + Network activeNetwork = getActiveNetwork(); + if (activeNetwork == null) { + String errorMessage = getString(R.string.vpnservice_error_no_active_network); + setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage); + Log.e(TAG, "No active network. Aborting..."); + return; + } + LinkProperties prop = cm.getLinkProperties(activeNetwork); + List servers = prop.getDnsServers(); + for (InetAddress candidate : servers) { + Log.d(TAG, "detected dns server: " + candidate); + if (candidate instanceof Inet4Address) { + tunnelNameserver = candidate.getHostAddress(); + break; + } + } + } else { + tunnelNameserver = IodineClient.getPropertyNetDns1(); + } + if (tunnelNameserver.isEmpty()) { String errorMessage = getString(R.string.vpnservice_error_dns_detect_failed); setStatus(ACTION_STATUS_ERROR, mConfiguration.getId(), errorMessage); diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 9ad840b..b39b207 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -51,6 +51,7 @@ Unbekannter Fehler. Grund: %s Es wurden keine gültigen IPv4-Nameserver erkannt Das Tunnel-Netzwerkgerät konnte nicht erstellt werden + Kein aktives Netzwerk Leerlauf Warnung Fehler diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index bd9709b..95b2250 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -76,6 +76,7 @@ Unknown Error. Reason: %s No valid IPv4 name servers detected Failed to create tunnel network device + No active network Idle Warning Error -- cgit v1.2.1