Example usage for android.telephony.cdma CdmaCellLocation getSystemId

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

Introduction

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

Prototype

public int getSystemId() 

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// w  w  w.  jav  a2s  . c o  m
 * @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:org.mozilla.mozstumbler.service.scanners.cellscanner.CellInfo.java

void setCellLocation(CellLocation cl, int networkType, String networkOperator, Integer gsmSignalStrength,
        Integer cdmaRssi) {//from  w ww.j a  v  a2 s  .  com
    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: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  w  ww .ja  va 2s  .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);/*from w w  w  .  j a  v  a  2 s. com*/
        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.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);//  w  w w  . java  2 s. c  o m

    // 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: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   ww w.jav  a  2s  .  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 (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: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 a v  a  2 s .com*/
            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: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 a v a  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;
}

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

/**
 * Add entries to the {@link com.secupwn.aimsicd.data.model.Measure Measure} realm
 *//*w w w . j a v a2 s.  c  o m*/
public void onLocationChanged(Location loc) {
    // TODO: See issue #555 (DeviceApi17.java is using API 18 CellInfoWcdma calls.
    if (Build.VERSION.SDK_INT > 17) {
        DeviceApi18.loadCellInfo(tm, device);
    }

    if (!device.cell.isValid()) {
        CellLocation cellLocation = tm.getCellLocation();
        if (cellLocation != null) {
            switch (device.getPhoneId()) {

            case TelephonyManager.PHONE_TYPE_NONE:
            case TelephonyManager.PHONE_TYPE_SIP:
            case TelephonyManager.PHONE_TYPE_GSM:
                GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
                device.cell.setCellId(gsmCellLocation.getCid()); // CID
                device.cell.setLocationAreaCode(gsmCellLocation.getLac()); // LAC
                device.cell.setPrimaryScramblingCode(gsmCellLocation.getPsc()); // PSC
                break;

            case TelephonyManager.PHONE_TYPE_CDMA:
                CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                device.cell.setCellId(cdmaCellLocation.getBaseStationId()); // BSID ??
                device.cell.setLocationAreaCode(cdmaCellLocation.getNetworkId()); // NID
                device.cell.setSid(cdmaCellLocation.getSystemId()); // SID
                device.cell.setMobileNetworkCode(cdmaCellLocation.getSystemId()); // MNC <== BUG!??

                break;
            }
        }
    }

    if (loc != null && (Double.doubleToRawLongBits(loc.getLatitude()) != 0
            && Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {

        device.cell.setLon(loc.getLongitude()); // gpsd_lon
        device.cell.setLat(loc.getLatitude()); // gpsd_lat
        device.cell.setSpeed(loc.getSpeed()); // speed        // TODO: Remove, we're not using it!
        device.cell.setAccuracy(loc.getAccuracy()); // gpsd_accu
        device.cell.setBearing(loc.getBearing()); // -- [deg]??   // TODO: Remove, we're not using it!
        device.setLastLocation(loc); //

        // Store last known location in preference
        SharedPreferences.Editor prefsEditor;
        prefsEditor = prefs.edit();
        prefsEditor.putString(context.getString(R.string.data_last_lat_lon),
                String.valueOf(loc.getLatitude()) + ":" + String.valueOf(loc.getLongitude()));
        prefsEditor.apply();

        // This only logs a BTS if we have GPS lock
        // TODO: Is correct behaviour? We should consider logging all cells, even without GPS.
        if (trackingCell) {
            // This also checks that the locationAreaCode are cid are not in DB before inserting
            @Cleanup
            Realm realm = Realm.getDefaultInstance();
            dbHelper.insertBTS(realm, device.cell);
        }
    }
}

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

private void checkCDMACellSID(CellLocation cell) {
    if (cell instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaCell = (CdmaCellLocation) cell;
        if (cdmaCell.getSystemId() <= 0) {
            Field getSIDPointer = null;
            Field getNIDPointer = null;
            int SID = 0, NID = 0, BID = cdmaCell.getBaseStationId();
            try {
                getSIDPointer = mPhoneState.previousServiceStateObj.getClass().getDeclaredField("mSystemId");
                if (getSIDPointer != null) {
                    getSIDPointer.setAccessible(true);
                    SID = (int) getSIDPointer.getInt(cdmaCell);
                }/*  w  w w .j  a  v a2s. c o m*/
                getNIDPointer = mPhoneState.previousServiceStateObj.getClass().getDeclaredField("mNetworkId");
                if (getNIDPointer != null) {
                    getNIDPointer.setAccessible(true);
                    NID = (int) getNIDPointer.getInt(cdmaCell);
                }
                cdmaCell.setCellLocationData(BID, cdmaCell.getBaseStationLatitude(),
                        cdmaCell.getBaseStationLongitude(), SID, NID); // Update the SID and NID that we read from teh Servicestate
            } catch (Exception e) {
                //MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "checkInnerGsmCellLocation","Field does not exist - mGsmCellLoc");
            }
        }
    }
}