This is an automated email from the ASF dual-hosted git repository.
manuelbeck pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/cordova-plugin-network-information.git
The following commit(s) were added to refs/heads/master by this push:
new 0a86a7b feat(android): add 5g check and test (#172)
0a86a7b is described below
commit 0a86a7b8a363b8f0b7a906dcac48b11192b72d2c
Author: Manuel Beck <[email protected]>
AuthorDate: Tue Mar 31 14:54:18 2026 +0200
feat(android): add 5g check and test (#172)
Generated-By: GPT-5.3-Codex, GitHub Copilot Chat
---
src/android/NetworkManager.java | 45 +++++++++++++++++++++++++----------------
tests/tests.js | 4 +++-
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java
index fa36d80..816b34f 100755
--- a/src/android/NetworkManager.java
+++ b/src/android/NetworkManager.java
@@ -36,6 +36,7 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
+import android.telephony.TelephonyManager;
import java.util.Locale;
@@ -71,6 +72,9 @@ public class NetworkManager extends CordovaPlugin {
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";
@@ -79,6 +83,7 @@ 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";
private static final String LOG_TAG = "NetworkManager";
@@ -271,26 +276,32 @@ public class NetworkManager extends CordovaPlugin {
} 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)) {
+ int subtype = info.getSubtype();
+ String subtypeName = info.getSubtypeName().toLowerCase(Locale.US);
+ if (subtypeName.equals(GSM) ||
+ subtypeName.equals(GPRS) ||
+ subtypeName.equals(EDGE) ||
+ subtypeName.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)) {
+ } else if (subtypeName.startsWith(CDMA) ||
+ subtypeName.equals(UMTS) ||
+ subtypeName.equals(ONEXRTT) ||
+ subtypeName.equals(EHRPD) ||
+ subtypeName.equals(HSUPA) ||
+ subtypeName.equals(HSDPA) ||
+ subtypeName.equals(HSPA) ||
+ subtypeName.equals(THREE_G)) {
return TYPE_3G;
- } else if (type.equals(LTE) ||
- type.equals(UMB) ||
- type.equals(HSPA_PLUS) ||
- type.equals(FOUR_G)) {
+ } else if (subtypeName.equals(LTE) ||
+ subtypeName.equals(UMB) ||
+ subtypeName.equals(HSPA_PLUS) ||
+ subtypeName.equals(FOUR_G)) {
return TYPE_4G;
+ // Android 10+ exposes 5G as NR (New Radio).
+ } else if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
subtype == TelephonyManager.NETWORK_TYPE_NR) ||
+ subtypeName.equals(NR) ||
+ subtypeName.equals(FIVE_G)) {
+ return TYPE_5G;
}
}
return TYPE_UNKNOWN;
diff --git a/tests/tests.js b/tests/tests.js
index 1954818..8d89c5f 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -32,6 +32,7 @@ exports.defineAutoTests = function () {
cellular: 1,
'3g': 1,
'4g': 1,
+ '5g': 1,
none: 1
};
expect(validValues[navigator.connection.type]).toBe(1);
@@ -44,6 +45,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');
});
@@ -76,7 +78,7 @@ exports.defineManualTests = function (contentEl,
createActionButton) {
'<span id="results"></span>' +
'</div><div id="connection"></div>' +
'Expected result: Status box will update with type of connection using
two different methods. Both values must match.' +
- ' The result will be unknown, ethernet, wifi, 2g, 3g, 4g, none, or
cellular. Make sure it matches what the device is connected to.' +
+ ' The result will be unknown, ethernet, wifi, 2g, 3g, 4g, 5g, none,
or cellular. Make sure it matches what the device is connected to.' +
'</p> <div id="actions"></div>';
document.addEventListener('online', onEvent, false);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]