diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-08 12:37:03 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-08 12:37:03 -0500 |
| commit | ef4f212fc1482136dba1e690ec589b315b4a377f (patch) | |
| tree | 0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-network-information/src | |
| parent | 5fa81da81260d65113f57a293b6256d334fe8e2d (diff) | |
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-network-information/src')
13 files changed, 138 insertions, 38 deletions
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; } } diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/blackberry10/index.js b/StoneIsland/plugins/cordova-plugin-network-information/src/blackberry10/index.js index d47d840e..c6cd00a9 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/blackberry10/index.js +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/blackberry10/index.js @@ -19,6 +19,8 @@ * */ +/* global PluginResult */ + //map from BB10 to cordova connection types: //https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js function mapConnectionType(con) { diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js b/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js new file mode 100644 index 00000000..8a6ddb0e --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +var cordova = require('cordova'), + proxy = require("cordova/exec/proxy"), + Connection = require('./Connection'); + +var type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE; + +// Subscribe to 'native' online/offline events +function onStatusChange(evt) { + type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE; + // force async + setTimeout(function(){ + cordova.fireDocumentEvent(evt.type); + },0); +} + +window.addEventListener('online', onStatusChange); +window.addEventListener('offline', onStatusChange); + +proxy.add("NetworkStatus", { + getConnectionInfo:function(cbSuccess) { + // force async + setTimeout(function(){ + cbSuccess(type); + },0); + } +}); + + diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/firefoxos/NetworkProxy.js b/StoneIsland/plugins/cordova-plugin-network-information/src/firefoxos/NetworkProxy.js index 40d61637..8c82557d 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/firefoxos/NetworkProxy.js +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/firefoxos/NetworkProxy.js @@ -24,8 +24,7 @@ and http://w3c.github.io/netinfo/ */ -var cordova = require('cordova'), - Connection = require('./Connection'), +var Connection = require('./Connection'), modulemapper = require('cordova/modulemapper'); var origConnection = modulemapper.getOriginalSymbol(window, 'navigator.connection'); @@ -47,7 +46,7 @@ module.exports = { metered = connection.metered, type = connection.type; - if (type != undefined) { + if (type !== undefined) { // For more information see: // https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API @@ -65,7 +64,7 @@ module.exports = { connectionType = Connection.NONE; break; } - } else if (bandwidth != undefined && metered != undefined) { + } else if (bandwidth !== undefined && metered !== undefined) { /* bandwidth of type double, readonly The user agent must set the value of the bandwidth attribute to: diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.h b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.h index 8add0279..8add0279 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.h +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.h diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.m b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.m index 37497675..6715322a 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.m +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVConnection.m @@ -16,6 +16,7 @@ specific language governing permissions and limitations under the License. */ +#import <CoreTelephony/CTTelephonyNetworkInfo.h> #import "CDVConnection.h" #import "CDVReachability.h" @@ -57,6 +58,32 @@ if (isConnectionRequired) { return @"none"; } else { + if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) { + CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new]; + if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) { + return @"2g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) { + return @"2g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) { + return @"3g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { + return @"4g"; + } + } return @"cellular"; } } @@ -118,7 +145,9 @@ [self.internetReach startNotifier]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:) name:kReachabilityChangedNotification object:nil]; - if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:) + name:CTRadioAccessTechnologyDidChangeNotification object:nil]; + if (UIApplicationDidEnterBackgroundNotification && UIApplicationWillEnterForegroundNotification) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil]; } diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.h b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.h index 01a95c35..01a95c35 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.h +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.h diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.m b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.m index c60261ae..1399867e 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.m +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ios/CDVReachability.m @@ -142,6 +142,9 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe retVal->reachabilityRef = reachability; retVal->localWiFiRef = NO; } + else { + CFRelease(reachability); + } } return retVal; } @@ -156,6 +159,9 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe retVal->reachabilityRef = reachability; retVal->localWiFiRef = NO; } + else { + CFRelease(reachability); + } } return retVal; } diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/tizen/NetworkProxy.js b/StoneIsland/plugins/cordova-plugin-network-information/src/tizen/NetworkProxy.js index cd9506e1..d2de2ccc 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/tizen/NetworkProxy.js +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/tizen/NetworkProxy.js @@ -19,7 +19,8 @@ * */ -var cordova = require('cordova'); +/* global tizen */ + var Connection = require('./Connection'); module.exports = { diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.cpp b/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.cpp index 8fdb4949..8fdb4949 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.cpp +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.cpp diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.h b/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.h index aca20e7b..aca20e7b 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.h +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/ubuntu/network_information.h diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/windows/NetworkInfoProxy.js b/StoneIsland/plugins/cordova-plugin-network-information/src/windows/NetworkInfoProxy.js index 27ad2f06..92153c7b 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/windows/NetworkInfoProxy.js +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/windows/NetworkInfoProxy.js @@ -21,15 +21,10 @@ /*global Windows:true */ -var cordova = require('cordova'); var Connection = require('./Connection'); var winNetConn = Windows.Networking.Connectivity; var networkInfo = winNetConn.NetworkInformation; -var networkCostInfo = winNetConn.NetworkCostType; -var networkConnectivityInfo = winNetConn.NetworkConnectivityLevel; -var networkAuthenticationInfo = winNetConn.NetworkAuthenticationType; -var networkEncryptionInfo = winNetConn.NetworkEncryptionType; function getCurrrentConnectionType() { @@ -76,7 +71,7 @@ module.exports = { { var reportConnectionInfoOnce = function () { win(getCurrrentConnectionType(), { keepCallback: true }); - } + }; // report current connection type setTimeout(reportConnectionInfoOnce, 0); diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/wp/NetworkStatus.cs b/StoneIsland/plugins/cordova-plugin-network-information/src/wp/NetworkStatus.cs index 12eb061d..12eb061d 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-network-information/src/wp/NetworkStatus.cs +++ b/StoneIsland/plugins/cordova-plugin-network-information/src/wp/NetworkStatus.cs |
