Example usage for android.telephony.cdma CdmaCellLocation getNetworkId

List of usage examples for android.telephony.cdma CdmaCellLocation getNetworkId

Introduction

In this page you can find the example usage for android.telephony.cdma CdmaCellLocation getNetworkId.

Prototype

public int getNetworkId() 

Source Link

Usage

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Parses data from PhoneStateListener.LISTEN_CELL_LOCATION.onCellLocationChanged
 * http://developer.android.com/reference/android/telephony/cdma/CdmaCellLocation.html
 * @param location CdmaCellLocation//  ww w .  j ava2  s  .c  om
 * @return JSON
 */
public static String cdmaCellLocationJSON(CdmaCellLocation location) {

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && location != null) {
        try {
            json.put("provider", CELLLOCATION_PROVIDER);
            json.put("type", CDMA);
            json.put("timestamp", calendar.getTimeInMillis());
            json.put("baseStationId", location.getBaseStationId()); // -1 if unknown
            json.put("networkId", location.getNetworkId()); // -1 if unknown
            json.put("systemId", location.getSystemId()); // -1 if unknown
            json.put("baseStationLatitude",
                    CdmaCellLocation.convertQuartSecToDecDegrees(location.getBaseStationLatitude()));
            json.put("baseStationLongitude",
                    CdmaCellLocation.convertQuartSecToDecDegrees(location.getBaseStationLongitude()));
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

From source file:pk.development.sms.detection.CellSniffer.java

@Override
public void onCellLocationChanged(CellLocation location) {

    switch (teleManager.getPhoneType()) {
    case TelephonyManager.PHONE_TYPE_GSM:
        GsmCellLocation gsmCellData = (GsmCellLocation) teleManager.getCellLocation();
        if (gsmCellData != null) {
            btsData.setLac(gsmCellData.getLac());
            btsData.setCid(gsmCellData.getCid());
            btsData.setRoaming(teleManager.isNetworkRoaming());
            btsData.setBtsType(BtsType.GSM);

            String networkProvider = teleManager.getNetworkOperator();
            if (!TextUtils.isEmpty(networkProvider)) {
                btsData.setMcc(Integer.parseInt(networkProvider.substring(0, 3)));
                btsData.setMnc(Integer.parseInt(networkProvider.substring(3)));
            }/*from   w w  w.j  a va  2 s .c om*/
        }
        break;
    case TelephonyManager.PHONE_TYPE_CDMA:
        CdmaCellLocation cdmaCellData = (CdmaCellLocation) teleManager.getCellLocation();
        if (cdmaCellData != null) {
            btsData.setLac(cdmaCellData.getNetworkId());
            btsData.setCid(cdmaCellData.getBaseStationId());
            btsData.setBtsType(BtsType.CDMA);
        }
        break;
    }
}

From source file:ru.dublgis.androidhelpers.mobility.CellListener.java

private void reportData() {
    if (ActivityCompat.checkSelfPermission(getContext(), ACCESS_FINE_LOCATION) != PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PERMISSION_GRANTED) {
        return;/*w  w  w .ja  v a  2  s .c o  m*/
    }

    int dbm = 99;
    boolean gsm = false;

    synchronized (TAG) {
        gsm = mSignalStrengthLast.isGsm();
        dbm = gsm ? getGsmDbm(mSignalStrengthLast.getGsmSignalStrength()) : mSignalStrengthLast.getCdmaDbm();
    }

    CellLocation loc = mManager.getCellLocation();

    if (gsm && loc instanceof GsmCellLocation) {
        GsmCellLocation locGsm = (GsmCellLocation) loc;
        cellUpdate(native_ptr_, "gsm", locGsm.getCid(), // gsm cell id, -1 if unknown, 0xffff max legal value
                locGsm.getLac(), // gsm location area code, -1 if unknown, 0xffff max legal value
                Integer.MAX_VALUE, Integer.MAX_VALUE, dbm, Integer.MAX_VALUE);
    } else if (loc instanceof CdmaCellLocation) {
        CdmaCellLocation locCdma = (CdmaCellLocation) loc;
        cellUpdate(native_ptr_, "cdma", locCdma.getBaseStationId(), // cdma base station identification number, -1 if unknown
                locCdma.getNetworkId(), // cdma network identification number, -1 if unknown
                Integer.MAX_VALUE, Integer.MAX_VALUE, dbm, Integer.MAX_VALUE);
    }
}

From source file:org.most.input.CellInput.java

@Override
public void workToDo() {
    CellLocation cellLocation = _telephonyManager.getCellLocation();
    _telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    nciList = _telephonyManager.getNeighboringCellInfo();
    DataBundle b = _bundlePool.borrowBundle();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmLocation = (GsmCellLocation) cellLocation;
        b.putInt(KEY_GSM_CELL_ID, gsmLocation.getCid());
        b.putInt(KEY_GSM_LAC, gsmLocation.getLac());
        b.putInt(KEY_RSSI, _phoneStateListener.signalStrengthValue);
        // gsmLocation.getPsc() require api 9
        // b.putInt(KEY_GSM_PSC, gsmLocation.getPsc());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_GSM);
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
        b.putInt(KEY_BASE_STATION_ID, cdmaLocation.getBaseStationId());
        b.putInt(KEY_BASE_STATION_LATITUDE, cdmaLocation.getBaseStationLatitude());
        b.putInt(KEY_BASE_STATION_LONGITUDE, cdmaLocation.getBaseStationLongitude());
        b.putInt(KEY_BASE_NETWORK_ID, cdmaLocation.getNetworkId());
        b.putInt(KEY_BASE_SYSTEM_ID, cdmaLocation.getSystemId());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_CDMA);
    } else {/*from   ww  w .  j  av a 2 s  . c  o  m*/
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_NONE);
    }
    b.putLong(Input.KEY_TIMESTAMP, System.currentTimeMillis());
    b.putInt(Input.KEY_TYPE, Input.Type.CELL.toInt());
    post(b);
    postResults(b, nciList);
    scheduleNextStart();
}

