use of com.secupwn.aimsicd.data.model.Measure in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class MeasureAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.bts_measure_data, parent, false);
holder = new ViewHolder(convertView);
} else {
holder = (ViewHolder) convertView.getTag();
}
final Measure item = getItem(position);
holder.updateDisplay(item, position);
return convertView;
}
use of com.secupwn.aimsicd.data.model.Measure in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class MeasuredCellStrengthAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.measured_signal_str, parent, false);
holder = new ViewHolder(convertView);
} else {
holder = (ViewHolder) convertView.getTag();
}
final Measure item = getItem(position);
holder.updateDisplay(item);
return convertView;
}
use of com.secupwn.aimsicd.data.model.Measure in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method ocidProcessed.
/**
* UPDATE {@link Measure} realm to indicate if OpenCellID DB contribution has been made
*/
public Realm.Transaction ocidProcessed() {
return new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<Measure> measures = realm.where(Measure.class).findAll();
for (int i = 0; i < measures.size(); i++) {
Measure measure = measures.get(i);
measure.setSubmitted(true);
}
}
};
}
use of com.secupwn.aimsicd.data.model.Measure 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());
}
}
use of com.secupwn.aimsicd.data.model.Measure in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method prepareOpenCellUploadData.
/**
* Prepares the CSV file used to upload new data to the OCID server.
* <p/>
* OCID CSV upload format:
* <p/>
* "cellid" = CID (in UMTS long format)
* "measured_at" = time
* "rating" = gpsd_accu
* "act" = RAT (TEXT):
* 1xRTT, CDMA, eHRPD, IS95A, IS95B, EVDO_0, EVDO_A, EVDO_B,
* UMTS, HSPA+, HSDPA, HSUPA, HSPA, LTE, EDGE, GPRS, GSM
*/
public boolean prepareOpenCellUploadData(Realm realm) {
boolean result;
File dir = new File(mExternalFilesDirPath + "OpenCellID/");
if (!dir.exists()) {
result = dir.mkdirs();
if (!result) {
return false;
}
}
File file = new File(dir, "aimsicd-ocid-data.csv");
try {
// Get data not yet submitted:
RealmResults<Measure> c;
c = getOCIDSubmitData(realm);
// Check if we have something to upload:
if (c.size() > 0) {
if (!file.exists()) {
result = file.createNewFile();
if (!result) {
return false;
}
// OCID CSV upload format and items
// mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating,speed,direction,act,ta,psc,tac,pci,sid,nid,bid
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
// TODO: Add "act"
csvWrite.writeNext("mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating");
int size = c.size();
log.debug("OCID UPLOAD: row count = " + size);
for (Measure measure : c) {
csvWrite.writeNext(String.valueOf(measure.getBaseStation().getMobileCountryCode()), String.valueOf(measure.getBaseStation().getMobileNetworkCode()), String.valueOf(measure.getBaseStation().getLocationAreaCode()), String.valueOf(measure.getBaseStation().getCellId()), String.valueOf(measure.getGpsLocation().getLongitude()), String.valueOf(measure.getGpsLocation().getLatitude()), String.valueOf(measure.getRxSignal()), String.valueOf(measure.getTime().getTime()), String.valueOf(measure.getGpsLocation().getAccuracy()));
}
csvWrite.close();
}
return true;
}
return false;
} catch (Exception e) {
log.error("prepareOpenCellUploadData(): Error creating OpenCellID Upload Data: ", e);
return false;
}
}
Aggregations