List of usage examples for android.telephony.gsm GsmCellLocation getCid
public int getCid()
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 av a 2s. 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) {// w ww .j a va 2 s . c o m 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.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);/*from ww w . j a v a2 s. c om*/ // 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:at.alladin.rmbt.android.util.InformationCollector.java
private void getTelephonyInfo() { initNetwork();// ww w . j av a2s .co m if (telManager != null) { try { // Get Cell Location CellLocation.requestLocationUpdate(); } catch (Exception e) { // some devices with Android 5.1 seem to throw a NPE is some cases e.printStackTrace(); } final CellLocation cellLocation = telManager.getCellLocation(); if (cellLocation != null && (cellLocation instanceof GsmCellLocation)) { final GsmCellLocation gcl = (GsmCellLocation) cellLocation; if (gcl.getCid() > 0 && this.collectInformation) { cellLocations.add(new CellLocationItem(new CellInfoPreV18(gcl))); } } fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR_NAME", String.valueOf(telManager.getNetworkOperatorName())); String networkOperator = telManager.getNetworkOperator(); if (networkOperator != null && networkOperator.length() >= 5) networkOperator = String.format("%s-%s", networkOperator.substring(0, 3), networkOperator.substring(3)); fullInfo.setProperty("TELEPHONY_NETWORK_OPERATOR", String.valueOf(networkOperator)); fullInfo.setProperty("TELEPHONY_NETWORK_COUNTRY", String.valueOf(telManager.getNetworkCountryIso())); fullInfo.setProperty("TELEPHONY_NETWORK_SIM_COUNTRY", String.valueOf(telManager.getSimCountryIso())); String simOperator = telManager.getSimOperator(); if (simOperator != null && simOperator.length() >= 5) simOperator = String.format("%s-%s", simOperator.substring(0, 3), simOperator.substring(3)); fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR", String.valueOf(simOperator)); try // hack for Motorola Defy (#594) { fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR_NAME", String.valueOf(telManager.getSimOperatorName())); } catch (SecurityException e) { e.printStackTrace(); fullInfo.setProperty("TELEPHONY_NETWORK_SIM_OPERATOR_NAME", "s.exception"); } fullInfo.setProperty("TELEPHONY_PHONE_TYPE", String.valueOf(telManager.getPhoneType())); try // some devices won't allow this w/o READ_PHONE_STATE. conflicts with Android API doc { fullInfo.setProperty("TELEPHONY_DATA_STATE", String.valueOf(telManager.getDataState())); } catch (SecurityException e) { e.printStackTrace(); fullInfo.setProperty("TELEPHONY_DATA_STATE", "s.exception"); } // telManager.listen(telListener, // PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); } }
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 va 2 s. com*/ 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:com.secupwn.aimsicd.service.CellTracker.java
/** * I removed the timer that activated this code and now the code will be run when * the cell changes so it will detect faster rather than using a timer that might * miss an imsi catcher, also says cpu rather than refreshing every x seconds. * * original comments below from xLaMbChOpSx * * * Description: (From xLaMbChOpSx commit comment) * * Initial implementation for detection method 1 to compare the CID & LAC with the Cell * Information Table contents as an initial implementation for detection of a changed LAC, * once OCID issues (API key use etc) have been finalised this detection method can be * extended to include checking of external data. * * REMOVED: refresh timer info/*w ww. ja v a 2s . co m*/ * * As I have no real way of testing this I require testing by other project members who * do have access to equipment or an environment where a changing LAC can be simulated * thus confirming the accuracy of this implementation. * * Presently this will only invoke the MEDIUM threat level through the notification and * does not fully implement the capturing and score based method as per the issue details * once further testing is complete the alert and tracking of information can be refined. * * See: * https://github.com/xLaMbChOpSx/Android-IMSI-Catcher-Detector/commit/43ae77e2a0cad10dfd50f92da5a998f9ece95b38 * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91#issuecomment-64391732 * * Short explanation: * * This is a polling mechanism for getting the LAC/CID and location * info for the currently connected cell. * * Variables: * FIXED: now updates on cell change rather than a timer * There is a "timer" here (REFRESH_RATE), what exactly is it timing? * "Every REFRESH_RATE seconds, get connected cell details." * * Issues: [ ] We shouldn't do any detection here! * [ ] We might wanna use a listener to do this? * Are there any reasons why not using a listener? * * ChangeLog: * 2015-03-03 E:V:A Changed getProp() to use TinyDB (SharedPreferences) * 2015-0x-xx banjaxbanjo Update: ??? (hey dude what did you do?) * */ public void compareLac(CellLocation location) { @Cleanup Realm realm = Realm.getDefaultInstance(); switch (device.getPhoneId()) { case TelephonyManager.PHONE_TYPE_NONE: case TelephonyManager.PHONE_TYPE_SIP: case TelephonyManager.PHONE_TYPE_GSM: GsmCellLocation gsmCellLocation = (GsmCellLocation) location; if (gsmCellLocation != null) { monitorCell.setLocationAreaCode(gsmCellLocation.getLac()); monitorCell.setCellId(gsmCellLocation.getCid()); // Check if LAC is ok boolean lacOK = dbHelper.checkLAC(realm, monitorCell); if (!lacOK) { changedLAC = true; dbHelper.toEventLog(realm, 1, "Changing LAC"); // Detection Logs are made in checkLAC() vibrate(100, Status.MEDIUM); } else { changedLAC = false; } if (tinydb.getBoolean("ocid_downloaded")) { if (!dbHelper.openCellExists(realm, monitorCell.getCellId())) { dbHelper.toEventLog(realm, 2, "CID not in Import realm"); log.info("ALERT: Connected to unknown CID not in Import realm: " + monitorCell.getCellId()); vibrate(100, Status.MEDIUM); cellIdNotInOpenDb = true; } else { cellIdNotInOpenDb = false; } } } break; case TelephonyManager.PHONE_TYPE_CDMA: CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location; if (cdmaCellLocation != null) { monitorCell.setLocationAreaCode(cdmaCellLocation.getNetworkId()); monitorCell.setCellId(cdmaCellLocation.getBaseStationId()); boolean lacOK = dbHelper.checkLAC(realm, monitorCell); if (!lacOK) { changedLAC = true; /*dbHelper.insertEventLog( MiscUtils.getCurrentTimeStamp(), monitorCell.getLAC(), monitorCell.getCid(), monitorCell.getPSC(),//This is giving weird values like 21478364... is this right? String.valueOf(monitorCell.getLat()), String.valueOf(monitorCell.getLon()), (int)monitorCell.getAccuracy(), 1, "Changing LAC" );*/ dbHelper.toEventLog(realm, 1, "Changing LAC"); } else { changedLAC = false; } } } setNotification(); }
From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java
private void checkInnerGsmCellLocation(CellLocation cell) { if (cell != null) { String strCells = ""; Field getFieldPointer = null; try {//from w ww .ja va 2 s . c o m 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); } } } }