android5g

How to get the physical channel configuration of the cellphone via programming


I want to get the PCI of both primary serving cell and secondary serving cell in 5G NSA, but it seems that I cannot get what I want using getAllCellInfo(). It seems that I need to parse the physical channel configuration as below:

{{mConnectionStatus=PrimaryServing,...,mRat=LTE,...,mPhysicalCellId=123},
 {mConnectionStatus=SecondaryServing,...,mRat=NR,...}

Does anyone know how to get the (real-time) configuration? Or can I get the PCIs in another way? Thanks very much!


Solution

  • About PhysicalChannelConfig

    The only possible way how to obtain PhysicalChannelConfig is via TelephonyManager.registerTelephonyCallback method. You can for example pass an instance of TelephonyCallback.PhysicalChannelConfigListener and you'll start obtaining what you need.

    Please note that permission Manifest.permission.READ_PRECISE_PHONE_STATE is required, so your app needs to be a system app of carrier-privileged app.

    There were some attempts to adjust this protection level, current status can be seen here. But as of Android 12 there's no way how to get PhysicalChannelConfig if you are a regular developer.

    About PCIs

    You can sometimes get PCIs of serving LTE and NR NSA cells via getAllCellInfo() as you mentioned. Sometimes there's one instance of CellInfoNr with PCI is present. This behaviour is device-specific.

    Generally speaking - Android does not provide any official API you request.