From 630c46cc32d8cb3e28bac375306cf26c80bf90ee Mon Sep 17 00:00:00 2001 From: "Security: Pwned." Date: Thu, 22 Jan 2015 15:41:05 +0000 Subject: [PATCH 1/6] Update CHANGELOG.md --- CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd38b90e..c5ca13d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,27 @@ # CHANGELOG of 'AIMSICD' ---------------------- +#### 22.01.2015 - WIP-Internal v0.1.25-alpha-build-22 + +* Changed: `setLocationUpdateMinTime` in OpenStreetMap from 60 to 10 s +* Changed: `setLocationUpdateMinDistance` in OSM from 1000 to 100 meters +* Added: Even more code comments, TODO's and code formatting to digg into + +--- + +#### 22.01.2015 - WIP-Internal v0.1.25-alpha-build-21 + +* Improved: Teweaked some log messages for a better output and clearer evaluation +* Removed: Commented out "Upload" code in the OCID download request handler +* Changed: Task request strings from `OPEN_CELL_ID_REQUEST` to `DBE_DOWNLOAD_REQUEST` +* Added: Lots of code placeholders to import CSV columns from OCID data and display them +* Added: Created `aimsicd.sql` as new SQL to create all new tables in the new structure +* Added: Created `CreateDBe_import.sql` which will be used to import the new Databases +* Added: More comments and basic code reformat for Database Viewer to support new tables +* Fixed: Clarified "range" vs "samples" confusion in Database Viewer + +--- + #### 20.01.2015 - WIP-Internal v0.1.25-alpha-build-20 * Improved: Silenced spammy Samsung Galaxy class debug logcat entries from DebugLog From 26360179be1e2a2bd8a6b1d632ad616cc8b633aa Mon Sep 17 00:00:00 2001 From: "E:V:A" Date: Thu, 22 Jan 2015 19:58:26 +0200 Subject: [PATCH 2/6] commented out MCC+MNC from map info xml etc - changed error messages to use msgLong instead of msgShort - commented out MCC, MNC from Map Viewer pin info XML - more comments --- .../AIMSICD/activities/MapViewerOsmDroid.java | 7 +- .../activities/OpenCellIdActivity.java | 5 +- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 103 ++++++++++++------ .../AIMSICD/fragments/DbViewerFragment.java | 9 +- .../SecUpwN/AIMSICD/service/CellTracker.java | 50 ++++++--- .../com/SecUpwN/AIMSICD/utils/Helpers.java | 84 ++++++++------ .../SecUpwN/AIMSICD/utils/RequestTask.java | 8 +- .../main/res/layout/marker_info_window.xml | 2 + 8 files changed, 171 insertions(+), 97 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java index 93a304de3..ae1d2dd2d 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java @@ -86,9 +86,8 @@ * * ChangeLog: * - * - * 2015-01-22 E:V:A Changed: setLocationUpdateMinTime: 60000 to 10000 ms - * setLocationUpdateMinDistance: 1000 to 100 meters + * 2015-01-22 E:V:A Changed: setLocationUpdateMinTime: 60000 to 10000 ms + * setLocationUpdateMinDistance: 1000 to 100 meters * * */ @@ -498,7 +497,7 @@ protected GeoPoint doInBackground(Void... voids) { runOnUiThread(new Runnable() { @Override public void run() { - Helpers.msgShort(MapViewerOsmDroid.this, "No tracked locations found to show on map."); + Helpers.msgLong(MapViewerOsmDroid.this, "No tracked locations found to show on map."); } }); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java index b262f1388..a2e6f0891 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java @@ -58,9 +58,8 @@ protected String doInBackground(Void... voids) { public void run() { pd.dismiss(); Helpers.msgLong(OpenCellIdActivity.this, - getString(R.string.ocid_api_error) - + e.getClass().getName() - + " - " + e.getMessage()); + getString(R.string.ocid_api_error) + e.getClass().getName() + + " - " + e.getMessage()); } }); return null; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index cb6ad84f4..571c89bbe 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -25,59 +25,81 @@ import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; + +/** + * Brief: Handles the AMISICD DataBase tables (creation, population, updates, + * + * Description: + * + * This class handle all the AMISICD DataBase maintenance operations, like + * creation, population, updates, backup, restore and various selections. + * + * Current Issues: + * + * As of 2015-01-01 we will start migrating from the old DB structure + * to the new one as detailed here: + * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/215 + * Please try to work on only one table at the time, before pushing + * new PRs. + * + * ChangeLog: + * + * 2015-01-22 E:V:A Started DBe_import migration + * + * Notes: + * + * + * + */ + public class AIMSICDDbAdapter { - /* - * This handles the AMISICD DataBase tables: - * - * As of 2015-01-01 we'll be slowly migrating from the old DB structure - * to the new one as detailed here: - * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/215 - * - * As you work on these tables, please try to implement the new tables by - * first changing the table names and then the table columns. - */ - private final String TAG = "AISMICD_DbAdaptor"; public static final String FOLDER = Environment.getExternalStorageDirectory() + "/AIMSICD/"; - private static final String COLUMN_ID = "_id"; // Underscore is no longer required... - - private final String LOCATION_TABLE = "locationinfo"; // TABLE_DBI_MEASURE:DBi_measure (volatile) - private final String CELL_TABLE = "cellinfo"; // TABLE_DBI_BTS:DBi_bts (physical) - private final String OPENCELLID_TABLE = "opencellid"; // TABLE_DBE_IMPORT:DBe_import - private final String DEFAULT_MCC_TABLE = "defaultlocation"; // TABLE_DEFAUKT_MCC:defaultlocation - private final String SILENT_SMS_TABLE = "silentsms"; // TABLE_SILENT_SMS:silentsms + public static final int DATABASE_VERSION = 8; - // Some placeholders for the use of the new tables: + private final String TAG = "AISMICD_DbAdaptor"; + private final String DB_NAME = "aimsicd.db"; + private static final String COLUMN_ID = "_id"; // Underscore is no longer required... - // private final String TABLE_DBE_IMPORT = "DBe_import"; // External: BTS import table - // private final String TABLE_DBE_CAPABILITIES = "DBe_capabilities" // External: MNO & BTS network capabilities - // private final String TABLE_DBI_BTS = "DBi_bts"; // Internal: (physical) BTS data - // private final String TABLE_DBI_MEASURE = "DBi_measure"; // Internal: (volatile) network measurements - // private final String TABLE_DEFAULT_MCC = "defaultlocation"; // Deafult MCC for each country - // private final String TABLE_DETECTION_FLAGS = "DetectionFlags" // Detection Flag description, settings and scoring table - // private final String TABLE_EVENT_LOG = "EventLog" // Detection and general EventLog (persistent) - // private final String TABLE_SECTORTYPE = "SectorType" // BTS tower sector configuration (Many CID, same BTS) - // private final String TABLE_SILENT_SMS = "silentsms"; // Silent SMS details - // private final String TABLE_CMEASURES = "CounterMeasures" // Counter Measures thresholds and description + private final String LOCATION_TABLE = "locationinfo"; // TABLE_DBI_MEASURE:DBi_measure (volatile) + private final String CELL_TABLE = "cellinfo"; // TABLE_DBI_BTS:DBi_bts (physical) + private final String OPENCELLID_TABLE = "opencellid"; // TABLE_DBE_IMPORT:DBe_import + private final String DEFAULT_MCC_TABLE = "defaultlocation"; // TABLE_DEFAULT_MCC:defaultlocation + private final String SILENT_SMS_TABLE = "silentsms"; // TABLE_SILENT_SMS:silentsms // cell tower signal strength collected by the device // ToDo: Remove this table and use "rx_signal" in the "TABLE_DBI_MEASURE:DBi_measure" table.. - private final String CELL_SIGNAL_TABLE = "cellSignal"; // - private final String DB_NAME = "aimsicd.db"; + private final String CELL_SIGNAL_TABLE = "cellSignal"; // TABLE_DBI_MEASURE::DBi_measure:rx_signal + + // Some placeholders for the use of the new tables: + + // private final String TABLE_DBE_IMPORT = "DBe_import"; // External: BTS import table + // private final String TABLE_DBE_CAPAB = "DBe_capabilities" // External: MNO & BTS network capabilities + // private final String TABLE_DBI_BTS = "DBi_bts"; // Internal: (physical) BTS data + // private final String TABLE_DBI_MEASURE = "DBi_measure"; // Internal: (volatile) network measurements + // private final String TABLE_DEFAULT_MCC = "defaultlocation"; // Default MCC for each country + // private final String TABLE_DET_FLAGS = "DetectionFlags" // Detection Flag description, settings and scoring table + // private final String TABLE_EVENTLOG = "EventLog" // Detection and general EventLog (persistent) + // private final String TABLE_SECTORTYPE = "SectorType" // BTS tower sector configuration (Many CID, same BTS) + // private final String TABLE_SILENTSMS = "silentsms"; // Silent SMS details + // private final String TABLE_CMEASURES = "CounterMeasures" // Counter Measures thresholds and description private final String[] mTables; private final DbHelper mDbHelper; private SQLiteDatabase mDb; private final Context mContext; - public static final int DATABASE_VERSION = 8; private Cursor signalStrengthMeasurementDatA; public AIMSICDDbAdapter(Context context) { mContext = context; mDbHelper = new DbHelper(context); - mTables = new String[]{LOCATION_TABLE, CELL_TABLE, OPENCELLID_TABLE, - SILENT_SMS_TABLE}; + mTables = new String[]{ + LOCATION_TABLE, + CELL_TABLE, + OPENCELLID_TABLE, + SILENT_SMS_TABLE + }; } public AIMSICDDbAdapter open() throws SQLException { @@ -389,7 +411,7 @@ public boolean checkLAC(Cell cell) { cursor.close(); return false; } else { - //Log.v(TAG, "LAC checked - no change. CID:" + cell.getCID() + " LAC(DBi):"+ cell.getLAC() + + //Log.v(TAG, "LAC checked - no change. CID:" + cell.getCID() + " LAC(DBi):" + cell.getLAC() + // " LAC(DBe): " + cursor.getInt(0) ); Log.v(TAG, "LAC checked - no change on CID:" + cell.getCID() + " LAC(API): " + cell.getLAC() @@ -894,6 +916,17 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE); db.execSQL("DROP TABLE IF EXISTS " + CELL_SIGNAL_TABLE); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_IMPORT); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_CAPABILITIES); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_BTS); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_MEASURE); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEFAULT_MCC); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DETECTION_FLAGS); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENT_LOG); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SECTORTYPE); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SILENT_SMS); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_CMEASURES); + onCreate(db); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java index ce2e82f2c..d54ad4644 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -192,16 +192,17 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { if (tableData != null && tableData.getCount() > 0) { switch (mTableSelected) { /* - * Was: "OpenCellID Data" New: "Imported OCID Data" - * * Table: DBi_import + * * CSV: lat,lon,mcc,mnc,lac,cellid,averageSignalStrength,range,samples,changeable,radio,rnc,cid,psc, tac,pci,sid,nid,bid + * * old: opencellid * _id|Lat|Lng|Mcc|Mnc|Lac|CellID|AvgSigStr|Samples|Timestamp * * new: DBe_import * _id,DBsource,RAT,MCC,MNC,LAC,CID,PSC,gps_lat,gps_lon,isGPSexact,avg_range,avg_signal,samples,time_first,time_last,rej_cause * + * Thus for OCID data we cannot use: time_first or time_last. * */ // Table: DBe_import @@ -210,6 +211,8 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { = new BaseInflaterAdapter<>( new OpenCellIdCardInflater() ); int count = tableData.getCount(); while (tableData.moveToNext()) { + // The getString(i) index refer to the table column in the "DBe_import" table + // OLD opencelid(i) // New "DBe_import" column name CardItemData data = new CardItemData( "CID: " + tableData.getString(0), // "LAC: " + tableData.getString(1), // @@ -218,7 +221,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { "Lat: " + tableData.getString(4), // "Lon: " + tableData.getString(5), // "AvgSignal: " + tableData.getString(6), // - "Samples: " + tableData.getString(7), // NOTE: #7 was range from ocid csv + "Samples: " + tableData.getString(7), // NOTE: #7 is range from ocid csv //"PSC: " + tableData.getString(7), // PSC //"first: " + tableData.getString(7), // time_first //"last: " + tableData.getString(7), // time_last diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java index 8a23eb340..8dbbb1468 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -690,13 +690,18 @@ public void cancelNotification() { /** * Set or update the Detection/Status Notification * - * TODO: Seem we're missing the other colors here: ORANGE and BLACK (skull) - * See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/wiki/Status-Icons - * Change names from "IDLE,NORMAL,MEDIUM,ALARM" to:"GRAY,GREEN,YELLOW,ORANGE,RED,BLACK", - * to reflect detection Icon colors. - * Dependencies: Status.java, CellTracker.java, Icon.java ( + others?) - * They should be based on the detection scores here: - * -- E:V:A 2015-01-19 + * Description: TODO: Please add details! + * + * Issues: + * + * TODO: Seem we're missing the other colors here: ORANGE and BLACK (skull) + * See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/wiki/Status-Icons + * Change names from "IDLE,NORMAL,MEDIUM,ALARM" to:"GRAY,GREEN,YELLOW,ORANGE,RED,BLACK", + * to reflect detection Icon colors. They should be based on the detection scores here: + * + * + * Dependencies: Status.java, CellTracker.java, Icon.java ( + others?) + * */ void setNotification() { String tickerText; @@ -723,14 +728,16 @@ void setNotification() { Status.setCurrentStatus(Status.Type.IDLE, this.context); } switch (Status.getStatus()) { - case IDLE: //IDLE + case IDLE: // GRAY contentText = "Phone Type " + mDevice.getPhoneType(); tickerText = context.getResources().getString(R.string.app_name_short) + " - Status: Idle."; break; - case NORMAL: //NORMAL + + case NORMAL: // GREEN tickerText = context.getResources().getString(R.string.app_name_short) + " - Status: Good. No Threats Detected."; break; - case MEDIUM: //MEDIUM + + case MEDIUM: // YELLOW or ORANGE? /** * New Issue (Noticed from #91): * Problem: @@ -757,7 +764,8 @@ void setNotification() { contentText = "Cell ID does not exist in OpenCellID Database!"; } break; - case ALARM: //DANGER (Is this RED?) + + case ALARM: // ORANGE, RED or BLACK ? tickerText = context.getResources().getString(R.string.app_name_short) + " - ALERT: Some Threat Detected!"; // Hmm, this is vague! if (mFemtoDetected) { contentText = "ALERT: FemtoCell Connection Detected!"; @@ -771,6 +779,7 @@ void setNotification() { break; } + // TODO: Explanation (see above) Intent notificationIntent = new Intent(context, AIMSICD.class); notificationIntent.putExtra("silent_sms", mTypeZeroSmsDetected); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND); @@ -793,6 +802,13 @@ void setNotification() { } + /** + * Description: TODO: Please add + * + * Variables: + * There is a "timer" here (REFRESH_RATE), what exactly is it timing? + * + */ private final Runnable timerRunnable = new Runnable() { @Override @@ -838,6 +854,7 @@ public void run() { } } + if (REFRESH_RATE != 0) { timerHandler.postDelayed(this, REFRESH_RATE); } else { @@ -847,6 +864,8 @@ public void run() { } }; + +//================================================================================================= /** * The below code section was copied and modified with permission from * Femtocatcher https://github.com/iSECPartners/femtocatcher @@ -983,33 +1002,31 @@ private boolean isEvDoNetwork(int networkType) { * Femtocatcher https://github.com/iSECPartners/femtocatcher * * Copyright (C) 2013 iSEC Partners + * */ +//================================================================================================= + final PhoneStateListener phoneStatelistener = new PhoneStateListener() { private void handle() { handlePhoneStateChange(); } - @Override public void onServiceStateChanged(ServiceState serviceState) { handle(); } - @Override public void onDataConnectionStateChanged(int state) { handle(); } - @Override public void onDataConnectionStateChanged(int state, int networkType) { handle(); } - @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { handle(); } - @Override public void onCellInfoChanged(List cellInfo) { handle(); @@ -1018,6 +1035,7 @@ public void onCellInfoChanged(List cellInfo) { /** * Getter for use in tests only + * TODO: What tests? */ public Cell getMonitorCell() { return mMonitorCell; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java index 0aae7357d..aafeb3b23 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java @@ -135,23 +135,48 @@ public static Boolean isNetAvailable(Context context) { return false; } - /** - * Requests Cell data from OpenCellID.org (OCID). - * - * The free OCID API has a download limit of 1000 BTSs for each download. - * Thus we need to carefully select the area we choose to download and make sure it is - * centered on the current GPS location. (It is also possible to query the number of - * cells in a particular bounding box (bbox), and use that.) - * - * The bbox is described in the OCID API here: - * http://wiki.opencellid.org/wiki/API#Getting_the_list_of_cells_in_a_specified_area - * - * In an urban area, we could try to limit ourselves to an area of ~10 Km. - * The (GSM) Timing Advance is limiting us to 35 Km. - * - * - * @param cell Current Cell Information - */ + /** + * Requests Cell data from OpenCellID.org (OCID). + * + * @param cell Current Cell Information + * + * The free OCID API has a download limit of 1000 BTSs for each download. + * Thus we need to carefully select the area we choose to download and make sure it is + * centered on the current GPS location. (It is also possible to query the number of + * cells in a particular bounding box (bbox), and use that.) + * + * The bbox is described in the OCID API here: + * http://wiki.opencellid.org/wiki/API#Getting_the_list_of_cells_in_a_specified_area + * + * In an urban area, we could try to limit ourselves to an area of ~10 Km. + * The (GSM) Timing Advance is limiting us to 35 Km. + * + * The OCID API payload: + * + * required: &BBOX=,,, + * optional: &mcc=&mnc=&lac=&radio= + * &limit=&offset=&format= + * + * Our API query is using: (Lat1,Lon1, Lat2,Lon2, mcc,mnc,lac) + * + * Issues: + * + * [ ] A too restrictive payload leads to many missing BTS in area, but a too liberal + * payload would return many less relevant ones and would cause us to reach the + * OCID API 1000 BTS download limit much faster. The solution would be to make the + * BBOX smaller, but that in turn, would result in the loss of some more distant, + * but still available towers. Possibly making them appears as RED, even when they + * are neither fake nor IMSI-catchers. However, a more realistic BTS picture is + * more useful, especially when sharing that info across different devices using + * on different RAT and MNO. + + * + * ChangeLog: + * + * 2015-01-22 E:V:A Removed some restrictive payload items, leaving MCC. + * + * + */ public static void getOpenCellData(Context context, Cell cell, char type) { if (Helpers.isNetAvailable(context)) { if (!CellTracker.OCID_API_KEY.equals("NA")) { @@ -161,12 +186,11 @@ public static void getOpenCellData(Context context, Cell cell, char type) { //New GeoLocation object to find bounding Coordinates GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon()); - //Calculate the Bounding Box Coordinates in a 10 Km radius - //0 = min 1 = max + //Calculate the Bounding Box Coordinates in a 10 Km radius //0 = min 1 = max GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(10, earthRadius); String boundParameter; - //Request OpenCellID data for Bounding Coordinates + //Request OpenCellID data for Bounding Coordinates //0 = min 1 = max boundParameter = String.valueOf(boundingCoords[0].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[0].getLongitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLatitudeInDegrees()) + "," @@ -180,22 +204,18 @@ public static void getOpenCellData(Context context, Cell cell, char type) { if (cell.getMCC() != Integer.MAX_VALUE) { sb.append("&mcc=").append(cell.getMCC()); } - - if (cell.getMNC() != Integer.MAX_VALUE) { - sb.append("&mnc=").append(cell.getMNC()); - } - - if (cell.getLAC() != Integer.MAX_VALUE) { - sb.append("&lac=").append(cell.getLAC()); - } + //if (cell.getMNC() != Integer.MAX_VALUE) { + // sb.append("&mnc=").append(cell.getMNC()); + //} + //if (cell.getLAC() != Integer.MAX_VALUE) { + // sb.append("&lac=").append(cell.getLAC()); + //} sb.append("&format=csv"); - new RequestTask(context, type).execute(sb.toString()); } } else { - Helpers.sendMsg(context, - "No OpenCellID API Key detected! \nPlease enter your key in settings first."); + Helpers.sendMsg(context, "No OpenCellID API Key detected! \nPlease enter your key in settings first."); } } else { final AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -356,7 +376,7 @@ public static List unpackByteListOfStrings(byte aob[]) { if (aob.length == 0) { // WARNING: This one is very chatty! - Log.v(TAG, "invokeOemRilRequestRaw: byte list response Length = 0"); + Log.v(TAG, "invokeOemRilRequestRaw: byte-list response Length = 0"); return Collections.emptyList(); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java index 0366ab816..aa93217ee 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java @@ -259,7 +259,7 @@ protected void onPostExecute(String result) { } mDbAdapter.close(); } else { - Helpers.msgShort(mContext, "Error retrieving OpenCellID data.\nCheck your network!"); + Helpers.msgLong(mContext, "Error retrieving OpenCellID data.\nCheck your network!"); } break; case DBE_DOWNLOAD_REQUEST_FROM_MAP: @@ -273,7 +273,7 @@ protected void onPostExecute(String result) { mDbAdapter.close(); } } else { - Helpers.msgShort(mContext, "Error retrieving OpenCellID data.\nCheck your network!"); + Helpers.msgLong(mContext, "Error retrieving OpenCellID data.\nCheck your network!"); } break; @@ -285,7 +285,7 @@ protected void onPostExecute(String result) { if (result != null && result.equals("Successful")) { Helpers.msgShort(mContext, "Restore database completed successfully"); } else { - Helpers.msgShort(mContext, "Error restoring database"); + Helpers.msgLong(mContext, "Error restoring database"); } break; @@ -305,7 +305,7 @@ protected void onPostExecute(String result) { + AIMSICDDbAdapter.FOLDER); builder.create().show(); } else { - Helpers.msgShort(mContext, "Error backing up database"); + Helpers.msgLong(mContext, "Error backing up database"); } } } diff --git a/app/src/main/res/layout/marker_info_window.xml b/app/src/main/res/layout/marker_info_window.xml index 39b6ff5bd..44cebc8fa 100644 --- a/app/src/main/res/layout/marker_info_window.xml +++ b/app/src/main/res/layout/marker_info_window.xml @@ -51,6 +51,7 @@ android:padding="2dip" android:gravity="start"/> + From 4e9c8e9026a2525f11e1a1a4c799915e4e7e203e Mon Sep 17 00:00:00 2001 From: "E:V:A" Date: Fri, 23 Jan 2015 07:03:08 +0200 Subject: [PATCH 3/6] Failed attempt to add EventLog table Warning BROKEN! I've tried to add the EventLog table by following the structure of the OPENCELLID_TABLE and adding: - eventlog_items.xml - EvenLogCardInflater.java But for some reason this doesn't work. So please have a look and don't hate me. I've also added: - more comments and placeholders --- .../java/com/SecUpwN/AIMSICD/AIMSICD.java | 13 + .../AIMSICD/adapters/AIMSICDDbAdapter.java | 344 +++++++++++++----- .../AIMSICD/adapters/CardItemData.java | 14 + .../adapters/EventLogCardInflater.java | 71 ++++ .../AIMSICD/fragments/DbViewerFragment.java | 17 +- .../SecUpwN/AIMSICD/service/CellTracker.java | 279 ++++++++------ .../com/SecUpwN/AIMSICD/utils/Helpers.java | 13 +- .../SecUpwN/AIMSICD/utils/RequestTask.java | 9 +- app/src/main/res/layout/eventlog_items.xml | 67 ++++ 9 files changed, 617 insertions(+), 210 deletions(-) create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java create mode 100644 app/src/main/res/layout/eventlog_items.xml diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java index 15eae8fb5..3e4e9a272 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java @@ -70,6 +70,17 @@ import java.util.ArrayList; import java.util.List; +/** + * + * Description: TODO: Please add some comments about this class + * + * Dependencies: TODO: Write a few words about where the content of this is used. + * + * Issues: + * + * ChangeLog: + * + */ public class AIMSICD extends BaseActivity implements AsyncResponse { private final String TAG = "AIMSICD"; @@ -293,6 +304,8 @@ void selectItem(int position) { Helpers.getOpenCellData(mContext, cell, RequestTask.DBE_DOWNLOAD_REQUEST); } else { Helpers.msgShort(mContext, "Waiting for location..."); + + // TODO: Is this implemented?? --E:V:A (2015-01-22) //Attempt to find location through CID //CID Location Async Output Delegate Interface Implementation LocationServices.LocationAsync locationAsync diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index 571c89bbe..70690d310 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -34,6 +34,8 @@ * This class handle all the AMISICD DataBase maintenance operations, like * creation, population, updates, backup, restore and various selections. * + * + * * Current Issues: * * As of 2015-01-01 we will start migrating from the old DB structure @@ -42,20 +44,41 @@ * Please try to work on only one table at the time, before pushing * new PRs. * + * [ ] We'd like to Export the entire DB (like a dump), so we need ... + * * ChangeLog: * * 2015-01-22 E:V:A Started DBe_import migration + * 2015-01-23 E:V:A ~~changed silent sms column names~~ NOT! + * Added EventLog table + * * * Notes: * + * ====== !! IMPORTANT !! ====================================================================== + * For damn good reasons, we should try to stay with mDb.rawQuery() and NOT with mDb.query(). + * In fact we should try to avoid the entire AOS SQLite API as much as possible, to keep our + * queries and SQL related clean, portable and neat. That's what most developers understand. + * See: http://stackoverflow.com/questions/1122679/querying-and-working-with-cursors-in-sqlite-on-android + * =============================================================================================== + * + * + We can use: + * + * rawQuery example: + * rawQuery("SELECT id, name FROM people WHERE name = ? AND id = ?", new String[] {"David", "2"}); * + * database.execSQL() * + * + A few words about DB "Cursors": + * http://developer.android.com/reference/android/database/Cursor.html + * http://stackoverflow.com/questions/3861558/what-are-the-benefits-of-using-database-cursor + * */ public class AIMSICDDbAdapter { public static final String FOLDER = Environment.getExternalStorageDirectory() + "/AIMSICD/"; - public static final int DATABASE_VERSION = 8; + public static final int DATABASE_VERSION = 8; // Is this "pragma user_version;" ? private final String TAG = "AISMICD_DbAdaptor"; private final String DB_NAME = "aimsicd.db"; @@ -74,15 +97,15 @@ public class AIMSICDDbAdapter { // Some placeholders for the use of the new tables: // private final String TABLE_DBE_IMPORT = "DBe_import"; // External: BTS import table - // private final String TABLE_DBE_CAPAB = "DBe_capabilities" // External: MNO & BTS network capabilities + // private final String TABLE_DBE_CAPAB = "DBe_capabilities"; // External: MNO & BTS network capabilities // private final String TABLE_DBI_BTS = "DBi_bts"; // Internal: (physical) BTS data // private final String TABLE_DBI_MEASURE = "DBi_measure"; // Internal: (volatile) network measurements // private final String TABLE_DEFAULT_MCC = "defaultlocation"; // Default MCC for each country - // private final String TABLE_DET_FLAGS = "DetectionFlags" // Detection Flag description, settings and scoring table - // private final String TABLE_EVENTLOG = "EventLog" // Detection and general EventLog (persistent) - // private final String TABLE_SECTORTYPE = "SectorType" // BTS tower sector configuration (Many CID, same BTS) + // private final String TABLE_DET_FLAGS = "DetectionFlags"; // Detection Flag description, settings and scoring table + private final String TABLE_EVENTLOG = "EventLog"; // Detection and general EventLog (persistent) + // private final String TABLE_SECTORTYPE = "SectorType"; // BTS tower sector configuration (Many CID, same BTS) // private final String TABLE_SILENTSMS = "silentsms"; // Silent SMS details - // private final String TABLE_CMEASURES = "CounterMeasures" // Counter Measures thresholds and description + // private final String TABLE_CMEASURES = "CounterMeasures"; // Counter Measures thresholds and description private final String[] mTables; private final DbHelper mDbHelper; @@ -95,10 +118,22 @@ public AIMSICDDbAdapter(Context context) { mContext = context; mDbHelper = new DbHelper(context); mTables = new String[]{ + // Oldies... LOCATION_TABLE, CELL_TABLE, OPENCELLID_TABLE, - SILENT_SMS_TABLE + SILENT_SMS_TABLE, + // New... + /*TABLE_DBE_IMPORT, + TABLE_DBE_CAPAB, + TABLE_DBI_BTS, + TABLE_DBI_MEASURE, + TABLE_DEFAULT_MCC, + TABLE_DET_FLAGS,*/ + TABLE_EVENTLOG, + /*TABLE_SECTORTYPE, + TABLE_SILENTSMS, + TABLE_CMEASURES*/ }; } @@ -113,11 +148,11 @@ public void close() { public long insertSilentSms(Bundle bundle) { ContentValues smsValues = new ContentValues(); - smsValues.put("Address", bundle.getString("address")); - smsValues.put("Display", bundle.getString("display_address")); - smsValues.put("Class", bundle.getString("class")); - smsValues.put("ServiceCtr", bundle.getString("service_centre")); - smsValues.put("Message", bundle.getString("message")); + smsValues.put("Address", bundle.getString("address")); // address + smsValues.put("Display", bundle.getString("display_address")); // display + smsValues.put("Class", bundle.getString("class")); // class + smsValues.put("ServiceCtr", bundle.getString("service_centre")); // SMSC + smsValues.put("Message", bundle.getString("message")); // message return mDb.insert(SILENT_SMS_TABLE, null, smsValues); } @@ -280,6 +315,8 @@ public long insertLocation(int lac, int cellID, /** * Delete cell info - for use in tests * + * TODO: What tests? + * * @param cellId * @return * @@ -289,6 +326,23 @@ public int deleteCell(int cellId) { return mDb.delete(CELL_TABLE, "CellID = ?", new String[]{ String.valueOf(cellId) }); } + + + // ==================================================================== + // mDbquery statements (get) SELECT + // ==================================================================== + + + // =========== NEW ============================================================================ + // TODO: + public Cursor getEventLogData() { + return mDb.query(TABLE_EVENTLOG, new String[]{"time", "LAC", "CID", "PSC", "gpsd_lat","gpsd_lon", "gpsd_accu", "DF_id", "DF_description"}, + null, null, null, null, null + ); + } + + + // =========== OLD ============================================================================ /** * Returns Silent SMS database (silentsms) contents */ @@ -311,6 +365,8 @@ public Cursor getCellData() { /** * Returns Cell Information for contribution to the OpenCellID Project + * + * Function: Seem to Return a list of all rows where OCID_SUBMITTED is not 1. */ public Cursor getOPCIDSubmitData() { return mDb.query(CELL_TABLE, new String[]{ "Lng", "Lat", "Mcc", "Mnc", "Lac", "CellID", @@ -348,6 +404,9 @@ public Cursor getDefaultMccLocationData() { null, null, null, null, null); } +// ==================================================================== + + /** * Checks to see if Location already exists in database */ @@ -366,7 +425,7 @@ boolean locationExists(int cellID, double lat, double lng, int signal) { * Checks to see if Cell already exists in database */ boolean cellExists(int cellID) { - Cursor cursor = mDb.rawQuery("SELECT 1 FROM " + CELL_TABLE + " WHERE CellID = " + cellID, + Cursor cursor = mDb.rawQuery("SELECT 1 FROM " + CELL_TABLE + " WHERE CellID = " + cellID, null); boolean exists = cursor.getCount() > 0; @@ -380,9 +439,9 @@ boolean cellExists(int cellID) { * Checks to see if Cell already exists in OpenCellID database */ public boolean openCellExists(int cellID) { - Cursor cursor = mDb.rawQuery("SELECT * FROM " + OPENCELLID_TABLE + " WHERE CellID = " + - cellID, null); - + Cursor cursor = mDb.rawQuery("SELECT * FROM " + OPENCELLID_TABLE + " WHERE CellID = " + cellID, + null); + boolean exists = cursor.getCount() > 0; Log.i(TAG, "Cell exists in OCID?: " + exists); cursor.close(); @@ -426,17 +485,17 @@ public boolean checkLAC(Cell cell) { /** * Updates Cell (cellinfo) records to indicate OpenCellID contribution has been made * TODO: This should be done on TABLE_DBI_MEASURE::DBi_measure:isSubmitted + * */ public void ocidProcessed() { ContentValues ocidValues = new ContentValues(); ocidValues.put("OCID_SUBMITTED", 1); // isSubmitted - mDb.update(CELL_TABLE, ocidValues, "OCID_SUBMITTED<>?", new String[]{"1"}); //isSubmitted + mDb.update(CELL_TABLE, ocidValues, "OCID_SUBMITTED<>?", new String[]{"1"}); // isSubmitted } public double[] getDefaultLocation(int mcc) { double[] loc = new double[2]; - Cursor cursor = mDb.rawQuery("SELECT Lat, Lng FROM " + - DEFAULT_MCC_TABLE + " WHERE Mcc = " + mcc, null); + Cursor cursor = mDb.rawQuery("SELECT Lat, Lng FROM " + DEFAULT_MCC_TABLE + " WHERE Mcc = " + mcc, null); if (cursor.moveToFirst()) { loc[0] = Double.parseDouble(cursor.getString(0)); @@ -458,10 +517,15 @@ public void cleanseCellTable() { mDb.execSQL("DELETE FROM " + CELL_TABLE + " WHERE CellID = " + Integer.MAX_VALUE + " OR CellID = -1"); } + /** + * Prepares the CSV file used to upload to OCID server. + * + */ public boolean prepareOpenCellUploadData() { boolean result; - // Q: Where is this? A: It is wherever your device has mounted its SDCard. - // For example: /data/media/0/AIMSICD/OpenCellID + // Q: Where is this? + // A: It is wherever your device has mounted its SDCard. + // For example: /data/media/0/AIMSICD/OpenCellID File dir = new File(FOLDER + "OpenCellID/"); if (!dir.exists()) { result = dir.mkdirs(); @@ -564,8 +628,8 @@ private void populateDefaultMCC(SQLiteDatabase db) { * - "samples" * - "range" * - * Also we should probably change this function name from: - * "updateOpenCellID" to "populateDBe_import" + * TODO: Also we should probably change this function name from: + * "updateOpenCellID" to "populateDBe_import" */ public boolean updateOpenCellID() { String fileName = Environment.getExternalStorageDirectory() @@ -789,14 +853,24 @@ private void backup(String tableName) { Log.i(TAG, "Database Export complete."); } - // ======================================================================================= - // TODO: @Tor, please add some comments, even if trivial. + /***************************************************************************************** + * What: DbHelper class for the SQLite Database functions + * + * Description: This class creates all the tables and DB structure in aimsicd.db when + * AIMSICD is first started or updated when DB version changed. + * + * Issues: + * + * TODO: @Tor, please add some comments, even if trivial. + * + ******************************************************************************************/ + public void cleanseCellStrengthTables(long maxTime) { - Log.d(TAG, "Cleaning "+CELL_SIGNAL_TABLE+" WHERE timestamp < "+maxTime); - mDb.execSQL("DELETE FROM "+CELL_SIGNAL_TABLE+" WHERE timestamp < "+maxTime); + Log.d(TAG, "Cleaning " + CELL_SIGNAL_TABLE + " WHERE timestamp < " + maxTime); + mDb.execSQL("DELETE FROM " + CELL_SIGNAL_TABLE + " WHERE timestamp < " + maxTime); } - public void addSignalStrength(int cellID, int signal, Long timestamp) { + public void addSignalStrength( int cellID, int signal, Long timestamp ) { ContentValues row = new ContentValues(); row.put("cellID", cellID); row.put("signal", signal); @@ -822,113 +896,199 @@ public Cursor getSignalStrengthMeasurementData() { // ======================================================================================= - /** - * DbHelper class for the SQLite Database functions - */ + /***************************************************************************************** + * What: DbHelper class for the SQLite Database functions + * + * Description: This class creates all the tables and DB structure in aimsicd.db when + * AIMSICD is first started or updated when DB version changed. + * + * Issues: + * + ******************************************************************************************/ public class DbHelper extends SQLiteOpenHelper { DbHelper(Context context) { super(context, DB_NAME, null, DATABASE_VERSION); } + + // This function drops all tables when SQLIte version has been upped + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", and destroy all old data."); + + db.execSQL("DROP TABLE IF EXISTS " + LOCATION_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + CELL_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + OPENCELLID_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + SILENT_SMS_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + CELL_SIGNAL_TABLE); + + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_IMPORT); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_CAPAB); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_BTS); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_MEASURE); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEFAULT_MCC); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DET_FLAGS); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTLOG); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SECTORTYPE); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SILENTSMS); + // db.execSQL("DROP TABLE IF EXISTS " + TABLE_CMEASURES); + + onCreate(db); + } + // Create aimsicd.db table structure @Override public void onCreate(SQLiteDatabase database) { - /* - * Cell Signal Measurements - * TODO move table into column "DBi_measure::rx_signal" + //============================================================= + // OLD tables + //============================================================= + + /** + * Table: CELL_SIGNAL_TABLE + * What: Cell Signal Measurements + * Columns: _id,cellID,signal,timestamp + * + * TODO: move table into column "DBi_measure::rx_signal" */ - database.execSQL("create table " + - CELL_SIGNAL_TABLE + " (" + COLUMN_ID + " integer primary key autoincrement, cellID INTEGER, signal INTEGER, timestamp INTEGER);"); - database.execSQL("create index cellID_index ON "+CELL_SIGNAL_TABLE+" (cellID);"); - database.execSQL("create index cellID_timestamp ON "+CELL_SIGNAL_TABLE+" (timestamp);"); - - /* - * Silent Sms Database + database.execSQL("create table " + + CELL_SIGNAL_TABLE + " (" + COLUMN_ID + + " integer primary key autoincrement, " + + "cellID INTEGER, signal INTEGER, " + + "timestamp INTEGER);"); + database.execSQL("create index cellID_index ON " + CELL_SIGNAL_TABLE + " (cellID);"); + database.execSQL("create index cellID_timestamp ON " + CELL_SIGNAL_TABLE + " (timestamp);"); + + /** + * Table: SILENT_SMS_TABLE + * What: Silent Sms Database + * Columns: _id,Address,Display,Class,ServiceCtr,Message,Timestamp + * + * TODO: */ String SMS_DATABASE_CREATE = "create table " + SILENT_SMS_TABLE + " (" + COLUMN_ID + - " integer primary key autoincrement, Address VARCHAR, Display VARCHAR, Class VARCHAR, " - + "ServiceCtr VARCHAR, Message VARCHAR, " + + " integer primary key autoincrement, " + + "Address VARCHAR, " + + "Display VARCHAR, " + + "Class VARCHAR, " + + "ServiceCtr VARCHAR, " + + "Message VARCHAR, " + "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);"; database.execSQL(SMS_DATABASE_CREATE); - /* - * Location Tracking Database - * TODO: rename to TABLE_DBI_MEASURE ("DBi_measure") - */ + /** + * Table: LOCATION_TABLE + * What: Location Tracking Database + * Columns: _id,Lac,CellID,Net,Lat,Lng,Signal,Connection,Timestamp + * + * TODO: rename to TABLE_DBI_MEASURE ("DBi_measure") + */ String LOC_DATABASE_CREATE = "create table " + LOCATION_TABLE + " (" + COLUMN_ID + - " integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " + - "Net VARCHAR, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Connection VARCHAR, " + + " integer primary key autoincrement, " + + "Lac INTEGER, CellID INTEGER, " + + "Net VARCHAR, " + + "Lat VARCHAR, " + + "Lng VARCHAR, " + + "Signal INTEGER, " + + "Connection VARCHAR, " + "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);"; database.execSQL(LOC_DATABASE_CREATE); - /* - * Cell Information Tracking Database + /** + * Table: CELL_TABLE + * What: Cell Information Tracking Database + * Columns: _id,Lac,CellID,Net,Lat,Lng,Signal,Mcc,Mnc,Accuracy,Speed,Direction,NetworkType,MeasurementTaken,OCID_SUBMITTED,Timestamp + * * TODO: rename to TABLE_DBI_BTS ("DBi_bts") */ String CELL_DATABASE_CREATE = "create table " + CELL_TABLE + " (" + COLUMN_ID + - " integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " + - "Net INTEGER, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Mcc INTEGER, Mnc INTEGER, " + - "Accuracy REAL, Speed REAL, Direction REAL, NetworkType VARCHAR, " + - "MeasurementTaken VARCHAR, OCID_SUBMITTED INTEGER DEFAULT 0, " + + " integer primary key autoincrement, " + + "Lac INTEGER, " + + "CellID INTEGER, " + + "Net INTEGER, " + + "Lat VARCHAR, " + + "Lng VARCHAR, " + + "Signal INTEGER, " + + "Mcc INTEGER, " + + "Mnc INTEGER, " + + "Accuracy REAL, " + + "Speed REAL, " + + "Direction REAL, " + + "NetworkType VARCHAR, " + + "MeasurementTaken VARCHAR, " + + "OCID_SUBMITTED INTEGER DEFAULT 0, " + "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);"; database.execSQL(CELL_DATABASE_CREATE); - /* - * OpenCellID Cell Information Database + + /** + * Table: OPENCELLID_TABLE + * What: OpenCellID Cell Information Database + * Columns: _id,Lat,Lng,Mcc,Mnc,Lac,CellID,AvgSigStr,Samples,Timestamp + * * TODO: rename to TABLE_DBE_IMPORT ("DBe_import".) */ String OPENCELLID_DATABASE_CREATE = "create table " + OPENCELLID_TABLE + " (" + COLUMN_ID + - " integer primary key autoincrement, Lat VARCHAR, Lng VARCHAR, Mcc INTEGER, " + - "Mnc INTEGER, Lac INTEGER, CellID INTEGER, AvgSigStr INTEGER, Samples INTEGER, " - + "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);"; + " integer primary key autoincrement, " + + "Lat VARCHAR, " + + "Lng VARCHAR, " + + "Mcc INTEGER, " + + "Mnc INTEGER, " + + "Lac INTEGER, " + + "CellID INTEGER, " + + "AvgSigStr INTEGER, " + + "Samples INTEGER, " + + "Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);"; database.execSQL(OPENCELLID_DATABASE_CREATE); - /* - * Default MCC Location Database + /** + * Table: DEFAULT_MCC_TABLE + * What: MCC Location Database + * Columns: _id,Country,Mcc,Lat,Lng */ String DEFAULT_MCC_DATABASE_CREATE = "create table " + DEFAULT_MCC_TABLE + " (" + COLUMN_ID + - " integer primary key autoincrement, Country VARCHAR, Mcc INTEGER, " - + "Lat VARCHAR, Lng VARCHAR);"; + " integer primary key autoincrement, " + + "Country VARCHAR, " + + "Mcc INTEGER, " + + "Lat VARCHAR, " + + "Lng VARCHAR);"; database.execSQL(DEFAULT_MCC_DATABASE_CREATE); - /* - * Repopulate the default MCC location table + //============================================================= + // NEW tables + //============================================================= + + /** + * Table: TABLE_EVENTLOG (EventLog) + * What: Event Log Database + * Columns: */ + String TABLE_EVENTLOG_CREATE = + "CREATE TABLE EventLog (" + + "_id INTEGER PRIMARY KEY AUTOINCREMENT," + + "time TEXT NOT NULL," + + "LAC INTEGER NOT NULL," + + "CID INTEGER NOT NULL," + + "PSC INTEGER," + + "gpsd_lat TEXT," + + "gpsd_lon TEXT," + + "gpsd_accu INTEGER," + + "DF_id INTEGER," + + "DF_description TEXT" + + ");"; + database.execSQL(TABLE_EVENTLOG_CREATE); + + + // Repopulate the default MCC location table populateDefaultMCC(database); } - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.w(TAG, - "Upgrading database from version " + oldVersion + " to " - + newVersion + ", which will destroy all old data" - ); - db.execSQL("DROP TABLE IF EXISTS " + LOCATION_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + CELL_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + OPENCELLID_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + SILENT_SMS_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + CELL_SIGNAL_TABLE); - - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_IMPORT); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_CAPABILITIES); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_BTS); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBI_MEASURE); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEFAULT_MCC); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DETECTION_FLAGS); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENT_LOG); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SECTORTYPE); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SILENT_SMS); - // db.execSQL("DROP TABLE IF EXISTS " + TABLE_CMEASURES); - - onCreate(db); - } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java index c2f1100f7..a0906dcf4 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java @@ -3,6 +3,20 @@ import com.SecUpwN.AIMSICD.utils.Cell; import com.SecUpwN.AIMSICD.utils.Device; +/** + * Description: TODO: A few comments please! + * TODO: Where is this used exactly? + * + * We often talk about "Network Type", when we actually refer to: + * "RAN" = Radio Access Network (cellular communaitcation only) + * "RAT" = Radio Access Technology (any wireless communication technology, like WiMax etc.) + * + * As for this application, we shall use the terms: + * "Type" for the text values like ( UMTS/WCDMA, HSDPA, CDMA, LTE etc) and + * "RAT" for the numerical equivalent (As obtained by AOS API?) + * + * + */ public class CardItemData { private final String mCellID; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java new file mode 100644 index 000000000..66dea6738 --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java @@ -0,0 +1,71 @@ +package com.SecUpwN.AIMSICD.adapters; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.SecUpwN.AIMSICD.R; + +public class EventLogCardInflater implements IAdapterViewInflater { + + @Override + public View inflate(final BaseInflaterAdapter adapter, + final int pos, View convertView, ViewGroup parent) { + ViewHolder holder; + + if (convertView == null) { + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + convertView = inflater.inflate(R.layout.opencelid_items, parent, false); + holder = new ViewHolder(convertView); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + final CardItemData item = adapter.getTItem(pos); + holder.updateDisplay(item); + + return convertView; + } + + private class ViewHolder { + + private final View mRootView; + private final TextView mtime; + private final TextView mLAC; + private final TextView mCID; + private final TextView mPSC; + private final TextView mgpsd_lat; + private final TextView mgpsd_lon; + private final TextView mgpsd_accur; + private final TextView mDF_id; + private final TextView mDF_description; + + public ViewHolder(View rootView) { + mRootView = rootView; + // + mtime = (TextView) mRootView.findViewById(R.id.time); + mLAC = (TextView) mRootView.findViewById(R.id.LAC); + mCID = (TextView) mRootView.findViewById(R.id.CID); + mPSC = (TextView) mRootView.findViewById(R.id.PSC); + mgpsd_lat = (TextView) mRootView.findViewById(R.id.gpsd_lat); + mgpsd_lon = (TextView) mRootView.findViewById(R.id.gpsd_lon); + mgpsd_accur = (TextView) mRootView.findViewById(R.id.gpsd_accur); + mDF_id = (TextView) mRootView.findViewById(R.id.DF_id); + mDF_description = (TextView) mRootView.findViewById(R.id.DF_description); + rootView.setTag(this); + } + + public void updateDisplay(CardItemData item) { + mtime.setText(item.getCellID()); + mLAC.setText(item.getLac()); + mCID.setText(item.getMcc()); + mPSC.setText(item.getMnc()); + mgpsd_lat.setText(item.getLat()); + mgpsd_lon.setText(item.getLng()); + mgpsd_accur.setText(item.getAvgSigStr()); + mDF_id.setText(item.getSamples()); + mDF_description.setText(item.getRecordId()); + } + } +} diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java index d54ad4644..12e58702c 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -128,10 +128,11 @@ protected BaseInflaterAdapter doInBackground(Void... params) { // ToBe merged into "DBi_measure:rx_signal" case "Measured Signal Strengths": result = mDb.getSignalStrengthMeasurementData(); + break; // Table: "EventLog" - //case "EventLog": - // result = mDb.getEventLogData(); + case "EventLog": + result = mDb.getEventLogData(); // Table: "DetectionFlags" //case "DetectionFlags": @@ -284,7 +285,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { } return adapter; } -/* + // Table: EventLog case "EventLog Data": { BaseInflaterAdapter adapter @@ -292,10 +293,10 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { int count = tableData.getCount(); while (tableData.moveToNext()) { CardItemData data = new CardItemData( - "time: " + tableData.getString(0), - "LAC: " + tableData.getString(1), - "CID: " + tableData.getString(2), - "PSC: " + tableData.getString(3), + "time: " + tableData.getString(0), // time + "LAC: " + tableData.getString(1), // LAC + "CID: " + tableData.getString(2), // CID + "PSC: " + tableData.getString(3), // PSC "Lat: " + tableData.getString(4), // gpsd_lat "Lon: " + tableData.getString(5), // gpsd_lon "accu: " + tableData.getString(6), // gpsd_accu (accuracy in [m]) @@ -306,7 +307,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { } return adapter; } - +/* // Maybe we can skip this one? // Table: DetectionFlags case "DetectionFlags Data": { diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java index 8dbbb1468..2b708d9a3 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -51,7 +51,14 @@ import java.util.concurrent.TimeUnit; /** - * Class to handle tracking of cell information + * Class to handle tracking of cell information + * + * Description: TODO: add more info + * + * Issues: + * + * ChangeLog + * */ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeListener { public static final String TAG = "CellTracker"; @@ -228,9 +235,9 @@ public void onReceive(Context context, Intent intent) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { final String KEY_UI_ICONS = context.getString(R.string.pref_ui_icons_key); final String FEMTO_DECTECTION = context.getString(R.string.pref_femto_detection_key); - final String REFRESH = context.getString(R.string.pref_refresh_key); // Refresh rate of ??? in [seconds]? + final String REFRESH = context.getString(R.string.pref_refresh_key); // Refresh rate of ??? in [seconds]? final String DB_VERSION = context.getString(R.string.pref_last_database_backup_version); - final String OCID_UPLOAD = context.getString(R.string.pref_ocid_upload); // BOOLEAN to enable OCID data upload + final String OCID_UPLOAD = context.getString(R.string.pref_ocid_upload); // BOOLEAN to enable OCID data upload final String OCID_KEY = context.getString(R.string.pref_ocid_key); if (key.equals(KEY_UI_ICONS)) { @@ -436,20 +443,25 @@ public void refreshDevice() { /** * Process User Preferences + * + * Description: TODO: add more info + * + * Handles the Preferences as set in the XXXXX file + * + * */ private void loadPreferences() { - boolean trackFemtoPref = prefs.getBoolean( context.getString(R.string.pref_femto_detection_key), false); - boolean trackCellPref = prefs.getBoolean( context.getString(R.string.pref_enable_cell_key), true); + boolean trackFemtoPref = prefs.getBoolean( context.getString(R.string.pref_femto_detection_key), false); + boolean trackCellPref = prefs.getBoolean( context.getString(R.string.pref_enable_cell_key), true); boolean monitorCellPref = prefs.getBoolean( context.getString(R.string.pref_enable_cell_monitoring_key), true); - LAST_DB_BACKUP_VERSION = prefs.getInt( context.getString(R.string.pref_last_database_backup_version), 1); - OCID_UPLOAD_PREF = prefs.getBoolean( context.getString(R.string.pref_ocid_upload), false); - CELL_TABLE_CLEANSED = prefs.getBoolean( context.getString(R.string.pref_cell_table_cleansed), false); + LAST_DB_BACKUP_VERSION = prefs.getInt( context.getString(R.string.pref_last_database_backup_version), 1); + OCID_UPLOAD_PREF = prefs.getBoolean( context.getString(R.string.pref_ocid_upload), false); + CELL_TABLE_CLEANSED = prefs.getBoolean( context.getString(R.string.pref_cell_table_cleansed), false); - String refreshRate = prefs.getString( context.getString(R.string.pref_refresh_key), "1"); - if (refreshRate.isEmpty()) { - refreshRate = "1"; - } + // TODO: Explain what this rate is doing... + String refreshRate = prefs.getString( context.getString(R.string.pref_refresh_key), "1"); + if (refreshRate.isEmpty()) { refreshRate = "1"; } int rate = Integer.parseInt(refreshRate); long t; @@ -461,70 +473,88 @@ private void loadPreferences() { t = (rate * 1L); break; } - REFRESH_RATE = TimeUnit.SECONDS.toMillis(t); + REFRESH_RATE = TimeUnit.SECONDS.toMillis(t); getOcidKey(); - if (trackFemtoPref) { - startTrackingFemto(); - } - - if (trackCellPref) { - setCellTracking(true); - } - - if (monitorCellPref) { - setCellMonitoring(true); - } + if (trackFemtoPref) { startTrackingFemto(); } + if (trackCellPref) { setCellTracking(true); } + if (monitorCellPref) { setCellMonitoring(true); } } + + /** + * Description: TODO: add more info + * + * This SEEM TO add entries to the "locationinfo" DB table in the?? + * + * Issues: + * + * [ ] We see that "Connection" items are messed up. What is the purpose of these? + * + * $ sqlite3.exe -header -csv aimsicd.db 'select * from locationinfo;' + * _id,Lac,CellID,Net,Lat,Lng,Signal,Connection,Timestamp + * 1,10401,6828111,10, 54.6787,25.2869, 24, "[10401,6828111,126]No|Di|HSPA|", "2015-01-21 20:45:10" + * + * [ ] + * + * ChangeLog: + * + * 2015-01-22 E:V:A Changed what appears to be a typo in the character + * following getNetworkTypeName(), "|" to "]" + * + */ private final PhoneStateListener mCellSignalListener = new PhoneStateListener() { public void onCellLocationChanged(CellLocation location) { - mDevice.setNetID(tm); - mDevice.getNetworkTypeName(); + mDevice.setNetID(tm); // ?? + mDevice.getNetworkTypeName(); // RAT?? switch (mDevice.getPhoneID()) { + case TelephonyManager.PHONE_TYPE_GSM: GsmCellLocation gsmCellLocation = (GsmCellLocation) location; if (gsmCellLocation != null) { mDevice.setCellInfo( gsmCellLocation.toString() + - mDevice.getDataActivityTypeShort() + "|" + - mDevice.getDataStateShort() + "|" + - mDevice.getNetworkTypeName() + "|"); - mDevice.mCell.setLAC(gsmCellLocation.getLac()); - mDevice.mCell.setCID(gsmCellLocation.getCid()); + mDevice.getDataActivityTypeShort() + "|" + // ?? + mDevice.getDataStateShort() + "|" + // ?? + mDevice.getNetworkTypeName() + "]" // ?? + ); + mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC + mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID if (gsmCellLocation.getPsc() != -1) - mDevice.mCell.setPSC(gsmCellLocation.getPsc()); + mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC } break; + case TelephonyManager.PHONE_TYPE_CDMA: CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location; if (cdmaCellLocation != null) { mDevice.setCellInfo( - cdmaCellLocation.toString() + - mDevice.getDataActivityTypeShort() + "|" + - mDevice.getDataStateShort() + "|" + - mDevice.getNetworkTypeName() + "|"); - mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); - mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); - mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); - mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); - mDevice.setNetworkName(tm.getNetworkOperatorName()); + cdmaCellLocation.toString() + // ?? + mDevice.getDataActivityTypeShort() + "|" + // ?? + mDevice.getDataStateShort() + "|" + // ?? + mDevice.getNetworkTypeName() + "]" // ?? + ); + mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); // NID + mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BID + mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); // SID + mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!? // MNC + mDevice.setNetworkName(tm.getNetworkOperatorName()); // ?? } } } public void onSignalStrengthsChanged(SignalStrength signalStrength) { - //Update Signal Strength + // Update Signal Strength if (signalStrength.isGsm()) { int dbm; if(signalStrength.getGsmSignalStrength() <= 2 || signalStrength.getGsmSignalStrength() == NeighboringCellInfo.UNKNOWN_RSSI) { - //Unknown signal strength, get it another way + // Unknown signal strength, get it another way String[] bits = signalStrength.toString().split(" "); dbm = Integer.parseInt(bits[9]); } else { @@ -535,10 +565,10 @@ public void onSignalStrengthsChanged(SignalStrength signalStrength) { int evdoDbm = signalStrength.getEvdoDbm(); int cdmaDbm = signalStrength.getCdmaDbm(); - //Use lowest signal to be conservative + // Use lowest signal to be conservative mDevice.setSignalDbm((cdmaDbm < evdoDbm) ? cdmaDbm : evdoDbm); } - //Send it to signal tracker + // Send it to signal tracker signalStrengthTracker.registerSignalStrength(mDevice.mCell.getCID(), mDevice.getSignalDBm()); //signalStrengthTracker.isMysterious(mDevice.mCell.getCID(), mDevice.getSignalDBm()); } @@ -596,8 +626,7 @@ void setSilentSmsStatus(boolean state) { setNotification(); if (state) { final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setMessage(R.string.sms_message) - .setTitle(R.string.sms_title); + builder.setMessage(R.string.sms_message).setTitle(R.string.sms_title); AlertDialog alert = builder.create(); alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); alert.show(); @@ -605,7 +634,26 @@ void setSilentSmsStatus(boolean state) { } } - public void onLocationChanged(Location loc) { + /** + * Description: TODO: add more info + * + * This SEEM TO add entries to the "locationinfo" DB table ??? + * + * From "locationinfo": + * + * $ sqlite3.exe -header aimsicd.db 'select * from locationinfo;' + * _id|Lac|CellID|Net|Lat|Lng|Signal|Connection|Timestamp + * 1|10401|6828xxx|10|54.67874392|25.28693531|24|[10401,6828320,126]No|Di|HSPA||2015-01-21 20:45:10 + * + * From "cellinfo": + * + * $ sqlite3.exe -header aimsicd.db 'select * from cellinfo;' + * _id|Lac|CellID|Net|Lat|Lng|Signal|Mcc|Mnc|Accuracy|Speed|Direction|NetworkType|MeasurementTaken|OCID_SUBMITTED|Timestamp + * 1|10401|6828xxx|10|54.67874392|25.28693531|24|246|2|69.0|0.0|0.0|HSPA|82964|0|2015-01-21 20:45:10 + * + * Issues: + */ + public void onLocationChanged(Location loc) { if (Build.VERSION.SDK_INT > 16) { DeviceApi17.loadCellInfo(tm, mDevice.mCell); @@ -617,60 +665,66 @@ public void onLocationChanged(Location loc) { switch (mDevice.getPhoneID()) { case TelephonyManager.PHONE_TYPE_GSM: GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation; - mDevice.mCell.setCID(gsmCellLocation.getCid()); - mDevice.mCell.setLAC(gsmCellLocation.getLac()); - mDevice.mCell.setPSC(gsmCellLocation.getPsc()); + mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID + mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC + mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC break; case TelephonyManager.PHONE_TYPE_CDMA: CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation; - mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); - mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); - mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); - mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); + mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BSID ?? + mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); // NID + mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); // SID + mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!?? // MNC } } } if (loc != null && (loc.getLatitude() != 0.0 && loc.getLongitude() != 0.0)) { - mDevice.mCell.setLon(loc.getLongitude()); - mDevice.mCell.setLat(loc.getLatitude()); - mDevice.mCell.setSpeed(loc.getSpeed()); - mDevice.mCell.setAccuracy(loc.getAccuracy()); - mDevice.mCell.setBearing(loc.getBearing()); - mDevice.setLastLocation(loc); + mDevice.mCell.setLon(loc.getLongitude()); // gpsd_lon + mDevice.mCell.setLat(loc.getLatitude()); // gpsd_lat + mDevice.mCell.setSpeed(loc.getSpeed()); // speed + mDevice.mCell.setAccuracy(loc.getAccuracy()); // gpsd_accu + mDevice.mCell.setBearing(loc.getBearing()); // -- [deg]?? + mDevice.setLastLocation(loc); // //Store last known location in preference SharedPreferences.Editor prefsEditor; prefsEditor = prefs.edit(); - prefsEditor.putString(context.getString(R.string.data_last_lat_lon), String.valueOf(loc.getLatitude()) + - ":" + String.valueOf(loc.getLongitude())); + prefsEditor.putString(context.getString(R.string.data_last_lat_lon), + String.valueOf(loc.getLatitude()) + ":" + + String.valueOf(loc.getLongitude())); prefsEditor.apply(); if (mTrackingCell) { dbHelper.open(); - dbHelper.insertLocation( - mDevice.mCell.getLAC(), - mDevice.mCell.getCID(), - mDevice.mCell.getNetType(), - mDevice.mCell.getLat(), - mDevice.mCell.getLon(), - mDevice.mCell.getDBM(), - mDevice.getCellInfo()); + // LOCATION_TABLE (locationinfo) ==> DBi_measure + DBi_bts + dbHelper.insertLocation( + mDevice.mCell.getLAC(), // Lac + mDevice.mCell.getCID(), // CellID + mDevice.mCell.getNetType(), // Net + mDevice.mCell.getLat(), // Lat + mDevice.mCell.getLon(), // Lng + mDevice.mCell.getDBM(), // Signal + mDevice.getCellInfo() // Connection + ); + + // CELL_TABLE (cellinfo)) ==> DBi_measure + DBi_bts dbHelper.insertCell( - mDevice.mCell.getLAC(), - mDevice.mCell.getCID(), - mDevice.mCell.getNetType(), - mDevice.mCell.getLat(), - mDevice.mCell.getLon(), - mDevice.mCell.getDBM(), - mDevice.mCell.getMCC(), - mDevice.mCell.getMNC(), - mDevice.mCell.getAccuracy(), - mDevice.mCell.getSpeed(), - mDevice.mCell.getBearing(), - mDevice.getNetworkTypeName(), - SystemClock.currentThreadTimeMillis()); + mDevice.mCell.getLAC(), // Lac + mDevice.mCell.getCID(), // CellID + mDevice.mCell.getNetType(), // Net + mDevice.mCell.getLat(), // Lat + mDevice.mCell.getLon(), // Lng + mDevice.mCell.getDBM(), // Signal + mDevice.mCell.getMCC(), // Mcc + mDevice.mCell.getMNC(), // Mnc + mDevice.mCell.getAccuracy(),// Accuracy + mDevice.mCell.getSpeed(), // Speed + mDevice.mCell.getBearing(), // Direction + mDevice.getNetworkTypeName(), // NetworkType + SystemClock.currentThreadTimeMillis() // MeasurementTaken + ); dbHelper.close(); } } @@ -694,13 +748,37 @@ public void cancelNotification() { * * Issues: * - * TODO: Seem we're missing the other colors here: ORANGE and BLACK (skull) - * See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/wiki/Status-Icons + * [ ] TODO: Seem we're missing the other colors here: ORANGE and BLACK (skull) + * See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/wiki/Status-Icons + * and: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/11#issuecomment-44670204 + * * Change names from "IDLE,NORMAL,MEDIUM,ALARM" to:"GRAY,GREEN,YELLOW,ORANGE,RED,BLACK", * to reflect detection Icon colors. They should be based on the detection scores here: * * - * Dependencies: Status.java, CellTracker.java, Icon.java ( + others?) + * [ ] We need to standardize the "contentText" and "tickerText" format + * + * [ ] From #91: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91 + * + * Problem: + * Having multiple notifications will cause an issue with + * notifications themselves AND tickerText. It seems that the + * most recent notification raised would overwrite any previous, + * notification or tickerText. This results in loss of information + * for any notification before the last one. + * + * Possible Solution: + * Perhaps arranging a queue implementation to deal with text + * being passed into tickerText only when any previous text has + * been entirely displayed. + * + * + * Dependencies: Status.java, CellTracker.java, Icon.java ( + others?) + * + * ChangeLog: + * + * 2015-01-22 E:V:A Added placeholder for "Missing Neighboring Cells Alert" + * * */ void setNotification() { @@ -727,6 +805,7 @@ void setNotification() { } else { Status.setCurrentStatus(Status.Type.IDLE, this.context); } + switch (Status.getStatus()) { case IDLE: // GRAY contentText = "Phone Type " + mDevice.getPhoneType(); @@ -737,28 +816,20 @@ void setNotification() { tickerText = context.getResources().getString(R.string.app_name_short) + " - Status: Good. No Threats Detected."; break; - case MEDIUM: // YELLOW or ORANGE? - /** - * New Issue (Noticed from #91): - * Problem: - * Having multiple notifications will cause an issue with - * notifications themselves AND tickerText. It seems that the - * most recent notification raised would overwrite any previous, - * notification or tickerText. This results in loss of information - * for any notification before the last one. - * - * Solution?: - * Perhaps arranging a queue implementation to deal with text - * being passed into tickerText only when any previous text has - * been entirely displayed. - **/ - //Initialize tickerText as the app name string + case MEDIUM: // YELLOW + // Initialize tickerText as the app name string + // See multiple detection comments above. tickerText = context.getResources().getString(R.string.app_name_short); if (mChangedLAC) { //Append changing LAC text tickerText += " - Hostile Service Area: Changing LAC Detected!"; contentText = "Hostile Service Area: Changing LAC Detected!"; - }else if (mCellIdNotInOpenDb) { + // See #264 + //} else if (NoNCL) { + // tickerText += " - BTS doesn't provide any neighbors!"; + // contentText = "CID: " + cellid + " is not providing a neighboring cell list!"; + + } else if (mCellIdNotInOpenDb) { //Append Cell ID not existing in external db text tickerText += " - Cell ID does not exist in OpenCellID Database!"; contentText = "Cell ID does not exist in OpenCellID Database!"; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java index aafeb3b23..69a5cac4b 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java @@ -45,7 +45,18 @@ import java.util.Date; import java.util.List; -public class Helpers { +/** + * + * Description: TODO: Please add some comments about this class + * + * Dependencies: TODO: Write a few words about where the content of this is used. + * + * Issues: + * + * ChangeLog: + * + */ + public class Helpers { private static final String TAG = "AIMSICD_Helpers"; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java index aa93217ee..3d4eb1b4a 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java @@ -277,6 +277,7 @@ protected void onPostExecute(String result) { } break; + // TODO: Do we need the DBE_UPLOAD_REQUEST here? //case DBE_UPLOAD_REQUEST: // // blah blah // break; @@ -296,13 +297,11 @@ protected void onPostExecute(String result) { AimsicdService.SHARED_PREFERENCES_BASENAME, 0); SharedPreferences.Editor prefsEditor; prefsEditor = prefs.edit(); - prefsEditor.putInt(mContext.getString(R.string.pref_last_database_backup_version), - AIMSICDDbAdapter.DATABASE_VERSION); + prefsEditor.putInt(mContext.getString(R.string.pref_last_database_backup_version), AIMSICDDbAdapter.DATABASE_VERSION); prefsEditor.apply(); final AlertDialog.Builder builder = new AlertDialog.Builder(mContext); - builder.setTitle(R.string.database_export_successful) - .setMessage("Database Backup successfully saved to:\n" - + AIMSICDDbAdapter.FOLDER); + builder.setTitle(R.string.database_export_successful).setMessage( + "Database Backup successfully saved to:\n" + AIMSICDDbAdapter.FOLDER); builder.create().show(); } else { Helpers.msgLong(mContext, "Error backing up database"); diff --git a/app/src/main/res/layout/eventlog_items.xml b/app/src/main/res/layout/eventlog_items.xml new file mode 100644 index 000000000..24a4b4e01 --- /dev/null +++ b/app/src/main/res/layout/eventlog_items.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + \ No newline at end of file From 3b5638d810535f3b28a9a67856f358ffff136f2f Mon Sep 17 00:00:00 2001 From: "E:V:A" Date: Fri, 23 Jan 2015 22:46:45 +0200 Subject: [PATCH 4/6] Commented out EventLog table code - Commented out bug prone EventLog table code - Reduced OCID data radius from 10 to 5 Km, still saturating DB limit. Now code compiles again. --- app/src/main/AndroidManifest.xml | 2 +- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 33 +++++++++------ .../AIMSICD/adapters/CardItemData.java | 42 +++++++++++++++---- .../AIMSICD/adapters/CellCardInflater.java | 42 +++++++++++++++++-- .../adapters/EventLogCardInflater.java | 34 +++++++++++---- .../AIMSICD/fragments/DbViewerFragment.java | 42 ++++++++++--------- .../com/SecUpwN/AIMSICD/utils/Helpers.java | 6 +-- 7 files changed, 148 insertions(+), 53 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f5f11020..fd6c89785 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="0.1.25-alpha-b23"> diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index 70690d310..c56bcb780 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -59,15 +59,24 @@ * For damn good reasons, we should try to stay with mDb.rawQuery() and NOT with mDb.query(). * In fact we should try to avoid the entire AOS SQLite API as much as possible, to keep our * queries and SQL related clean, portable and neat. That's what most developers understand. - * See: http://stackoverflow.com/questions/1122679/querying-and-working-with-cursors-in-sqlite-on-android + * + * See: + * [1] http://stackoverflow.com/questions/1122679/querying-and-working-with-cursors-in-sqlite-on-android + * [2] http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery%28java.lang.String,%20java.lang.String%5B%5D%29 * =============================================================================================== * - * + We can use: + * + Some examples we can use: * - * rawQuery example: + * 1) "Proper" style: * rawQuery("SELECT id, name FROM people WHERE name = ? AND id = ?", new String[] {"David", "2"}); * - * database.execSQL() + * 2) Hack style: (avoiding the use of "?") + * String q = "SELECT * FROM customer WHERE _id = " + customerDbId ; + * Cursor mCursor = mDb.rawQuery(q, null); + * + * 3) Info on execSQL(): + * Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE staement. + * Suggested use with: ALTER, CREATE or DROP. * * + A few words about DB "Cursors": * http://developer.android.com/reference/android/database/Cursor.html @@ -87,7 +96,7 @@ public class AIMSICDDbAdapter { private final String LOCATION_TABLE = "locationinfo"; // TABLE_DBI_MEASURE:DBi_measure (volatile) private final String CELL_TABLE = "cellinfo"; // TABLE_DBI_BTS:DBi_bts (physical) private final String OPENCELLID_TABLE = "opencellid"; // TABLE_DBE_IMPORT:DBe_import - private final String DEFAULT_MCC_TABLE = "defaultlocation"; // TABLE_DEFAULT_MCC:defaultlocation + private final String TABLE_DEFAULT_MCC = "defaultlocation"; // TABLE_DEFAULT_MCC:defaultlocation private final String SILENT_SMS_TABLE = "silentsms"; // TABLE_SILENT_SMS:silentsms // cell tower signal strength collected by the device @@ -128,7 +137,7 @@ public AIMSICDDbAdapter(Context context) { TABLE_DBE_CAPAB, TABLE_DBI_BTS, TABLE_DBI_MEASURE, - TABLE_DEFAULT_MCC, + TABLE_DEFAULT_MCC, // Why isn't this in here? TABLE_DET_FLAGS,*/ TABLE_EVENTLOG, /*TABLE_SECTORTYPE, @@ -399,7 +408,7 @@ public Cursor getOpenCellIDData() { * Returns Default MCC Locations (defaultlocation) database contents */ public Cursor getDefaultMccLocationData() { - return mDb.query(DEFAULT_MCC_TABLE, + return mDb.query(TABLE_DEFAULT_MCC, new String[]{"Country", "Mcc", "Lat", "Lng"}, null, null, null, null, null); } @@ -495,7 +504,7 @@ public void ocidProcessed() { public double[] getDefaultLocation(int mcc) { double[] loc = new double[2]; - Cursor cursor = mDb.rawQuery("SELECT Lat, Lng FROM " + DEFAULT_MCC_TABLE + " WHERE Mcc = " + mcc, null); + Cursor cursor = mDb.rawQuery("SELECT Lat, Lng FROM " + TABLE_DEFAULT_MCC + " WHERE Mcc = " + mcc, null); if (cursor.moveToFirst()) { loc[0] = Double.parseDouble(cursor.getString(0)); @@ -601,7 +610,7 @@ private void populateDefaultMCC(SQLiteDatabase db) { defaultMccValues.put("Mcc", csvMcc.get(i)[1]); defaultMccValues.put("Lng", csvMcc.get(i)[2]); defaultMccValues.put("Lat", csvMcc.get(i)[3]); - db.insert(DEFAULT_MCC_TABLE, null, defaultMccValues); + db.insert(TABLE_DEFAULT_MCC, null, defaultMccValues); } } catch (Exception e) { @@ -920,7 +929,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + CELL_TABLE); db.execSQL("DROP TABLE IF EXISTS " + OPENCELLID_TABLE); db.execSQL("DROP TABLE IF EXISTS " + SILENT_SMS_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + DEFAULT_MCC_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEFAULT_MCC); db.execSQL("DROP TABLE IF EXISTS " + CELL_SIGNAL_TABLE); // db.execSQL("DROP TABLE IF EXISTS " + TABLE_DBE_IMPORT); @@ -1047,12 +1056,12 @@ public void onCreate(SQLiteDatabase database) { database.execSQL(OPENCELLID_DATABASE_CREATE); /** - * Table: DEFAULT_MCC_TABLE + * Table: TABLE_DEFAULT_MCC * What: MCC Location Database * Columns: _id,Country,Mcc,Lat,Lng */ String DEFAULT_MCC_DATABASE_CREATE = "create table " + - DEFAULT_MCC_TABLE + " (" + COLUMN_ID + + TABLE_DEFAULT_MCC + " (" + COLUMN_ID + " integer primary key autoincrement, " + "Country VARCHAR, " + "Mcc INTEGER, " + diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java index a0906dcf4..e453b0eff 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java @@ -7,18 +7,30 @@ * Description: TODO: A few comments please! * TODO: Where is this used exactly? * - * We often talk about "Network Type", when we actually refer to: - * "RAN" = Radio Access Network (cellular communaitcation only) - * "RAT" = Radio Access Technology (any wireless communication technology, like WiMax etc.) + * Dependencies: * - * As for this application, we shall use the terms: - * "Type" for the text values like ( UMTS/WCDMA, HSDPA, CDMA, LTE etc) and - * "RAT" for the numerical equivalent (As obtained by AOS API?) + * Usage: * + * Issues: * + * ChangeLog: + * + * + * ----------------------------------------------------------------------------------------- + * Notes: + * + * We often talk about "Network Type", when we actually refer to: + * "RAN" = Radio Access Network (cellular communaitcation only) + * "RAT" = Radio Access Technology (any wireless communication technology, like WiMax etc.) + * + * As for this application, we shall use the terms: + * "Type" for the text values like ( UMTS/WCDMA, HSDPA, CDMA, LTE etc) and + * "RAT" for the numerical equivalent (As obtained by AOS API?) + * + * ------------------------------------------------------------------------------------------ */ public class CardItemData { - + // OLD (in old DB tables) private final String mCellID; private final String mLac; private final String mMcc; @@ -34,6 +46,22 @@ public class CardItemData { private final String mTimestamp; private final String mRecordId; + // NEW (in new DB tables) +/* + private final String mtime; + private final String mLAC; + private final String mCID; + private final String mPSC; + private final String mgpsd_lat; + private final String mgpsd_lon; + private final String mgpsd_accur; + private final String mDF_id; + private final String mDF_description; +*/ + + + // OLD items in old DB table structure + public CardItemData(Cell cell, String recordId) { if (cell.getCID() != Integer.MAX_VALUE && cell.getCID() != -1) { mCellID = "CID: " + cell.getCID(); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CellCardInflater.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CellCardInflater.java index ffdcc159d..0c0ca94a0 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CellCardInflater.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/CellCardInflater.java @@ -7,11 +7,29 @@ import android.view.ViewGroup; import android.widget.TextView; + +/** + * Brief: TODO: Please explain its use. + * + * Description: + * + * This class handle all the AMISICD DataBase ... TODO: Add info here ! + * + * + * + * Issues: TODO: !! === I'm not sure this is the right place... == !! --E:V:A + * + * ChangeLog: + * + * + * Notes: + * + */ public class CellCardInflater implements IAdapterViewInflater { @Override - public View inflate(final BaseInflaterAdapter adapter, final int pos, - View convertView, ViewGroup parent) { + public View inflate(final BaseInflaterAdapter adapter, + final int pos, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { @@ -30,6 +48,7 @@ public View inflate(final BaseInflaterAdapter adapter, final int p private class ViewHolder { + // OLD (in old DB tables) private final View mRootView; private final TextView mCellID; private final TextView mPsc; @@ -40,9 +59,22 @@ private class ViewHolder { private final TextView mLat; private final TextView mLng; private final TextView mSignal; - private final TextView mRecordId; + /*// NEW (in new DB tables) + private final View mRootView; + private final TextView mtime; + private final TextView mLAC; + private final TextView mCID; + private final TextView mPSC; + private final TextView mgpsd_lat; + private final TextView mgpsd_lon; + private final TextView mgpsd_accur; + private final TextView mDF_id; + private final TextView mDF_description; + */ + + // OLD (in old DB tables) public ViewHolder(View rootView) { mRootView = rootView; mCellID = (TextView) mRootView.findViewById(R.id.cellID); @@ -64,6 +96,10 @@ public ViewHolder(View rootView) { mSignal = (TextView) mRootView.findViewById(R.id.signal); mSignal.setVisibility(View.GONE); mRecordId = (TextView) mRootView.findViewById(R.id.record_id); + + // NEW (in new DB tables) + + rootView.setTag(this); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java index 66dea6738..7289f0093 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java @@ -7,6 +7,23 @@ import com.SecUpwN.AIMSICD.R; +/** + * Brief: TODO: Please explain its use. + * + * Description: + * + * This class handle all the AMISICD DataBase ... TODO: Add info here ! + * + * Dependencies: CardItemData.java + * + * Issues: + * + * ChangeLog: + * + * + * Notes: + * + */ public class EventLogCardInflater implements IAdapterViewInflater { @Override @@ -44,15 +61,16 @@ private class ViewHolder { public ViewHolder(View rootView) { mRootView = rootView; // - mtime = (TextView) mRootView.findViewById(R.id.time); - mLAC = (TextView) mRootView.findViewById(R.id.LAC); - mCID = (TextView) mRootView.findViewById(R.id.CID); - mPSC = (TextView) mRootView.findViewById(R.id.PSC); - mgpsd_lat = (TextView) mRootView.findViewById(R.id.gpsd_lat); - mgpsd_lon = (TextView) mRootView.findViewById(R.id.gpsd_lon); - mgpsd_accur = (TextView) mRootView.findViewById(R.id.gpsd_accur); - mDF_id = (TextView) mRootView.findViewById(R.id.DF_id); + mtime = (TextView) mRootView.findViewById(R.id.time); + mLAC = (TextView) mRootView.findViewById(R.id.LAC); + mCID = (TextView) mRootView.findViewById(R.id.CID); + mPSC = (TextView) mRootView.findViewById(R.id.PSC); + mgpsd_lat = (TextView) mRootView.findViewById(R.id.gpsd_lat); + mgpsd_lon = (TextView) mRootView.findViewById(R.id.gpsd_lon); + mgpsd_accur = (TextView) mRootView.findViewById(R.id.gpsd_accur); + mDF_id = (TextView) mRootView.findViewById(R.id.DF_id); mDF_description = (TextView) mRootView.findViewById(R.id.DF_description); + rootView.setTag(this); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java index 12e58702c..e642c4c13 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -213,21 +213,24 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { int count = tableData.getCount(); while (tableData.moveToNext()) { // The getString(i) index refer to the table column in the "DBe_import" table - // OLD opencelid(i) // New "DBe_import" column name + // OLD opencellid(i) // New "DBe_import" column name CardItemData data = new CardItemData( - "CID: " + tableData.getString(0), // - "LAC: " + tableData.getString(1), // - "MCC: " + tableData.getString(2), // - "MNC: " + tableData.getString(3), // - "Lat: " + tableData.getString(4), // - "Lon: " + tableData.getString(5), // - "AvgSignal: " + tableData.getString(6), // - "Samples: " + tableData.getString(7), // NOTE: #7 is range from ocid csv - //"PSC: " + tableData.getString(7), // PSC - //"first: " + tableData.getString(7), // time_first - //"last: " + tableData.getString(7), // time_last - //"isExact: " + tableData.getString(7), // isGPSexact - //"reject: " + tableData.getString(7), // rej_cause + //"Source: " + tableData.getString(0), // DBsource + //"RAT: " + tableData.getString(0), // RAT + "CID: " + tableData.getString(0), // + "LAC: " + tableData.getString(1), // + "MCC: " + tableData.getString(2), // + "MNC: " + tableData.getString(3), // + //"PSC: " + tableData.getString(7), // PSC + "Lat: " + tableData.getString(4), // gps_lat + "Lon: " + tableData.getString(5), // gps_lon + //"isExact: " + tableData.getString(7), // isGPSexact + //"Range: " + tableData.getString(7), // avg_range // + "AvgSignal: " + tableData.getString(6), // avg_signal + "Samples: " + tableData.getString(7), // samples // NOTE: #7 is range from ocid csv + //"first: " + tableData.getString(7), // time_first + //"last: " + tableData.getString(7), // time_last + //"reject: " + tableData.getString(7), // rej_cause "" + (tableData.getPosition() + 1) + " / " + count); adapter.addItem(data, false); } @@ -241,10 +244,10 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { int count = tableData.getCount(); while (tableData.moveToNext()) { CardItemData data = new CardItemData( - "Country: " + tableData.getString(0), - "MCC: " + tableData.getString(1), - "Lat: " + tableData.getString(2), - "Lon: " + tableData.getString(3), + "Country: " + tableData.getString(0),// Country --> country + "MCC: " + tableData.getString(1), // Mcc --> MCC + "Lat: " + tableData.getString(2), // Lat --> lat + "Lon: " + tableData.getString(3), // Lng --> lon "" + (tableData.getPosition() + 1) + " / " + count); adapter.addItem(data, false); } @@ -286,7 +289,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { return adapter; } - // Table: EventLog +/* // Table: EventLog case "EventLog Data": { BaseInflaterAdapter adapter = new BaseInflaterAdapter<>( new EventLogCardInflater() ); @@ -307,6 +310,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { } return adapter; } +*/ /* // Maybe we can skip this one? // Table: DetectionFlags diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java index 69a5cac4b..a0c753777 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java @@ -185,7 +185,7 @@ public static Boolean isNetAvailable(Context context) { * ChangeLog: * * 2015-01-22 E:V:A Removed some restrictive payload items, leaving MCC. - * + * 2015-01-23 E:V:A Tightened the BBOX from 10 to 5 Km, because of above. * */ public static void getOpenCellData(Context context, Cell cell, char type) { @@ -197,8 +197,8 @@ public static void getOpenCellData(Context context, Cell cell, char type) { //New GeoLocation object to find bounding Coordinates GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon()); - //Calculate the Bounding Box Coordinates in a 10 Km radius //0 = min 1 = max - GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(10, earthRadius); + //Calculate the Bounding Box Coordinates in a 5 Km radius //0 = min 1 = max + GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(5, earthRadius); String boundParameter; //Request OpenCellID data for Bounding Coordinates //0 = min 1 = max From c9999c729451eae3612a1502c69bc8604c473a25 Mon Sep 17 00:00:00 2001 From: "E:V:A" Date: Sat, 24 Jan 2015 06:51:46 +0200 Subject: [PATCH 5/6] Restrict MNC - re-introduced the OCID MNC restriction on CSV data - reverted "]" to "|". --- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 7 +- .../SecUpwN/AIMSICD/service/CellTracker.java | 110 +++++++++++------- .../java/com/SecUpwN/AIMSICD/utils/Cell.java | 7 ++ .../com/SecUpwN/AIMSICD/utils/Helpers.java | 35 +++--- app/src/main/res/layout/eventlog_items.xml | 2 +- app/src/main/res/layout/opencelid_items.xml | 2 +- 6 files changed, 100 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index c56bcb780..97e9f409d 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -863,14 +863,13 @@ private void backup(String tableName) { } /***************************************************************************************** - * What: DbHelper class for the SQLite Database functions + * What: TODO: @Tor, please add some comments, even if trivial. * - * Description: This class creates all the tables and DB structure in aimsicd.db when - * AIMSICD is first started or updated when DB version changed. + * Description: * * Issues: * - * TODO: @Tor, please add some comments, even if trivial. + * * ******************************************************************************************/ diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java index 2b708d9a3..4059af520 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -62,18 +62,18 @@ */ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeListener { public static final String TAG = "CellTracker"; - public static String OCID_API_KEY = null; // see getOcidKey() - private final int NOTIFICATION_ID = 1; + public static String OCID_API_KEY = null; // see getOcidKey() + private final int NOTIFICATION_ID = 1; // ? private static TelephonyManager tm; private final SignalStrengthTracker signalStrengthTracker; private PhoneStateListener mPhoneStateListener; private SharedPreferences prefs; - public static int PHONE_TYPE; - public static long REFRESH_RATE; - public static int LAST_DB_BACKUP_VERSION; - public static boolean OCID_UPLOAD_PREF; + public static int PHONE_TYPE; // + public static long REFRESH_RATE; // + public static int LAST_DB_BACKUP_VERSION; // + public static boolean OCID_UPLOAD_PREF; // public static final String SILENT_SMS = "SILENT_SMS_INTERCEPTED"; private boolean CELL_TABLE_CLEANSED; @@ -101,6 +101,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi public CellTracker(Context context, SignalStrengthTracker sst) { this.context = context; this.signalStrengthTracker = sst; + // TelephonyManager provides system details tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); prefs = context.getSharedPreferences(AimsicdService.SHARED_PREFERENCES_BASENAME, 0); @@ -108,7 +109,7 @@ public CellTracker(Context context, SignalStrengthTracker sst) { loadPreferences(); setNotification(); - PHONE_TYPE = tm.getPhoneType(); + PHONE_TYPE = tm.getPhoneType(); //PHONE_TYPE_GSM /CDMA /SIP dbHelper = new AIMSICDDbAdapter(context); if (!CELL_TABLE_CLEANSED) { @@ -122,7 +123,6 @@ public CellTracker(Context context, SignalStrengthTracker sst) { } mDevice.refreshDeviceInfo(tm, context); //Telephony Manager - mMonitorCell = new Cell(); //Register receiver for Silent SMS Interception Notification @@ -154,7 +154,6 @@ public void setCellMonitoring(boolean monitor) { mMonitoringCell = false; Helpers.msgShort(context, "Stopped monitoring Cell Information."); } - setNotification(); } @@ -184,16 +183,24 @@ public void stop() { cancelNotification(); tm.listen(mCellSignalListener, PhoneStateListener.LISTEN_NONE); prefs.unregisterOnSharedPreferenceChangeListener(this); - context.unregisterReceiver(mMessageReceiver); + context.unregisterReceiver(mMessageReceiver); } /** * Cell Information Tracking and database logging * - * TODO: This is the "Tracking cell information" that need better explanation - * and clarification. (What exactly are we "tracking" here? The GPS, the LAC/CID, - * and where doe it go?) + * Description: + * + * If the "tracking" option is enabled (as it is by default) then we are keeping + * a record (tracking) of the device location "gpsd_lat/lon", the connection + * signal strength (rx_signal) and data activity (?) and data connection state (?). + * The items included in these are stored in the "cellinfo" table. + * + * DATA_ACTIVITY: + * DATA_CONNECTION_STATE: + * + * TODO: * * * @param track Enable/Disable tracking @@ -201,10 +208,10 @@ public void stop() { public void setCellTracking(boolean track) { if (track) { tm.listen(mCellSignalListener, - PhoneStateListener.LISTEN_CELL_LOCATION | - PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | - PhoneStateListener.LISTEN_DATA_ACTIVITY | - PhoneStateListener.LISTEN_DATA_CONNECTION_STATE + PhoneStateListener.LISTEN_CELL_LOCATION | // gpsd_lat/lon ? + PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | // rx_signal + PhoneStateListener.LISTEN_DATA_ACTIVITY | // + PhoneStateListener.LISTEN_DATA_CONNECTION_STATE // ); mTrackingCell = true; Helpers.msgShort(context, "Tracking Cell Information."); @@ -233,12 +240,12 @@ public void onReceive(Context context, Intent intent) { }; public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - final String KEY_UI_ICONS = context.getString(R.string.pref_ui_icons_key); + final String KEY_UI_ICONS = context.getString(R.string.pref_ui_icons_key); final String FEMTO_DECTECTION = context.getString(R.string.pref_femto_detection_key); - final String REFRESH = context.getString(R.string.pref_refresh_key); // Refresh rate of ??? in [seconds]? - final String DB_VERSION = context.getString(R.string.pref_last_database_backup_version); - final String OCID_UPLOAD = context.getString(R.string.pref_ocid_upload); // BOOLEAN to enable OCID data upload - final String OCID_KEY = context.getString(R.string.pref_ocid_key); + final String REFRESH = context.getString(R.string.pref_refresh_key); // Refresh rate of ??? in [seconds]? + final String DB_VERSION = context.getString(R.string.pref_last_database_backup_version); + final String OCID_UPLOAD = context.getString(R.string.pref_ocid_upload); // BOOLEAN to enable OCID data upload + final String OCID_KEY = context.getString(R.string.pref_ocid_key); if (key.equals(KEY_UI_ICONS)) { //Update Notification to display selected icon type @@ -320,8 +327,7 @@ public static String requestNewOCIDKey() throws Exception { // a new API key within 24 hours of the last request. // Make toast message: "Only one new API key request per 24 hours. Please try again later." - Helpers.msgLong(context, - "Only one new API key request per 24 hours!\nPlease try again later."); + Helpers.msgLong(context, "Only one new API key request per 24 hours!\nPlease try again later."); if (result.getEntity() != null) { InputStream is = result.getEntity().getContent(); ByteArrayOutputStream content = new ByteArrayOutputStream(); @@ -364,7 +370,7 @@ public List updateNeighbouringCells() { // try to poll the neighboring cells for a few seconds neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100); Log.i(TAG, "neighbouringCellInfo empty - start polling"); - //Log.i(TAG, "signal: "+mDevice.getSignalDBm()); + //Log.i(TAG, "signal: " + mDevice.getSignalDBm()); //LISTEN_CELL_INFO added in API 17 if (Build.VERSION.SDK_INT > 16) { @@ -502,6 +508,7 @@ private void loadPreferences() { * * 2015-01-22 E:V:A Changed what appears to be a typo in the character * following getNetworkTypeName(), "|" to "]" + * 2015-01-24 E:V:A WTF!? Changed back ^ to "|" (Where is this parsed?) * */ private final PhoneStateListener mCellSignalListener = new PhoneStateListener() { @@ -511,14 +518,15 @@ public void onCellLocationChanged(CellLocation location) { switch (mDevice.getPhoneID()) { + // case TelephonyManager.PHONE_TYPE_SIP: case TelephonyManager.PHONE_TYPE_GSM: GsmCellLocation gsmCellLocation = (GsmCellLocation) location; if (gsmCellLocation != null) { mDevice.setCellInfo( - gsmCellLocation.toString() + - mDevice.getDataActivityTypeShort() + "|" + // ?? - mDevice.getDataStateShort() + "|" + // ?? - mDevice.getNetworkTypeName() + "]" // ?? + gsmCellLocation.toString() + // + mDevice.getDataActivityTypeShort() + "|" + // No,In,Ou,IO,Do + mDevice.getDataStateShort() + "|" + // Di,Ct,Cd,Su + mDevice.getNetworkTypeName() + "|" // TODO: Is "|" a typo? ); mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID @@ -533,20 +541,37 @@ public void onCellLocationChanged(CellLocation location) { if (cdmaCellLocation != null) { mDevice.setCellInfo( cdmaCellLocation.toString() + // ?? - mDevice.getDataActivityTypeShort() + "|" + // ?? - mDevice.getDataStateShort() + "|" + // ?? - mDevice.getNetworkTypeName() + "]" // ?? + mDevice.getDataActivityTypeShort() + "|" + // No,In,Ou,IO,Do + mDevice.getDataStateShort() + "|" + // Di,Ct,Cd,Su + mDevice.getNetworkTypeName() + "|" // TODO: Is "|" a typo? ); mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); // NID mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BID mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); // SID - mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!? // MNC + mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!? // MNC mDevice.setNetworkName(tm.getNetworkOperatorName()); // ?? } } } + /** + * Description: TODO: add more info + * + * Issues: + * + * [ ] Getting and comparing signal strengths between different RATs can be very + * tricky, since they all return different ranges of values. AOS doesn't + * specify very clearly what exactly is returned, even though people have + * a good idea, by trial and error. + * + * See note in : SignalStrengthTracker.java + * + * Notes: + * + * + * + */ public void onSignalStrengthsChanged(SignalStrength signalStrength) { // Update Signal Strength if (signalStrength.isGsm()) { @@ -573,6 +598,7 @@ public void onSignalStrengthsChanged(SignalStrength signalStrength) { //signalStrengthTracker.isMysterious(mDevice.mCell.getCID(), mDevice.getSignalDBm()); } + // In DB: No,In,Ou,IO,Do public void onDataActivity(int direction) { switch (direction) { case TelephonyManager.DATA_ACTIVITY_NONE: @@ -598,6 +624,7 @@ public void onDataActivity(int direction) { } } + // In DB: Di,Ct,Cd,Su public void onDataConnectionStateChanged(int state) { switch (state) { case TelephonyManager.DATA_DISCONNECTED: @@ -635,11 +662,11 @@ void setSilentSmsStatus(boolean state) { } /** - * Description: TODO: add more info + * Description: TODO: add more info * - * This SEEM TO add entries to the "locationinfo" DB table ??? + * This SEEM TO add entries to the "locationinfo" DB table ??? * - * From "locationinfo": + * From "locationinfo": * * $ sqlite3.exe -header aimsicd.db 'select * from locationinfo;' * _id|Lac|CellID|Net|Lat|Lng|Signal|Connection|Timestamp @@ -651,7 +678,8 @@ void setSilentSmsStatus(boolean state) { * _id|Lac|CellID|Net|Lat|Lng|Signal|Mcc|Mnc|Accuracy|Speed|Direction|NetworkType|MeasurementTaken|OCID_SUBMITTED|Timestamp * 1|10401|6828xxx|10|54.67874392|25.28693531|24|246|2|69.0|0.0|0.0|HSPA|82964|0|2015-01-21 20:45:10 * - * Issues: + * Issues: + * */ public void onLocationChanged(Location loc) { @@ -674,7 +702,7 @@ public void onLocationChanged(Location loc) { mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BSID ?? mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); // NID mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); // SID - mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!?? // MNC + mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!?? // MNC } } } @@ -709,7 +737,7 @@ public void onLocationChanged(Location loc) { mDevice.getCellInfo() // Connection ); - // CELL_TABLE (cellinfo)) ==> DBi_measure + DBi_bts + // CELL_TABLE (cellinfo) ==> DBi_measure + DBi_bts dbHelper.insertCell( mDevice.mCell.getLAC(), // Lac mDevice.mCell.getCID(), // CellID @@ -722,8 +750,8 @@ public void onLocationChanged(Location loc) { mDevice.mCell.getAccuracy(),// Accuracy mDevice.mCell.getSpeed(), // Speed mDevice.mCell.getBearing(), // Direction - mDevice.getNetworkTypeName(), // NetworkType - SystemClock.currentThreadTimeMillis() // MeasurementTaken + mDevice.getNetworkTypeName(), // NetworkType + SystemClock.currentThreadTimeMillis() // MeasurementTaken [ms] ); dbHelper.close(); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Cell.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Cell.java index d728ace10..82872de23 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Cell.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Cell.java @@ -396,6 +396,13 @@ public int getRssi() { return this.rssi; } + + /** + * TODO: What is this, and where is it supposed to be used ??? + * + * + * @return + */ @Override public int hashCode() { final int prime = 31; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java index a0c753777..b28406e9d 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java @@ -47,11 +47,21 @@ /** * - * Description: TODO: Please add some comments about this class + * Description: This class contain many various functions to: + * + * - present Toast messages + * - getTimestamp + * - Check network connectivity + * - Download CSV file with BTS data via HTTP API from OCID servers + * - Convert ByteToString + * - unpackListOfStrings + * - Check if SD is writeable + * - get System properties + * - Check for SU and BusyBox * * Dependencies: TODO: Write a few words about where the content of this is used. * - * Issues: + * Issues: AS complaints that several of these methods are not used... * * ChangeLog: * @@ -186,6 +196,8 @@ public static Boolean isNetAvailable(Context context) { * * 2015-01-22 E:V:A Removed some restrictive payload items, leaving MCC. * 2015-01-23 E:V:A Tightened the BBOX from 10 to 5 Km, because of above. + * 2015-01-24 E:V:A Re-imposed the MNC constraint. + * TODO: Inform user that BTSs from other networks are not shown. * */ public static void getOpenCellData(Context context, Cell cell, char type) { @@ -201,7 +213,7 @@ public static void getOpenCellData(Context context, Cell cell, char type) { GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(5, earthRadius); String boundParameter; - //Request OpenCellID data for Bounding Coordinates //0 = min 1 = max + //Request OpenCellID data for Bounding Coordinates (0 = min, 1 = max) boundParameter = String.valueOf(boundingCoords[0].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[0].getLongitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLatitudeInDegrees()) + "," @@ -215,9 +227,9 @@ public static void getOpenCellData(Context context, Cell cell, char type) { if (cell.getMCC() != Integer.MAX_VALUE) { sb.append("&mcc=").append(cell.getMCC()); } - //if (cell.getMNC() != Integer.MAX_VALUE) { - // sb.append("&mnc=").append(cell.getMNC()); - //} + if (cell.getMNC() != Integer.MAX_VALUE) { + sb.append("&mnc=").append(cell.getMNC()); + } //if (cell.getLAC() != Integer.MAX_VALUE) { // sb.append("&lac=").append(cell.getLAC()); //} @@ -256,8 +268,7 @@ public static String ByteToString(byte[] byteArray) { * @param dataLength length of byte array * @return String array copy of passed byte array */ - public static List ByteArrayToStringList(byte[] byteArray, - int dataLength) { + public static List ByteArrayToStringList(byte[] byteArray, int dataLength) { if (byteArray == null) { return null; } @@ -303,7 +314,6 @@ public static List ByteArrayToStringList(byte[] byteArray, result.add(ByteToString(mBlockData)); i += blockLength; } - if (result.size() <= 0) { return null; } @@ -369,12 +379,10 @@ public static List unpackListOfStrings(byte aob[]) { } display[i] = new String(aob, offset, byteCount).trim(); } - int newLength = display.length; while (newLength > 0 && TextUtils.isEmpty(display[newLength - 1])) { newLength -= 1; } - return Arrays.asList(Arrays.copyOf(display, newLength)); } @@ -390,9 +398,7 @@ public static List unpackByteListOfStrings(byte aob[]) { Log.v(TAG, "invokeOemRilRequestRaw: byte-list response Length = 0"); return Collections.emptyList(); } - int lines = aob.length / CHARS_PER_LINE; - String[] display = new String[lines]; for (int i = 0; i < lines; i++) { int offset, byteCount; @@ -403,7 +409,6 @@ public static List unpackByteListOfStrings(byte aob[]) { Log.e(TAG, "Unexpected EOF"); break; } - while (aob[offset + byteCount] != 0 && (byteCount < CHARS_PER_LINE)) { byteCount += 1; if (offset + byteCount >= aob.length) { @@ -413,12 +418,10 @@ public static List unpackByteListOfStrings(byte aob[]) { } display[i] = new String(aob, offset, byteCount).trim(); } - int newLength = display.length; while (newLength > 0 && TextUtils.isEmpty(display[newLength - 1])) { newLength -= 1; } - return Arrays.asList(Arrays.copyOf(display, newLength)); } diff --git a/app/src/main/res/layout/eventlog_items.xml b/app/src/main/res/layout/eventlog_items.xml index 24a4b4e01..71710b8bf 100644 --- a/app/src/main/res/layout/eventlog_items.xml +++ b/app/src/main/res/layout/eventlog_items.xml @@ -64,4 +64,4 @@ android:layout_height="wrap_content" android:textColor="@color/medium_blue"/> - \ No newline at end of file + diff --git a/app/src/main/res/layout/opencelid_items.xml b/app/src/main/res/layout/opencelid_items.xml index e499ae7a7..22aa10508 100644 --- a/app/src/main/res/layout/opencelid_items.xml +++ b/app/src/main/res/layout/opencelid_items.xml @@ -64,4 +64,4 @@ android:layout_height="wrap_content" android:textColor="@color/medium_blue" android:gravity="end"/> - \ No newline at end of file + From c92ef9fcaf69c74f31dba26871987bc6fe7fa6bb Mon Sep 17 00:00:00 2001 From: "E:V:A" Date: Mon, 26 Jan 2015 19:59:55 +0200 Subject: [PATCH 6/6] Preparing for EventLog table and small fixes - added EventLog to selector in strings - some (code) formatting of marker_info_window items. - try to get rid of black background line in "Neighboring Cells" window - fixed name typo in Cell Tracker (FEMTO_DECTECTION) - Comment out MCC/MNC in pin info detail (to be completely replaced by ProviderCode (PC = MCC+MNC) to save DB card space. - added HEX value to CID in Cell Strength table (DB Viewer) - --- .../MeasuredCellStrengthCardData.java | 11 ++++- .../AIMSICD/fragments/DbViewerFragment.java | 12 +++--- .../SecUpwN/AIMSICD/map/CellTowerMarker.java | 16 ++++--- .../com/SecUpwN/AIMSICD/map/MarkerData.java | 2 +- .../SecUpwN/AIMSICD/service/CellTracker.java | 42 ++++++++++++++----- app/src/main/res/layout/cell_fragment.xml | 4 +- .../main/res/layout/marker_info_window.xml | 32 +++++++------- app/src/main/res/values/strings.xml | 1 + 8 files changed, 77 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/MeasuredCellStrengthCardData.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/MeasuredCellStrengthCardData.java index d92dd0763..4426dc4ff 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/MeasuredCellStrengthCardData.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/MeasuredCellStrengthCardData.java @@ -20,14 +20,21 @@ public MeasuredCellStrengthCardData(int cellID, int signal, long timestamp) { this.timestamp = timestamp; } + + // Let's try to get it in HEX as well public String getCellID() { - return "CID: "+cellID; + return "CID: "+cellID + " (0x" + Integer.toHexString(cellID) +")"; } + //original + // public String getCellID() { + // return "CID: "+cellID; + //} + // This is probably not dBm but ASU ? // Please see: http://wiki.opencellid.org/wiki/API#Filtering_of_data public String getSignal() { - return"RSS: "+signal+" dBm"; + return "RSS: "+signal+" dBm"; } public String getTimestamp() { diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java index e642c4c13..799b59dee 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -213,23 +213,23 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) { int count = tableData.getCount(); while (tableData.moveToNext()) { // The getString(i) index refer to the table column in the "DBe_import" table - // OLD opencellid(i) // New "DBe_import" column name + // OLD opencellid(i) // New "DBe_import" column name CardItemData data = new CardItemData( //"Source: " + tableData.getString(0), // DBsource - //"RAT: " + tableData.getString(0), // RAT + //"RAT: " + tableData.getString(0), // RAT "CID: " + tableData.getString(0), // "LAC: " + tableData.getString(1), // "MCC: " + tableData.getString(2), // "MNC: " + tableData.getString(3), // - //"PSC: " + tableData.getString(7), // PSC + //"PSC: " + tableData.getString(7), // PSC "Lat: " + tableData.getString(4), // gps_lat "Lon: " + tableData.getString(5), // gps_lon //"isExact: " + tableData.getString(7), // isGPSexact - //"Range: " + tableData.getString(7), // avg_range // + //"Range: " + tableData.getString(7), // avg_range // "AvgSignal: " + tableData.getString(6), // avg_signal "Samples: " + tableData.getString(7), // samples // NOTE: #7 is range from ocid csv - //"first: " + tableData.getString(7), // time_first - //"last: " + tableData.getString(7), // time_last + //"first: " + tableData.getString(7), // time_first + //"last: " + tableData.getString(7), // time_last //"reject: " + tableData.getString(7), // rej_cause "" + (tableData.getPosition() + 1) + " / " + count); adapter.addItem(data, false); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/map/CellTowerMarker.java b/app/src/main/java/com/SecUpwN/AIMSICD/map/CellTowerMarker.java index 0cf9efe01..b4284887f 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/map/CellTowerMarker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/map/CellTowerMarker.java @@ -45,6 +45,10 @@ public MarkerData getMarkerData() { * more available items as explained in the related issue here: * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/234 * + * Dependency: marker_info_window.xml + * MarkerData.java + * marker_info_window.xml + * */ public View getInfoContents(MarkerData data) { @@ -55,6 +59,7 @@ public View getInfoContents(MarkerData data) { if (v != null) { if (data != null) { + // We would also like to show this in HEX: "CID: 65535 (0xFFFF)" if (data.openCellID) { TableRow tr = (TableRow) v.findViewById(R.id.open_cell_label); tr.setVisibility(View.VISIBLE); @@ -62,7 +67,7 @@ public View getInfoContents(MarkerData data) { tv = (TextView) v.findViewById(R.id.cell_id); // CID tv.setText(data.cellID); - tv = (TextView) v.findViewById(R.id.lac); // LAC + tv = (TextView) v.findViewById(R.id.lac); // LAC tv.setText(data.lac); tv = (TextView) v.findViewById(R.id.lat); // LAT tv.setText(String.valueOf(data.lat)); @@ -70,10 +75,10 @@ public View getInfoContents(MarkerData data) { tv.setText(String.valueOf(data.lng)); // TODO replace MCC & MNC with PC: - tv = (TextView) v.findViewById(R.id.mcc); // MCC - tv.setText(data.getMCC()); - tv = (TextView) v.findViewById(R.id.mnc); // MNC - tv.setText(data.getMNC()); + //tv = (TextView) v.findViewById(R.id.mcc); // MCC + //tv.setText(data.getMCC()); + //tv = (TextView) v.findViewById(R.id.mnc); // MNC + //tv.setText(data.getMNC()); tv = (TextView) v.findViewById(R.id.pc); // MNC+MCC tv.setText(data.getPC()); @@ -81,7 +86,6 @@ public View getInfoContents(MarkerData data) { tv.setText(data.getSamples()); } } - // Returning the view containing InfoWindow contents return v; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/map/MarkerData.java b/app/src/main/java/com/SecUpwN/AIMSICD/map/MarkerData.java index 37a244650..a1232638b 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/map/MarkerData.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/map/MarkerData.java @@ -1,7 +1,7 @@ package com.SecUpwN.AIMSICD.map; /** - * Class to hold data for displaying in BTS pin popup dialog + * Class to hold data for displaying in BTS pin popup dialog ?? * * TODO: Consider adding more details, similar as for the DB Viewer UI: * see: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/234 diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java index 4059af520..bc9c9090b 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -241,7 +241,7 @@ public void onReceive(Context context, Intent intent) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { final String KEY_UI_ICONS = context.getString(R.string.pref_ui_icons_key); - final String FEMTO_DECTECTION = context.getString(R.string.pref_femto_detection_key); + final String FEMTO_DETECTION = context.getString(R.string.pref_femto_detection_key); final String REFRESH = context.getString(R.string.pref_refresh_key); // Refresh rate of ??? in [seconds]? final String DB_VERSION = context.getString(R.string.pref_last_database_backup_version); final String OCID_UPLOAD = context.getString(R.string.pref_ocid_upload); // BOOLEAN to enable OCID data upload @@ -250,8 +250,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin if (key.equals(KEY_UI_ICONS)) { //Update Notification to display selected icon type setNotification(); - } else if (key.equals(FEMTO_DECTECTION)) { - boolean trackFemtoPref = sharedPreferences.getBoolean(FEMTO_DECTECTION, false); + } else if (key.equals(FEMTO_DETECTION)) { + boolean trackFemtoPref = sharedPreferences.getBoolean(FEMTO_DETECTION, false); if (trackFemtoPref) { startTrackingFemto(); } else { @@ -502,13 +502,21 @@ private void loadPreferences() { * _id,Lac,CellID,Net,Lat,Lng,Signal,Connection,Timestamp * 1,10401,6828111,10, 54.6787,25.2869, 24, "[10401,6828111,126]No|Di|HSPA|", "2015-01-21 20:45:10" * - * [ ] + * [ ] TODO: CDMA has to extract the MCC and MNC using something like: + * + * String mccMnc = phoneMgr.getNetworkOperator(); + * String cdmaMcc = ""; + * String cdmaMnc = ""; + * if (mccMnc != null && mccMnc.length() >= 5) { + * cdmaMcc = mccMnc.substring(0, 3); + * cdmaMnc = mccMnc.substring(3, 5); + } } * * ChangeLog: * * 2015-01-22 E:V:A Changed what appears to be a typo in the character * following getNetworkTypeName(), "|" to "]" - * 2015-01-24 E:V:A WTF!? Changed back ^ to "|" (Where is this parsed?) + * 2015-01-24 E:V:A WTF!? Changed back ^ to "|". (Where is this info parsed?) * */ private final PhoneStateListener mCellSignalListener = new PhoneStateListener() { @@ -523,7 +531,7 @@ public void onCellLocationChanged(CellLocation location) { GsmCellLocation gsmCellLocation = (GsmCellLocation) location; if (gsmCellLocation != null) { mDevice.setCellInfo( - gsmCellLocation.toString() + // + gsmCellLocation.toString() + // ?? mDevice.getDataActivityTypeShort() + "|" + // No,In,Ou,IO,Do mDevice.getDataStateShort() + "|" + // Di,Ct,Cd,Su mDevice.getNetworkTypeName() + "|" // TODO: Is "|" a typo? @@ -548,7 +556,7 @@ public void onCellLocationChanged(CellLocation location) { mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId()); // NID mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BID mDevice.mCell.setSID(cdmaCellLocation.getSystemId()); // SID - mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!? // MNC + mDevice.mCell.setMNC(cdmaCellLocation.getSystemId()); // <== BUG!? See issue above! // MNC mDevice.setNetworkName(tm.getNetworkOperatorName()); // ?? } } @@ -852,7 +860,7 @@ void setNotification() { //Append changing LAC text tickerText += " - Hostile Service Area: Changing LAC Detected!"; contentText = "Hostile Service Area: Changing LAC Detected!"; - // See #264 + // See #264 and ask He3556 //} else if (NoNCL) { // tickerText += " - BTS doesn't provide any neighbors!"; // contentText = "CID: " + cellid + " is not providing a neighboring cell list!"; @@ -902,10 +910,22 @@ void setNotification() { /** - * Description: TODO: Please add + * Description: TODO: Please add + * + * Possible explanation: + * + * This is a polling mechanism for getting the LAC/CID and location + * info for the currently connected cell. * - * Variables: + * Variables: * There is a "timer" here (REFRESH_RATE), what exactly is it timing? + * "Every REFRESH_RATE seconds, get connected cell details." + * + * see: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91#issuecomment-64391732 + * + * Issues: We might wanna use a listener to do this? + * Are there any reasons why not using a listener? + * * */ private final Runnable timerRunnable = new Runnable() { @@ -1010,7 +1030,7 @@ public void stopTrackingFemto() { private void getServiceStateInfo(ServiceState s) { if (s != null) { if (IsConnectedToCdmaFemto(s)) { - Helpers.msgShort(context, "ALERT!! FemtoCell Connection Detected!!"); + Helpers.msgShort(context, "ALERT! FemtoCell Connection Detected."); mFemtoDetected = true; setNotification(); //toggleRadio(); diff --git a/app/src/main/res/layout/cell_fragment.xml b/app/src/main/res/layout/cell_fragment.xml index 0fd696eb8..caa86895d 100644 --- a/app/src/main/res/layout/cell_fragment.xml +++ b/app/src/main/res/layout/cell_fragment.xml @@ -37,8 +37,8 @@ android:layout_below="@id/ciphering_indicator"> + android:layout_width="fill_parent"> + + android:id="@+id/mainView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@color/black" + android:padding="12dp"> + android:id="@+id/open_cell_label" + android:gravity="center_horizontal" + android:visibility="gone" + android:tag="device"> + + android:tag="device"> - @@ -81,7 +83,7 @@ android:textColor="@color/medium_blue" android:padding="2dip" android:gravity="start"/> - END remove --> + @@ -99,7 +101,7 @@ + android:tag="device"> + android:tag="device"> + android:tag="device"> Default MCC Locations Silent SMS Measured Signal Strengths + EventLog Export Successful