use of com.secupwn.aimsicd.data.model.GpsLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method insertDBeImport.
/**
* This method is used to insert and populate the downloaded or previously
* backed up OCID details into the {@link Import} realm table.
* <p/>
* It also prevents adding multiple entries of the same cell-id, when OCID
* downloads are repeated.
*/
public Realm.Transaction insertDBeImport(final String db_src, final String rat, final int mcc, final int mnc, final int lac, final int cid, final int psc, final double lat, final double lon, final boolean isGpsExact, final int avg_range, final int avg_signal, final int samples, final Date time_first, final Date time_last) {
return new Realm.Transaction() {
@Override
public void execute(Realm realm) {
long count = realm.where(Import.class).equalTo("locationAreaCode", lac).equalTo("cellId", cid).count();
if (count <= 0) {
Import anImport = realm.createObject(Import.class);
anImport.setDbSource(db_src);
anImport.setRadioAccessTechnology(rat);
anImport.setMobileCountryCode(mcc);
anImport.setMobileNetworkCode(mnc);
anImport.setLocationAreaCode(lac);
anImport.setCellId(cid);
anImport.setPrimaryScramblingCode(psc);
GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
gpsLocation.setLatitude(lat);
gpsLocation.setLongitude(lon);
anImport.setGpsLocation(gpsLocation);
anImport.setGpsExact(isGpsExact);
anImport.setAvgRange(avg_range);
anImport.setAvgSignal(avg_signal);
anImport.setSamples(samples);
anImport.setTimeFirst(time_first);
anImport.setTimeLast(time_last);
}
}
};
}
use of com.secupwn.aimsicd.data.model.GpsLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class SmsDetector method setCurrentLocationData.
private void setCurrentLocationData(Realm realm, SmsData capturedSms) {
capturedSms.setLocationAreaCode(mAIMSICDService.getCellTracker().getMonitorCell().getLocationAreaCode());
capturedSms.setCellId(mAIMSICDService.getCellTracker().getMonitorCell().getCellId());
capturedSms.setRadioAccessTechnology(mAIMSICDService.getCell().getRat());
boolean isRoaming = false;
if (mAIMSICDService.getCellTracker().getDevice().isRoaming()) {
isRoaming = true;
}
capturedSms.setRoaming(isRoaming);
GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
gpsLocation.setLatitude(mAIMSICDService.lastKnownLocation().getLatitudeInDegrees());
gpsLocation.setLongitude(mAIMSICDService.lastKnownLocation().getLongitudeInDegrees());
capturedSms.setGpsLocation(gpsLocation);
}
use of com.secupwn.aimsicd.data.model.GpsLocation 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;
}
use of com.secupwn.aimsicd.data.model.GpsLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method toEventLog.
/**
* Defining a new simpler version of insertEventLog for use in CellTracker.
*/
public void toEventLog(Realm realm, final int DF_id, final String DF_desc) {
final Date timestamp = new Date();
final int lac = CellTracker.monitorCell.getLocationAreaCode();
final int cid = CellTracker.monitorCell.getCellId();
//[UMTS,LTE]
final int psc = CellTracker.monitorCell.getPrimaryScramblingCode();
final double gpsd_lat = CellTracker.monitorCell.getLat();
final double gpsd_lon = CellTracker.monitorCell.getLon();
final double gpsd_accu = CellTracker.monitorCell.getAccuracy();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// skip CID/LAC of "-1" (due to crappy API, Roaming or Air-Plane Mode)
if (cid != -1 || lac != -1) {
// Check if LAST entry is the same!
RealmResults<Event> events = realm.where(Event.class).findAllSorted("timestamp");
boolean insertData;
if (events.isEmpty()) {
insertData = true;
} else {
Event lastEvent = events.last();
insertData = !(lastEvent.getCellId() == cid && lastEvent.getLocationAreaCode() == lac && lastEvent.getPrimaryScramblingCode() == psc && lastEvent.getDfId() == DF_id);
}
if (insertData) {
Event event = realm.createObject(Event.class);
event.setTimestamp(timestamp);
event.setLocationAreaCode(lac);
event.setCellId(cid);
event.setPrimaryScramblingCode(psc);
GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
gpsLocation.setLatitude(gpsd_lat);
gpsLocation.setLongitude(gpsd_lon);
gpsLocation.setAccuracy(gpsd_accu);
event.setGpsLocation(gpsLocation);
event.setDfId(DF_id);
event.setDfDescription(DF_desc);
}
}
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
log.info("ToEventLog(): Added new event: id=" + DF_id + " time=" + timestamp + " cid=" + cid);
// Short 100 ms Vibration
// TODO not elegant solution, vibrator invocation should be moved somewhere else imho
boolean vibrationEnabled = mPreferences.getBoolean(mContext.getString(R.string.pref_notification_vibrate_enable), true);
int thresholdLevel = Integer.valueOf(mPreferences.getString(mContext.getString(R.string.pref_notification_vibrate_min_level), String.valueOf(Status.MEDIUM.ordinal())));
boolean higherLevelThanThreshold = Status.MEDIUM.ordinal() <= thresholdLevel;
if (vibrationEnabled && higherLevelThanThreshold) {
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
}
// Short sound:
// TODO see issue #15
}
});
}
use of com.secupwn.aimsicd.data.model.GpsLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method insertBTS.
/**
* Created this because we don't need to insert all the data in this table
* since we don't yet have items like TMSI etc.
*/
public void insertBTS(Realm realm, Cell cell) {
// If LAC and CID are not already in BTS realm, then add them.
if (!cellInDbiBts(realm, cell.getLocationAreaCode(), cell.getCellId())) {
realm.beginTransaction();
BaseTransceiverStation baseStation = realm.createObject(BaseTransceiverStation.class);
baseStation.setMobileCountryCode(cell.getMobileCountryCode());
baseStation.setMobileNetworkCode(cell.getMobileNetworkCode());
baseStation.setLocationAreaCode(cell.getLocationAreaCode());
baseStation.setCellId(cell.getCellId());
baseStation.setPrimaryScramblingCode(cell.getPrimaryScramblingCode());
baseStation.setTimeFirst(new Date());
baseStation.setTimeLast(new Date());
GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
// TODO NO! These should be exact GPS from Import or by manual addition!
gpsLocation.setLatitude(cell.getLat());
// TODO NO! These should be exact GPS from Import or by manual addition!
gpsLocation.setLongitude(cell.getLon());
baseStation.setGpsLocation(gpsLocation);
realm.commitTransaction();
} else {
// If cell is already in the DB, update it to last time seen and
// update its GPS coordinates, if not 0.0
BaseTransceiverStation baseStation = realm.where(BaseTransceiverStation.class).equalTo("cellId", cell.getCellId()).findFirst();
realm.beginTransaction();
baseStation.setTimeLast(new Date());
// Only update if GPS coordinates are good
if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
if (baseStation.getGpsLocation() == null) {
baseStation.setGpsLocation(realm.createObject(GpsLocation.class));
}
baseStation.getGpsLocation().setLatitude(cell.getLat());
baseStation.getGpsLocation().setLongitude(cell.getLon());
}
realm.commitTransaction();
log.info("BTS updated: CID=" + cell.getCellId() + " LAC=" + cell.getLocationAreaCode());
}
// Checking to see if CID (now bts_id) is already in DBi_measure, if not add it.
if (!cellInDbiMeasure(realm, cell.getCellId())) {
realm.beginTransaction();
Measure measure = realm.createObject(Measure.class);
BaseTransceiverStation baseStation = realm.where(BaseTransceiverStation.class).equalTo("cellId", cell.getCellId()).findFirst();
measure.setBaseStation(baseStation);
measure.setTime(new Date());
GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
gpsLocation.setLatitude(cell.getLat());
gpsLocation.setLongitude(cell.getLon());
gpsLocation.setAccuracy(cell.getAccuracy());
measure.setGpsLocation(gpsLocation);
measure.setRxSignal(cell.getDbm());
measure.setRadioAccessTechnology(String.valueOf(cell.getRat()));
//TODO does this actually get timing advance?
measure.setTimingAdvance(cell.getTimingAdvance());
measure.setSubmitted(false);
measure.setNeighbor(false);
realm.commitTransaction();
log.info("Measure inserted cellId=" + cell.getCellId());
} else {
// Updating DBi_measure tables if already exists.
realm.beginTransaction();
RealmResults<Measure> all = realm.where(Measure.class).equalTo("baseStation.cellId", cell.getCellId()).findAll();
for (int i = 0; i < all.size(); i++) {
Measure measure = all.get(i);
if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
measure.getGpsLocation().setLatitude(cell.getLat());
measure.getGpsLocation().setLongitude(cell.getLon());
}
if (Double.doubleToRawLongBits(cell.getAccuracy()) != 0 && cell.getAccuracy() > 0) {
measure.getGpsLocation().setAccuracy(cell.getAccuracy());
}
if (cell.getDbm() > 0) {
measure.setRxSignal(cell.getDbm());
}
if (cell.getTimingAdvance() > 0) {
// Only available on API >16 on LTE
measure.setTimingAdvance(cell.getTimingAdvance());
}
}
realm.commitTransaction();
log.info("DBi_measure updated bts_id=" + cell.getCellId());
}
}
Aggregations