aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-09-17 13:55:27 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-09-17 13:55:27 +0200
commit7e712d9d4cdd7fb8aa6c7ef68ce2d5c39ff1c257 (patch)
tree43c4e25a68d04b16a4eb2a37c5daed65d5a3e370 /src
parentb1b13ba0e52a42e4c978cd77b75a3d750642f53d (diff)
fixed rare NPE in DnsHelper. fixed spelling and added logging
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/DNSHelper.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
index 70bc73606..863cfb66b 100644
--- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
@@ -45,7 +45,7 @@ public class DNSHelper {
public static Bundle getSRVRecord(final Jid jid, Context context) throws IOException {
final String host = jid.getDomainpart();
- final List<InetAddress> servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLolipop();
+ final List<InetAddress> servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLollipop();
Bundle b = null;
for(InetAddress server : servers) {
b = queryDNS(host, server);
@@ -60,15 +60,23 @@ public class DNSHelper {
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- Network[] networks = connectivityManager.getAllNetworks();
+ Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
+ if (networks == null) {
+ return getDnsServersPreLollipop();
+ }
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
- servers.addAll(linkProperties.getDnsServers());
+ if (linkProperties != null) {
+ servers.addAll(linkProperties.getDnsServers());
+ }
+ }
+ if (servers.size() > 0) {
+ Log.d(Config.LOGTAG,"used lollipop variant to discover dns servers in "+networks.length+" networks");
}
- return servers.size() > 0 ? servers : getDnsServersPreLolipop();
+ return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
- private static List<InetAddress> getDnsServersPreLolipop() {
+ private static List<InetAddress> getDnsServersPreLollipop() {
List<InetAddress> servers = new ArrayList<>();
String[] dns = client.findDNS();
for(int i = 0; i < dns.length; ++i) {