Search in sources :

Example 1 with CellInfo

use of edu.berkeley.cs.amplab.carat.thrift.CellInfo in project carat by amplab.

the class SamplingLibrary method getCellInfo.

/* check the GSM cell information */
public static CellInfo getCellInfo(Context context) {
    CellInfo curCell = new CellInfo();
    TelephonyManager myTelManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String netOperator = myTelManager.getNetworkOperator();
    // etc)
    if (netOperator == null || netOperator.length() < 3) {
        return curCell;
    }
    if (SamplingLibrary.getPhoneType(context) == PHONE_TYPE_CDMA) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) myTelManager.getCellLocation();
        if (cdmaLocation == null) {
        // Log.v("cdmaLocation", "CDMA Location:" + cdmaLocation);
        } else {
            int cid = cdmaLocation.getBaseStationId();
            int lac = cdmaLocation.getNetworkId();
            int mnc = cdmaLocation.getSystemId();
            int mcc = Integer.parseInt(netOperator.substring(0, 3));
            curCell.CID = cid;
            curCell.LAC = lac;
            curCell.MNC = mnc;
            curCell.MCC = mcc;
            curCell.radioType = SamplingLibrary.getMobileNetworkType(context);
        // Log.v("MCC", "MCC is:" + mcc);
        // Log.v("MNC", "MNC is:" + mnc);
        // Log.v("CID", "CID is:" + cid);
        // Log.v("LAC", "LAC is:" + lac);
        }
    } else if (SamplingLibrary.getPhoneType(context) == PHONE_TYPE_GSM) {
        GsmCellLocation gsmLocation = (GsmCellLocation) myTelManager.getCellLocation();
        if (gsmLocation == null) {
        // Log.v("gsmLocation", "GSM Location:" + gsmLocation);
        } else {
            int cid = gsmLocation.getCid();
            int lac = gsmLocation.getLac();
            int mcc = Integer.parseInt(netOperator.substring(0, 3));
            int mnc = Integer.parseInt(netOperator.substring(3));
            curCell.MCC = mcc;
            curCell.MNC = mnc;
            curCell.LAC = lac;
            curCell.CID = cid;
            curCell.radioType = SamplingLibrary.getMobileNetworkType(context);
        // Log.v("MCC", "MCC is:" + mcc);
        // Log.v("MNC", "MNC is:" + mnc);
        // Log.v("CID", "CID is:" + cid);
        // Log.v("LAC", "LAC is:" + lac);
        }
    }
    return curCell;
}
Also used : CellInfo(edu.berkeley.cs.amplab.carat.thrift.CellInfo) TelephonyManager(android.telephony.TelephonyManager) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Aggregations

TelephonyManager (android.telephony.TelephonyManager)1 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 CellInfo (edu.berkeley.cs.amplab.carat.thrift.CellInfo)1