FileDocCategorySizeDatePackage
CellState.javaAPI DocAndroid 1.5 API9170Wed May 06 22:42:00 BST 2009com.android.internal.location

CellState

public class CellState extends Object
Stores the cell tower state {@hide}

Fields Summary
public static String
TAG
public static int
RADIO_TYPE_GPRS
public static int
RADIO_TYPE_CDMA
public static int
RADIO_TYPE_WCDMA
private int
mCid
private int
mLac
private int
mMcc
private int
mMnc
private int
mHomeMcc
private int
mHomeMnc
private String
mCarrier
private int
mRadioType
private long
mTime
private int
mSignalStrength
private List
mNeighbors
Constructors Summary
public CellState()


      
        // constructor for invalid cell location
    
public CellState(android.telephony.TelephonyManager telephonyManager, android.telephony.CellLocation location, int signalStrength)

        GsmCellLocation loc = (GsmCellLocation)location;
        mLac = loc.getLac(); // example: 6032
        mCid = loc.getCid(); // example: 31792
        mTime = System.currentTimeMillis();

        // Get radio type
        int radioType = telephonyManager.getNetworkType();
        if (radioType == TelephonyManager.NETWORK_TYPE_GPRS ||
            radioType == TelephonyManager.NETWORK_TYPE_EDGE) {
            mRadioType = RADIO_TYPE_GPRS;
        } else if (radioType == TelephonyManager.NETWORK_TYPE_UMTS) {
            mRadioType = RADIO_TYPE_WCDMA;
        }

        // Get neighboring cells
        mNeighbors = new ArrayList<NeighborCell>();
        List<NeighboringCellInfo> neighboringCells = telephonyManager.getNeighboringCellInfo();
        if (neighboringCells != null) {
            for (NeighboringCellInfo n : neighboringCells) {
                if (n.getCid() == NeighboringCellInfo.UNKNOWN_CID) {
                    continue;
                }

                if (mRadioType == RADIO_TYPE_WCDMA) {
                    mNeighbors.add(new NeighborCell(-1, -1, n.getCid(), n.getRssi()));
                } else if (mRadioType == RADIO_TYPE_GPRS) {
                    try {
                        String hexCidLac = Integer.toHexString(n.getCid());
                        int l = hexCidLac.length();
                        if (l > 8) {
                            Log.w(TAG, "Unable to parse 2G Cell \"" + hexCidLac + "\"");
                            continue;
                        }
                        if (l < 8) {
                            for (int i = 0; i < (8-l); i++) {
                                hexCidLac = "0" + hexCidLac;
                            }
                        }
                        int lac = Integer.valueOf(hexCidLac.substring(0, 4), 16);
                        int cid  = Integer.valueOf(hexCidLac.substring(4), 16);
                        mNeighbors.add(new NeighborCell(cid, lac, -1, n.getRssi()));

                    } catch (Exception e) {
                        Log.e(TAG, "Error parsing 2G Cell \"" + n.getCid() + "\"", e);
                    }
                }
            }
        }

        // Get MCC/MNC
        String operator = telephonyManager.getNetworkOperator();
        if (operator != null && !operator.equals("")) {
            // Use a try/catch block to detect index out of bounds or number format exceptions.
            // If an error occurs, both mMcc and mMnc will be equal to -1.
            try {
                String mcc = operator.substring(0, 3);
                String mnc = operator.substring(3);
                int mccTmp = Integer.parseInt(mcc);
                int mncTmp = Integer.parseInt(mnc);
                
                // Parsing succeeded, update the instance variables together
                mMcc = mccTmp;
                mMnc = mncTmp;
            } catch (Exception e) {
                Log.e(TAG, "Error parsing MCC/MNC from operator \"" + operator + "\"", e);
            }
        }

        // Get Home MCC/MNC
        String homeOperator = telephonyManager.getSimOperator();
        if (homeOperator != null && !homeOperator.equals("")) {
            // Use a try/catch block to detect index out of bounds or number format exceptions.
            // If an error occurs, both mHomeMcc and mHomeMnc will be equal to -1.
            try {
                String mcc = homeOperator.substring(0, 3);
                String mnc = homeOperator.substring(3);
                int mccTmp = Integer.parseInt(mcc);
                int mncTmp = Integer.parseInt(mnc);
                
                // Parsing succeeded, update the instance variables together
                mHomeMcc = mccTmp;
                mHomeMnc = mncTmp;
            } catch (Exception e) {
                Log.e(TAG, "Error parsing MCC/MNC from home operator \"" + homeOperator + "\"", e);
            }
        }

        // Get Carrier
        String carrier = telephonyManager.getNetworkOperatorName();
        if (carrier != null && !carrier.equals("")) {
            mCarrier = carrier;
        }

        // Initial signal strength
        mSignalStrength = signalStrength;

        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            String neighbors = "[";
            for (NeighborCell n : mNeighbors) {
                neighbors += n.toString() + ",";
            }
            neighbors += "]";
            Log.d(TAG, "CellState(): " + mLac +"," + mCid + "," + mMnc +"," + mMcc + "," +
                mHomeMcc + "," + mHomeMnc + "," + mCarrier + "," + mRadioType + "," +
                mSignalStrength + "," + neighbors);
        }
    
Methods Summary
public booleanequals(com.android.internal.location.CellState other)

        return (mCid == other.mCid && mLac == other.mLac);
    
public java.lang.StringgetCarrier()

        return mCarrier;
    
public intgetCid()

        return mCid;
    
public intgetHomeMcc()

        return mHomeMcc;
    
public intgetHomeMnc()

        return mHomeMnc;
    
public intgetLac()

        return mLac;
    
public intgetMcc()

        return mMcc;
    
public intgetMnc()

        return mMnc;
    
public java.util.ListgetNeighbors()

        return mNeighbors;
    
public intgetRadioType()

        return mRadioType;
    
public intgetSignalStrength()

        return mSignalStrength;
    
public longgetTime()

        return mTime;
    
public booleanisValid()

        return (mCid != -1 && mLac != -1);
    
public voidsetCarrier(java.lang.String carrier)

        this.mCarrier = carrier;
    
public voidsetHomeMcc(int homeMcc)

        this.mHomeMcc = homeMcc;
    
public voidsetHomeMnc(int homeMnc)

        this.mHomeMnc = homeMnc;
    
public voidupdateRadioType(int radioType)

        mRadioType = radioType;

        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.d(TAG, "updateRadioType(): " + mLac +"," + mCid + "," + mMnc +"," + mMcc + "," +
                mHomeMcc + "," + mHomeMnc + "," + mCarrier + "," + mRadioType + "," +
                mSignalStrength);
        }
    
public voidupdateSignalStrength(int signalStrength)

        mSignalStrength = signalStrength;

        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.d(TAG, "updateSignal(): " + mLac +"," + mCid + "," + mMnc +"," + mMcc + "," + 
                mHomeMcc + "," + mHomeMnc + "," + mCarrier + "," + mRadioType + "," +
                mSignalStrength);
        }