Example usage for android.telephony NeighboringCellInfo getRssi

List of usage examples for android.telephony NeighboringCellInfo getRssi

Introduction

In this page you can find the example usage for android.telephony NeighboringCellInfo getRssi.

Prototype

public int getRssi() 

Source Link

Usage

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildNeighboringCellInfo(NeighboringCellInfo data) throws JSONException {
    // TODO(damonkohler): Additional information available at API level 5.
    JSONObject result = new JSONObject();
    result.put("cid", data.getCid());
    result.put("rssi", data.getRssi());
    return result;
}

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

private void addCellData(List<String> list, NeighboringCellInfo cellInfo) {
    DCSStringBuilder builder = new DCSStringBuilder();
    builder.append(ID_NEIGHBOR);//from ww w . j  a v  a  2 s.  co  m
    builder.append(time / 1000);
    builder.append(cellInfo.getCid());
    builder.append(cellInfo.getLac());
    builder.append(cellInfo.getPsc());
    builder.append(cellInfo.getRssi());
    builder.append(DCSConvertorUtil.convertNetworkType(cellInfo.getNetworkType()));
    list.add(builder.build());
}

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 {/* w  ww.  j a  v  a2  s  .  co  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:ru.dublgis.androidhelpers.mobility.CellListener.java

private void reportDataNeighboringCellInfo(List<NeighboringCellInfo> neighboringCellInfoList) {
    for (NeighboringCellInfo cellInfo : neighboringCellInfoList) {
        cellUpdate(native_ptr_, "unknown", cellInfo.getCid(), // cell id in GSM, 0xffff max legal value UNKNOWN_CID if in UMTS or CDMA or unknown
                cellInfo.getLac(), // LAC in GSM, 0xffff max legal value UNKNOWN_CID if in UMTS or CMDA or unknown
                Integer.MAX_VALUE, Integer.MAX_VALUE, getGsmDbm(cellInfo.getRssi()), // received signal strength or UNKNOWN_RSSI if unknown For GSM, it is in "asu" ranging from 0 to 31 (dBm = -113 + 2*asu) 0 means "-113 dBm or less" and 31 means "-51 dBm or greater" For UMTS, it is the Level index of CPICH RSCP defined in TS 25.125
                Integer.MAX_VALUE);
    }/*from w w  w  .  j av a  2  s  .  c o  m*/
}

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

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

    reset();//from   w  w w .  j av  a 2  s .  c o m
    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;
}

From source file:com.google.android.gms.location.sample.geofencing.MainActivity.java

public void GetID() {

    List<NeighboringCellInfo> neighCell = null;
    TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    neighCell = telManager.getNeighboringCellInfo();
    for (int i = 0; i < neighCell.size(); i++) {
        try {//from w ww . j ava 2 s  .c o  m
            NeighboringCellInfo thisCell = neighCell.get(i);
            int thisNeighCID = thisCell.getCid();
            int thisNeighRSSI = thisCell.getRssi();
            Log.i("Info:", " cid:" + thisNeighCID + " - " + thisNeighRSSI);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            NeighboringCellInfo thisCell = neighCell.get(i);
            Log.i("exception", neighCell.toString());
        }
    }
    String networkOperator = telManager.getNetworkOperator();
    String mcc = "not avl", mnc = "not avl";
    if (networkOperator != null) {
        mcc = networkOperator.substring(0, 3);
        mnc = networkOperator.substring(3);
    }
    Log.i("", "mcc:" + mcc);
    Log.i("", "mnc:" + mnc);
}

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

