|
@@ -25,7 +25,9 @@ import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.PacketEnt
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.ProfileEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncDeviceEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncInfoEntry;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.helper.ColorSequenceGenerator;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.LogFilter;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.model.PlotComparisonItem;
|
|
|
|
|
|
/**
|
|
|
* Database Helper class to create, read and write the database.
|
|
@@ -40,6 +42,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
private Context context;
|
|
|
|
|
|
static {
|
|
|
+ // NETWORK
|
|
|
StringBuilder networkSQLBuilder = new StringBuilder("CREATE TABLE ").append(NetworkEntry.TABLE_NAME).append("(");
|
|
|
networkSQLBuilder.append(NetworkEntry.COLUMN_NAME_BSSID).append(" TEXT PRIMARY KEY,");
|
|
|
networkSQLBuilder.append(NetworkEntry.COLUMN_NAME_SSID).append(" TEXT,");
|
|
@@ -50,6 +53,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
networkSQLBuilder.append(")");
|
|
|
SQL_CREATE_NETWORK_ENTRIES = networkSQLBuilder.toString();
|
|
|
|
|
|
+ // ATTACK
|
|
|
StringBuilder attackSQLBuilder = new StringBuilder("CREATE TABLE ").append(AttackEntry.TABLE_NAME).append("(");
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_ATTACK_ID).append(" INTEGER PRIMARY KEY,");
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_PROTOCOL).append(" TEXT,");
|
|
@@ -58,12 +62,14 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_LOCAL_PORT).append(" INTEGER,");
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_REMOTE_IP).append(" BLOB,");
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_REMOTE_PORT).append(" INTEGER,");
|
|
|
+ attackSQLBuilder.append(AttackEntry.COLUMN_NAME_INTERNAL_ATTACK).append(" INTEGER,");
|
|
|
attackSQLBuilder.append(AttackEntry.COLUMN_NAME_BSSID).append(" TEXT,");
|
|
|
attackSQLBuilder.append(String.format("FOREIGN KEY(%s) REFERENCES %s(%s)", AttackEntry.COLUMN_NAME_BSSID, NetworkEntry.TABLE_NAME,
|
|
|
NetworkEntry.COLUMN_NAME_BSSID));
|
|
|
attackSQLBuilder.append(")");
|
|
|
SQL_CREATE_ATTACK_ENTRIES = attackSQLBuilder.toString();
|
|
|
|
|
|
+ // PACKET
|
|
|
StringBuilder packetSQLBuilder = new StringBuilder("CREATE TABLE ").append(PacketEntry.TABLE_NAME).append("(");
|
|
|
packetSQLBuilder.append(PacketEntry.COLUMN_NAME_ID).append(" INTEGER NOT NULL,");
|
|
|
packetSQLBuilder.append(PacketEntry.COLUMN_NAME_ATTACK_ID).append(" INTEGER NOT NULL,");
|
|
@@ -75,13 +81,15 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
AttackEntry.COLUMN_NAME_ATTACK_ID));
|
|
|
packetSQLBuilder.append(")");
|
|
|
SQL_CREATE_PACKET_ENTRIES = packetSQLBuilder.toString();
|
|
|
-
|
|
|
+
|
|
|
+ // SyncDeviceEntry
|
|
|
StringBuilder syncDevicesSQLBuilder = new StringBuilder("CREATE TABLE ").append(SyncDeviceEntry.TABLE_NAME).append("(");
|
|
|
syncDevicesSQLBuilder.append(SyncDeviceEntry.COLUMN_NAME_DEVICE_ID).append(" TEXT PRIMARY KEY,");
|
|
|
syncDevicesSQLBuilder.append(SyncDeviceEntry.COLUMN_NAME_DEVICE_TIMESTAMP).append(" INTEGER");
|
|
|
syncDevicesSQLBuilder.append(")");
|
|
|
SQL_CREATE_SYNC_DEVICES_ENTRIES = syncDevicesSQLBuilder.toString();
|
|
|
-
|
|
|
+
|
|
|
+ // SyncInfoEntry
|
|
|
StringBuilder syncInfoSQLBuilder = new StringBuilder("CREATE TABLE ").append(SyncInfoEntry.TABLE_NAME).append("(");
|
|
|
syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_DEVICE_ID).append(" TEXT,");
|
|
|
syncInfoSQLBuilder.append(SyncInfoEntry.COLUMN_NAME_BSSID).append(" TEXT,");
|
|
@@ -92,7 +100,8 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
NetworkEntry.COLUMN_NAME_BSSID));
|
|
|
syncInfoSQLBuilder.append(")");
|
|
|
SQL_CREATE_SYNC_INFO_ENTRIES = syncInfoSQLBuilder.toString();
|
|
|
-
|
|
|
+
|
|
|
+ // ProfileEntry
|
|
|
StringBuilder profilSQLBuilder = new StringBuilder("CREATE TABLE ").append(ProfileEntry.TABLE_NAME).append("(");
|
|
|
profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ID).append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
|
|
|
profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_NAME).append(" TEXT,");
|
|
@@ -102,20 +111,20 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_EDITABLE).append(" INTEGER,");
|
|
|
profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ACTIVE).append(" INTEGER");
|
|
|
profilSQLBuilder.append(")");
|
|
|
- SQL_CREATE_PROFIL_ENTRIES = profilSQLBuilder.toString();
|
|
|
+ SQL_CREATE_PROFILE_ENTRIES = profilSQLBuilder.toString();
|
|
|
}
|
|
|
|
|
|
private static final String SQL_CREATE_NETWORK_ENTRIES;
|
|
|
private static final String SQL_CREATE_ATTACK_ENTRIES;
|
|
|
private static final String SQL_CREATE_PACKET_ENTRIES;
|
|
|
- private static final String SQL_CREATE_PROFIL_ENTRIES;
|
|
|
+ private static final String SQL_CREATE_PROFILE_ENTRIES;
|
|
|
private static final String SQL_CREATE_SYNC_DEVICES_ENTRIES;
|
|
|
private static final String SQL_CREATE_SYNC_INFO_ENTRIES;
|
|
|
|
|
|
private static final String SQL_DELETE_PACKET_ENTRIES = "DROP TABLE IF EXISTS " + PacketEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_ATTACK_ENTRIES = "DROP TABLE IF EXISTS " + AttackEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_NETWORK_ENTRIES = "DROP TABLE IF EXISTS " + NetworkEntry.TABLE_NAME;
|
|
|
- private static final String SQL_DELETE_PROFIL_ENTRIES = "DROP TABLE IF EXISTS " + ProfileEntry.TABLE_NAME;
|
|
|
+ private static final String SQL_DELETE_PROFILE_ENTRIES = "DROP TABLE IF EXISTS " + ProfileEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_SYNC_DEVICES_ENTRIES = "DROP TABLE IF EXISTS " + SyncDeviceEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_SYNC_INFO_ENTRIES = "DROP TABLE IF EXISTS " + SyncInfoEntry.TABLE_NAME;
|
|
|
|
|
@@ -129,7 +138,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.execSQL(SQL_CREATE_NETWORK_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_ATTACK_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_PACKET_ENTRIES);
|
|
|
- db.execSQL(SQL_CREATE_PROFIL_ENTRIES);
|
|
|
+ db.execSQL(SQL_CREATE_PROFILE_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_SYNC_DEVICES_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_SYNC_INFO_ENTRIES);
|
|
|
}
|
|
@@ -139,7 +148,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.execSQL(SQL_DELETE_SYNC_INFO_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_PACKET_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_ATTACK_ENTRIES);
|
|
|
- db.execSQL(SQL_DELETE_PROFIL_ENTRIES);
|
|
|
+ db.execSQL(SQL_DELETE_PROFILE_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_NETWORK_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_SYNC_DEVICES_ENTRIES);
|
|
|
onCreate(db);
|
|
@@ -184,6 +193,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_PORT, record.getLocalPort());
|
|
|
attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_IP, record.getRemoteIP()); // Log Remote IP
|
|
|
attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_PORT, record.getRemotePort()); // Log Remote Port
|
|
|
+ attackValues.put(AttackEntry.COLUMN_NAME_INTERNAL_ATTACK, record.getWasInternalAttack());
|
|
|
attackValues.put(AttackEntry.COLUMN_NAME_BSSID, record.getBssid());
|
|
|
|
|
|
|
|
@@ -779,7 +789,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
/**
|
|
|
* Updates the sync_info table with the information contained in the parameter.
|
|
|
- * @param networkInformation ArrayList of {@link SyncInfoRecord SyncInfoRecords}
|
|
|
+ * @param syncInfo ArrayList of {@link SyncInfoRecord SyncInfoRecords}
|
|
|
* @see {@link HostageDBOpenHelper#updateSyncInfo(SyncInfoRecord syncInfo)}
|
|
|
*/
|
|
|
public synchronized void updateSyncInfo(ArrayList<SyncInfoRecord> syncInfo){
|
|
@@ -806,7 +816,6 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
/**
|
|
|
* Deletes a device with given id from the device {@link SyncDeviceEntry.TABLE_NAME} and also all data captured by this device in {@link SyncInfoEntry.TABLE_NAME}
|
|
|
- * @param device_id The id of the device that is to be deleted.
|
|
|
*/
|
|
|
public void clearSyncInfos(){
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
@@ -900,7 +909,8 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
record.setLocalPort(Integer.parseInt(cursor.getString(4)));
|
|
|
record.setRemoteIP(cursor.getString(5));
|
|
|
record.setRemotePort(Integer.parseInt(cursor.getString(6)));
|
|
|
- record.setBssid(cursor.getString(7));
|
|
|
+ record.setWasInternalAttack(cursor.getInt(7) == 1);
|
|
|
+ record.setBssid(cursor.getString(8));
|
|
|
|
|
|
return record;
|
|
|
}
|
|
@@ -928,12 +938,14 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
record.setRemoteIP(cursor.getString(9));
|
|
|
record.setRemotePort(Integer.parseInt(cursor.getString(10)));
|
|
|
|
|
|
- record.setBssid(cursor.getString(11));
|
|
|
- record.setSsid(cursor.getString(12));
|
|
|
- record.setLatitude(Double.parseDouble(cursor.getString(13)));
|
|
|
- record.setLongitude(Double.parseDouble(cursor.getString(14)));
|
|
|
- record.setAccuracy(Float.parseFloat(cursor.getString(15)));
|
|
|
- record.setTimestampLocation(cursor.getLong(16));
|
|
|
+ record.setWasInternalAttack(Integer.parseInt(cursor.getString(11)) == 1);
|
|
|
+
|
|
|
+ record.setBssid(cursor.getString(12));
|
|
|
+ record.setSsid(cursor.getString(13));
|
|
|
+ record.setLatitude(Double.parseDouble(cursor.getString(14)));
|
|
|
+ record.setLongitude(Double.parseDouble(cursor.getString(15)));
|
|
|
+ record.setAccuracy(Float.parseFloat(cursor.getString(16)));
|
|
|
+ record.setTimestampLocation(cursor.getLong(17));
|
|
|
|
|
|
return record;
|
|
|
}
|
|
@@ -947,38 +959,8 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
*/
|
|
|
public synchronized ArrayList<Record> getRecordsForFilter(LogFilter filter) {
|
|
|
ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
- String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
- + ")";
|
|
|
-
|
|
|
- // TIMESTAMPS
|
|
|
- selectQuery = selectQuery + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
- selectQuery = selectQuery + " < " + filter.getBelowTimestamp();
|
|
|
- selectQuery = selectQuery + " AND " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
- selectQuery = selectQuery + " > " + filter.getAboveTimestamp();
|
|
|
-
|
|
|
- if (filter.getBSSIDs() != null && filter.getBSSIDs().size() > 0) {
|
|
|
- selectQuery = selectQuery + " AND ";
|
|
|
- selectQuery = selectQuery + filter.getBSSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID);
|
|
|
- }
|
|
|
- if (filter.getESSIDs() != null && filter.getESSIDs().size() > 0) {
|
|
|
- selectQuery = selectQuery + " AND ";
|
|
|
- selectQuery = selectQuery + filter.getESSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_SSID);
|
|
|
- }
|
|
|
- if (filter.getProtocols() != null && filter.getProtocols().size() > 0) {
|
|
|
- selectQuery = selectQuery + " AND ";
|
|
|
- selectQuery = selectQuery + filter.getProtocolsQueryStatement(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_PROTOCOL);
|
|
|
- }
|
|
|
-
|
|
|
- selectQuery = selectQuery + " GROUP BY " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ATTACK_ID;
|
|
|
-
|
|
|
- if (filter.getSorttype() == LogFilter.SortType.packet_timestamp) {
|
|
|
- // DESC
|
|
|
- selectQuery = selectQuery + " ORDER BY " + filter.getSorttype() + " DESC";
|
|
|
- } else {
|
|
|
- selectQuery = selectQuery + " ORDER BY " + filter.getSorttype();
|
|
|
- }
|
|
|
+ String selectQuery = this.selectionQueryFromFilter(filter, "*");
|
|
|
|
|
|
- System.out.println(selectQuery);
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
|
Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
|
|
@@ -996,8 +978,53 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.close();
|
|
|
return recordList;
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the query for the given filter.
|
|
|
+ * @param filter (LogFilter)
|
|
|
+ * @param selectionString (String) for everything: "*"
|
|
|
+ * @return (String) query string
|
|
|
+ */
|
|
|
+ public String selectionQueryFromFilter(LogFilter filter, String selectionString)
|
|
|
+ {
|
|
|
+
|
|
|
+ String selectQuery = "SELECT " + selectionString + " FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")";
|
|
|
+ if (filter == null) return selectQuery;
|
|
|
+
|
|
|
+ // TIMESTAMPS
|
|
|
+ selectQuery = selectQuery + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
+ selectQuery = selectQuery + " < " + filter.getBelowTimestamp();
|
|
|
+ selectQuery = selectQuery + " AND " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
+ selectQuery = selectQuery + " > " + filter.getAboveTimestamp();
|
|
|
+
|
|
|
+ if (filter.getBSSIDs() != null && filter.getBSSIDs().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getBSSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID);
|
|
|
+ }
|
|
|
+ if (filter.getESSIDs() != null && filter.getESSIDs().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getESSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_SSID);
|
|
|
+ }
|
|
|
+ if (filter.getProtocols() != null && filter.getProtocols().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getProtocolsQueryStatement(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_PROTOCOL);
|
|
|
+ }
|
|
|
+
|
|
|
+ selectQuery = selectQuery + " GROUP BY " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ATTACK_ID;
|
|
|
+
|
|
|
+ if (filter.getSorttype() == LogFilter.SortType.packet_timestamp) {
|
|
|
+ // DESC
|
|
|
+ selectQuery = selectQuery + " ORDER BY " + filter.getSorttype() + " DESC";
|
|
|
+ } else {
|
|
|
+ selectQuery = selectQuery + " ORDER BY " + filter.getSorttype();
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(selectQuery);
|
|
|
+ return selectQuery;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Returns the Conversation of a specific attack id
|
|
|
*
|
|
|
* @param attack_id Tha attack id to match the query against.
|
|
@@ -1339,4 +1366,90 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
return recordList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns PlotComparisionItems for attacks per essid.
|
|
|
+ * @param filter (LogFilter) filter object
|
|
|
+ * @return ArrayList<PlotComparisonItem>
|
|
|
+ */
|
|
|
+ public synchronized ArrayList<PlotComparisonItem> attacksPerESSID(LogFilter filter) {
|
|
|
+
|
|
|
+ String filterQuery = this.selectionQueryFromFilter(filter, AttackEntry.COLUMN_NAME_ATTACK_ID);
|
|
|
+
|
|
|
+ String attackPerESSID_Query = "SELECT " + NetworkEntry.COLUMN_NAME_SSID + " , " + "COUNT( " + AttackEntry.COLUMN_NAME_ATTACK_ID + " ) " + " "
|
|
|
+ + " FROM " + AttackEntry.TABLE_NAME + " a " + " , " + NetworkEntry.TABLE_NAME
|
|
|
+ + " WHERE " + " a." + AttackEntry.COLUMN_NAME_ATTACK_ID + " IN " + " ( " + filterQuery + " ) "
|
|
|
+ + " GROUP BY " + NetworkEntry.TABLE_NAME+"."+NetworkEntry.COLUMN_NAME_SSID;
|
|
|
+
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(attackPerESSID_Query, null);
|
|
|
+ ArrayList<PlotComparisonItem> plots = new ArrayList<PlotComparisonItem>();
|
|
|
+
|
|
|
+ int counter = 0;
|
|
|
+
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ String title = cursor.getString(0); // COLUMN_NAME_SSID
|
|
|
+ double value = cursor.getDouble(1); // COUNT
|
|
|
+ if (value == 0.) continue;
|
|
|
+ PlotComparisonItem plotItem = new PlotComparisonItem(title, this.getColor(counter), 0. , value);
|
|
|
+ plots.add(plotItem);
|
|
|
+
|
|
|
+ counter++;
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+
|
|
|
+ return plots;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Attacks per BSSID
|
|
|
+ * @param filter (LogFilter) query filter
|
|
|
+ * @return ArrayList<PlotComparisonItem>
|
|
|
+ */
|
|
|
+ public synchronized ArrayList<PlotComparisonItem> attacksPerBSSID(LogFilter filter) {
|
|
|
+
|
|
|
+ String filterQuery = this.selectionQueryFromFilter(filter, AttackEntry.COLUMN_NAME_ATTACK_ID);
|
|
|
+
|
|
|
+ String attackPerBSSID_Query = "SELECT " + NetworkEntry.COLUMN_NAME_BSSID + " , " + "COUNT( " + AttackEntry.COLUMN_NAME_ATTACK_ID + " ) " + " "
|
|
|
+ + " FROM " + AttackEntry.TABLE_NAME + " a " + " , " + NetworkEntry.TABLE_NAME
|
|
|
+ + " WHERE " + " a." + AttackEntry.COLUMN_NAME_ATTACK_ID + " IN " + " ( " + filterQuery + " ) "
|
|
|
+ + " GROUP BY " + NetworkEntry.TABLE_NAME+"."+NetworkEntry.COLUMN_NAME_BSSID;
|
|
|
+
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(attackPerBSSID_Query, null);
|
|
|
+ ArrayList<PlotComparisonItem> plots = new ArrayList<PlotComparisonItem>();
|
|
|
+
|
|
|
+ int counter = 0;
|
|
|
+
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ String title = cursor.getString(0); // COLUMN_NAME_BSSID
|
|
|
+ double value = cursor.getDouble(1); // COUNT
|
|
|
+
|
|
|
+ if (value == 0.) continue;
|
|
|
+ PlotComparisonItem plotItem = new PlotComparisonItem(title, this.getColor(counter), 0. , value);
|
|
|
+ plots.add(plotItem);
|
|
|
+
|
|
|
+ counter++;
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+
|
|
|
+ return plots;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /** Returns the color for the given index
|
|
|
+ * @return int color*/
|
|
|
+ public Integer getColor(int index) {
|
|
|
+ return ColorSequenceGenerator.getColorForIndex(index);
|
|
|
+ }
|
|
|
+
|
|
|
}
|