Example usage for android.telephony.gsm GsmCellLocation getPsc

List of usage examples for android.telephony.gsm GsmCellLocation getPsc

Introduction

In this page you can find the example usage for android.telephony.gsm GsmCellLocation getPsc.

Prototype

public int getPsc() 

Source Link

Document

On a UMTS network, returns the primary scrambling code of the serving cell.

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 GsmCellLocation//from  w  ww.  ja  va2s.c  om
 * @return JSON
 */
public static String gsmCellLocationJSON(GsmCellLocation location) {

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

    if (location != null) {
        try {
            json.put("provider", CELLLOCATION_PROVIDER);
            json.put("type", GSM);
            json.put("timestamp", calendar.getTimeInMillis());
            json.put("cid", location.getCid());
            json.put("lac", location.getLac());
            json.put("psc", location.getPsc());
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

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  ww .  j  a v  a 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:com.samknows.measurement.environment.CellTowersData.java

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

    try {/* w  ww  .  ja va 2 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: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 a  2 s  .c  om*/
    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:com.secupwn.aimsicd.service.CellTracker.java

/**
 * Add entries to the {@link com.secupwn.aimsicd.data.model.Measure Measure} realm
 *//*from  w  w  w .j a v  a 2s . c  om*/
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 checkInnerGsmCellLocation(CellLocation cell) {
    if (cell != null) {
        String strCells = "";

        Field getFieldPointer = null;
        try {//w  ww .  j a v a 2  s  .  c  om
            getFieldPointer = cell.getClass().getDeclaredField("mGsmCellLoc"); //NoSuchFieldException 

        } catch (Exception e) {
            //MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "checkInnerGsmCellLocation","Field does not exist - mGsmCellLoc");
        }
        if (getFieldPointer != null) {
            //now we're in business!
            try {
                getFieldPointer.setAccessible(true);
                GsmCellLocation gsmCell = (GsmCellLocation) getFieldPointer.get(cell);
                if (gsmCell != null) {
                    int bsHigh = gsmCell.getLac();
                    int bsLow = gsmCell.getCid();
                    LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "checkInnerGsmCellLocation",
                            "Obtained mGsmCellLoc LAC=" + gsmCell.getLac() + " toString=" + gsmCell.toString());

                    if (mPhoneState.getNetworkType() == mPhoneState.NETWORK_NEWTYPE_LTE) {
                        int psc = 0;
                        if (android.os.Build.VERSION.SDK_INT >= 10)
                            psc = gsmCell.getPsc();
                        String neighbors = owner.getCellHistory().updateLteNeighborHistory(bsHigh, bsLow, psc);
                        owner.getIntentDispatcher().updateLTEIdentity(neighbors);
                        owner.getReportManager().setNeighbors(neighbors);
                    }
                }
            } catch (Exception e) {
                Log.d(TAG, "Could not get the inner GSM", e);
            }
        }
    }
}