@Override
public List<JSONObject> convertToJSON() {
    List<JSONObject> ret = new ArrayList<JSONObject>();

    try {/*from w  ww.j a  v  a2 s.  c  o m*/
        JSONObject cellLoc = null;
        if (cellLocation instanceof GsmCellLocation) {
            GsmCellLocation l = (GsmCellLocation) cellLocation;
            JSONObject gsm = new JSONObject();
            gsm.put(JSON_TYPE, JSON_TYPE_GSM_CELL_LOCATION);
            gsm.put(JSON_TIMESTAMP, time / 1000 + "");
            gsm.put(JSON_DATETIME, new java.util.Date(time).toString());
            gsm.put(JSON_CELL_TOWER_ID, l.getCid() + "");
            gsm.put(JSON_LOCATION_AREA_CODE, l.getLac());
            gsm.put(JSON_UMTS_PSC, Build.VERSION.SDK_INT >= 9 ? l.getPsc() + "" : "-1");
            if (signal.isGsm()) {
                gsm.put(JSON_SIGNAL_STRENGTH, signal.getGsmSignalStrength() + "");
                //gsm.put(JSON_BIT_ERROR_RATE, signal.getGsmBitErrorRate()+"");
            }
            ret.add(gsm);

        } else if (cellLocation instanceof CdmaCellLocation) {
            CdmaCellLocation l = (CdmaCellLocation) cellLocation;
            JSONObject cdma = new JSONObject();
            cdma.put(JSON_TYPE, JSON_TYPE_CDMA_CELL_LOCATION);
            cdma.put(JSON_TIMESTAMP, time / 1000 + "");
            cdma.put(JSON_DATETIME, new java.util.Date(time).toString());
            cdma.put(JSON_BASE_STATION_ID, l.getBaseStationId() + "");
            cdma.put(JSON_BASE_STATION_LATITUDE, l.getBaseStationLatitude() + "");
            cdma.put(JSON_BASE_STATION_LONGITUDE, l.getBaseStationLongitude() + "");
            cdma.put(JSON_SYSTEM_ID, l.getSystemId() + "");
            cdma.put(JSON_NETWORK_ID, l.getNetworkId() + "");
            if (!signal.isGsm()) {
                cdma.put(JSON_DBM, signal.getCdmaDbm() + "");
                cdma.put(JSON_ECIO, signal.getCdmaEcio() + "");
            }
            ret.add(cdma);
        }

        for (NeighboringCellInfo cellInfo : neighbors) {
            JSONObject neighbour = new JSONObject();
            neighbour.put(JSON_TYPE, JSON_TYPE_CELL_TOWER_NEIGHBOUR);
            neighbour.put(JSON_TIMESTAMP, time / 1000 + "");
            neighbour.put(JSON_DATETIME, new java.util.Date(time).toString());
            neighbour.put(JSON_NETWORK_TYPE_CODE, cellInfo.getNetworkType() + "");
            neighbour.put(JSON_NETWORK_TYPE, DCSConvertorUtil.convertNetworkType(cellInfo.getNetworkType()));
            neighbour.put(JSON_RSSI, cellInfo.getRssi() + "");
            neighbour.put(JSON_UMTS_PSC, cellInfo.getPsc() + "");
            neighbour.put(JSON_CELL_TOWER_ID, cellInfo.getCid() + "");
            neighbour.put(JSON_LOCATION_AREA_CODE, cellInfo.getLac() + "");
            ret.add(neighbour);
        }

    } catch (JSONException je) {
        Logger.e(CellTowersData.class, "Error in creating JSONObject: " + je.getMessage());
        ret = null;
    }
    return ret;
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private JSONObject getMobile(TelephonyManager tm) throws JSONException {
    JSONObject mob = new JSONObject();

    mob.put("call_state", tm.getCallState());
    mob.put("data_activity", tm.getDataActivity());
    mob.put("network_type", tm.getNetworkType());
    mob.put("network_type_str", Helpers.getTelephonyNetworkType(tm.getNetworkType()));
    mob.put("phone_type", tm.getPhoneType());
    mob.put("phone_type_str", Helpers.getTelephonyPhoneType(tm.getPhoneType()));
    mob.put("sim_state", tm.getSimState());
    mob.put("network_country", tm.getNetworkCountryIso());
    mob.put("network_operator", tm.getNetworkOperator());
    mob.put("network_operator_name", tm.getNetworkOperatorName());

    // current cell location
    CellLocation cl = tm.getCellLocation();
    if (cl != null) {
        JSONObject loc = new JSONObject();
        if (cl instanceof GsmCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("cid", ((GsmCellLocation) cl).getCid());
            cell.put("lac", ((GsmCellLocation) cl).getLac());
            cell.put("psc", ((GsmCellLocation) cl).getPsc());
            loc.put("gsm", cell);
        } else if (cl instanceof CdmaCellLocation) {
            JSONObject cell = new JSONObject();
            cell.put("bs_id", ((CdmaCellLocation) cl).getBaseStationId());
            cell.put("bs_lat", ((CdmaCellLocation) cl).getBaseStationLatitude());
            cell.put("bs_lon", ((CdmaCellLocation) cl).getBaseStationLongitude());
            cell.put("net_id", ((CdmaCellLocation) cl).getNetworkId());
            cell.put("sys_id", ((CdmaCellLocation) cl).getSystemId());
            loc.put("cdma", cell);
        }/* w  w w  .  j  a  va  2 s .  c  o m*/
        mob.put("cell_location", loc);
    }

    // Cell neighbors
    List<NeighboringCellInfo> ncl = tm.getNeighboringCellInfo();
    if (ncl != null) {
        JSONArray cells = new JSONArray();
        for (NeighboringCellInfo nc : ncl) {
            JSONObject jnc = new JSONObject();
            jnc.put("cid", nc.getCid());
            jnc.put("lac", nc.getLac());
            jnc.put("network_type", nc.getNetworkType());
            jnc.put("network_type_str", Helpers.getTelephonyNetworkType(nc.getNetworkType()));
            jnc.put("psc", nc.getPsc());
            jnc.put("rssi", nc.getRssi());
            cells.put(jnc);
        }
        mob.put("neigh_cells", cells);
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // only works for API level >=17
        List<CellInfo> aci = (List<CellInfo>) tm.getAllCellInfo();
        if (aci != null) {
            JSONArray cells = new JSONArray();
            for (CellInfo ci : aci) {
                JSONObject jci = new JSONObject();
                if (ci instanceof CellInfoGsm) {
                    CellInfoGsm cigsm = (CellInfoGsm) ci;
                    jci.put("is_registered", cigsm.isRegistered());
                    jci.put("type", "gsm");
                    jci.put("cid", cigsm.getCellIdentity().getCid());
                    jci.put("lac", cigsm.getCellIdentity().getLac());
                    jci.put("mcc", cigsm.getCellIdentity().getMcc());
                    jci.put("mnc", cigsm.getCellIdentity().getMnc());
                    jci.put("psc", cigsm.getCellIdentity().getPsc());

                    jci.put("asu_level", cigsm.getCellSignalStrength().getAsuLevel());
                    jci.put("level", cigsm.getCellSignalStrength().getLevel());
                    jci.put("dbm", cigsm.getCellSignalStrength().getDbm());

                } else if (ci instanceof CellInfoCdma) {
                    CellInfoCdma cicdma = (CellInfoCdma) ci;
                    jci.put("is_registered", cicdma.isRegistered());
                    jci.put("type", "cdma");
                    jci.put("bs_id", cicdma.getCellIdentity().getBasestationId());
                    jci.put("bs_lat", cicdma.getCellIdentity().getLatitude());
                    jci.put("bs_lon", cicdma.getCellIdentity().getLongitude());
                    jci.put("net_id", cicdma.getCellIdentity().getNetworkId());
                    jci.put("sys_id", cicdma.getCellIdentity().getSystemId());

                    jci.put("asu_level", cicdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cicdma.getCellSignalStrength().getDbm());
                    jci.put("level", cicdma.getCellSignalStrength().getLevel());
                    jci.put("cdma_dbm", cicdma.getCellSignalStrength().getCdmaDbm());
                    jci.put("cdma_ecio", cicdma.getCellSignalStrength().getCdmaEcio());
                    jci.put("cdma_level", cicdma.getCellSignalStrength().getCdmaLevel());
                    jci.put("evdo_dbm", cicdma.getCellSignalStrength().getEvdoDbm());
                    jci.put("evdo_ecio", cicdma.getCellSignalStrength().getEvdoEcio());
                    jci.put("evdo_level", cicdma.getCellSignalStrength().getEvdoLevel());
                    jci.put("evdo_snr", cicdma.getCellSignalStrength().getEvdoSnr());

                } else if (ci instanceof CellInfoWcdma) {
                    CellInfoWcdma ciwcdma = (CellInfoWcdma) ci;
                    jci.put("is_registered", ciwcdma.isRegistered());
                    jci.put("type", "wcdma");
                    jci.put("cid", ciwcdma.getCellIdentity().getCid());
                    jci.put("lac", ciwcdma.getCellIdentity().getLac());
                    jci.put("mcc", ciwcdma.getCellIdentity().getMcc());
                    jci.put("mnc", ciwcdma.getCellIdentity().getMnc());
                    jci.put("psc", ciwcdma.getCellIdentity().getPsc());

                    jci.put("asu_level", ciwcdma.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", ciwcdma.getCellSignalStrength().getDbm());
                    jci.put("level", ciwcdma.getCellSignalStrength().getLevel());

                } else if (ci instanceof CellInfoLte) {
                    CellInfoLte cilte = (CellInfoLte) ci;
                    jci.put("is_registered", cilte.isRegistered());
                    jci.put("type", "lte");
                    jci.put("ci", cilte.getCellIdentity().getCi());
                    jci.put("mcc", cilte.getCellIdentity().getMcc());
                    jci.put("mnc", cilte.getCellIdentity().getMnc());
                    jci.put("pci", cilte.getCellIdentity().getPci());
                    jci.put("tac", cilte.getCellIdentity().getTac());

                    jci.put("asu_level", cilte.getCellSignalStrength().getAsuLevel());
                    jci.put("dbm", cilte.getCellSignalStrength().getDbm());
                    jci.put("level", cilte.getCellSignalStrength().getLevel());
                    jci.put("timing_adv", cilte.getCellSignalStrength().getTimingAdvance());

                }
                cells.put(jci);
            }
            mob.put("all_cells", cells);
        }
    }
    return mob;
}

From source file:com.mobilyzer.util.PhoneUtils.java

/**
 * Returns the information about cell towers in range. Returns null if the information is 
 * not available /*  ww  w. j a va  2  s. c o  m*/
 * 
 * TODO(wenjiezeng): As folklore has it and Wenjie has confirmed, we cannot get cell info from
 * Samsung phones.
 */
public String getCellInfo(boolean cidOnly) {
    if (!(ContextCompat.checkSelfPermission(context,
            Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
        return null;
    }

    initNetwork();
    List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo();
    StringBuffer buf = new StringBuffer();
    String tempResult = "";
    if (infos.size() > 0) {
        for (NeighboringCellInfo info : infos) {
            tempResult = cidOnly ? info.getCid() + ";"
                    : info.getLac() + "," + info.getCid() + "," + info.getRssi() + ";";
            buf.append(tempResult);
        }
        // Removes the trailing semicolon
        buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
    } else {
        return null;
    }
}

From source file:com.secupwn.aimsicd.service.CellTracker.java

/**
 *  Description:    Updates Neighboring Cell details
 *
 *                  TODO: add more details...
 *
 *
 *///w ww .j a va  2s.c  om
public List<Cell> updateNeighboringCells() {
    List<Cell> neighboringCells = new ArrayList<>();
    List<NeighboringCellInfo> neighboringCellInfo = tm.getNeighboringCellInfo();
    if (neighboringCellInfo == null) {
        neighboringCellInfo = new ArrayList<>();
    }

    Boolean nclp = tinydb.getBoolean("nc_list_present"); // NC list present? (default is false)

    //if nclp = true then check for neighboringCellInfo
    if (neighboringCellInfo != null && neighboringCellInfo.size() == 0 && nclp) {

        log.info("NeighboringCellInfo is empty: start polling...");

        // Try to poll the neighboring cells for a few seconds
        neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100); // TODO What is this ??

        //LISTEN_CELL_INFO added in API 17
        // TODO: See issue #555 (DeviceApi17.java is using API 18 CellInfoWcdma calls.
        if (Build.VERSION.SDK_INT > 17) {
            DeviceApi18.startListening(tm, phoneStatelistener);
        } else {
            tm.listen(phoneStatelistener,
                    PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_CELL_INFO | // API 17
                            PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                            | PhoneStateListener.LISTEN_SERVICE_STATE
                            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        // TODO: Consider removing ??
        for (int i = 0; i < 10 && neighboringCellInfo.size() == 0; i++) {
            try {
                log.debug("NeighboringCellInfo empty: trying " + i);
                NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                if (info == null) {
                    neighboringCellInfo = tm.getNeighboringCellInfo();
                    if (neighboringCellInfo != null) {
                        if (neighboringCellInfo.size() > 0) {
                            // Can we think of a better log message here?
                            log.debug("NeighboringCellInfo found on " + i + " try. (time based)");
                            break;
                        } else {
                            continue;
                        }
                    }
                }
                List<NeighboringCellInfo> cellInfoList = new ArrayList<>(
                        neighboringCellBlockingQueue.size() + 1);
                while (info != null) {
                    cellInfoList.add(info);
                    info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                }
                neighboringCellInfo = cellInfoList;
            } catch (InterruptedException e) {
                // TODO: Add a more valuable message here!
                log.error("", e);
            }
        }
    }

    //log.debug(mTAG + ": neighboringCellInfo size: " + neighboringCellInfo.size());

    // Add NC list to DBi_measure:nc_list
    for (NeighboringCellInfo neighborCell : neighboringCellInfo) {
        log.info("NeighboringCellInfo -" + " LAC:" + neighborCell.getLac() + " CID:" + neighborCell.getCid()
                + " PSC:" + neighborCell.getPsc() + " RSSI:" + neighborCell.getRssi());

        final Cell cell = new Cell(neighborCell.getCid(), neighborCell.getLac(), neighborCell.getRssi(),
                neighborCell.getPsc(), neighborCell.getNetworkType(), false);
        neighboringCells.add(cell);
    }
    return neighboringCells;
}