I'm not sure if it's normal, but even though I instantiated a specific TelephonyManager for each of my SIM cards (with the subscriptionId), calling allCellInfo returns all cells detected by the device.
I use these APIs to monitor cells with CellInfo objects.
Our algorithm is now quite easy: a timer running every second retrieve CellInfo objects through 2 APIs:
- for
Android Q+,requestCellInfoUpdatewhich works well - for older versions, I fallback to
allCellInfo
We used to listen to callbacks using PhoneStateListener, but it works erratically depending on manufacturers and devices (some Samsung devices for example).
Possible solutions:
- filter
CellInfoon MCC/MNC: impossible as some carriers share networks. Don't know if a customer of "carrier #1" sees an antenna from "carrier #2" with MCC/MNC from "carrier #1" or "carrier #2". - re-use
PhoneStateListener / TelephonyCallback:TelephonyCallbackmay be working correctly, but it's only available sinceAndroid S.PhoneStateListeneradded a complexity to our algorithm (if it doesn't give us the right answer, then fallback to the timer). That's why we decided to remove this logic.
Does anyone have a solution to suggest to make work allCellInfo as intended?