From ef4f212fc1482136dba1e690ec589b315b4a377f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 8 Nov 2016 12:37:03 -0500 Subject: build 0.7.0 --- .../src/android/NetworkManager.java | 72 ++++++++++++++-------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'StoneIsland/plugins/cordova-plugin-network-information/src/android') diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/android/NetworkManager.java b/StoneIsland/plugins/cordova-plugin-network-information/src/android/NetworkManager.java index 4c85ddab..614b6e7b 100755 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/android/NetworkManager.java +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/android/NetworkManager.java @@ -21,6 +21,7 @@ package org.apache.cordova.networkinformation; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.LOG; import org.apache.cordova.PluginResult; import org.apache.cordova.CordovaWebView; import org.json.JSONArray; @@ -33,7 +34,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.util.Log; + +import java.util.Locale; public class NetworkManager extends CordovaPlugin { @@ -45,14 +47,16 @@ public class NetworkManager extends CordovaPlugin { public static final String WIMAX = "wimax"; // mobile public static final String MOBILE = "mobile"; - - // Android L calls this Cellular, because I have no idea! + + // Android L calls this Cellular, because I have no idea! public static final String CELLULAR = "cellular"; // 2G network types + public static final String TWO_G = "2g"; public static final String GSM = "gsm"; public static final String GPRS = "gprs"; public static final String EDGE = "edge"; // 3G network types + public static final String THREE_G = "3g"; public static final String CDMA = "cdma"; public static final String UMTS = "umts"; public static final String HSPA = "hspa"; @@ -61,12 +65,14 @@ public class NetworkManager extends CordovaPlugin { public static final String ONEXRTT = "1xrtt"; public static final String EHRPD = "ehrpd"; // 4G network types + public static final String FOUR_G = "4g"; public static final String LTE = "lte"; public static final String UMB = "umb"; public static final String HSPA_PLUS = "hspa+"; // return type public static final String TYPE_UNKNOWN = "unknown"; public static final String TYPE_ETHERNET = "ethernet"; + public static final String TYPE_ETHERNET_SHORT = "eth"; public static final String TYPE_WIFI = "wifi"; public static final String TYPE_2G = "2g"; public static final String TYPE_3G = "3g"; @@ -125,7 +131,9 @@ public class NetworkManager extends CordovaPlugin { String connectionType = ""; try { connectionType = this.getConnectionInfo(info).get("type").toString(); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG, e.getLocalizedMessage()); + } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType); pluginResult.setKeepCallback(true); @@ -143,7 +151,7 @@ public class NetworkManager extends CordovaPlugin { try { webView.getContext().unregisterReceiver(this.receiver); } catch (Exception e) { - Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); + LOG.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); } finally { receiver = null; } @@ -169,7 +177,9 @@ public class NetworkManager extends CordovaPlugin { String connectionType = ""; try { connectionType = thisInfo.get("type").toString(); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG, e.getLocalizedMessage()); + } sendUpdate(connectionType); lastInfo = thisInfo; @@ -196,15 +206,17 @@ public class NetworkManager extends CordovaPlugin { extraInfo = info.getExtraInfo(); } - Log.d("CordovaNetworkManager", "Connection Type: " + type); - Log.d("CordovaNetworkManager", "Connection Extra Info: " + extraInfo); + LOG.d(LOG_TAG, "Connection Type: " + type); + LOG.d(LOG_TAG, "Connection Extra Info: " + extraInfo); JSONObject connectionInfo = new JSONObject(); try { connectionInfo.put("type", type); connectionInfo.put("extraInfo", extraInfo); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG, e.getLocalizedMessage()); + } return connectionInfo; } @@ -231,30 +243,38 @@ public class NetworkManager extends CordovaPlugin { */ private String getType(NetworkInfo info) { if (info != null) { - String type = info.getTypeName(); + String type = info.getTypeName().toLowerCase(Locale.US); - if (type.toLowerCase().equals(WIFI)) { + LOG.d(LOG_TAG, "toLower : " + type.toLowerCase()); + LOG.d(LOG_TAG, "wifi : " + WIFI); + if (type.equals(WIFI)) { return TYPE_WIFI; } - else if (type.toLowerCase().equals(MOBILE) || type.toLowerCase().equals(CELLULAR)) { - type = info.getSubtypeName(); - if (type.toLowerCase().equals(GSM) || - type.toLowerCase().equals(GPRS) || - type.toLowerCase().equals(EDGE)) { + else if (type.toLowerCase().equals(TYPE_ETHERNET) || type.toLowerCase().startsWith(TYPE_ETHERNET_SHORT)) { + return TYPE_ETHERNET; + } + else if (type.equals(MOBILE) || type.equals(CELLULAR)) { + type = info.getSubtypeName().toLowerCase(Locale.US); + if (type.equals(GSM) || + type.equals(GPRS) || + type.equals(EDGE) || + type.equals(TWO_G)) { return TYPE_2G; } - else if (type.toLowerCase().startsWith(CDMA) || - type.toLowerCase().equals(UMTS) || - type.toLowerCase().equals(ONEXRTT) || - type.toLowerCase().equals(EHRPD) || - type.toLowerCase().equals(HSUPA) || - type.toLowerCase().equals(HSDPA) || - type.toLowerCase().equals(HSPA)) { + else if (type.startsWith(CDMA) || + type.equals(UMTS) || + type.equals(ONEXRTT) || + type.equals(EHRPD) || + type.equals(HSUPA) || + type.equals(HSDPA) || + type.equals(HSPA) || + type.equals(THREE_G)) { return TYPE_3G; } - else if (type.toLowerCase().equals(LTE) || - type.toLowerCase().equals(UMB) || - type.toLowerCase().equals(HSPA_PLUS)) { + else if (type.equals(LTE) || + type.equals(UMB) || + type.equals(HSPA_PLUS) || + type.equals(FOUR_G)) { return TYPE_4G; } } -- cgit v1.2.3-70-g09d2