I'm trying to make use of a mobile information about neighbouring cells, available on Android via TelephonyManager
class and its getNeighboringCellInfo
method. Below I'm posting a part of code (mostly taken from publicly available sources) which does the job, and one example of output which this code produces (shown in attached screenshot). The code and the image are placed "as is" without any changes, so it should be relatively easy to associate one with the other and make sure it should work correctly (of course, there can be errors which I overlooked).
The problem is that the list of neighbouring cells does often contain elements with "incorrect" (to my understanding) data, such as:
- a
NeighboringCellInfo
with all properties -lac
,cid
,psc
- set to -1, and onlyrssi
field seems meaningful; - a
NeighboringCellInfo
withlac
equal to 0; does this mean that thelac
is the same as current active cell? - a
NeighboringCellInfo
withrssi
value outside the range [0, 31] and notUNKNOWN_RSSI
; such values can be as positive (33, as shown in the screenshot), as negative (they look like a proper raw rssi value, that is without the need to convert fromasu
); - list elements obtained in the same geolocation do not demonstrate consistency as much as I'd expect, that is in two consecutive scans every one can have an element omitted in the other one, and the omitted elements' rssi levels are not of a most low level in the list (in fact their rssi's can be larger than for currently used cell); I admit this could be right behaviour if every cell signal tends to be very unstable, but I'm not sure if it's true in general for GSM and/or UMTS networks. Current cell always has all fields defined well, but its rssi can vary very quickly in a range of 30 dBm (say from -60 to -90).
- The same as 4, but about consistency from one day to another. In a highly urbanized and matured environment I'd expect to see the same list of cells every day, yet they vary in such a way, that one day I don't even see a mention about a cell that was active cell in a previuos day.
Does all this mean a normal functioning of mobile technology, some sort of possibly powersaving optimizations, or a flaw in a specific device (LG Optimus One in my case)?
Please suggest how can one obtain consistent readings from cell environment on Android, if this is possible.
GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
String networkOperator = telephonyManager.getNetworkOperator();
int type = telephonyManager.getNetworkType();
String mcc = networkOperator.substring(0, 3);
String mnc = networkOperator.substring(3);
textMCC.setText("mcc: " + mcc + " mnc: " + mnc);
textMNC.setText("operator: " + networkOperator);
int cid = cellLocation.getCid();
int lac = cellLocation.getLac();
int psc = cellLocation.getPsc();
textGsmCellLocation.setText(cellLocation.toString());
textCID.setText("lac: " + String.valueOf(lac) + " cid: " + String.valueOf(cid) + " psc: " + String.valueOf(psc) + " type: " + String.valueOf(type) + " rssi: " + String.valueOf(currentCellRSSI));
TextView Neighboring = (TextView)findViewById(R.id.neighboring);
List<NeighboringCellInfo> NeighboringList = telephonyManager.getNeighboringCellInfo();
String stringNeighboring = "Neighboring List - Lac : Cid : Psc : type : RSSI\n";
for(int i = 0; i < NeighboringList.size(); i++)
{
String dBm;
int rssi = NeighboringList.get(i).getRssi();
if(rssi == NeighboringCellInfo.UNKNOWN_RSSI)
{
dBm = "Unknown RSSI";
}
else
{
if(rssi >= 0 && rssi < 32)
{
dBm = String.valueOf(-113 + 2 * rssi) + " dBm";
}
else
{
dBm = "Unknown value:" + Integer.toString(rssi);
}
}
stringNeighboring = stringNeighboring
+ String.valueOf(NeighboringList.get(i).getLac()) + " : "
+ String.valueOf(NeighboringList.get(i).getCid()) + " : "
+ String.valueOf(NeighboringList.get(i).getPsc()) + " : "
+ String.valueOf(NeighboringList.get(i).getNetworkType()) + " : "
+ dBm + "\n";
}
Neighboring.setText(stringNeighboring);