From source file:com.samknows.measurement.environment.CellTowersData.java

private void addCellData(List<String> list) {
    DCSStringBuilder builder = new DCSStringBuilder();

    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmLocation = (GsmCellLocation) cellLocation;
        builder.append(ID + GSM + VERSION);
        builder.append(time / 1000);/* w  w  w. j ava 2 s  .co m*/
        builder.append(GSM);
        builder.append(gsmLocation.getCid());
        builder.append(gsmLocation.getLac());
        builder.append(Build.VERSION.SDK_INT >= 9 ? gsmLocation.getPsc() : -1);

    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
        builder.append(ID + CDMA);
        builder.append(time / 1000);
        builder.append(CDMA);
        builder.append(cdmaLocation.getBaseStationId());
        builder.append(cdmaLocation.getBaseStationLatitude());
        builder.append(cdmaLocation.getBaseStationLongitude());
        builder.append(cdmaLocation.getNetworkId());
        builder.append(cdmaLocation.getSystemId());
    }

    if (signal.isGsm()) {
        builder.append(signal.getGsmSignalStrength());
        builder.append(signal.getGsmBitErrorRate());
    } else {
        builder.append(signal.getCdmaDbm());
        builder.append(signal.getCdmaEcio());
    }
    list.add(builder.build());
}

From source file:org.mozilla.mozstumbler.service.scanners.cellscanner.CellInfo.java

void setCellLocation(CellLocation cl, int networkType, String networkOperator, Integer gsmSignalStrength,
        Integer cdmaRssi) {/*  ww  w. j  a v  a  2  s  .  co  m*/
    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());
    }
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellLocationChannel.java

