2
2
3
3
import com .SecUpwN .AIMSICD .AIMSICD ;
4
4
import com .SecUpwN .AIMSICD .utils .Cell ;
5
+ import com .SecUpwN .AIMSICD .utils .CMDProcessor ;
5
6
6
7
import android .content .ContentValues ;
7
8
import android .content .Context ;
@@ -275,8 +276,19 @@ public long insertCell(Cell cell) {
275
276
* TODO: Is this where CSV data is populating the opencellid table?
276
277
*
277
278
*/
278
- long insertOpenCell (double latitude , double longitude , int mcc , int mnc , int lac ,
279
- int cellID , int avgSigStr , int samples ) {
279
+ long insertOpenCell (double latitude ,
280
+ double longitude ,
281
+ int mcc ,
282
+ int mnc ,
283
+ int lac ,
284
+ int cellID ,
285
+ int avgSigStr ,
286
+ int range , // new
287
+ int samples ,
288
+ int isGPSexact , // new
289
+ String RAT // new
290
+ //int rej_cause // new
291
+ ) {
280
292
281
293
//Populate Content Values for Insert or Update
282
294
ContentValues cellIDValues = new ContentValues ();
@@ -287,8 +299,11 @@ long insertOpenCell(double latitude, double longitude, int mcc, int mnc, int lac
287
299
cellIDValues .put ("Lac" , lac );
288
300
cellIDValues .put ("CellID" , cellID );
289
301
cellIDValues .put ("AvgSigStr" , avgSigStr );
290
- // cellIDValues.put("Range ", range );
302
+ cellIDValues .put ("avg_range " , range ); // new
291
303
cellIDValues .put ("Samples" , samples );
304
+ cellIDValues .put ("isGPSexact" , isGPSexact ); // new
305
+ cellIDValues .put ("Type" , RAT ); // new
306
+ //cellIDValues.put("rej_cause", rej_cause ); // new
292
307
293
308
if (openCellExists (cellID )) {
294
309
Log .v (TAG , "CID already in OCID DB (db update): " + cellID );
@@ -415,10 +430,20 @@ public Cursor getLocationData() {
415
430
416
431
/**
417
432
* Returns OpenCellID (DBe_import) database contents
433
+ *
434
+ * TODO: Need to implement new items!!
435
+ * URGENT: Maybe not so urgent, but need looking after, since we added items.
436
+ *
437
+ * Used in:
438
+ * DbViewerFragment.java
439
+ * MapViewerOsmDroid.java
440
+ *
441
+ *
418
442
*/
419
443
public Cursor getOpenCellIDData () {
420
444
return mDb .query ( OPENCELLID_TABLE ,
421
445
new String []{"CellID" , "Lac" , "Mcc" , "Mnc" , "Lat" , "Lng" , "AvgSigStr" , "Samples" },
446
+ // avg_range, rej_cause, Type
422
447
null , null , null , null , null
423
448
);
424
449
}
@@ -458,7 +483,7 @@ boolean cellExists(int cellID) {
458
483
Cursor cursor = mDb .rawQuery ("SELECT 1 FROM " + CELL_TABLE +
459
484
" WHERE CellID = " + cellID , null );
460
485
boolean exists = cursor .getCount () > 0 ;
461
- Log .i (TAG , "Cell exists in local DB?: " + exists );
486
+ Log .v (TAG , "CID: " + cellID + " exists in local DB (DBi_bts) ?: " + exists );
462
487
cursor .close ();
463
488
return exists ;
464
489
}
@@ -471,7 +496,7 @@ public boolean openCellExists(int cellID) {
471
496
Cursor cursor = mDb .rawQuery ("SELECT * FROM " + OPENCELLID_TABLE +
472
497
" WHERE CellID = " + cellID , null );
473
498
boolean exists = cursor .getCount () > 0 ;
474
- Log .i (TAG , "Cell exists in OCID?: " + exists );
499
+ Log .v (TAG , "CID: " + cellID + " exists in OCID (DBe_import) ?: " + exists );
475
500
cursor .close ();
476
501
return exists ;
477
502
}
@@ -643,12 +668,21 @@ private void populateDefaultMCC(SQLiteDatabase db) {
643
668
* Description: Parses the downloaded CSV from OpenCellID and uses it to populate "DBe_import".
644
669
* ("opencellid" table.)
645
670
*
671
+ *
672
+ * Dependency: RequestTask.java :: onPostExecute()
673
+ * insertOpenCell()
646
674
* Issues:
647
675
*
648
- * [ ] Why are we only populating 8 items out of 19 ?
676
+ * [ ] Progress is not shown or is the operation too quick ?
649
677
*
678
+ * [ ] Why are we only populating 8 items out of 19?
650
679
* From downloaded OCID CSV file: (19 items)
651
680
*
681
+ * NOTES:
682
+ *
683
+ * a) We do not include "rej_cause" in backups.
684
+ * b)
685
+ *
652
686
* # head -2 opencellid.csv
653
687
* lat,lon,mcc,mnc,lac,cellid,averageSignalStrength,range,samples,changeable,radio,rnc,cid,psc,tac,pci,sid,nid,bid
654
688
* 54.63376,25.160243,246,3,20,1294,0,-1,1,1,GSM,,,,,,,,
@@ -676,6 +710,7 @@ public boolean updateOpenCellID() {
676
710
int count = 0 ;
677
711
AIMSICD .mProgressBar .setProgress (0 );
678
712
AIMSICD .mProgressBar .setMax (csvCellID .size ());
713
+ Log .i (TAG , "updateOpenCellID: OCID CSV size (lines?): " + csvCellID .size () );
679
714
while ((next = csvReader .readNext ()) != null ) {
680
715
csvCellID .add (next );
681
716
AIMSICD .mProgressBar .setProgress (count ++);
@@ -687,7 +722,7 @@ public boolean updateOpenCellID() {
687
722
for (int i = 1 ; i < lines ; i ++) {
688
723
AIMSICD .mProgressBar .setProgress (i );
689
724
690
- // Insert details into OpenCellID Database
725
+ // Insert details into OpenCellID Database using: insertOpenCell()
691
726
// Beware of negative values of "range" and "samples"!!
692
727
insertOpenCell ( Double .parseDouble (csvCellID .get (i )[0 ]), // gps_lat
693
728
Double .parseDouble (csvCellID .get (i )[1 ]), // gps_lon
@@ -696,10 +731,10 @@ public boolean updateOpenCellID() {
696
731
Integer .parseInt (csvCellID .get (i )[4 ]), // LAC
697
732
Integer .parseInt (csvCellID .get (i )[5 ]), // CID (cellid) ?
698
733
Integer .parseInt (csvCellID .get (i )[6 ]), // avg_signal [dBm]
699
- // Integer.parseInt(csvCellID.get(i)[7]), // avg_range [m]
700
- Integer .parseInt (csvCellID .get (i )[8 ]) // samples
701
- // Integer.parseInt(csvCellID.get(i)[9]), // isGPSexact
702
- //Integer.parseInt (csvCellID.get(i)[10]), // RAT
734
+ Integer .parseInt (csvCellID .get (i )[7 ]), // avg_range [m]
735
+ Integer .parseInt (csvCellID .get (i )[8 ]), // samples
736
+ Integer .parseInt (csvCellID .get (i )[9 ]), // isGPSexact
737
+ String . valueOf (csvCellID .get (i )[10 ]) // RAT
703
738
//Integer.parseInt(csvCellID.get(i)[11]), // --- RNC
704
739
//Integer.parseInt(csvCellID.get(i)[12]), // --- (cid) ?
705
740
//Integer.parseInt(csvCellID.get(i)[13]), // --- PSC
@@ -783,14 +818,20 @@ public boolean restoreDB() {
783
818
784
819
case OPENCELLID_TABLE :
785
820
insertOpenCell (
786
- Double .parseDouble (records .get (i )[1 ]), //
787
- Double .parseDouble (records .get (i )[2 ]), //
788
- Integer .parseInt (records .get (i )[3 ]), //
789
- Integer .parseInt (records .get (i )[4 ]), //
790
- Integer .parseInt (records .get (i )[5 ]), //
791
- Integer .parseInt (records .get (i )[6 ]), //
792
- Integer .parseInt (records .get (i )[7 ]), //
793
- Integer .parseInt (records .get (i )[8 ])); //
821
+ // not sure about the naming of these, need CHECK!
822
+ Double .parseDouble (records .get (i )[1 ]), // lat
823
+ Double .parseDouble (records .get (i )[2 ]), // lng
824
+ Integer .parseInt (records .get (i )[3 ]), // mcc
825
+ Integer .parseInt (records .get (i )[4 ]), // mnc
826
+ Integer .parseInt (records .get (i )[5 ]), // lac
827
+ Integer .parseInt (records .get (i )[6 ]), // cid
828
+ Integer .parseInt (records .get (i )[7 ]), // avg_sig..
829
+ Integer .parseInt (records .get (i )[8 ]), // ); range
830
+ Integer .parseInt (records .get (i )[9 ]), // new samples
831
+ Integer .parseInt (records .get (i )[10 ]), // new isGPSexact
832
+ String .valueOf (records .get (i )[11 ]) // new RAT
833
+ //Integer.parseInt(records.get(i)[10]), // new rej_cause
834
+ );
794
835
break ;
795
836
796
837
case SILENT_SMS_TABLE :
@@ -840,19 +881,28 @@ public boolean restoreDB() {
840
881
* @return
841
882
*/
842
883
private void dumpDB () {
843
- File dir = new File (FOLDER );
884
+ File dumpdir = new File (FOLDER );
844
885
//if (!dir.exists()) { dir.mkdirs(); }
845
- File file = new File (dir , "aimsicd_dump.db" );
886
+ File file = new File (dumpdir , "aimsicd_dump.db" );
887
+
888
+ //Bad coding:
889
+ String aimdir = "/data/data/com.SecUpwN.AIMSICD/databases/" ;
890
+ //Context.getFilesDir().getPath("com.SecUpwN.AIMSICD/databases"); ????
846
891
847
- // We probably also need to test if we have the sqlite3 binary. (See Busbox checking code.)
892
+ // We probably also need to test if we have the sqlite3 binary. (See Busybox checking code.)
848
893
// Apparently pipes doesn't work from Java... (No idea why!?)
849
894
//String execString = "/system/xbin/sqlite3 " + dir + "aimsicd.db '.dump' | gzip -c >" + file;
850
- String execString = "/system/xbin/sqlite3 " + dir + "aimsicd.db '.dump' >" + file ;
895
+
896
+ // Both of these work, but "dump" makes an SQL file, whereas "backup" make a binary SQLite DB.
897
+ //String execString = "/system/xbin/sqlite3 " + aimdir + "aimsicd.db '.dump' >" + file;
898
+ String execString = "/system/xbin/sqlite3 " + aimdir + "aimsicd.db '.backup " +file + "'" ;
851
899
852
900
try {
853
901
Log .i (TAG , "dumpDB() Attempting to dump DB to: " + file + "\n Using: \" " + execString + "\" \n " );
854
- // We may need SU here and cd...
855
- Process process = Runtime .getRuntime ().exec (execString );
902
+ // We need SU here and cd...
903
+ CMDProcessor .runSuCommand (execString );
904
+ //CMDProcessor.runSuCommand(execString).getStdout(); // Need import!
905
+ //Process process = Runtime.getRuntime().exec(execString);
856
906
857
907
} catch (Exception e ) {
858
908
Log .e (TAG , "dumpDB() Failed to export DB dump file: " + e );
@@ -947,28 +997,39 @@ private void backup(String tableName) {
947
997
* min_gps_precision (currently hard-coded)
948
998
*
949
999
* So there are really two steps in this procedure:
950
- * a) Remove false BTS from DBe_import
951
- * b) Mark unsafe BTSs in the DBe_import with "ref_cause " value.
1000
+ * a) Remove bad BTSs from DBe_import
1001
+ * b) Mark unsafe BTSs in the DBe_import with "rej_cause " value.
952
1002
*
953
1003
* See: #253 http://tinyurl.com/lybrfxb
954
1004
* #203 http://tinyurl.com/mzgjdcz
955
1005
*
956
1006
* We filter:
957
1007
*
1008
+ * Used:
1009
+ * RequestTask.java :: onPostExecute()
1010
+ *
958
1011
* Issues:
959
1012
*
960
- * [ ] OPENCELLID_TABLE doesn't have a "Net" entry! WTF!
1013
+ * [x] OPENCELLID_TABLE doesn't have a "Net" entry!
1014
+ * [x] OPENCELLID_TABLE doesn't have a "Range" entry!
1015
+ *
961
1016
* [ ] Look into "long CID" and "Short CID" for UMTS/LTE...
962
1017
* http://wiki.opencellid.org/wiki/FAQ
963
1018
*
964
- * The formula for the long cell ID is as follows:
965
- * Long CID = 65536 * RNC + CID
1019
+ * The formula for the long cell ID is as follows:
1020
+ * Long CID = 65536 * RNC + CID
966
1021
*
967
- * If you have the Long CID, you can get RNC and CID in the following way:
968
- * RNC = Long CID / 65536 (integer division)
969
- * CID = Long CID mod 65536 (modulo operation)
1022
+ * If you have the Long CID, you can get RNC and CID in the following way:
1023
+ * RNC = Long CID / 65536 (integer division)
1024
+ * CID = Long CID mod 65536 (modulo operation)
970
1025
*
1026
+ * ChangeLog:
1027
+ * 2015-01-29 E:V:A Added
971
1028
*
1029
+ * TODO: (1) Implement some kind of counter, to count how many cells was removed.
1030
+ * TODO: (2) Better description of what was removed.
1031
+ * TODO: (3) Give a return value for success/failure
1032
+ * TODO: (4) Implement the "rej_cause" check and UPDATE table.
972
1033
*/
973
1034
//public void checkDBe( String tf_settings, int min_gps_precision ) {
974
1035
public void checkDBe () {
@@ -977,29 +1038,63 @@ public void checkDBe() {
977
1038
int min_gps_precision =50 ; // [m] Minimum acceptable GPS accuracy in meters.
978
1039
979
1040
String sqlq ; // SQL Query string
1041
+
1042
+ //=============================================================
1043
+ //=== DELETE bad cells from BTS data
1044
+ //=============================================================
1045
+
980
1046
Log .d ("checkDBe()" , "Attempting to delete bad import data from DBe_import table..." );
981
1047
1048
+ // =========== samples ===========
1049
+ sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Samples < 1" ;
1050
+ mDb .rawQuery (sqlq , null );
1051
+
1052
+ // =========== range (DBe_import::avg_range) ===========
1053
+ // TODO: OCID data marks many good BTS with a negative range so we can't use this yet.
1054
+ //sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Range < 1";
1055
+ //mDb.rawQuery(sqlq, null);
1056
+
982
1057
// =========== LAC ===========
983
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac <= 0 " ;
1058
+ sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac < 1 " ;
984
1059
mDb .rawQuery (sqlq , null );
985
- // Delete cells with CDMA (4) LAC not in [1,65534]
986
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac > 65534 AND Net=4" ;
1060
+
1061
+ // We should delete cells with CDMA (4) LAC not in [1,65534] but we can simplify this to:
1062
+ // Delete ANY cells with a LAC not in [1,65534]
1063
+ sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac > 65534" ;
987
1064
mDb .rawQuery (sqlq , null );
988
1065
// Delete cells with GSM/UMTS/LTE (1/2/3/13 ??) (or all others?) LAC not in [1,65533]
989
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac > 65533 AND Net!=4 " ;
990
- mDb .rawQuery (sqlq , null );
1066
+ // sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE Lac > 65533 AND Type!='CDMA' ";
1067
+ // mDb.rawQuery(sqlq, null);
991
1068
992
1069
// =========== CID ===========
993
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID <= 0 " ;
1070
+ sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID < 1 " ;
994
1071
mDb .rawQuery (sqlq , null );
995
- // Delete cells with UMTS/LTE (3,13) CID not in [1,268435455] (0xFFF FFFF)
996
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID > 268435455 AND (Net=3 OR Net=13)" ;
1072
+
1073
+ // We should delete cells with UMTS/LTE (3,13) CID not in [1,268435455] (0xFFF FFFF) but
1074
+ // we can simplify this to:
1075
+ // Delete ANY cells with a CID not in [1,268435455]
1076
+ sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID > 268435455" ;
997
1077
mDb .rawQuery (sqlq , null );
998
1078
// Delete cells with GSM/CDMA (1-3,4) CID not in [1,65534]
999
- sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID > 65534 AND (Net!=3 OR Net!=13)" ;
1000
- mDb .rawQuery (sqlq , null );
1079
+ //sqlq = "DELETE FROM " + OPENCELLID_TABLE + " WHERE CellID > 65534 AND (Net!=3 OR Net!=13)";
1080
+ //mDb.rawQuery(sqlq, null);
1081
+
1082
+ Log .i ("checkDBe()" , "Deleted BTS entries from DBe_import table with bad LAC/CID..." );
1083
+
1084
+ //=============================================================
1085
+ //=== UPDATE "rej_cause" in BTS data (DBe_import)
1086
+ //=============================================================
1087
+
1088
+ // =========== isGPSexact ===========
1089
+ // NOTE!! OCID present "changeable"=1 ==> isGPSexact (until we get new import!)
1090
+ // UPADTE opencellid SET rej_cause = rej_cause + 3 WHERE isGPSexact=1;
1091
+
1092
+ // =========== avg_range ===========
1093
+ // "UPDATE opencellid SET rej_cause = rej_cause + 3 WHERE avg_range < " + min_gps_precision;
1094
+
1095
+ // =========== time_first ===========
1096
+ // "UPDATE opencellid SET rej_cause = rej_cause + 1 WHERE time_first < " + tf_settings;
1001
1097
1002
- Log .i ("checkDBe()" , "Deleted entries from DBe_import table with bad LAC/CID..." );
1003
1098
}
1004
1099
1005
1100
@@ -1152,6 +1247,19 @@ public void onCreate(SQLiteDatabase database) {
1152
1247
* What: OpenCellID Cell Information Database
1153
1248
* Columns: _id,Lat,Lng,Mcc,Mnc,Lac,CellID,AvgSigStr,Samples,Timestamp
1154
1249
*
1250
+ * Additional items (CSV):
1251
+ * lat,lon,mcc,mnc,lac,cellid,averageSignalStrength,range,samples,changeable,radio,rnc,cid,psc,tac,pci,sid,nid,bid
1252
+ * We need:
1253
+ * lat,lon,mcc,mnc,lac,cellid,averageSignalStrength,range,samples,changeable,radio
1254
+ *
1255
+ * Dependencies:
1256
+ * updateOpenCellID
1257
+ * + "backup"
1258
+ *
1259
+ * ChengeLog:
1260
+ * 2015-01-29 E:V:A Added: CSV: range, changeable, radio as:
1261
+ * DBe: avg_range, isGPSexact, Type.
1262
+ *
1155
1263
* TODO: (1) rename to TABLE_DBE_IMPORT ("DBe_import".)
1156
1264
* TODO: (2) add more items from CSV file to table.
1157
1265
*/
@@ -1165,8 +1273,14 @@ public void onCreate(SQLiteDatabase database) {
1165
1273
"Lac INTEGER, " +
1166
1274
"CellID INTEGER, " +
1167
1275
"AvgSigStr INTEGER, " +
1168
- "Samples INTEGER, " +
1169
- "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);" ;
1276
+ "avg_range INTEGER, " + // new
1277
+ "Samples INTEGER, " +
1278
+ "isGPSexact INTEGER, " + // new
1279
+ "Type TEXT, " + // new
1280
+ // "rej_cause" // new
1281
+ "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp" +
1282
+ //"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp, " +
1283
+ ");" ;
1170
1284
database .execSQL (OPENCELLID_DATABASE_CREATE );
1171
1285
1172
1286
/**
0 commit comments