From cede8a917379406f0501dc5ed5c7f53ece8d7957 Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 13 May 2021 10:26:27 +0200 Subject: [PATCH 01/19] 5g feature --- package-lock.json | 2 +- package.json | 2 +- plugin.xml | 2 +- src/android/NetworkManager.java | 199 ++++++++++++++++++++++++-------- src/ios/CDVConnection.m | 13 ++- types/index.d.ts | 2 + www/Connection.js | 1 + 7 files changed, 169 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8f544f0..a815da8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-network-information", - "version": "3.0.0-dev", + "version": "3.0.1-dev", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3de84e3..58cf636 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-network-information", - "version": "3.0.0-dev", + "version": "3.0.1-dev", "description": "Cordova Network Information Plugin", "types": "./types/index.d.ts", "cordova": { diff --git a/plugin.xml b/plugin.xml index a05111f..71a4030 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ + version="3.0.1-dev"> Network Information Cordova Network Information Plugin diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 95c8f07..096b832 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -25,19 +25,28 @@ Licensed to the Apache Software Foundation (ASF) under one import org.apache.cordova.PluginResult; import org.apache.cordova.CordovaWebView; import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import android.Manifest; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; +import android.telephony.ServiceState; + +import androidx.annotation.RequiresApi; +import androidx.core.app.ActivityCompat; import java.util.Locale; +import static android.telephony.PhoneStateListener.LISTEN_SERVICE_STATE; + public class NetworkManager extends CordovaPlugin { public static int NOT_REACHABLE = 0; @@ -46,17 +55,17 @@ public class NetworkManager extends CordovaPlugin { public static final String WIFI = "wifi"; public static final String WIMAX = "wimax"; - // mobile + // 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 + // 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 + // 3G network types public static final String THREE_G = "3g"; public static final String CDMA = "cdma"; public static final String UMTS = "umts"; @@ -65,11 +74,16 @@ public class NetworkManager extends CordovaPlugin { public static final String HSDPA = "hsdpa"; public static final String ONEXRTT = "1xrtt"; public static final String EHRPD = "ehrpd"; - // 4G network types + // 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+"; + + // 5G network types + public static final String FIVE_G = "5g"; + public static final String NR = "nr"; + // return type public static final String TYPE_UNKNOWN = "unknown"; public static final String TYPE_ETHERNET = "ethernet"; @@ -78,29 +92,37 @@ public class NetworkManager extends CordovaPlugin { public static final String TYPE_2G = "2g"; public static final String TYPE_3G = "3g"; public static final String TYPE_4G = "4g"; + public static final String TYPE_5G = "5g"; public static final String TYPE_NONE = "none"; + public static final int NETWORK_TYPE_NR = 20; + public static final int NETWORK_TYPE_LTE_CA = 19; + private static final String LOG_TAG = "NetworkManager"; private CallbackContext connectionCallbackContext; ConnectivityManager sockMan; BroadcastReceiver receiver; - private String lastTypeOfNetwork; + private String lastTypeOfNetwork = TYPE_UNKNOWN; + TelephonyManager telMan; + private static boolean isNrAvailable; /** - * Sets the context of the Command. This can then be used to do things like - * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. - */ + * Sets the context of the Command. This can then be used to do things like + * get file paths associated with the Activity. + * + * @param cordova The context of the main Activity. + * @param webView The CordovaWebView Cordova is running in. + */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); - this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); - this.connectionCallbackContext = null; + super.initialize(cordova, webView); + this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); + this.telMan = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); + this.telMan.listen( phoneStateListener, LISTEN_SERVICE_STATE); + this.connectionCallbackContext = null; - this.registerConnectivityActionReceiver(); + this.registerConnectivityActionReceiver(); } /** @@ -158,7 +180,7 @@ private void registerConnectivityActionReceiver() { public void onReceive(Context context, Intent intent) { // (The null check is for the ARM Emulator, please use Intel Emulator for better results) if (NetworkManager.this.webView != null) { - updateConnectionInfo(sockMan.getActiveNetworkInfo()); + updateConnectionInfo(sockMan.getActiveNetworkInfo(), true); } String connectionType; @@ -204,10 +226,10 @@ private void unregisterReceiver() { * @param info the current active network info * @return */ - private void updateConnectionInfo(NetworkInfo info) { + private void updateConnectionInfo(NetworkInfo info, boolean forceRefresh) { // send update to javascript "navigator.connection" // Jellybean sends its own info - String currentNetworkType = this.getTypeOfNetworkFallbackToTypeNoneIfNotConnected(info); + String currentNetworkType = this.getTypeOfNetworkFallbackToTypeNoneIfNotConnected(info, forceRefresh); if (currentNetworkType.equals(this.lastTypeOfNetwork)) { LOG.d(LOG_TAG, "Networkinfo state didn't change, there is no event propagated to the JavaScript side."); } else { @@ -222,16 +244,20 @@ private void updateConnectionInfo(NetworkInfo info) { * @param info the current active network info * @return type the type of network */ - private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info) { + @RequiresApi(api = Build.VERSION_CODES.N) + private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info, Boolean forceRefresh) { // the info might still be null in this part of the code String type; if (info != null) { // If we are not connected to any network set type to none if (!info.isConnected()) { type = TYPE_NONE; - } - else { - type = getType(info); + } else { + if(lastTypeOfNetwork.equals(TYPE_UNKNOWN) || forceRefresh) { + type = getType(info); + } else { + type = lastTypeOfNetwork; + } } } else { type = TYPE_NONE; @@ -240,6 +266,11 @@ private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info LOG.d(LOG_TAG, "Connection Type: " + type); return type; } + @RequiresApi(api = Build.VERSION_CODES.N) + private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info) { + // the info might still be null in this part of the code + return this.getTypeOfNetworkFallbackToTypeNoneIfNotConnected(info, false); + } /** * Create a new plugin result and send it back to JavaScript @@ -259,7 +290,7 @@ private void sendUpdate(String type) { * Determine the type of connection * * @param info the network info so we can determine connection type. - * @return the type of mobile network we are on + * @return the type of network we are on */ private String getType(NetworkInfo info) { String type = info.getTypeName().toLowerCase(Locale.US); @@ -270,28 +301,104 @@ private String getType(NetworkInfo info) { } 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.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.equals(LTE) || - type.equals(UMB) || - type.equals(HSPA_PLUS) || - type.equals(FOUR_G)) { - return TYPE_4G; + return getMobileType(info); + } + return TYPE_UNKNOWN; + } + + /** + * Determine the subtype of mobile connection + * + * @param info the network info so we can determine connection type. + * @return the type of mobile network we are on + */ + private String getMobileType(NetworkInfo info){ + int subTypeId = info.getSubtype(); + String subTypeName = info.getSubtypeName().toLowerCase(Locale.US); + if(is2G(subTypeId, subTypeName)){ + return TYPE_2G; + } else if(is3G(subTypeId, subTypeName)) { + return TYPE_3G; + } else if(is4G(subTypeId, subTypeName)) { + if(isNrAvailable){ // if is LTE network could be 5g if NR is available + return TYPE_5G; } + return TYPE_4G; + } else if(is5G(subTypeId, subTypeName)) { + return TYPE_5G; } return TYPE_UNKNOWN; } + + private boolean is2G(int type, String name){ + return type == TelephonyManager.NETWORK_TYPE_GPRS || + type == TelephonyManager.NETWORK_TYPE_EDGE || + type == TelephonyManager.NETWORK_TYPE_CDMA || + type == TelephonyManager.NETWORK_TYPE_1xRTT || + type == TelephonyManager.NETWORK_TYPE_IDEN || // api< 8: replace by 11 + type == TelephonyManager.NETWORK_TYPE_GSM || // api<25: replace by 16 + name.equals(GSM) || + name.equals(GPRS) || + name.equals(EDGE) || + name.equals(TWO_G); + } + + private boolean is3G(int type, String name){ + return type == TelephonyManager.NETWORK_TYPE_UMTS || + type == TelephonyManager.NETWORK_TYPE_EVDO_0 || + type == TelephonyManager.NETWORK_TYPE_EVDO_A || + type == TelephonyManager.NETWORK_TYPE_HSDPA || + type == TelephonyManager.NETWORK_TYPE_HSUPA || + type == TelephonyManager.NETWORK_TYPE_HSPA || + type == TelephonyManager.NETWORK_TYPE_EVDO_B || // api< 9: replace by 12 + type == TelephonyManager.NETWORK_TYPE_EHRPD || // api<11: replace by 14 + type == TelephonyManager.NETWORK_TYPE_HSPAP || // api<13: replace by 15 + type == TelephonyManager.NETWORK_TYPE_TD_SCDMA || // api<25: replace by 17 + name.startsWith(CDMA) || + name.equals(UMTS) || + name.equals(ONEXRTT) || + name.equals(EHRPD) || + name.equals(HSUPA) || + name.equals(HSDPA) || + name.equals(HSPA) || + name.equals(THREE_G); + } + + private boolean is4G(int type, String name){ + + return type == TelephonyManager.NETWORK_TYPE_LTE || // api<11: replace by 13 + type == TelephonyManager.NETWORK_TYPE_IWLAN || // api<25: replace by 18 + type == NETWORK_TYPE_LTE_CA || // LTE_CA + name.equals(LTE) || + name.equals(UMB) || + name.equals(HSPA_PLUS) || + name.equals(FOUR_G); + } + + private boolean is5G(int type, String name){ + + return type == TelephonyManager.NETWORK_TYPE_LTE || // api<11: replace by 13 + type == NETWORK_TYPE_NR || // api<25: replace by 18 + name.equals(FIVE_G) || + name.equals(NR); + } + + private PhoneStateListener phoneStateListener = new PhoneStateListener() { + @Override + public void onServiceStateChanged(ServiceState serviceState) { + NetworkManager.this.isNrAvailable = isNrAvailable(serviceState); + updateConnectionInfo(sockMan.getActiveNetworkInfo(), true); + } + }; + + /** + * Determine if NR network is available, for detect sdk < 30 + * + * @param serviceState the ServiceState from PhoneStateListener + * @return flag boolean if NR is available + */ + private boolean isNrAvailable(ServiceState serviceState ){ + String stateStr = serviceState.toString(); + return stateStr.contains("nrState=CONNECTED") || stateStr.contains("isNrAvailable = true"); + } } diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m index 40b2e42..014534b 100644 --- a/src/ios/CDVConnection.m +++ b/src/ios/CDVConnection.m @@ -82,6 +82,12 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability return @"3g"; } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { return @"4g"; + } else if (@available(iOS 14.0, *)) { + if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) { + return @"5g"; + } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) { + return @"5g"; + } } } return @"cellular"; @@ -104,9 +110,10 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability - (BOOL)isCellularConnection:(NSString*)theConnectionType { return [theConnectionType isEqualToString:@"2g"] || - [theConnectionType isEqualToString:@"3g"] || - [theConnectionType isEqualToString:@"4g"] || - [theConnectionType isEqualToString:@"cellular"]; + [theConnectionType isEqualToString:@"3g"] || + [theConnectionType isEqualToString:@"4g"] || + [theConnectionType isEqualToString:@"5g"] || + [theConnectionType isEqualToString:@"cellular"]; } - (void)updateReachability:(CDVReachability*)reachability diff --git a/types/index.d.ts b/types/index.d.ts index 60b6c26..77e68b6 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -42,6 +42,7 @@ interface Connection { * Connection.CELL_2G * Connection.CELL_3G * Connection.CELL_4G + * Connection.CELL_5G * Connection.CELL * Connection.NONE */ @@ -57,6 +58,7 @@ declare var Connection: { CELL_2G: string; CELL_3G: string; CELL_4G: string; + CELL_5G: string; CELL: string; NONE: string; } \ No newline at end of file diff --git a/www/Connection.js b/www/Connection.js index fb1d0ad..962908e 100644 --- a/www/Connection.js +++ b/www/Connection.js @@ -29,6 +29,7 @@ module.exports = { CELL_2G: '2g', CELL_3G: '3g', CELL_4G: '4g', + CELL_5G: '5g', CELL: 'cellular', NONE: 'none' }; From 59d8dedd8480bf02decbac1ce3af9ceb4d425d88 Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 13 May 2021 10:38:54 +0200 Subject: [PATCH 02/19] tests --- tests/tests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests.js b/tests/tests.js index 30e590a..a1fb507 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -37,6 +37,7 @@ exports.defineAutoTests = function () { cellular: 1, '3g': 1, '4g': 1, + '5g': 1, none: 1 }; expect(validValues[navigator.connection.type]).toBe(1); @@ -49,6 +50,7 @@ exports.defineAutoTests = function () { expect(Connection.CELL_2G).toBe('2g'); expect(Connection.CELL_3G).toBe('3g'); expect(Connection.CELL_4G).toBe('4g'); + expect(Connection.CELL_5G).toBe('5g'); expect(Connection.NONE).toBe('none'); expect(Connection.CELL).toBe('cellular'); }); From 0919fa7a07293ab1f64031ccc1122c2bee78c5e9 Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 7 Apr 2022 16:46:50 +0200 Subject: [PATCH 03/19] fixes from feebbacks --- package.json | 2 +- plugin.xml | 2 +- src/android/NetworkManager.java | 19 ++++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 58cf636..3de84e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-network-information", - "version": "3.0.1-dev", + "version": "3.0.0-dev", "description": "Cordova Network Information Plugin", "types": "./types/index.d.ts", "cordova": { diff --git a/plugin.xml b/plugin.xml index 71a4030..a05111f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ + version="3.0.0-dev"> Network Information Cordova Network Information Plugin diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 096b832..b148347 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -109,12 +109,12 @@ public class NetworkManager extends CordovaPlugin { private static boolean isNrAvailable; /** - * Sets the context of the Command. This can then be used to do things like - * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. - */ + * Sets the context of the Command. This can then be used to do things like + * get file paths associated with the Activity. + * + * @param cordova The context of the main Activity. + * @param webView The CordovaWebView Cordova is running in. + */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); @@ -126,7 +126,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { } /** - * Executes the request and returns PluginResult. + Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. @@ -244,6 +244,7 @@ private void updateConnectionInfo(NetworkInfo info, boolean forceRefresh) { * @param info the current active network info * @return type the type of network */ + // ENCAPSULATE @RequiresApi(api = Build.VERSION_CODES.N) private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info, Boolean forceRefresh) { // the info might still be null in this part of the code @@ -366,7 +367,7 @@ private boolean is3G(int type, String name){ private boolean is4G(int type, String name){ - return type == TelephonyManager.NETWORK_TYPE_LTE || // api<11: replace by 13 + return type == TelephonyManager.NETWORK_TYPE_LTE && name.equals(FOUR_G) || // api<11: replace by 13 type == TelephonyManager.NETWORK_TYPE_IWLAN || // api<25: replace by 18 type == NETWORK_TYPE_LTE_CA || // LTE_CA name.equals(LTE) || @@ -377,7 +378,7 @@ private boolean is4G(int type, String name){ private boolean is5G(int type, String name){ - return type == TelephonyManager.NETWORK_TYPE_LTE || // api<11: replace by 13 + return type == TelephonyManager.NETWORK_TYPE_LTE && name.equals(FIVE_G) || // api<11: replace by 13 type == NETWORK_TYPE_NR || // api<25: replace by 18 name.equals(FIVE_G) || name.equals(NR); From 0488d1d03954ef9c732971329d4f839122e3c459 Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 7 Apr 2022 16:48:38 +0200 Subject: [PATCH 04/19] missing changes --- src/android/NetworkManager.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index b148347..eb3d40a 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -40,7 +40,6 @@ Licensed to the Apache Software Foundation (ASF) under one import android.telephony.TelephonyManager; import android.telephony.ServiceState; -import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; import java.util.Locale; @@ -244,8 +243,6 @@ private void updateConnectionInfo(NetworkInfo info, boolean forceRefresh) { * @param info the current active network info * @return type the type of network */ - // ENCAPSULATE - @RequiresApi(api = Build.VERSION_CODES.N) private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info, Boolean forceRefresh) { // the info might still be null in this part of the code String type; @@ -267,7 +264,6 @@ private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info LOG.d(LOG_TAG, "Connection Type: " + type); return type; } - @RequiresApi(api = Build.VERSION_CODES.N) private String getTypeOfNetworkFallbackToTypeNoneIfNotConnected(NetworkInfo info) { // the info might still be null in this part of the code return this.getTypeOfNetworkFallbackToTypeNoneIfNotConnected(info, false); From 839745558a1a13faadbe14dadc1efcd9ae08c10f Mon Sep 17 00:00:00 2001 From: czu Date: Fri, 8 Apr 2022 11:08:42 +0200 Subject: [PATCH 05/19] reverted package-lock.json --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index a815da8..8f544f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-network-information", - "version": "3.0.1-dev", + "version": "3.0.0-dev", "lockfileVersion": 1, "requires": true, "dependencies": { From 448902eae08fac4be9f32f5af3f1ac1394880e2a Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Tue, 14 Jun 2022 13:30:05 -0300 Subject: [PATCH 06/19] fix: Update iOS availability check to 14.1 APIs are only available in 14.1, not in 14.0 Co-authored-by: David Boho --- src/ios/CDVConnection.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m index 014534b..0314b4a 100644 --- a/src/ios/CDVConnection.m +++ b/src/ios/CDVConnection.m @@ -82,7 +82,7 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability return @"3g"; } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { return @"4g"; - } else if (@available(iOS 14.0, *)) { + } else if (@available(iOS 14.1, *)) { if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) { return @"5g"; } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) { From b65a78315c6ed5e309fc639a2c02f9069d49505e Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 16 Jun 2022 14:22:46 +0200 Subject: [PATCH 07/19] currentRadioAccessTechnology value for different version of iOS. --- src/ios/CDVConnection.m | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m index 0314b4a..7f03948 100644 --- a/src/ios/CDVConnection.m +++ b/src/ios/CDVConnection.m @@ -60,32 +60,33 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability } else { if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) { CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new]; - if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) { + NSString *currentRadioAccessTechnology = radioAccessNameIn(telephonyInfo) + if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) { return @"2g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) { return @"2g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) { return @"3g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { return @"4g"; } else if (@available(iOS 14.1, *)) { - if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) { + if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) { return @"5g"; - } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) { + } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) { return @"5g"; } } @@ -166,4 +167,13 @@ - (void)pluginInitialize } } +static NSString *radioAccessNameIn(CTTelephonyNetworkInfo *networkInfo) { + if (@available(iOS 13.0, *)) { + if (networkInfo.currentRadioAccessTechnology == nil && networkInfo.dataServiceIdentifier) { + return [networkInfo.serviceCurrentRadioAccessTechnology objectForKey:networkInfo.dataServiceIdentifier]; + } + } + return networkInfo.currentRadioAccessTechnology; +} + @end From 71a04bf76221dcdd26373fac5c25d6b0e1095e67 Mon Sep 17 00:00:00 2001 From: czu Date: Thu, 16 Jun 2022 22:06:23 +0200 Subject: [PATCH 08/19] missing ; --- src/ios/CDVConnection.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m index 7f03948..465ac23 100644 --- a/src/ios/CDVConnection.m +++ b/src/ios/CDVConnection.m @@ -60,7 +60,7 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability } else { if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) { CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new]; - NSString *currentRadioAccessTechnology = radioAccessNameIn(telephonyInfo) + NSString *currentRadioAccessTechnology = radioAccessNameIn(telephonyInfo); if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) { return @"2g"; } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) { From e903a42102ddb9517f35c5d7aaff39bdae8a9783 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:38:18 +0200 Subject: [PATCH 09/19] Update src/ios/CDVConnection.m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/ios/CDVConnection.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m index 465ac23..ad67977 100644 --- a/src/ios/CDVConnection.m +++ b/src/ios/CDVConnection.m @@ -83,13 +83,17 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability return @"3g"; } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { return @"4g"; - } else if (@available(iOS 14.1, *)) { + } + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_1 + else if (@available(iOS 14.1, *)) { if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) { return @"5g"; } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) { return @"5g"; } } + #endif + } } return @"cellular"; } From 8298111faa6c4dd892fdfb536733c5d1d596608d Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:39:10 +0200 Subject: [PATCH 10/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index eb3d40a..5b5539a 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -373,7 +373,6 @@ private boolean is4G(int type, String name){ } private boolean is5G(int type, String name){ - return type == TelephonyManager.NETWORK_TYPE_LTE && name.equals(FIVE_G) || // api<11: replace by 13 type == NETWORK_TYPE_NR || // api<25: replace by 18 name.equals(FIVE_G) || From 0425d330124f11d5dea5dfa117524162c28d869f Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:39:24 +0200 Subject: [PATCH 11/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 5b5539a..d2fc6e2 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -362,7 +362,6 @@ private boolean is3G(int type, String name){ } private boolean is4G(int type, String name){ - return type == TelephonyManager.NETWORK_TYPE_LTE && name.equals(FOUR_G) || // api<11: replace by 13 type == TelephonyManager.NETWORK_TYPE_IWLAN || // api<25: replace by 18 type == NETWORK_TYPE_LTE_CA || // LTE_CA From 86b0b83495c6d25b326edd5eb7204a52f71eedc8 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:39:39 +0200 Subject: [PATCH 12/19] Update types/index.d.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 77e68b6..4fee538 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -61,4 +61,4 @@ declare var Connection: { CELL_5G: string; CELL: string; NONE: string; -} \ No newline at end of file +} From 4a2deb8117b223e735b3d4874a1e609a169c0f21 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:39:57 +0200 Subject: [PATCH 13/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index d2fc6e2..0bf3501 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -125,7 +125,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { } /** - Executes the request and returns PluginResult. + * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. From 52c397bb7091d81a67ecc8a1ce4be0b9fcceda1c Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:40:12 +0200 Subject: [PATCH 14/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 0bf3501..16bbfce 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -121,7 +121,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { this.telMan.listen( phoneStateListener, LISTEN_SERVICE_STATE); this.connectionCallbackContext = null; - this.registerConnectivityActionReceiver(); + this.registerConnectivityActionReceiver(); } /** From 6d94ca616762c725cc7f211f6df2186f30930f59 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:40:22 +0200 Subject: [PATCH 15/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 16bbfce..2efcad1 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -115,11 +115,11 @@ public class NetworkManager extends CordovaPlugin { * @param webView The CordovaWebView Cordova is running in. */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); - this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); - this.telMan = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); - this.telMan.listen( phoneStateListener, LISTEN_SERVICE_STATE); - this.connectionCallbackContext = null; + super.initialize(cordova, webView); + this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); + this.telMan = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); + this.telMan.listen( phoneStateListener, LISTEN_SERVICE_STATE); + this.connectionCallbackContext = null; this.registerConnectivityActionReceiver(); } From cc23a5cd70bcdcc776f40407e901d3d0dcef71e1 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:40:58 +0200 Subject: [PATCH 16/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 2efcad1..cacbf63 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -79,7 +79,7 @@ public class NetworkManager extends CordovaPlugin { public static final String UMB = "umb"; public static final String HSPA_PLUS = "hspa+"; - // 5G network types + // 5G network types public static final String FIVE_G = "5g"; public static final String NR = "nr"; From 0ccde7f3470368ac5ffee6459e9164b644d223fd Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:41:07 +0200 Subject: [PATCH 17/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index cacbf63..9974d03 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -73,7 +73,7 @@ public class NetworkManager extends CordovaPlugin { public static final String HSDPA = "hsdpa"; public static final String ONEXRTT = "1xrtt"; public static final String EHRPD = "ehrpd"; - // 4G network types + // 4G network types public static final String FOUR_G = "4g"; public static final String LTE = "lte"; public static final String UMB = "umb"; From 3f2c93e65896c530605ab6d9dda0ca1ad0f61f2c Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:41:16 +0200 Subject: [PATCH 18/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 9974d03..7f5fc56 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -57,7 +57,7 @@ public class NetworkManager extends CordovaPlugin { // 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"; From 555f5595061361d8a9cc16eb6703218d8754bce7 Mon Sep 17 00:00:00 2001 From: Mikhail Zumelzu Date: Tue, 25 Oct 2022 19:41:30 +0200 Subject: [PATCH 19/19] Update src/android/NetworkManager.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- src/android/NetworkManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java index 7f5fc56..f24d0f7 100755 --- a/src/android/NetworkManager.java +++ b/src/android/NetworkManager.java @@ -54,7 +54,7 @@ public class NetworkManager extends CordovaPlugin { public static final String WIFI = "wifi"; public static final String WIMAX = "wimax"; - // mobile + // mobile public static final String MOBILE = "mobile"; // Android L calls this Cellular, because I have no idea!