Skip to content

Commit

Permalink
feat: Modified the 'networkGeneration' field to include the 'radioType'
Browse files Browse the repository at this point in the history
fix: If there is no SIM card connected, do not throw an exception.
  • Loading branch information
thorito committed Apr 18, 2024
1 parent 8c51c7f commit 3b1de57
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 165 deletions.
32 changes: 21 additions & 11 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/runConfigurations/example_lib_main_dart.xml

This file was deleted.

142 changes: 99 additions & 43 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## 3.0.1
* Modified the 'networkGeneration' field to include the 'radioType'
* If there is no SIM card connected, do not throw an exception.

## 3.0.0
* Breaking changes for android 10 and below as Telephony is no longer supported by them
* Removal of permission checking from package, you'll need to manage permission on the mobile end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ internal class MethodCallHandlerImpl(context: Context, activity: Activity?) : Me
this.context = context

// Retrieve the default subscription's TelephonyManager used for all calls"
mDefaultTelephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
try {
mDefaultTelephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
Expand Down Expand Up @@ -257,34 +261,35 @@ internal class MethodCallHandlerImpl(context: Context, activity: Activity?) : Me
@RequiresApi(Build.VERSION_CODES.N)
private fun networkGeneration(telephonyManager: TelephonyManager): String {
when (val radioType = telephonyManager.dataNetworkType) {
TelephonyManager.NETWORK_TYPE_GPRS,
TelephonyManager.NETWORK_TYPE_EDGE,
TelephonyManager.NETWORK_TYPE_CDMA,
TelephonyManager.NETWORK_TYPE_1xRTT,
TelephonyManager.NETWORK_TYPE_IDEN,
TelephonyManager.NETWORK_TYPE_GSM
-> return "2G"

TelephonyManager.NETWORK_TYPE_UMTS,
TelephonyManager.NETWORK_TYPE_EVDO_0,
TelephonyManager.NETWORK_TYPE_EVDO_A,
TelephonyManager.NETWORK_TYPE_HSDPA,
TelephonyManager.NETWORK_TYPE_HSUPA,
TelephonyManager.NETWORK_TYPE_HSPA,
TelephonyManager.NETWORK_TYPE_EVDO_B,
TelephonyManager.NETWORK_TYPE_EHRPD,
TelephonyManager.NETWORK_TYPE_HSPAP,
TelephonyManager.NETWORK_TYPE_TD_SCDMA
-> return "3G"

TelephonyManager.NETWORK_TYPE_LTE
-> return "4G"

TelephonyManager.NETWORK_TYPE_NR,
-> return "5G"
TelephonyManager.NETWORK_TYPE_GPRS -> return "2G (GPRS)"
TelephonyManager.NETWORK_TYPE_EDGE -> return "2G (EDGE)"
TelephonyManager.NETWORK_TYPE_CDMA -> return "2G (CDMA)"
TelephonyManager.NETWORK_TYPE_1xRTT -> return "2G (1xRTT)"
TelephonyManager.NETWORK_TYPE_IDEN -> return "2G (IDEN)"
TelephonyManager.NETWORK_TYPE_GSM -> return "2G (GSM)"

TelephonyManager.NETWORK_TYPE_UMTS -> return "3G (UMTS)"
TelephonyManager.NETWORK_TYPE_EVDO_0 -> return "3G (EVDO rev. 0)"
TelephonyManager.NETWORK_TYPE_EVDO_A -> return "3G (EVDO rev. A)"
TelephonyManager.NETWORK_TYPE_HSDPA -> return "3G (HSDPA)"
TelephonyManager.NETWORK_TYPE_HSUPA -> return "3G (HSUPA)"
TelephonyManager.NETWORK_TYPE_HSPA -> return "3G (HSPA)"
TelephonyManager.NETWORK_TYPE_EVDO_B -> return "3G (EVDO rev. B)"
TelephonyManager.NETWORK_TYPE_EHRPD -> return "3G (EHRPD)"
TelephonyManager.NETWORK_TYPE_HSPAP -> return "3G (HSPA+)"
TelephonyManager.NETWORK_TYPE_TD_SCDMA -> return "3G (TD-SCDMA)"

TelephonyManager.NETWORK_TYPE_LTE -> return "4G (5G NSA)"

TelephonyManager.NETWORK_TYPE_NR -> return "5G (5G SA)"

TelephonyManager.NETWORK_TYPE_IWLAN -> return "IWLAN"

TelephonyManager.NETWORK_TYPE_UNKNOWN -> return "Unknown"

else -> radioType.toString()
}

return "unknown"
}

Expand Down
Loading

0 comments on commit 3b1de57

Please sign in to comment.