Skip to content

Commit

Permalink
Remove CellsRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
illarionov committed Jan 4, 2014
1 parent 58c2d23 commit 9cbfaad
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 239 deletions.
217 changes: 217 additions & 0 deletions src/org/mozilla/mozstumbler/cellscanner/CellInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package org.mozilla.mozstumbler.cellscanner;

import android.os.Build;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;

import org.json.JSONException;
import org.json.JSONObject;

public class CellInfo {
public static final String RADIO_GSM = "gsm";
public static final String RADIO_CDMA = "cdma";
public static final String RADIO_WCDMA = "wcdma";

public static final String CELL_RADIO_GSM = "gsm";
public static final String CELL_RADIO_UMTS = "umts";
public static final String CELL_RADIO_CDMA = "cdma";
public static final String CELL_RADIO_LTE = "lte";

static final int UNKNOWN_CID = -1;
static final int UNKNOWN_SIGNAL = -1000;

private String mRadio = RADIO_GSM;
private String mCellRadio;

private int mMcc;
private int mMnc;
private int mCid;
private int mLac;
private int mSignal;
private int mAsu;
private int mTa;
private int mPsc;

CellInfo(int phoneType) {
reset();
setRadio(phoneType);
}

public String getRadio() { return mRadio; }

public String getCellRadio() {
return mCellRadio;
}

public JSONObject toJSONObject() {
final JSONObject obj = new JSONObject();

try {
obj.put("radio", getCellRadio());
obj.put("mcc", mMcc);
obj.put("mnc", mMnc);
if (mLac != UNKNOWN_CID) obj.put("lac", mLac);
if (mCid != UNKNOWN_CID) obj.put("cid", mCid);
if (mSignal != UNKNOWN_SIGNAL) obj.put("signal", mSignal);
if (mAsu != UNKNOWN_SIGNAL) obj.put("asu", mAsu);
if (mTa != UNKNOWN_CID) obj.put("ta", mTa);
if (mPsc != UNKNOWN_CID) obj.put("psc", mPsc);
} catch (JSONException jsonE) {
throw new IllegalStateException(jsonE);
}

return obj;
}

void reset() {
mRadio = RADIO_GSM;
mCellRadio = CELL_RADIO_GSM;
mMcc = UNKNOWN_CID;
mMnc = UNKNOWN_CID;
mLac = UNKNOWN_CID;
mCid = UNKNOWN_CID;
mSignal = UNKNOWN_SIGNAL;
mAsu = UNKNOWN_SIGNAL;
mTa = UNKNOWN_CID;
mPsc = UNKNOWN_CID;
}

void setRadio(int phoneType) {
String radio = getRadioTypeName(phoneType);
if (radio == null) {
throw new IllegalArgumentException("Unexpected Phone Type: " + phoneType);
}
mRadio = radio;
}

void setCellLocation(CellLocation cl,
int networkType,
String networkOperator,
Integer gsmSignalStrength,
Integer cdmaRssi) {
if (cl instanceof GsmCellLocation) {
final int lac, cid;
final GsmCellLocation gcl = (GsmCellLocation) cl;

reset();
mCellRadio = getCellRadioTypeName(networkType);
setNetworkOperator(networkOperator);

lac = gcl.getLac();
cid = gcl.getCid();
if (lac >= 0) mLac = lac;
if (cid >= 0) mCid = cid;

if (Build.VERSION.SDK_INT >= 9) {
final int psc = gcl.getPsc();
if (psc >= 0) mPsc = psc;
}

if (gsmSignalStrength != null) {
mAsu = gsmSignalStrength;
}
} else if (cl instanceof CdmaCellLocation) {
final CdmaCellLocation cdl = (CdmaCellLocation) cl;

reset();
mCellRadio = getCellRadioTypeName(networkType);

setNetworkOperator(networkOperator);

mMnc = cdl.getSystemId();

mLac = cdl.getNetworkId();
mCid = cdl.getBaseStationId();

if (cdmaRssi != null) {
mSignal = cdmaRssi;
}
} else {
throw new IllegalArgumentException("Unexpected CellLocation type: " + cl.getClass().getName());
}
}

void setNeighboringCellInfo(NeighboringCellInfo nci, String networkOperator) {
final int lac, cid, psc, rssi;

reset();
mCellRadio = getCellRadioTypeName(nci.getNetworkType());
setNetworkOperator(networkOperator);

lac = nci.getLac();
cid = nci.getCid();
psc = nci.getPsc();
rssi = nci.getRssi();

if (lac >= 0) mLac = lac;
if (cid >= 0) mCid = cid;
if (psc >= 0) mPsc = psc;
if (rssi != NeighboringCellInfo.UNKNOWN_RSSI) mAsu = rssi;
}

void setNetworkOperator(String mccMnc) {
if (mccMnc == null || mccMnc.length() < 5 || mccMnc.length() > 8) {
throw new IllegalArgumentException("Bad mccMnc: " + mccMnc);
}
mMcc = Integer.parseInt(mccMnc.substring(0, 3));
mMnc = Integer.parseInt(mccMnc.substring(3));
}

static String getCellRadioTypeName(int networkType) {
String name;
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
return CELL_RADIO_GSM;
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_HSPAP:
return CELL_RADIO_UMTS;
case TelephonyManager.NETWORK_TYPE_LTE:
return CELL_RADIO_LTE;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
name = "CDMA - EvDo rev. 0";
break;
case TelephonyManager.NETWORK_TYPE_EVDO_A:
name = "CDMA - EvDo rev. A";
break;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
name = "CDMA - EvDo rev. B";
break;
case TelephonyManager.NETWORK_TYPE_1xRTT:
name = "CDMA - 1xRTT";
break;
case TelephonyManager.NETWORK_TYPE_EHRPD:
name = "CDMA - eHRPD";
break;
case TelephonyManager.NETWORK_TYPE_IDEN:
name = "iDEN";
break;
default:
name = "UNKNOWN (" + String.valueOf(networkType) + ")";
break;
}
throw new IllegalArgumentException("Unexpected Network Type: " + name);
}

private static String getRadioTypeName(int phoneType) {
switch (phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
return RADIO_CDMA;

case TelephonyManager.PHONE_TYPE_GSM:
return RADIO_GSM;

case TelephonyManager.PHONE_TYPE_NONE:
case TelephonyManager.PHONE_TYPE_SIP:
// These devices have no radio.
default:
return null;
}
}
}
6 changes: 3 additions & 3 deletions src/org/mozilla/mozstumbler/cellscanner/CellScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface CellScannerImpl {

public void stop();

public List<CellsRecord.CellInfo> getCellInfo();
public List<CellInfo> getCellInfo();
}

public CellScanner(Context context) {
Expand Down Expand Up @@ -53,13 +53,13 @@ public void start() {
public void run() {
Log.d(LOGTAG, "Cell Scanning Timer fired");
final long curTime = System.currentTimeMillis();
List<CellsRecord.CellInfo> cells = mImpl.getCellInfo();
List<CellInfo> cells = mImpl.getCellInfo();
if (cells.isEmpty()) {
return;
}

JSONArray cellsJson = new JSONArray();
for (CellsRecord.CellInfo cell : cells) cellsJson.put(cell.toJSONObject());
for (CellInfo cell : cells) cellsJson.put(cell.toJSONObject());

Intent intent = new Intent(ScannerService.MESSAGE_TOPIC);
intent.putExtra(Intent.EXTRA_SUBJECT, "CellScanner");
Expand Down
Loading

0 comments on commit 9cbfaad

Please sign in to comment.