Example usage for android.telephony CellInfoGsm getCellIdentity

List of usage examples for android.telephony CellInfoGsm getCellIdentity

Introduction

In this page you can find the example usage for android.telephony CellInfoGsm getCellIdentity.

Prototype

@Override
public @NonNull CellIdentityGsm getCellIdentity() 

Source Link

Usage

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

/**
 * Converts CellInfoGsm into JSON//from ww  w .ja  v a2 s.c  o m
 * @param cellInfo CellInfoGsm
 * @return JSON
 */
public static String cellInfoGSMJSON(CellInfoGsm cellInfo, boolean returnSignalStrength) {

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo != null) {
        try {
            json.put("provider", CELLINFO_PROVIDER);
            json.put("type", GSM);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityGsm identityGsm = cellInfo.getCellIdentity();

            json.put("cid", identityGsm.getCid());
            json.put("lac", identityGsm.getLac());
            json.put("mcc", identityGsm.getMcc());
            json.put("mnc", identityGsm.getMnc());

            if (returnSignalStrength) {
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthGsm cellSignalStrengthGsm = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthGsm.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthGsm.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthGsm.getLevel());

                json.put("cellSignalStrengthGsm", jsonSignalStrength);
            }
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}

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

private void reportDataCellInfo(List<CellInfo> cellInfoList) {
    for (CellInfo cellInfo : cellInfoList) {
        if (Build.VERSION.SDK_INT >= 17) {
            if (cellInfo instanceof CellInfoCdma) {
                CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfo;
                cellUpdate(native_ptr_, "cdma", cellInfoCdma.getCellIdentity().getBasestationId(), // Base Station Id 0..65535, Integer.MAX_VALUE if unknown
                        cellInfoCdma.getCellIdentity().getNetworkId(), // Network Id 0..65535, Integer.MAX_VALUE if unknown
                        Integer.MAX_VALUE, cellInfoCdma.getCellIdentity().getSystemId(), // System Id 0..32767, Integer.MAX_VALUE if unknown
                        cellInfoCdma.getCellSignalStrength().getCdmaDbm(), // Get the CDMA RSSI value in dBm
                        Integer.MAX_VALUE);
            }/* w w w  . j ava2  s  .c  o m*/
            if (cellInfo instanceof CellInfoGsm) {
                CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                cellUpdate(native_ptr_, "gsm", cellInfoGsm.getCellIdentity().getCid(), // CID Either 16-bit GSM Cell Identity described in TS 27.007, 0..65535, Integer.MAX_VALUE if unknown
                        cellInfoGsm.getCellIdentity().getLac(), // 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
                        cellInfoGsm.getCellIdentity().getMcc(), // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoGsm.getCellIdentity().getMnc(), // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoGsm.getCellSignalStrength().getDbm(), // Get the signal strength as dBm
                        android.os.Build.VERSION.SDK_INT >= 26
                                ? cellInfoGsm.getCellSignalStrength().getTimingAdvance()
                                : Integer.MAX_VALUE // Get the GSM timing advance between 0..219 symbols (normally 0..63). Integer.MAX_VALUE is reported when there is no RR connection.
                );
            }
            if (cellInfo instanceof CellInfoLte) {
                CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                cellUpdate(native_ptr_, "lte", cellInfoLte.getCellIdentity().getCi(), // 28-bit Cell Identity, Integer.MAX_VALUE if unknown
                        cellInfoLte.getCellIdentity().getTac(), // 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown
                        cellInfoLte.getCellIdentity().getMcc(), // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoLte.getCellIdentity().getMnc(), // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoLte.getCellSignalStrength().getDbm(), // Get signal strength as dBm
                        cellInfoLte.getCellSignalStrength().getTimingAdvance() // Get the timing advance value for LTE, as a value between 0..63. Integer.MAX_VALUE is reported when there is no active RRC connection. Refer to 3GPP 36.213 Sec 4.2.3
                );
            }
        }
        if (Build.VERSION.SDK_INT >= 18) {
            if (cellInfo instanceof CellInfoWcdma) {
                CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                cellUpdate(native_ptr_, "wcdma", cellInfoWcdma.getCellIdentity().getCid(), // CID 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, Integer.MAX_VALUE if unknown
                        cellInfoWcdma.getCellIdentity().getLac(), // 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
                        cellInfoWcdma.getCellIdentity().getMcc(), // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoWcdma.getCellIdentity().getMnc(), // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                        cellInfoWcdma.getCellSignalStrength().getDbm(), // Get the signal strength as dBm
                        Integer.MAX_VALUE);
            }
        }
    }
}

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);
        }//ww w.  j  a v  a  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;
}