CellInfoManager
importjava.lang.reflect.Method;
importjava.util.Iterator;
importjava.util.List;
importorg.json.JSONArray;
importorg.json.JSONException;
importorg.json.JSONObject;
importandroid.content.Context;
importandroid.telephony.CellLocation;
importandroid.telephony.NeighboringCellInfo;
importandroid.telephony.PhoneStateListener;
importandroid.telephony.TelephonyManager;
importandroid.telephony.gsm.GsmCellLocation;
importandroid.util.Log;
publicclassCellInfoManager {
privateintasu;
privateintbid;
privateintcid;
privatebooleanisCdma;
privatebooleanisGsm;
privateintlac;
privateintlat;
privatefinalPhoneStateListener listener;
privateintlng;
privateintmcc;
privateintmnc;
privateintnid;
privateintsid;
privateTelephonyManager tel;
privatebooleanvalid;
privateContext context;
publicCellInfoManager(Context paramContext) {
this.listener =newCellInfoListener(this);
tel = (TelephonyManager) paramContext.getSystemService(Context.TELEPHONY_SERVICE);
this.tel.listen(this.listener, PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
context = paramContext;
}
publicstaticintdBm(inti) {
intj;
if(i >=0&& i <=31)
j = i * 2+ -113;
else
j = 0;
returnj;
}
publicintasu() {
returnthis.asu;
}
publicintbid() {
if(!this.valid)
update();
returnthis.bid;
}
publicJSONObject cdmaInfo() {
if(!isCdma()) {
returnnull;
}
JSONObject jsonObject = newJSONObject();
try{
jsonObject.put("bid", bid());
jsonObject.put("sid", sid());
jsonObject.put("nid", nid());
jsonObject.put("lat", lat());
jsonObject.put("lng", lng());
} catch(JSONException ex) {
jsonObject = null;
Log.e("CellInfoManager", ex.getMessage());
}
returnjsonObject;
}
publicJSONArray cellTowers() {
JSONArray jsonarray = newJSONArray();
intlat;
intmcc;
intmnc;
intaryCell[] = dumpCells();
lat = lac();
mcc = mcc();
mnc = mnc();
if(aryCell ==null|| aryCell.length <2) {
aryCell = newint[2];
aryCell[0] = cid;
aryCell[1] = -60;
}
for(inti =0; i
try{
intj2 = dBm(i +1);
JSONObject jsonobject = newJSONObject();
jsonobject.put("cell_id", aryCell[i]);
jsonobject.put("location_area_code", lat);
jsonobject.put("mobile_country_code", mcc);
jsonobject.put("mobile_network_code", mnc);
jsonobject.put("signal_strength", j2);
jsonobject.put("age",0);
jsonarray.put(jsonobject);
} catch(Exception ex) {
ex.printStackTrace();
Log.e("CellInfoManager", ex.getMessage());
}
}
if(isCdma())
jsonarray = newJSONArray();
returnjsonarray;
}
publicintcid() {
if(!this.valid)
update();
returnthis.cid;
}
publicint[] dumpCells() {
int[] aryCells;
if(cid() ==0) {
aryCells = newint[0];
returnaryCells;
}
List lsCellInfo = this.tel.getNeighboringCellInfo();
if(lsCellInfo ==null|| lsCellInfo.size() ==0) {
aryCells = newint[1];
inti = cid();
aryCells[0] = i;
returnaryCells;
}
int[] arrayOfInt1 =newint[lsCellInfo.size() *2+2];
intj =0+1;
intk = cid();
arrayOfInt1[0] = k;
intm = j +1;
intn = asu();
arrayOfInt1[j] = n;
Iterator iter = lsCellInfo.iterator();
while(true) {
if(!iter.hasNext()) {
break;
}
NeighboringCellInfo localNeighboringCellInfo = (NeighboringCellInfo) iter.next();
inti2 = localNeighboringCellInfo.getCid();
if((i2 <=0) || (i2 ==65535))
continue;
inti3 = m +1;
arrayOfInt1[m] = i2;
m = i3 + 1;
inti4 = localNeighboringCellInfo.getRssi();
arrayOfInt1[i3] = i4;
}
int[] arrayOfInt2 =newint[m];
System.arraycopy(arrayOfInt1, 0, arrayOfInt2,0, m);
aryCells = arrayOfInt2;
returnaryCells;
}
publicJSONObject gsmInfo() {
if(!isGsm()) {
returnnull;
}
JSONObject localObject = null;
while(true) {
try{
JSONObject localJSONObject1 = newJSONObject();
String str1 = this.tel.getNetworkOperatorName();
localJSONObject1.put("operator", str1);
String str2 = this.tel.getNetworkOperator();
if((str2.length() ==5) || (str2.length() ==6)) {
String str3 = str2.substring(0,3);
String str4 = str2.substring(3, str2.length());
localJSONObject1.put("mcc", str3);
localJSONObject1.put("mnc", str4);
}
localJSONObject1.put("lac", lac());
int[] arrayOfInt = dumpCells();
JSONArray localJSONArray1 = newJSONArray();
intk =0;
intm = arrayOfInt.length /2;
while(true) {
if(k >= m) {
localJSONObject1.put("cells", localJSONArray1);
localObject = localJSONObject1;
break;
}
intn = k *2;
inti1 = arrayOfInt[n];
inti2 = k *2+1;
inti3 = arrayOfInt[i2];
JSONObject localJSONObject7 = newJSONObject();
localJSONObject7.put("cid", i1);
localJSONObject7.put("asu", i3);
localJSONArray1.put(localJSONObject7);
k += 1;
}
} catch(JSONException localJSONException) {
localObject = null;
}
}
}
publicbooleanisCdma() {
if(!this.valid)
update();
returnthis.isCdma;
}
publicbooleanisGsm() {
if(!this.valid)
update();
returnthis.isGsm;
}
publicintlac() {
if(!this.valid)
update();
returnthis.lac;
}
publicintlat() {
if(!this.valid)
update();
returnthis.lat;
}
publicintlng() {
if(!this.valid)
update();
returnthis.lng;
}
publicintmcc() {
if(!this.valid)
update();
returnthis.mcc;
}
publicintmnc() {
if(!this.va