Search in sources :

Example 6 with Cell

use of com.secupwn.aimsicd.utils.Cell in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class MainActivity method importCellTowersData.

private void importCellTowersData(Uri importFile) {
    Cell cell = new Cell();
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tm.getNetworkOperator();
    if (networkOperator != null && !networkOperator.isEmpty()) {
        int mcc = Integer.parseInt(networkOperator.substring(0, 3));
        cell.setMobileCountryCode(mcc);
        int mnc = Integer.parseInt(networkOperator.substring(3));
        cell.setMobileNetworkCode(mnc);
        log.debug("CELL:: mobileCountryCode=" + mcc + " mobileNetworkCode=" + mnc);
    }
    GeoLocation loc = mAimsicdService.lastKnownLocation();
    if (loc != null) {
        Helpers.msgLong(this, getString(R.string.imporing_celltowers_data));
        cell.setLon(loc.getLongitudeInDegrees());
        cell.setLat(loc.getLatitudeInDegrees());
        Helpers.importCellTowersData(this, cell, importFile, mAimsicdService);
    } else {
        Helpers.msgShort(this, getString(R.string.needs_location));
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) GeoLocation(com.secupwn.aimsicd.utils.GeoLocation) Cell(com.secupwn.aimsicd.utils.Cell)

Example 7 with Cell

use of com.secupwn.aimsicd.utils.Cell in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class CellInfoFragment method updateStockNeighboringCells.

void updateStockNeighboringCells() {
    mNeighboringTotal.setText(String.valueOf(neighboringCells.size()));
    if (neighboringCells.size() != 0) {
        BaseInflaterAdapter<CardItemData> adapter = new BaseInflaterAdapter<>(new CellCardInflater());
        int i = 1;
        int total = neighboringCells.size();
        for (Cell cell : neighboringCells) {
            CardItemData data = new CardItemData(cell, i++ + " / " + total);
            adapter.addItem(data, false);
        }
        lv.setAdapter(adapter);
        mNeighboringCells.setVisibility(View.GONE);
        mNeighboringTotalView.setVisibility(View.VISIBLE);
    }
}
Also used : CellCardInflater(com.secupwn.aimsicd.adapters.CellCardInflater) CardItemData(com.secupwn.aimsicd.adapters.CardItemData) Cell(com.secupwn.aimsicd.utils.Cell) BaseInflaterAdapter(com.secupwn.aimsicd.adapters.BaseInflaterAdapter)

Example 8 with Cell

use of com.secupwn.aimsicd.utils.Cell in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class DeviceFragment method responseToCell.

private Cell responseToCell(Response response) {
    try {
        JSONObject jsonCell = new JSONObject(response.body().string());
        Cell cell = new Cell();
        cell.setLat(jsonCell.getDouble("lat"));
        cell.setLon(jsonCell.getDouble("lon"));
        cell.setMobileCountryCode(jsonCell.getInt("mcc"));
        cell.setMobileNetworkCode(jsonCell.getInt("mnc"));
        cell.setCellId(jsonCell.getInt("cellid"));
        cell.setLocationAreaCode(jsonCell.getInt("lac"));
        return cell;
    } catch (JSONException | IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) Cell(com.secupwn.aimsicd.utils.Cell)

Example 9 with Cell

use of com.secupwn.aimsicd.utils.Cell in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class LocationTracker method lastKnownLocation.

public GeoLocation lastKnownLocation() {
    GeoLocation loc = null;
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null && (Double.doubleToLongBits(location.getLatitude()) != 0 && Double.doubleToLongBits(location.getLongitude()) != 0)) {
        TruncatedLocation TruncatedLocation = new TruncatedLocation(location);
        loc = GeoLocation.fromDegrees(TruncatedLocation.getLatitude(), TruncatedLocation.getLongitude());
    } else {
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null && (Double.doubleToLongBits(location.getLatitude()) != 0 && Double.doubleToLongBits(location.getLongitude()) != 0)) {
            TruncatedLocation TruncatedLocation = new TruncatedLocation(location);
            loc = GeoLocation.fromDegrees(TruncatedLocation.getLatitude(), TruncatedLocation.getLongitude());
        } else {
            String coords = prefs.getString(context.getString(R.string.data_last_lat_lon), null);
            if (coords != null) {
                String[] coord = coords.split(":");
                loc = GeoLocation.fromDegrees(Double.valueOf(coord[0]), Double.valueOf(coord[1]));
            } else {
                // get location from MCC
                try {
                    Cell cell = context.getCell();
                    if (cell != null) {
                        log.debug("Looking up MCC " + cell.getMobileCountryCode());
                        @Cleanup Realm realm = Realm.getDefaultInstance();
                        GpsLocation defLoc = mDbHelper.getDefaultLocation(realm, cell.getMobileCountryCode());
                        loc = GeoLocation.fromDegrees(defLoc.getLatitude(), defLoc.getLongitude());
                    }
                } catch (Exception e) {
                    log.error("Unable to get location from MCC", e);
                }
            }
        }
    }
    if (loc != null) {
        log.info("Last known location " + loc.toString());
    }
    return loc;
}
Also used : TruncatedLocation(com.secupwn.aimsicd.utils.TruncatedLocation) GpsLocation(com.secupwn.aimsicd.data.model.GpsLocation) GeoLocation(com.secupwn.aimsicd.utils.GeoLocation) Cell(com.secupwn.aimsicd.utils.Cell) Cleanup(lombok.Cleanup) Realm(io.realm.Realm) GeoLocation(com.secupwn.aimsicd.utils.GeoLocation) GpsLocation(com.secupwn.aimsicd.data.model.GpsLocation) TruncatedLocation(com.secupwn.aimsicd.utils.TruncatedLocation) Location(android.location.Location)

