Search in sources :

Example 1 with NetworkType

use of net.wigle.wigleandroid.model.NetworkType in project wigle-wifi-wardriving by wiglenet.

the class DatabaseHelper method getNetwork.

public Network getNetwork(final String bssid) {
    // check cache
    Network retval = MainActivity.getNetworkCache().get(bssid);
    if (retval == null) {
        try {
            checkDB();
            final String[] args = new String[] { bssid };
            final Cursor cursor = db.rawQuery("select ssid,frequency,capabilities,type,lastlat,lastlon,bestlat,bestlon FROM " + NETWORK_TABLE + " WHERE bssid = ?", args);
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                final String ssid = cursor.getString(0);
                final int frequency = cursor.getInt(1);
                final String capabilities = cursor.getString(2);
                final float lastlat = cursor.getFloat(4);
                final float lastlon = cursor.getFloat(5);
                final float bestlat = cursor.getFloat(6);
                final float bestlon = cursor.getFloat(7);
                final NetworkType type = NetworkType.typeForCode(cursor.getString(3));
                retval = new Network(bssid, ssid, frequency, capabilities, 0, type);
                if (bestlat != 0 && bestlon != 0) {
                    retval.setLatLng(new LatLng(bestlat, bestlon));
                } else {
                    retval.setLatLng(new LatLng(lastlat, lastlon));
                }
                MainActivity.getNetworkCache().put(bssid, retval);
            }
            cursor.close();
        } catch (DBException ex) {
            deathDialog("getNetwork", ex);
        }
    }
    return retval;
}
Also used : NetworkType(net.wigle.wigleandroid.model.NetworkType) Network(net.wigle.wigleandroid.model.Network) LatLng(com.google.android.gms.maps.model.LatLng) Cursor(android.database.Cursor)

Example 2 with NetworkType

use of net.wigle.wigleandroid.model.NetworkType 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)

Aggregations

LatLng (com.google.android.gms.maps.model.LatLng)2 Network (net.wigle.wigleandroid.model.Network)2 NetworkType (net.wigle.wigleandroid.model.NetworkType)2 Cursor (android.database.Cursor)1 CellLocation (android.telephony.CellLocation)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1