@Override
protected boolean startPoll() {
    if (telephony != null) {
        CellLocation loc = telephony.getCellLocation();
        JSONObject value = new JSONObject();
        try {/*from w w w.j  av a 2  s .  c o  m*/
            value.put("timestamp", System.currentTimeMillis());
            if (loc instanceof GsmCellLocation) {
                GsmCellLocation gsm = (GsmCellLocation) loc;
                if (gsm.getCid() != (-1))
                    value.put("cid", gsm.getCid());
                if (gsm.getLac() != (-1))
                    value.put("lac", gsm.getLac());
                value.put("type", "gsm");
            } else if (loc instanceof CdmaCellLocation) {
                CdmaCellLocation cdma = (CdmaCellLocation) loc;
                if (cdma.getBaseStationId() != (-1))
                    value.put("baseStationId", cdma.getBaseStationId());
                if (cdma.getBaseStationLatitude() != Integer.MAX_VALUE)
                    value.put("baseStationLat", cdma.getBaseStationLatitude());
                if (cdma.getBaseStationLongitude() != Integer.MAX_VALUE)
                    value.put("baseStationLon", cdma.getBaseStationLongitude());
                if (cdma.getNetworkId() != (-1))
                    value.put("baseStationId", cdma.getNetworkId());
                if (cdma.getNetworkId() != (-1))
                    value.put("networkId", cdma.getNetworkId());
                if (cdma.getSystemId() != (-1))
                    value.put("systemId", cdma.getSystemId());
                value.put("type", "cdma");
            } else if (loc != null) {
                value.put("type", loc.getClass().getName());
            }
            if (includeNeighbours) {
                List<NeighboringCellInfo> neighbors = telephony.getNeighboringCellInfo();
                JSONArray ns = new JSONArray();
                value.put("neighbors", ns);
                for (NeighboringCellInfo neighbor : neighbors) {
                    JSONObject n = new JSONObject();
                    if (neighbor.getCid() != (-1))
                        n.put("cid", neighbor.getCid());
                    if (neighbor.getLac() != (-1))
                        n.put("lac", neighbor.getLac());
                    n.put("networkType", neighbor.getNetworkType());
                    n.put("rssi", neighbor.getRssi());
                    ns.put(n);
                }
            }
        } catch (JSONException e) {
            // shouldn't
        }
        onNewValue(value);
    }
    return false;
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellStrengthChannel.java

protected void update(CellLocation loc, SignalStrength ss) {
    if (loc == null && telephony != null)
        loc = telephony.getCellLocation();
    // TODO Auto-generated method stub
    JSONObject value = new JSONObject();
    try {/*from  w w w . j  a  va  2s .c om*/
        value.put("timestamp", System.currentTimeMillis());
        if (loc instanceof GsmCellLocation) {
            GsmCellLocation gsm = (GsmCellLocation) loc;
            if (gsm.getCid() != (-1))
                value.put("cid", gsm.getCid());
            if (gsm.getLac() != (-1))
                value.put("lac", gsm.getLac());
            value.put("type", "gsm");
        } else if (loc instanceof CdmaCellLocation) {
            CdmaCellLocation cdma = (CdmaCellLocation) loc;
            if (cdma.getBaseStationId() != (-1))
                value.put("baseStationId", cdma.getBaseStationId());
            if (cdma.getBaseStationLatitude() != Integer.MAX_VALUE)
                value.put("baseStationLat", cdma.getBaseStationLatitude());
            if (cdma.getBaseStationLongitude() != Integer.MAX_VALUE)
                value.put("baseStationLon", cdma.getBaseStationLongitude());
            if (cdma.getNetworkId() != (-1))
                value.put("baseStationId", cdma.getNetworkId());
            if (cdma.getNetworkId() != (-1))
                value.put("networkId", cdma.getNetworkId());
            if (cdma.getSystemId() != (-1))
                value.put("systemId", cdma.getSystemId());
            value.put("type", "cdma");
        } else if (loc != null) {
            value.put("type", loc.getClass().getName());
        }

        if (ss != null) {
            if (ss.getCdmaDbm() != (-1))
                value.put("cdmsDbm", ss.getCdmaDbm());
            if (ss.getCdmaEcio() != (-1))
                value.put("cdmaEcio", ss.getCdmaEcio());
            if (ss.getEvdoDbm() != (-1))
                value.put("evdoDbm", ss.getEvdoDbm());
            if (ss.getEvdoEcio() != (-1))
                value.put("evdiEcio", ss.getEvdoEcio());
            if (ss.getEvdoSnr() != (-1))
                value.put("evdoSnr", ss.getEvdoSnr());
            if (ss.getGsmBitErrorRate() != (-1))
                value.put("gsmBER", ss.getGsmBitErrorRate());
            if (ss.getGsmSignalStrength() != (-1))
                value.put("gsmSS", ss.getGsmSignalStrength());
            value.put("gsm", ss.isGsm());
        }
    } catch (JSONException e) {
        // shouldn't
    }
    onNewValue(value);
}

From source file:org.restcomm.app.qoslib.UtilsOld.CellHistory.java

public long getLastCellSeen(CellLocation cellLoc) // MMCCellLocationOld cellInfo)
{
    if (cellLoc == null)
        return -1;
    if (tmLastCellUpdate + 60000 > System.currentTimeMillis() && cellLoc.toString().equals(lastCellString))
        return -1;
    long timelastSeen = 0;
    tmLastCellUpdate = System.currentTimeMillis();

    // Is it reporting an unknown cell id? ignore those
    //        int cellId = 0;//cellInfo.getBSLow(); //low
    //        if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM && cellLoc instanceof GsmCellLocation)
    //         cellId = ((GsmCellLocation)cellLoc).getCid();
    //      else if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA && cellLoc instanceof CdmaCellLocation)
    //         cellId = ((CdmaCellLocation)cellLoc).getBaseStationId();
    //      if (cellId <= 0)
    //         return -1;

    CellidSample smp = new CellidSample(cellLoc);
    cell_history.add(smp);/*www  .ja  va  2  s.com*/

    // How long has it been since we last saw this basestation
    //int bs_high = cellInfo.getBSHigh(), bs_mid = cellInfo.getBSMid(), bs_low = cellInfo.getBSLow();
    int bs_high = 0, bs_mid = 0, bs_low = 0;
    if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM
            && cellLoc instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLoc;
        bs_high = gsmCellLocation.getLac();
        bs_mid = gsmCellLocation.getCid() >> 16;
        bs_low = gsmCellLocation.getCid() & 0xffff;
    } else if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA
            && cellLoc instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLoc;
        bs_high = cdmaCellLocation.getSystemId();
        bs_mid = cdmaCellLocation.getNetworkId();
        bs_low = cdmaCellLocation.getBaseStationId();
    }
    if (bs_low <= 0)
        return -1;
    int j;
    int histlen = cell_history.size();
    // How long has it been since we last saw this basestation
    long timestamp = System.currentTimeMillis();
    for (j = histlen - 2; j >= 0; j--) {
        if (cell_history.get(j).val2 == bs_low) //  && cell_history.get(j).val1 == bs_high)
        {
            // time last seen is the first timestamp after the cell was last seen
            // (the time this cell handed off to another cell)
            // (if the last known cell was this same cell, then the time last seen is now)
            timelastSeen = timestamp;
            break;
        } else
            timestamp = cell_history.get(j).timestamp;

    }

    return timelastSeen;
}

