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 --- build.gradle | 2 +- 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 + 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 779e8e3..25b4423 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { apply plugin: 'com.android.application' android { - compileSdkVersion 15 + compileSdkVersion 21 buildToolsVersion "21.1.2" sourceSets.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