Search in sources :

Example 16 with CellLocation

use of android.telephony.CellLocation in project wigle-wifi-wardriving by wiglenet.

the class WifiReceiver method recordCellInfo.

private Network recordCellInfo(final Location location) {
    TelephonyManager tele = (TelephonyManager) mainActivity.getSystemService(Context.TELEPHONY_SERVICE);
    Network network = null;
    if (tele != null) {
        /*
      List<NeighboringCellInfo> list = tele.getNeighboringCellInfo();
      for (final NeighboringCellInfo cell : list ) {
        MainActivity.info("neigh cell: " + cell + " class: " + cell.getClass().getCanonicalName() );
        MainActivity.info("cid: " + cell.getCid());

        // api level 5!!!!
        MainActivity.info("lac: " + cell.getLac() );
        MainActivity.info("psc: " + cell.getPsc() );
        MainActivity.info("net type: " + cell.getNetworkType() );
        MainActivity.info("nettypename: " + getNetworkTypeName() );
      }
      */
        String bssid = null;
        NetworkType type = null;
        CellLocation cellLocation = null;
        try {
            cellLocation = tele.getCellLocation();
        } catch (NullPointerException ex) {
        // bug in Archos7 can NPE there, just ignore
        } catch (final SecurityException ex) {
            MainActivity.info("Security exception tele.getCellLocation: " + ex);
        }
        // noinspection StatementWithEmptyBody
        if (cellLocation == null) {
        // ignore
        } else if (cellLocation.getClass().getSimpleName().equals("CdmaCellLocation")) {
            try {
                final int systemId = (Integer) cellLocation.getClass().getMethod("getSystemId").invoke(cellLocation);
                final int networkId = (Integer) cellLocation.getClass().getMethod("getNetworkId").invoke(cellLocation);
                final int baseStationId = (Integer) cellLocation.getClass().getMethod("getBaseStationId").invoke(cellLocation);
                if (systemId > 0 && networkId >= 0 && baseStationId >= 0) {
                    bssid = systemId + "_" + networkId + "_" + baseStationId;
                    type = NetworkType.CDMA;
                }
            } catch (Exception ex) {
                MainActivity.error("cdma reflection exception: " + ex);
            }
        } else if (cellLocation instanceof GsmCellLocation) {
            GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
            if (gsmCellLocation.getLac() >= 0 && gsmCellLocation.getCid() >= 0) {
                bssid = tele.getNetworkOperator() + "_" + gsmCellLocation.getLac() + "_" + gsmCellLocation.getCid();
                type = NetworkType.GSM;
            }
        }
        if (bssid != null) {
            final String ssid = tele.getNetworkOperatorName();
            final String networkType = getNetworkTypeName();
            final String capabilities = networkType + ";" + tele.getNetworkCountryIso();
            int strength = 0;
            PhoneState phoneState = mainActivity.getPhoneState();
            if (phoneState != null) {
                strength = phoneState.getStrength();
            }
            if (NetworkType.GSM.equals(type)) {
                strength = gsmRssiMagicDecoderRing(strength);
            }
            // MainActivity.info( "bssid: " + bssid );
            // MainActivity.info( "strength: " + strength );
            // MainActivity.info( "ssid: " + ssid );
            // MainActivity.info( "capabilities: " + capabilities );
            // MainActivity.info( "networkType: " + networkType );
            // MainActivity.info( "location: " + location );
            final ConcurrentLinkedHashMap<String, Network> networkCache = MainActivity.getNetworkCache();
            final boolean newForRun = runNetworks.add(bssid);
            network = networkCache.get(bssid);
            if (network == null) {
                network = new Network(bssid, ssid, 0, capabilities, strength, type);
                networkCache.put(network.getBssid(), network);
            } else {
                network.setLevel(strength);
            }
            if (location != null && (newForRun || network.getLatLng() == null)) {
                // set the LatLng for mapping
                final LatLng LatLng = new LatLng(location.getLatitude(), location.getLongitude());
                network.setLatLng(LatLng);
            }
            if (location != null) {
                dbHelper.addObservation(network, location, newForRun);
            }
        }
    }
    return network;
}
Also used : GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) TelephonyManager(android.telephony.TelephonyManager) NetworkType(net.wigle.wigleandroid.model.NetworkType) Network(net.wigle.wigleandroid.model.Network) GsmCellLocation(android.telephony.gsm.GsmCellLocation) LatLng(com.google.android.gms.maps.model.LatLng)

Example 17 with CellLocation

use of android.telephony.CellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class CellTracker method onLocationChanged.

/**
 * Add entries to the {@link com.secupwn.aimsicd.data.model.Measure Measure} realm
 */
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;
                    // CID
                    device.cell.setCellId(gsmCellLocation.getCid());
                    // LAC
                    device.cell.setLocationAreaCode(gsmCellLocation.getLac());
                    // PSC
                    device.cell.setPrimaryScramblingCode(gsmCellLocation.getPsc());
                    break;
                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                    // BSID ??
                    device.cell.setCellId(cdmaCellLocation.getBaseStationId());
                    // NID
                    device.cell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
                    // SID
                    device.cell.setSid(cdmaCellLocation.getSystemId());
                    // MNC <== BUG!??
                    device.cell.setMobileNetworkCode(cdmaCellLocation.getSystemId());
                    break;
            }
        }
    }
    if (loc != null && (Double.doubleToRawLongBits(loc.getLatitude()) != 0 && Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {
        // gpsd_lon
        device.cell.setLon(loc.getLongitude());
        // gpsd_lat
        device.cell.setLat(loc.getLatitude());
        // speed        // TODO: Remove, we're not using it!
        device.cell.setSpeed(loc.getSpeed());
        // gpsd_accu
        device.cell.setAccuracy(loc.getAccuracy());
        // -- [deg]??   // TODO: Remove, we're not using it!
        device.cell.setBearing(loc.getBearing());
        // 
        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();
        // 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);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Cleanup(lombok.Cleanup) Realm(io.realm.Realm)

Example 18 with CellLocation

use of android.telephony.CellLocation in project carat by amplab.

the class SamplingLibrary method getDeviceLocation.

/* Get the current location of the device */
public static CellLocation getDeviceLocation(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    CellLocation LocDevice = telManager.getCellLocation();
    // Log.v("DeviceLocation", "Device Location:" + LocDevice);
    return LocDevice;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation)

Aggregations

CellLocation (android.telephony.CellLocation)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)12 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)8 SuppressLint (android.annotation.SuppressLint)4 PhoneStateListener (android.telephony.PhoneStateListener)2 TelephonyManager (android.telephony.TelephonyManager)2 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 NetworkInfo (android.net.NetworkInfo)1 AsyncResult (android.os.AsyncResult)1 CellInfo (android.telephony.CellInfo)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 SmsCbLocation (android.telephony.SmsCbLocation)1 LatLng (com.google.android.gms.maps.model.LatLng)1 CellTowerCdma (com.vonglasow.michael.satstat.data.CellTowerCdma)1 CellTowerGsm (com.vonglasow.michael.satstat.data.CellTowerGsm)1 Realm (io.realm.Realm)1 Date (java.util.Date)1 Cleanup (lombok.Cleanup)1 Network (net.wigle.wigleandroid.model.Network)1