From 582a00c024dbb0fbe4489b5fd4ada8ab3008dbcf Mon Sep 17 00:00:00 2001 From: He3556 <info@eventgroup-kl.de> Date: Thu, 5 Feb 2015 20:28:45 +0100 Subject: [PATCH 1/2] EventLog Table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DB View of EL-Table and Export .csv are working now, edited some table styling. Added a new file „EventLogItemData.java“ --- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 67 +++++++++- .../adapters/EventLogCardInflater.java | 27 ++-- .../AIMSICD/adapters/EventLogItemData.java | 112 ++++++++++++++++ .../AIMSICD/fragments/DbViewerFragment.java | 25 ++++ app/src/main/res/layout/eventlog_items.xml | 120 +++++++++++------- app/src/main/res/values/colors.xml | 2 + 6 files changed, 291 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogItemData.java 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 bf1a6f72..fc5000cf 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -150,11 +150,11 @@ public class AIMSICDDbAdapter { CELL_TABLE, OPENCELLID_TABLE, SILENT_SMS_TABLE, + TABLE_EVENTLOG, // New... /*TABLE_DBE_IMPORT, TABLE_DBI_BTS, TABLE_DBI_MEASURE, - TABLE_EVENTLOG, TABLE_SILENTSMS, TABLE_CMEASURES*/ }; @@ -392,6 +392,38 @@ public class AIMSICDDbAdapter { return mDb.delete(CELL_TABLE, "CellID = ?", new String[]{ String.valueOf(cellId) }); } + /** + * Inserts Logs about Detections into Database, EventLog_Table + * + * @return row id or -1 if error + */ + public long insertDetection(long Time, + int LAC, + int CID, + int PSC, + double latitude, + double longitude, + double accu, + int DF_id, + String DF_description) { + + //Populate Content Values for Insert or Update + ContentValues detectionValues = new ContentValues(); + detectionValues.put("time", Time); + detectionValues.put("LAC", LAC); + detectionValues.put("CID", CID); + detectionValues.put("PSC", PSC); + detectionValues.put("gpsd_lat", latitude); + detectionValues.put("gpsd_lon", longitude); + detectionValues.put("gpsd_accu", accu); + detectionValues.put("DF_id", DF_id); + detectionValues.put("DF_description", DF_description); + + Log.v(TAG, "Insert Detection into EventLog Table: " + CID); + return mDb.insert(TABLE_EVENTLOG, null, detectionValues); + } + + // ==================================================================== @@ -403,7 +435,7 @@ public class AIMSICDDbAdapter { // TODO: public Cursor getEventLogData() { return mDb.query(TABLE_EVENTLOG, - new String[]{"time", "LAC", "CID", "PSC", "gpsd_lat","gpsd_lon", "gpsd_accu", "DF_id", "DF_desc"}, + new String[]{"time", "LAC", "CID", "PSC", "gpsd_lat","gpsd_lon", "gpsd_accu", "DF_id", "DF_description"}, null, null, null, null, null ); } @@ -529,7 +561,10 @@ public class AIMSICDDbAdapter { public boolean checkLAC(Cell cell) { Cursor cursor = mDb.query( CELL_TABLE, - new String[]{"Lac"}, "CellID=" + cell.getCID(), null,null,null,null); + new String[]{"CellID", "Lac", "Net", "Lat", "Lng", "Signal", "Mcc", "Mnc", + "Accuracy", "Speed", "Direction"}, + "CellID=" + cell.getCID(), + null,null,null,null); // 2015-01-20 // This is using the LAC found by API and comparing to LAC found from a previous @@ -538,13 +573,13 @@ public class AIMSICDDbAdapter { // as soon as the API gets a new LAC. Then the detection can be done by SQL. // -- E:V:A while (cursor.moveToNext()) { - if (cell.getLAC() != cursor.getInt(0)) { + if (cell.getLAC() != cursor.getInt(1)) { //Log.i(TAG, "ALERT: Changing LAC on CID: " + cell.getCID() // + " Current LAC(DBi): " + cell.getLAC() // + " Database LAC(DBe): " + cursor.getInt(0)); Log.i(TAG, "ALERT: Changing LAC on CID: " + cell.getCID() + " LAC(API): " + cell.getLAC() - + " LAC(DBi): " + cursor.getInt(0) ); + + " LAC(DBi): " + cursor.getInt(1) ); cursor.close(); return false; } else { @@ -552,7 +587,10 @@ public class AIMSICDDbAdapter { // " LAC(DBe): " + cursor.getInt(0) ); Log.v(TAG, "LAC checked - no change on CID:" + cell.getCID() + " LAC(API): " + cell.getLAC() - + " LAC(DBi): " + cursor.getInt(0) ); + + " LAC(DBi): " + cursor.getInt(1) ); + // **** only for testing EventLog Table - until correct values are saved in table EventLog + //insertDetection(cell.getTimestamp(), cell.getLAC(), cell.getCID(), cell.getPSC(), cell.getLat(), cell.getLon(), cell.getAccuracy(), 0, "LAC checked - no changes"); + insertDetection(1234, cell.getLAC(), cell.getCID(), cell.getPSC(), cursor.getDouble(3), cursor.getDouble(4), cursor.getInt(8), 99, "write test into EventLog_Table see LacCheck routine"); } } cursor.close(); @@ -1332,7 +1370,7 @@ public class AIMSICDDbAdapter { * What: Event Log Database * Columns: */ - String TABLE_EVENTLOG_CREATE = + /*String TABLE_EVENTLOG_CREATE = "CREATE TABLE EventLog (" + "_id INTEGER PRIMARY KEY AUTOINCREMENT," + "time TEXT NOT NULL," + @@ -1346,6 +1384,21 @@ public class AIMSICDDbAdapter { "DF_desc TEXT" + ");"; database.execSQL(TABLE_EVENTLOG_CREATE); + */ + // Implementation of he3556 + String TABLE_EVENTLOG_CREATE = "create table " + + TABLE_EVENTLOG + " (" + COLUMN_ID + + " INTEGER PRIMARY KEY AUTOINCREMENT," + + "time TIMESTAMP NOT NULL DEFAULT current_timestamp," + + "LAC INTEGER NOT NULL," + + "CID INTEGER NOT NULL," + + "PSC INTEGER," + + "gpsd_lat DOUBLE," + + "gpsd_lon DOUBLE," + + "gpsd_accu DOUBLE," + + "DF_id INTEGER," + + "DF_description TEXT" + ");"; + database.execSQL(TABLE_EVENTLOG_CREATE); // Re-populate the default MCC location table populateDefaultMCC(database); 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 494607bf..27631885 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogCardInflater.java @@ -28,10 +28,10 @@ import com.SecUpwN.AIMSICD.R; * Notes: * */ -public class EventLogCardInflater implements IAdapterViewInflater<CardItemData> { +public class EventLogCardInflater implements IAdapterViewInflater<EventLogItemData> { @Override - public View inflate(final BaseInflaterAdapter<CardItemData> adapter, + public View inflate(final BaseInflaterAdapter<EventLogItemData> adapter, final int pos, View convertView, ViewGroup parent) { ViewHolder holder; @@ -43,7 +43,7 @@ public class EventLogCardInflater implements IAdapterViewInflater<CardItemData> holder = (ViewHolder) convertView.getTag(); } - final CardItemData item = adapter.getTItem(pos); + final EventLogItemData item = adapter.getTItem(pos); holder.updateDisplay(item); return convertView; @@ -58,9 +58,10 @@ public class EventLogCardInflater implements IAdapterViewInflater<CardItemData> private final TextView mPSC; private final TextView mgpsd_lat; private final TextView mgpsd_lon; -// private final TextView mgpsd_accu; + private final TextView mgpsd_accur; private final TextView mDF_id; -// private final TextView mDF_desc; + private final TextView mDF_description; + private final TextView mRecordId; public ViewHolder(View rootView) { mRootView = rootView; @@ -71,23 +72,25 @@ public class EventLogCardInflater implements IAdapterViewInflater<CardItemData> 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_accu = (TextView) mRootView.findViewById(R.id.gpsd_accu); // need fix - mDF_id = (TextView) mRootView.findViewById(R.id.DF_id);// need fix -// mDF_desc = (TextView) mRootView.findViewById(R.id.DF_desc);// need fix + 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); + mRecordId = (TextView) mRootView.findViewById(R.id.record_id); rootView.setTag(this); } - public void updateDisplay(CardItemData item) { + public void updateDisplay(EventLogItemData item) { mtime.setText( item.getTimestamp()); // need fix ? mLAC.setText( item.getLac()); mCID.setText( item.getCellID()); mPSC.setText( item.getPsc()); mgpsd_lat.setText( item.getLat()); mgpsd_lon.setText( item.getLng()); -// mgpsd_accu.setText( item.getAccu()); // need fix -// mDF_id.setText( item.getDFid()); // need fix -// mDF_desc.setText(item.getDescription()); // need fix + mgpsd_accur.setText(item.getgpsd_accur()); + mDF_id.setText(item.getDF_id()); + mDF_description.setText(item.getmDF_description()); + mRecordId.setText(item.getRecordId()); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogItemData.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogItemData.java new file mode 100644 index 00000000..a353f5cf --- /dev/null +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/EventLogItemData.java @@ -0,0 +1,112 @@ +package com.SecUpwN.AIMSICD.adapters; + +import com.SecUpwN.AIMSICD.utils.Cell; +import com.SecUpwN.AIMSICD.utils.Device; +import java.text.SimpleDateFormat; + +/** + * Description: Class to show data of table "EventLog" in "db-View" > "EventLog" + * + * Dependencies: EventLogCardInflater.java + * Data representation on eventlog_items.xml (from Array in DdViewerFragment) + * Data query on AIMSICDDbAdapter.java + * Data representation on APP see menu "db-View" > "EventLog" + * + * Usage: DdViewerFragment, AIMSICDDbAdapter.java + * + * Issues: See AIMSICDDbAdapter.java line518 - How to find the right values (timestamp, lat, lan, accur) for saving in the db + * + * 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 EventLogItemData { + // OLD (in old DB tables) + private final String mTimestamp; + private final String mCellID; + private final String mLac; + private final String mPsc; + private final String mLat; + private final String mLng; + private final String mgpsd_accur; + private final String mDF_id; + private final String mDF_description; + private final String mRecordId; + + + + + public EventLogItemData(String time, String LAC, String CID, String PSC, String gpsd_lat, + String gpsd_lon, String gpsd_accur, String DF_id, String DF_description, String recordId) { + mTimestamp = time; + mLac = LAC; + mCellID = CID; + mPsc = PSC; + mLat = gpsd_lat; + mLng = gpsd_lon; + mgpsd_accur = gpsd_accur; + mDF_id = DF_id; + mDF_description = DF_description; + mRecordId = recordId; + + + + } + + + public String getTimestamp() { + return mTimestamp; + } + + public String getCellID() { + return mCellID; + } + + public String getLac() { + return mLac; + } + + public String getPsc() { + return mPsc; + } + + + public String getLat() { + return mLat; + } + + public String getLng() { + return mLng; + } + + public String getgpsd_accur() { + return mgpsd_accur; + } + + public String getDF_id() { + return mDF_id; + } + + public String getmDF_description() { + return mDF_description; + } + + public String getRecordId() { + return mRecordId; + } + + + +} \ No newline at end of file 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 799b59de..23e12f19 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DbViewerFragment.java @@ -20,6 +20,8 @@ import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter; import com.SecUpwN.AIMSICD.adapters.CardItemData; import com.SecUpwN.AIMSICD.adapters.CellCardInflater; import com.SecUpwN.AIMSICD.adapters.DefaultLocationCardInflater; +import com.SecUpwN.AIMSICD.adapters.EventLogCardInflater; +import com.SecUpwN.AIMSICD.adapters.EventLogItemData; import com.SecUpwN.AIMSICD.adapters.MeasuredCellStrengthCardData; import com.SecUpwN.AIMSICD.adapters.MeasuredCellStrengthCardInflater; import com.SecUpwN.AIMSICD.adapters.OpenCellIdCardInflater; @@ -289,6 +291,29 @@ public class DbViewerFragment extends Fragment { return adapter; } + // Table: EventLog Table is displayed with EventLogCardInflater and EventLogItemData + case "EventLog": { + BaseInflaterAdapter<EventLogItemData> adapter + = new BaseInflaterAdapter<>( new EventLogCardInflater() ); + + int count = tableData.getCount(); + while (tableData.moveToNext()) { + EventLogItemData data = new EventLogItemData( + "Time: " + tableData.getDouble(0), // time + "CID: " + tableData.getInt(2), // CID + "LAC: " + tableData.getInt(1), // LAC + "PSC: " + tableData.getInt(3), // PSC + "Lat: " + tableData.getDouble(4), // gpsd_lat + "Lon: " + tableData.getDouble(5), // gpsd_lon + "Accuracy: " + tableData.getDouble(6), // gpsd_accu (accuracy in [m]) + "Detection ID: " + tableData.getInt(7), // DF_id + "Event: " + tableData.getString(8), // DF_description + "" + (tableData.getPosition() + 1) + " / " + count); + adapter.addItem(data, false); + } + return adapter; + } + /* // Table: EventLog case "EventLog Data": { BaseInflaterAdapter<CardItemData> adapter diff --git a/app/src/main/res/layout/eventlog_items.xml b/app/src/main/res/layout/eventlog_items.xml index 71710b8b..2024f65f 100644 --- a/app/src/main/res/layout/eventlog_items.xml +++ b/app/src/main/res/layout/eventlog_items.xml @@ -1,67 +1,101 @@ <?xml version="1.0" encoding="utf-8"?> <FrameLayout - xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="15dp" + android:paddingRight="15dp" + android:descendantFocusability="beforeDescendants"> + + <LinearLayout + android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="15dp" + android:paddingTop="15dp" + android:paddingBottom="15dp" android:paddingRight="15dp" - android:descendantFocusability="beforeDescendants"> + android:background="@drawable/selector_card_background" + android:descendantFocusability="afterDescendants"> - <LinearLayout - android:orientation="vertical" - android:layout_width="match_parent" + <TextView + android:id="@+id/time" + android:layout_width="fill_parent" android:layout_height="wrap_content" - android:paddingLeft="15dp" - android:paddingTop="15dp" - android:paddingBottom="15dp" - android:paddingRight="15dp" - android:background="@drawable/selector_card_background" - android:descendantFocusability="afterDescendants"> + android:textColor="@color/standard_grey" + android:textStyle="bold" /> - <TextView - android:id="@+id/time" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> - <TextView + <GridLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:focusableInTouchMode="false"> + + <TextView android:id="@+id/LAC" - android:layout_width="fill_parent" + android:layout_width="144dp" android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> - <TextView + android:textColor="@color/standard_grey" /> + + <TextView android:id="@+id/CID" - android:layout_width="fill_parent" + android:layout_width="180dp" android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> - <TextView + android:textColor="@color/standard_grey" /> + + </GridLayout> + + <GridLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView android:id="@+id/PSC" - android:layout_width="fill_parent" + android:layout_width="144dp" android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> - <TextView + android:textColor="@color/standard_grey" /> + + <TextView + android:id="@+id/gpsd_accur" + android:layout_width="180dp" + android:layout_height="wrap_content" + android:textColor="@color/standard_grey" /> + </GridLayout> + + <GridLayout + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <TextView android:id="@+id/gpsd_lat" - android:layout_width="fill_parent" + android:layout_width="144dp" android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> - <TextView + android:textColor="@color/standard_grey" /> + + <TextView android:id="@+id/gpsd_lon" - android:layout_width="fill_parent" + android:layout_width="180dp" android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> + android:textColor="@color/standard_grey" /> + </GridLayout> + <TextView - android:id="@+id/gpsd_accur" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textColor="@color/medium_blue" /> + android:id="@+id/DF_id" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:textColor="@color/standard_yellow"/> <TextView - android:id="@+id/DF_id" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textColor="@color/medium_blue"/> + android:id="@+id/DF_description" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:textColor="@color/standard_yellow"/> <TextView - android:id="@+id/DF_description" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:textColor="@color/medium_blue"/> + android:id="@+id/record_id" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:textColor="@color/standard_grey" + android:gravity="end"/> </LinearLayout> + + </FrameLayout> + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5b64e316..e18a54ca 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -22,6 +22,8 @@ <color name="action_bar_color">#ff0d0d0d</color> <color name="green_text">#ff00FF00</color> <color name="medium_blue">#ff33B5E5</color> + <color name="standard_yellow">#ffea59</color> + <color name="standard_grey">#dddddd</color> <!-- MAP COLOURS --> <color name="map_unknown">#fff0f8ff</color> -- GitLab From c66fcd8541e0a45c521033fb5fb2a9fa3c63c66c Mon Sep 17 00:00:00 2001 From: He3556 <info@eventgroup-kl.de> Date: Fri, 6 Feb 2015 20:22:04 +0100 Subject: [PATCH 2/2] changed where "save EventLog" action takes place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Save Log when Detecting „Changed LAC“ (line 585) ToDo: get the right values for the Timestamp and save it in EventLog Table 2. Save Log when CellID is not in OCID db (line 559) ToDo: get all the values - only CellID is already there. --- .../com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 fc5000cf..6346d41a 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -554,7 +554,9 @@ public class AIMSICDDbAdapter { Cursor cursor = mDb.rawQuery("SELECT * FROM " + OPENCELLID_TABLE + " WHERE CellID = " + cellID, null); boolean exists = cursor.getCount() > 0; - Log.v(TAG, "CID: " + cellID + " exists in OCID (DBe_import)?: " + exists); + + if (exists == false) { Log.v(TAG, "CID: " + cellID + " exists in OCID (DBe_import)?: " + exists); + insertDetection(1234, 001, cellID, 111, 1.1, 2.2, 3, 2, "CellID not found in OCID Database"); } cursor.close(); return exists; } @@ -562,7 +564,7 @@ public class AIMSICDDbAdapter { public boolean checkLAC(Cell cell) { Cursor cursor = mDb.query( CELL_TABLE, new String[]{"CellID", "Lac", "Net", "Lat", "Lng", "Signal", "Mcc", "Mnc", - "Accuracy", "Speed", "Direction"}, + "Accuracy", "Speed", "Direction", "Timestamp"}, "CellID=" + cell.getCID(), null,null,null,null); @@ -580,6 +582,8 @@ public class AIMSICDDbAdapter { Log.i(TAG, "ALERT: Changing LAC on CID: " + cell.getCID() + " LAC(API): " + cell.getLAC() + " LAC(DBi): " + cursor.getInt(1) ); + insertDetection(cursor.getInt(11), cell.getLAC(), cell.getCID(), cell.getPSC(), cursor.getDouble(3), cursor.getDouble(4), cursor.getInt(8), 1, "Changing LAC"); + cursor.close(); return false; } else { @@ -590,7 +594,7 @@ public class AIMSICDDbAdapter { + " LAC(DBi): " + cursor.getInt(1) ); // **** only for testing EventLog Table - until correct values are saved in table EventLog //insertDetection(cell.getTimestamp(), cell.getLAC(), cell.getCID(), cell.getPSC(), cell.getLat(), cell.getLon(), cell.getAccuracy(), 0, "LAC checked - no changes"); - insertDetection(1234, cell.getLAC(), cell.getCID(), cell.getPSC(), cursor.getDouble(3), cursor.getDouble(4), cursor.getInt(8), 99, "write test into EventLog_Table see LacCheck routine"); + //insertDetection(cursor.getInt(11), cell.getLAC(), cell.getCID(), cell.getPSC(), cursor.getDouble(3), cursor.getDouble(4), cursor.getInt(8), 99, "write test into EventLog_Table see LacCheck routine"); } } cursor.close(); -- GitLab