Skip to content

Commit

Permalink
Collect more signal related values for all network types.
Browse files Browse the repository at this point in the history
  • Loading branch information
zamojski committed May 9, 2020
1 parent b1629e2 commit 3faa8e5
Show file tree
Hide file tree
Showing 22 changed files with 639 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@

public class CellSignalConverter {

private static final boolean isApi26 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
private static final boolean isApi29 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;

public void update(Cell cell, CellInfo cellInfo) {
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm gsmCellInfo = (CellInfoGsm) cellInfo;
CellSignalStrengthGsm signal = gsmCellInfo.getCellSignalStrength();
int asu = signal.getAsuLevel();
int dbm = signal.getDbm();
int ta = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? signal.getTimingAdvance() : Cell.UNKNOWN_SIGNAL;
int ta = isApi26 ? signal.getTimingAdvance() : Cell.UNKNOWN_SIGNAL;
if (asu == NeighboringCellInfo.UNKNOWN_RSSI)
asu = Cell.UNKNOWN_SIGNAL;
// TODO add RSSI to GSM on Android R
cell.setGsmSignalInfo(asu, dbm, ta);
} else if (cellInfo instanceof CellInfoWcdma) {
CellInfoWcdma wcdmaCellInfo = (CellInfoWcdma) cellInfo;
Expand All @@ -41,6 +45,7 @@ public void update(Cell cell, CellInfo cellInfo) {
if (asu == NeighboringCellInfo.UNKNOWN_RSSI)
asu = Cell.UNKNOWN_SIGNAL;
int dbm = signal.getDbm();
// TODO add EC/NO to WCDMA on Android R
cell.setWcdmaSignalInfo(asu, dbm);
} else if (cellInfo instanceof CellInfoLte) {
CellInfoLte lteCellInfo = (CellInfoLte) cellInfo;
Expand All @@ -50,31 +55,48 @@ public void update(Cell cell, CellInfo cellInfo) {
asu = Cell.UNKNOWN_SIGNAL;
int dbm = signal.getDbm();
int ta = signal.getTimingAdvance();
cell.setLteSignalInfo(asu, dbm, ta);
int rsrp = isApi26 ? signal.getRsrp() : Cell.UNKNOWN_SIGNAL;
int rsrq = isApi26 ? signal.getRsrq() : Cell.UNKNOWN_SIGNAL;
int rssi = isApi29 ? signal.getRssi() : Cell.UNKNOWN_SIGNAL;
int rssnr = isApi26 ? signal.getRssnr() : Cell.UNKNOWN_SIGNAL;
int cqi = isApi26 ? signal.getCqi() : Cell.UNKNOWN_SIGNAL;
cell.setLteSignalInfo(asu, dbm, ta, rsrp, rsrq, rssi, rssnr, cqi);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && cellInfo instanceof CellInfoNr) {
CellInfoNr nrCellInfo = (CellInfoNr) cellInfo;
CellSignalStrengthNr signal = (CellSignalStrengthNr) nrCellInfo.getCellSignalStrength();
int asu = signal.getAsuLevel();
if (asu == 99) // CellSignalStrengthNr.UNKNOWN_ASU_LEVEL not available
asu = Cell.UNKNOWN_SIGNAL;
int dbm = signal.getDbm();
cell.setNrSignalInfo(asu, dbm);
int csiRsrp = signal.getCsiRsrp();
int csiRsrq = signal.getCsiRsrq();
int csiSinr = signal.getCsiSinr();
int ssRsrp = signal.getSsRsrp();
int ssRsrq = signal.getSsRsrq();
int ssSinr = signal.getSsSinr();
cell.setNrSignalInfo(asu, dbm, csiRsrp, csiRsrq, csiSinr, ssRsrp, ssRsrq, ssSinr);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && cellInfo instanceof CellInfoTdscdma) {
CellInfoTdscdma tdscdmaCellInfo = (CellInfoTdscdma) cellInfo;
CellSignalStrengthTdscdma signal = tdscdmaCellInfo.getCellSignalStrength();
int asu = signal.getAsuLevel();
if (asu == 255 || asu == 99) // depending on RSSI (99) or RSCP (255)
asu = Cell.UNKNOWN_SIGNAL;
int dbm = signal.getDbm();
cell.setTdscdmaSignalInfo(asu, dbm);
int rscp = signal.getRscp();
cell.setTdscdmaSignalInfo(asu, dbm, rscp);
} else if (cellInfo instanceof CellInfoCdma) {
CellInfoCdma cdmaCellInfo = (CellInfoCdma) cellInfo;
CellSignalStrengthCdma signal = cdmaCellInfo.getCellSignalStrength();
int asu = signal.getAsuLevel();
if (asu == NeighboringCellInfo.UNKNOWN_RSSI)
asu = Cell.UNKNOWN_SIGNAL;
int dbm = signal.getDbm();
cell.setCdmaSignalInfo(asu, dbm);
int cdmaDbm = signal.getCdmaDbm();
int cdmaEcio = signal.getCdmaEcio();
int evdoDbm = signal.getEvdoDbm();
int evdoEcio = signal.getEvdoEcio();
int evdoSnr = signal.getEvdoSnr();
cell.setCdmaSignalInfo(asu, dbm, cdmaDbm, cdmaEcio, evdoDbm, evdoEcio, evdoSnr);
} else {
throw new UnsupportedOperationException("Cell signal type not supported `" + cellInfo.getClass().getName() + "`");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ final class CellSignalsTable implements ITable {
static final String COLUMN_TA = "ta";
static final String COLUMN_ASU = "asu";
static final String COLUMN_DBM = "dbm";
static final String COLUMN_RSRP = "rsrp";
static final String COLUMN_RSRQ = "rsrq";
static final String COLUMN_RSSI = "rssi";
static final String COLUMN_RSSNR = "rssnr";
static final String COLUMN_CQI = "cqi";
static final String COLUMN_RSCP = "rscp";
static final String COLUMN_CSI_RSRP = "csi_rsrp";
static final String COLUMN_CSI_RSRQ = "csi_rsrq";
static final String COLUMN_CSI_SINR = "csi_sinr";
static final String COLUMN_SS_RSRP = "ss_rsrp";
static final String COLUMN_SS_RSRQ = "ss_rsrq";
static final String COLUMN_SS_SINR = "ss_sinr";
static final String COLUMN_CDMA_DBM = "cdma_dbm";
static final String COLUMN_CDMA_ECIO = "cdma_ecio";
static final String COLUMN_EVDO_DBM = "evdo_dbm";
static final String COLUMN_EVDO_ECIO = "evdo_ecio";
static final String COLUMN_EVDO_SNR = "evdo_snr";

private static final String QUERY_CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ROW_ID + " INTEGER PRIMARY KEY NOT NULL, " +
Expand All @@ -25,6 +42,23 @@ final class CellSignalsTable implements ITable {
COLUMN_TA + " INTEGER NOT NULL, " +
COLUMN_ASU + " INTEGER NOT NULL, " +
COLUMN_DBM + " INTEGER NOT NULL, " +
COLUMN_RSRP + " INTEGER NOT NULL, " +
COLUMN_RSRQ + " INTEGER NOT NULL, " +
COLUMN_RSSI + " INTEGER NOT NULL, " +
COLUMN_RSSNR + " INTEGER NOT NULL, " +
COLUMN_CQI + " INTEGER NOT NULL, " +
COLUMN_RSCP + " INTEGER NOT NULL, " +
COLUMN_CSI_RSRP + " INTEGER NOT NULL, " +
COLUMN_CSI_RSRQ + " INTEGER NOT NULL, " +
COLUMN_CSI_SINR + " INTEGER NOT NULL, " +
COLUMN_SS_RSRP + " INTEGER NOT NULL, " +
COLUMN_SS_RSRQ + " INTEGER NOT NULL, " +
COLUMN_SS_SINR + " INTEGER NOT NULL, " +
COLUMN_CDMA_DBM + " INTEGER NOT NULL, " +
COLUMN_CDMA_ECIO + " INTEGER NOT NULL, " +
COLUMN_EVDO_DBM + " INTEGER NOT NULL, " +
COLUMN_EVDO_ECIO + " INTEGER NOT NULL, " +
COLUMN_EVDO_SNR + " INTEGER NOT NULL, " +
"FOREIGN KEY(" + COLUMN_MEASUREMENT_ID + ") REFERENCES " + MeasurementsTable.TABLE_NAME + "(" + MeasurementsTable.COLUMN_ROW_ID + ")," +
"FOREIGN KEY(" + COLUMN_CELL_ID + ") REFERENCES " + CellsTable.TABLE_NAME + "(" + CellsTable.COLUMN_ROW_ID + "))";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class MeasurementsDatabase {

public static final String DATABASE_FILE_NAME = "measurements.db";
public static final int DATABASE_FILE_VERSION = 15;
public static final int DATABASE_FILE_VERSION = 16;

private static final int NUM_OF_DELETIONS_PER_ONE_QUERY = 50;

Expand Down Expand Up @@ -141,6 +141,23 @@ public boolean insertMeasurement(Measurement measurement) {
values.put(CellSignalsTable.COLUMN_TA, cell.getTa());
values.put(CellSignalsTable.COLUMN_ASU, cell.getAsu());
values.put(CellSignalsTable.COLUMN_DBM, cell.getDbm());
values.put(CellSignalsTable.COLUMN_RSRP, cell.getRsrp());
values.put(CellSignalsTable.COLUMN_RSRQ, cell.getRsrq());
values.put(CellSignalsTable.COLUMN_RSSI, cell.getRssi());
values.put(CellSignalsTable.COLUMN_RSSNR, cell.getRssnr());
values.put(CellSignalsTable.COLUMN_CQI, cell.getCqi());
values.put(CellSignalsTable.COLUMN_RSCP, cell.getRscp());
values.put(CellSignalsTable.COLUMN_CSI_RSRP, cell.getCsiRsrp());
values.put(CellSignalsTable.COLUMN_CSI_RSRQ, cell.getCsiRsrq());
values.put(CellSignalsTable.COLUMN_CSI_SINR, cell.getCsiSinr());
values.put(CellSignalsTable.COLUMN_SS_RSRP, cell.getSsRsrp());
values.put(CellSignalsTable.COLUMN_SS_RSRQ, cell.getSsRsrq());
values.put(CellSignalsTable.COLUMN_SS_SINR, cell.getSsSinr());
values.put(CellSignalsTable.COLUMN_CDMA_DBM, cell.getCdmaDbm());
values.put(CellSignalsTable.COLUMN_CDMA_ECIO, cell.getCdmaEcio());
values.put(CellSignalsTable.COLUMN_EVDO_DBM, cell.getEvdoDbm());
values.put(CellSignalsTable.COLUMN_EVDO_ECIO, cell.getEvdoEcio());
values.put(CellSignalsTable.COLUMN_EVDO_SNR, cell.getEvdoSnr());
long rowId = db.insert(CellSignalsTable.TABLE_NAME, null, values);
boolean localResult = false;
if (rowId != -1) {
Expand Down Expand Up @@ -379,6 +396,23 @@ private List<Measurement> getMeasurements(String selection, String[] selectionAr
CellSignalsTable.COLUMN_TA,
CellSignalsTable.COLUMN_ASU,
CellSignalsTable.COLUMN_DBM,
CellSignalsTable.COLUMN_RSRP,
CellSignalsTable.COLUMN_RSRQ,
CellSignalsTable.COLUMN_RSSI,
CellSignalsTable.COLUMN_RSSNR,
CellSignalsTable.COLUMN_CQI,
CellSignalsTable.COLUMN_RSCP,
CellSignalsTable.COLUMN_CSI_RSRP,
CellSignalsTable.COLUMN_CSI_RSRQ,
CellSignalsTable.COLUMN_CSI_SINR,
CellSignalsTable.COLUMN_SS_RSRP,
CellSignalsTable.COLUMN_SS_RSRQ,
CellSignalsTable.COLUMN_SS_SINR,
CellSignalsTable.COLUMN_CDMA_DBM,
CellSignalsTable.COLUMN_CDMA_ECIO,
CellSignalsTable.COLUMN_EVDO_DBM,
CellSignalsTable.COLUMN_EVDO_ECIO,
CellSignalsTable.COLUMN_EVDO_SNR,
MeasurementsTable.COLUMN_MEASURED_AT,
MeasurementsTable.COLUMN_UPLOADED_TO_OCID_AT,
MeasurementsTable.COLUMN_UPLOADED_TO_MLS_AT,
Expand Down Expand Up @@ -409,6 +443,23 @@ private List<Measurement> getMeasurements(String selection, String[] selectionAr
int taColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_TA);
int asuColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_ASU);
int dbmColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_DBM);
int rsrpColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_RSRP);
int rsrqColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_RSRQ);
int rssiColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_RSSI);
int rssnrColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_RSSNR);
int cqiColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CQI);
int rscpColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_RSCP);
int csiRsrpColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CSI_RSRP);
int csiRsrqColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CSI_RSRQ);
int csiSinrColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CSI_SINR);
int ssRsrpColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_SS_RSRP);
int ssRsrqColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_SS_RSRQ);
int ssSinrColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_SS_SINR);
int cdmaDbmColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CDMA_DBM);
int cdmaEcioColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_CDMA_ECIO);
int evdoDbmColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_EVDO_DBM);
int evdoEcioColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_EVDO_ECIO);
int evdoSnrColumnIndex = cursor.getColumnIndex(CellSignalsTable.COLUMN_EVDO_SNR);
int latitudeColumnIndex = cursor.getColumnIndex(MeasurementsTable.COLUMN_LATITUDE);
int longitudeColumnIndex = cursor.getColumnIndex(MeasurementsTable.COLUMN_LONGITUDE);
int gpsAccuracyColumnIndex = cursor.getColumnIndex(MeasurementsTable.COLUMN_GPS_ACCURACY);
Expand Down Expand Up @@ -454,6 +505,23 @@ private List<Measurement> getMeasurements(String selection, String[] selectionAr
cell.setTa(cursor.getInt(taColumnIndex));
cell.setAsu(cursor.getInt(asuColumnIndex));
cell.setDbm(cursor.getInt(dbmColumnIndex));
cell.setRsrp(cursor.getInt(rsrpColumnIndex));
cell.setRsrq(cursor.getInt(rsrqColumnIndex));
cell.setRssi(cursor.getInt(rssiColumnIndex));
cell.setRssnr(cursor.getInt(rssnrColumnIndex));
cell.setCqi(cursor.getInt(cqiColumnIndex));
cell.setRscp(cursor.getInt(rscpColumnIndex));
cell.setCsiRsrp(cursor.getInt(csiRsrpColumnIndex));
cell.setCsiRsrq(cursor.getInt(csiRsrqColumnIndex));
cell.setCsiSinr(cursor.getInt(csiSinrColumnIndex));
cell.setSsRsrp(cursor.getInt(ssRsrpColumnIndex));
cell.setSsRsrq(cursor.getInt(ssRsrqColumnIndex));
cell.setSsSinr(cursor.getInt(ssSinrColumnIndex));
cell.setCdmaDbm(cursor.getInt(cdmaDbmColumnIndex));
cell.setCdmaEcio(cursor.getInt(cdmaEcioColumnIndex));
cell.setEvdoDbm(cursor.getInt(evdoDbmColumnIndex));
cell.setEvdoEcio(cursor.getInt(evdoEcioColumnIndex));
cell.setEvdoSnr(cursor.getInt(evdoSnrColumnIndex));
measurement.addCell(cell);
}
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ private void registerScripts(int from) {
if (from < 15) {
this.upgradeScripts.add(new UpgradeScript15());
}
if (from < 16) {
this.upgradeScripts.add(new UpgradeScript16());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package info.zamojski.soft.towercollector.dao.migration;

import android.database.sqlite.SQLiteDatabase;

class UpgradeScript16 implements IUpgradeScript {

@Override
public void performUpgrade(SQLiteDatabase database) {
// backup old tables
database.execSQL("ALTER TABLE cell_signals RENAME TO cell_signals_backup");
// drop index on old table
database.execSQL("DROP INDEX IF EXISTS IX_cell_signals_measurement_id");
database.execSQL("DROP INDEX IF EXISTS IX_cell_signals_cell_id");
// drop trigger on old table
database.execSQL("DROP TRIGGER IF EXISTS update_cell_signals_stats");
// create new table and index
database.execSQL("CREATE TABLE cell_signals (row_id INTEGER PRIMARY KEY NOT NULL, measurement_id INTEGER NOT NULL, cell_id INTEGER NOT NULL, psc INTEGER NOT NULL, neighboring INTEGER NOT NULL, ta INTEGER NOT NULL, asu INTEGER NOT NULL, dbm INTEGER NOT NULL, rsrp INTEGER NOT NULL, rsrq INTEGER NOT NULL, rssi INTEGER NOT NULL, rssnr INTEGER NOT NULL, cqi INTEGER NOT NULL, rscp INTEGER NOT NULL, csi_rsrp INTEGER NOT NULL, csi_rsrq INTEGER NOT NULL, csi_sinr INTEGER NOT NULL, ss_rsrp INTEGER NOT NULL, ss_rsrq INTEGER NOT NULL, ss_sinr INTEGER NOT NULL, cdma_dbm INTEGER NOT NULL, cdma_ecio INTEGER NOT NULL, evdo_dbm INTEGER NOT NULL, evdo_ecio INTEGER NOT NULL, evdo_snr INTEGER NOT NULL, FOREIGN KEY(measurement_id) REFERENCES measurements(row_id), FOREIGN KEY(cell_id) REFERENCES cells(row_id))");
database.execSQL("CREATE INDEX 'IX_cell_signals_measurement_id' on cell_signals (measurement_id DESC)");
database.execSQL("CREATE INDEX 'IX_cell_signals_cell_id' on cell_signals (cell_id DESC)");
// migrate data
database.execSQL("CREATE TRIGGER 'migrate_cell_signals' BEFORE DELETE ON cell_signals_backup BEGIN INSERT INTO cell_signals (measurement_id, cell_id, psc, neighboring, ta, asu, dbm, rsrp, rsrq, rssi, rssnr, cqi, rscp, csi_rsrp, csi_rsrq, csi_sinr, ss_rsrp, ss_rsrq, ss_sinr, cdma_dbm, cdma_ecio, evdo_dbm, evdo_ecio, evdo_snr) VALUES (old.measurement_id, old.cell_id, old.psc, old.neighboring, old.ta, old.asu, old.dbm, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647); END");
database.execSQL("DELETE FROM cell_signals_backup");
// create new trigger
database.execSQL("CREATE TRIGGER 'update_cell_signals_stats' AFTER INSERT ON cell_signals "
+ "BEGIN "
+ "UPDATE stats SET total_measurements = total_measurements + 1; "
+ "END;");
// delete backup
database.execSQL("DROP TABLE cell_signals_backup");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ public MeasurementBuilder setWcdmaSignal(int asu, int dbm) {
return this;
}

public MeasurementBuilder setLteSignal(int asu, int dbm, int ta) {
c.setLteSignalInfo(asu, dbm, ta);
public MeasurementBuilder setLteSignal(int asu, int dbm, int ta, int rsrp, int rsrq, int rssi, int rssnr, int cqi) {
c.setLteSignalInfo(asu, dbm, ta, rsrp, rsrq, rssi, rssnr, cqi);
return this;
}

public MeasurementBuilder setCdmaSignal(int asu, int dbm) {
c.setCdmaSignalInfo(asu, dbm);
public MeasurementBuilder setCdmaSignal(int asu, int dbm, int cdmaDbm, int cdmaEcio, int evdoDbm, int evdoEcio, int evdoSnr) {
c.setCdmaSignalInfo(asu, dbm, cdmaDbm, cdmaEcio, evdoDbm, evdoEcio, evdoSnr);
return this;
}

public MeasurementBuilder setNrSignal(int asu, int dbm) {
c.setNrSignalInfo(asu, dbm);
public MeasurementBuilder setNrSignal(int asu, int dbm, int csiRsrp, int csiRsrq, int csiSinr, int ssRsrp, int ssRsrq, int ssSinr) {
c.setNrSignalInfo(asu, dbm, csiRsrp, csiRsrq, csiSinr, ssRsrp, ssRsrq, ssSinr);
return this;
}

public MeasurementBuilder setTdscdmaSignal(int asu, int dbm) {
c.setTdscdmaSignalInfo(asu, dbm);
public MeasurementBuilder setTdscdmaSignal(int asu, int dbm, int rscp) {
c.setTdscdmaSignalInfo(asu, dbm, rscp);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static Measurement mockLastMeasurement() {

Cell c = new Cell();
c.setLteCellInfo(260, 6, 5114, 1055842, 28);
c.setLteSignalInfo(46, -94, 76);
c.setLteSignalInfo(46, -94, 76, Cell.UNKNOWN_SIGNAL, Cell.UNKNOWN_SIGNAL, Cell.UNKNOWN_SIGNAL, Cell.UNKNOWN_SIGNAL, Cell.UNKNOWN_SIGNAL);
m.addCell(c);

return m;
Expand Down
Loading

0 comments on commit 3faa8e5

Please sign in to comment.