Search in sources :

Example 1 with TruncatedLocation

use of com.secupwn.aimsicd.utils.TruncatedLocation 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)

Aggregations

Location (android.location.Location)1 GpsLocation (com.secupwn.aimsicd.data.model.GpsLocation)1 Cell (com.secupwn.aimsicd.utils.Cell)1 GeoLocation (com.secupwn.aimsicd.utils.GeoLocation)1 TruncatedLocation (com.secupwn.aimsicd.utils.TruncatedLocation)1 Realm (io.realm.Realm)1 Cleanup (lombok.Cleanup)1