3

The phone show me 5G, but telephoneManager.getDataNetworkType is LTE. In the settings, the sim card State show me the Mobile Voice Network Type(translate from Chinese, maybe not correct) is NR NSA (non standalone), but the Mobile data network type (translate from Chinese) is LTE.

So, how can I judge the 5G NSA or SA (standalone)?

I'm a new hand in Android, I'm not good at English, hhhh...thank you. That's my first question in Stackoverflow.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
程志超
  • 39
  • 1
  • 2

2 Answers2

2

In case you may have an Android 11 device, please refer to: https://source.android.com/devices/tech/connect/acts-5g-testing https://developer.android.com/about/versions/11/features/5g#detection

The emulator would also support faking a 5G network connection since 30.0.22: https://developer.android.com/about/versions/11/behavior-changes-all#emulator-5g


TelephonyManager and TelephonyDisplayInfo are both required for proper detection:

SL4A uses the following values to distinguish between NSA (non standalone), mmWave (millimeter wave) and SA (standalone) connection types for 5G:

Type Values
5G NSA TelephonyManager.getDataNetworkType() = LTE
TelephonyDisplayInfo.getNetworkType() = LTE
TelephonyDisplayInfo.getOverrideNetworkType() = NR_NSA
5G mmWaveTelephonyDisplayInfo.getOverrideNetworkType() = NR_MMWAVE
5G SA TelephonyManager.getDataNetworkType() = NR
TelephonyDisplayInfo.getNetworkType() = NR

TelephonyDisplayInfo.getOverrideNetworkType() can be used to tell apart 4G LTE from 5G NSA. While in most areas, an Android 11 emulator might be the best chance to actually test this.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • This is not 100% correct. NR NSA is not the same as LTE and it does not use always just the same bands as LTE. Android does support NR SA that has already been deployed in some area – kingston Apr 13 '21 at 16:38
  • It uses the same band and shares the channel names with identical frequencies (only the channels vary - and with SA, there's another band with then more unique channels). The AOSP source code would tell for certain, how well it is supported - and how to precisely tell the modes apart (hearsay is not that reliable)... my concern is based upon the fact, that the documentation does not mention 5G SA at all. – Martin Zeitler Apr 14 '21 at 09:05
  • The [release notes](https://source.android.com/setup/start/android-10-release) also read: "Android 10 adds support for 5G non-standalone (NSA)" ...while with Android 11 this appears to be better supported: https://source.android.com/devices/tech/connect/signal-strength – Martin Zeitler Apr 14 '21 at 09:12
  • You can find here https://developer.android.com/about/versions/11/features/5g#detection something about NRSA. I think that the article you linked says that Android supports non-standalone AS WELL as NRSA. About the bands used by NR NSA, are you sure that all the installations are using the same bands as LTE? Anyway, there is a boost in performance that you might be interested in detecting. – kingston Apr 14 '21 at 09:29
  • 5G New Radio uses these [frequency bands](https://en.wikipedia.org/wiki/5G_NR_frequency_bands) - compared to 4G LTE [frequency bands](https://en.wikipedia.org/wiki/LTE_frequency_bands). And Android 11 is most likely required (see URL above). – Martin Zeitler Apr 14 '21 at 10:39
  • I agree. Please notice that the APIs you referenced are currently not working properly even on Pixel 5 with Android 11. They return LTE even if you are on 5G and the `TelephonyDisplayInfo` does not report the value correctly either. It might get better later. Even the cellInfo are often not as you would expect: sometimes an NR cell that is used is reported as not used for example – kingston Apr 14 '21 at 11:54
  • Thank you very much~非常感谢! – 程志超 Jun 04 '21 at 13:10
1

Unfortunately, you can't rely on the APIs for many of these cases. The only method I found is to register a listener to get the ServiceState from the TelephonyManager and then parse the result of serviceState.toString()

telephonyManager.listen(object : PhoneStateListener() {
    override fun onServiceStateChanged(state: ServiceState) {
        val serviceState = state.toString()
        val nr = serviceState.isNrAvailable()
        ...
    }
}, PhoneStateListener.LISTEN_SERVICE_STATE)
fun String.isNrAvailable() =
        contains("nrState=CONNECTED") ||
        contains("nsaState=5"))

This gives you the correct answer most of the times. BTW NR NSA is the correct name for NR non-standalone.

If you want to distinguish between NRSA and NRNSA you need to fetch all the cellInfo from the TelephonyManager

telephonyManager.allCellInfo 

and check whether the primary cell is NR.

cellInfo.cellConnectionStatus

In some cases what you will see is that there are no NR cells. In that case, you can be sure that the connection is NRNSA (assuming that it is 5G). In other cases, there will be NR cells but they won't be reported as primary-cell. It is possible that the device will even report the NR cell as not connected at all even if it is used. Again in that case you know it is NRNSA. You might detect the NR cell that is used even if it is reported as not connected by checking the strengths.

cellInfo.cellSignalStrength.dbm

You will see that the strength reported is the same as the strength of the NR cell with the highest SS-RSRP (Synchronization Signal Reference Signal Received Power)

I would avoid using the TelephonyDisplayInfo since it is not reliable. These values are shown to the users and they follow the carrier policy or brand preferences.

kingston
  • 11,053
  • 14
  • 62
  • 116