From source file:com.samknows.measurement.environment.CellTowersData.java

@Override
public List<JSONObject> getPassiveMetric() {
    List<JSONObject> ret = new ArrayList<JSONObject>();
    if (cellLocation instanceof GsmCellLocation) {
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.GSMLAC, time,
                ((GsmCellLocation) cellLocation).getLac() + ""));
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.GSMCID, time,
                ((GsmCellLocation) cellLocation).getCid() + ""));
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMABSID, time,
                cdmaLocation.getBaseStationId() + ""));
        if (cdmaLocation.getBaseStationLatitude() != Integer.MAX_VALUE) {
            ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMABSLAT, time,
                    cdmaLocation.getBaseStationLatitude() + ""));
        }/*  w ww  . j ava 2 s.c o  m*/
        if (cdmaLocation.getBaseStationLongitude() != Integer.MAX_VALUE) {
            ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMABSLNG, time,
                    cdmaLocation.getBaseStationLongitude() + ""));
        }
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMANETWORKID, time,
                cdmaLocation.getNetworkId() + ""));
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMASYSTEMID, time,
                cdmaLocation.getSystemId() + ""));
    }
    if (signal.isGsm()) {
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.GSMSIGNALSTRENGTH, time,
                DCSConvertorUtil.convertGsmSignalStrength(signal.getGsmSignalStrength())));
        //   ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.GSMBER, time, DCSConvertorUtil.convertGsmBitErroRate(signal.getGsmBitErrorRate())));
    } else {
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMADBM, time, signal.getCdmaDbm() + ""));
        ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.CDMAECIO, time, signal.getCdmaEcio() + ""));
    }
    return ret;
}