Example 10 with Cell

use of com.secupwn.aimsicd.utils.Cell in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class CellTracker method updateNeighboringCells.

/**
 *  Description:    Updates Neighboring Cell details
 *
 *                  TODO: add more details...
 */
public List<Cell> updateNeighboringCells() {
    List<Cell> neighboringCells = new ArrayList<>();
    List<NeighboringCellInfo> neighboringCellInfo = tm.getNeighboringCellInfo();
    if (neighboringCellInfo == null) {
        neighboringCellInfo = new ArrayList<>();
    }
    // NC list present? (default is false)
    Boolean nclp = tinydb.getBoolean("nc_list_present");
    // if nclp = true then check for neighboringCellInfo
    if (neighboringCellInfo != null && neighboringCellInfo.size() == 0 && nclp) {
        log.info("NeighboringCellInfo is empty: start polling...");
        // Try to poll the neighboring cells for a few seconds
        // TODO What is this ??
        neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100);
        // TODO: See issue #555 (DeviceApi17.java is using API 18 CellInfoWcdma calls.
        if (Build.VERSION.SDK_INT > 17) {
            DeviceApi18.startListening(tm, phoneStatelistener);
        } else {
            tm.listen(phoneStatelistener, PhoneStateListener.LISTEN_CELL_LOCATION | // API 17
            PhoneStateListener.LISTEN_CELL_INFO | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }
        // TODO: Consider removing ??
        for (int i = 0; i < 10 && neighboringCellInfo.size() == 0; i++) {
            try {
                log.debug("NeighboringCellInfo empty: trying " + i);
                NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                if (info == null) {
                    neighboringCellInfo = tm.getNeighboringCellInfo();
                    if (neighboringCellInfo != null) {
                        if (neighboringCellInfo.size() > 0) {
                            // Can we think of a better log message here?
                            log.debug("NeighboringCellInfo found on " + i + " try. (time based)");
                            break;
                        } else {
                            continue;
                        }
                    }
                }
                List<NeighboringCellInfo> cellInfoList = new ArrayList<>(neighboringCellBlockingQueue.size() + 1);
                while (info != null) {
                    cellInfoList.add(info);
                    info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                }
                neighboringCellInfo = cellInfoList;
            } catch (InterruptedException e) {
                // TODO: Add a more valuable message here!
                log.error("", e);
            }
        }
    }
    // Add NC list to DBi_measure:nc_list
    for (NeighboringCellInfo neighborCell : neighboringCellInfo) {
        log.info("NeighboringCellInfo -" + " LAC:" + neighborCell.getLac() + " CID:" + neighborCell.getCid() + " PSC:" + neighborCell.getPsc() + " RSSI:" + neighborCell.getRssi());
        final Cell cell = new Cell(neighborCell.getCid(), neighborCell.getLac(), neighborCell.getRssi(), neighborCell.getPsc(), neighborCell.getNetworkType(), false);
        neighboringCells.add(cell);
    }
    return neighboringCells;
}
Also used : NeighboringCellInfo(android.telephony.NeighboringCellInfo) ArrayList(java.util.ArrayList) Cell(com.secupwn.aimsicd.utils.Cell)

Aggregations

Cell (com.secupwn.aimsicd.utils.Cell)10 GeoLocation (com.secupwn.aimsicd.utils.GeoLocation)5 Intent (android.content.Intent)3 TelephonyManager (android.telephony.TelephonyManager)2 IOException (java.io.IOException)2 Location (android.location.Location)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 BaseInflaterAdapter (com.secupwn.aimsicd.adapters.BaseInflaterAdapter)1 CardItemData (com.secupwn.aimsicd.adapters.CardItemData)1 CellCardInflater (com.secupwn.aimsicd.adapters.CellCardInflater)1 GpsLocation (com.secupwn.aimsicd.data.model.GpsLocation)1 LocationServices (com.secupwn.aimsicd.utils.LocationServices)1 TruncatedLocation (com.secupwn.aimsicd.utils.TruncatedLocation)1 Callback (com.squareup.okhttp.Callback)1 Request (com.squareup.okhttp.Request)1 Response (com.squareup.okhttp.Response)1 InjectionAppCompatActivity (io.freefair.android.injection.app.InjectionAppCompatActivity)1 Realm (io.realm.Realm)1