Example usage for android.telephony.cdma CdmaCellLocation getBaseStationLongitude

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

Introduction

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

Prototype

public int getBaseStationLongitude() 

Source Link

Document

Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.

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//from w w  w  . ja  v a 2  s . com
 * @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.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 {/* ww  w.  j a va2s  . 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: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  va2s . 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  ww  . j a v  a2s  .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: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 www . j  a  v  a  2s.c  om*/
        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: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() + ""));
        }//from w  w w  .  j  ava2  s. com
        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: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 a2  s.  c om
                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");
            }
        }
    }
}