0

So I need to get RSSI of LTE network and I know that CellSignalStrengthLte has special method for getting RSSI, but it is available for API >= 29, but my app has min API of 23. However I can get a RSRP value for signal strength and I saw that there are some formulas to convert RSSI to RSRP and back, but I don't know how to apply them in Android.

So does anyone have a solution? Here is a small example of code:

    val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
        telephonyManager.allCellInfo.first().let { info ->
            when (info) {
                is CellInfoLte -> {
                    val signalStrengthLte = info.cellSignalStrength as CellSignalStrengthLte
                    signalStrengthLte.rssi // requires API >= 29
                    signalStrengthLte.dbm  // returns RSRP value
                    // Needs to convert RSRP to RSSI
                }
            }
        }
MrArtyD
  • 113
  • 1
  • 9

1 Answers1

0

In the end I wasn't able to convert RSRP to RSSI, but I have managed to get approximate RSSI value. After going through source code of CellSignalStrengthLte class - I found an old deprecated private field for the signal strength and the method to convert this signal to approximate RSSI value.

So to access this mSignalStrength private property I used reflection and then applied the formula from the source code.

Extension for getting private property from the class:

@Suppress("UNCHECKED_CAST")
inline fun <reified T : Any, R> T.getPrivateProperty(name: String): R? =
    T::class
        .memberProperties
        .firstOrNull { it.name == name }
        ?.apply { isAccessible = true }
        ?.get(this) as? R

And the calculation of approximate RSSI value from the code in the question:

val signalStrength = signalStrengthLte.getPrivateProperty<CellSignalStrengthLte, Int>("mSignalStrength")
val rssiValue = (signalStrength?.times(2))?.minus(113)

And again - this solution needs to be implemented only for devices which uses API < 29, because for newer versions there is a variable, which returns almost(if not fully) the same value.

MrArtyD
  • 113
  • 1
  • 9