问题
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);
回答1:
Neighboring cells are reported in two different ways:
On GSM/GPRS (which seems to be the network you were on when you took your screenshot) you should get the MCC/MNC/LAC/CID tuple for the neighboring cells. I see you get valid CID values. The PSC will always be -1 if you're on a GSM (2.xG) network, as the PSC has no meaning on GSM (PSC is a CDMA parameter and GSM is TDMA-based).
On UMTS things are different: For neighboring cells only the PSC is reported, and you will not find out their other parameters unless you connect to them.
LTE is in principle similar to UMTS, but with slightly different names: instead of LAC and CID you have TAC (Tracking Area Code) and CI (Cell Identity); instead of a PSC you have a PCI (Physical Cell ID). However, they do essentially the same as their UMTS counterparts.
Note, however, that implementation varies greatly between devices: Some phones will not report PSC even on 3G networks, and some will never report neighboring cells. The Nexus S (as most Samsung-built devices) reports neither.
Not sure about the LAC=0, though. It might mean "same LAC as current cell", in which case it would be interesting to see the output from the boundary of a Location Area, where the phone can pick up cells with multiple LACs. (Would we be seeing cells from both LAs? Or just from "our" LA? What LAC would be reported for cells from a neighboring LA?)
回答2:
The mobile device should be aware of the neighbouring cells, so that it can hand over to a better cell if necessary. In any case, you've told it to get information about neighbouring cells, so that's what it should do. Your results don't seem to match up to what is described in the Android documentation either. I would report this problem to the device vendor as a firmware bug.
I can imagine a situation where you would see a neighbouring cell with a stronger signal if for example the cell was GSM, and the device preferred a UMTS cell with a weaker signal, but this should be obvious from the network type field.
来源:https://stackoverflow.com/questions/13208236/neighbouring-cell-information-is-inaccurate