From 7e712d9d4cdd7fb8aa6c7ef68ce2d5c39ff1c257 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 17 Sep 2015 13:55:27 +0200 Subject: fixed rare NPE in DnsHelper. fixed spelling and added logging --- .../java/eu/siacs/conversations/utils/DNSHelper.java | 18 +++++++++++++----- 1 file 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 70bc7360..863cfb66 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 servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLolipop(); + final List 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 getDnsServers(Context context) { List 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 getDnsServersPreLolipop() { + private static List getDnsServersPreLollipop() { List servers = new ArrayList<>(); String[] dns = client.findDNS(); for(int i = 0; i < dns.length; ++i) { -- cgit v1.2.3