From ebf64ec78df62195b8e8c5e64b9b7c55037c5cdc Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 17 May 2018 20:41:26 +0200 Subject: add null check --- .../java/de/pixart/messenger/services/XmppConnectionService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index c4a40c1a3..cae50e6e5 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1002,7 +1002,7 @@ public class XmppConnectionService extends Service { public boolean hasInternetConnection() { final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); try { - final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + final NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnected(); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "unable to check for internet connection", e); @@ -1013,7 +1013,7 @@ public class XmppConnectionService extends Service { public boolean isWIFI() { final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); try { - final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + final NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo(); if (activeNetwork != null) { // connected to the internet if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { return true; @@ -1029,7 +1029,7 @@ public class XmppConnectionService extends Service { public boolean isMobile() { final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); try { - final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + final NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo(); if (activeNetwork != null) { // connected to the internet if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { if (!activeNetwork.isRoaming()) { @@ -1047,7 +1047,7 @@ public class XmppConnectionService extends Service { public boolean isMobileRoaming() { final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); try { - final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + final NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo(); if (activeNetwork != null) { // connected to the internet if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { if (activeNetwork.isRoaming()) { -- cgit v1.2.3