From a24b3a74d9a8fae8a6620302a9de972a4e832d7b Mon Sep 17 00:00:00 2001 From: Andrew Jack Date: Wed, 17 Apr 2019 17:33:26 +0100 Subject: [PATCH] fix(android): Check if NetworkInfo is null to avoid crashes (#66) Previously the `networkInfo` could be `null` and it would cause a crash when we try to decide the network type. This adds a `null` check to avoid this. --- .../reactnativecommunity/netinfo/ConnectivityReceiver.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java index a7b5e14b..0bb7009e 100644 --- a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java +++ b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java @@ -91,6 +91,10 @@ public void setNoNetworkPermission() { } String getEffectiveConnectionType(NetworkInfo networkInfo) { + if (networkInfo == null) { + return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; + } + switch (networkInfo.getSubtype()) { case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_CDMA: