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;
}
Aggregations