|
@@ -7,12 +7,15 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
import android.content.Context;
|
|
|
+import android.content.SharedPreferences;
|
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
|
+import android.preference.PreferenceManager;
|
|
|
import android.util.Log;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
|
|
@@ -29,6 +32,7 @@ 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.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.helper.ColorSequenceGenerator;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.LogFilter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.model.PlotComparisonItem;
|
|
@@ -191,7 +195,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
* The added {@link AttackRecord} .
|
|
|
*/
|
|
|
public void addAttackRecord(AttackRecord record) {
|
|
|
- Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
|
|
|
+ //Log.i("DBHelper", "Add Attack Record with id: " + record.getAttack_id());
|
|
|
SQLiteDatabase db = this.getWritableDatabase();
|
|
|
|
|
|
ContentValues attackValues = new ContentValues();
|
|
@@ -214,7 +218,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
/**
|
|
|
* Adds a given {@link AttackRecord}s to the database.
|
|
|
*
|
|
|
- * @param List<AttackRecord>
|
|
|
+ * @param {@link List}<AttackRecord>
|
|
|
* The added {@link AttackRecord}s .
|
|
|
*/
|
|
|
public void insertAttackRecords(List<AttackRecord> records) {
|
|
@@ -865,7 +869,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
/**
|
|
|
* Updates the sync_info table with the information contained in the parameter.
|
|
|
- * @param syncInfo ArrayList of {@link SyncInfoRecord SyncInfoRecords}
|
|
|
+ * @param syncInfos ArrayList of {@link SyncInfoRecord SyncInfoRecords}
|
|
|
* @see {@link HostageDBOpenHelper#updateSyncInfo(SyncInfoRecord syncInfo)}
|
|
|
*/
|
|
|
public synchronized void updateSyncInfo(ArrayList<SyncInfoRecord> syncInfos){
|
|
@@ -907,7 +911,7 @@ 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}
|
|
|
+ * Deletes a device with given id from the device {@link de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncDeviceEntry} and also all data captured by this device in {@link SyncInfoEntry}
|
|
|
*/
|
|
|
public void clearSyncInfos(){
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
@@ -918,7 +922,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * Deletes all records from {@link #PacketEntry.TABLE_NAME}.
|
|
|
+ * Deletes all records from {@link PacketEntry}s and {@link de.tudarmstadt.informatik.hostage.logging.AttackRecord}.
|
|
|
*/
|
|
|
public void clearData() {
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
@@ -928,7 +932,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a specific BSSID.
|
|
|
+ * Deletes all records from {@link PacketEntry}s with a specific BSSID.
|
|
|
*
|
|
|
* @param bssid
|
|
|
* The BSSID to match against.
|
|
@@ -941,7 +945,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a time stamp smaller
|
|
|
+ * Deletes all records from {@link de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.PacketEntry}s with a time stamp smaller
|
|
|
* then the given
|
|
|
*
|
|
|
* @param date
|
|
@@ -955,7 +959,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Deletes all records from {@link #TABLE_RECORDS} with a specific Attack ID.
|
|
|
+ * Deletes all {@link de.tudarmstadt.informatik.hostage.logging.AttackRecord} with a specific Attack ID.
|
|
|
*
|
|
|
* @param attackID
|
|
|
* The Attack ID to match against.
|
|
@@ -1502,7 +1506,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
* Creates a {@link de.tudarmstadt.informatik.hostage.logging.SyncDevice} from a Cursor. If the cursor does not show to a
|
|
|
* valid data structure a runtime exception is thrown.
|
|
|
*
|
|
|
- * @param cursor
|
|
|
+ * @param cursor the cursor
|
|
|
* @return Returns the created {@link de.tudarmstadt.informatik.hostage.logging.SyncDevice} .
|
|
|
*/
|
|
|
private synchronized SyncDevice createSyncDevice(Cursor cursor) {
|
|
@@ -1583,13 +1587,15 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
|
|
|
// looping through all rows and adding to list
|
|
|
- if (cursor != null && cursor.moveToFirst()) {
|
|
|
- do {
|
|
|
- AttackRecord record = createAttackRecord(cursor);
|
|
|
- recordList.add(record);
|
|
|
- } while (cursor.moveToNext());
|
|
|
+ if (cursor != null){
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ AttackRecord record = createAttackRecord(cursor);
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
}
|
|
|
- cursor.close();
|
|
|
}
|
|
|
|
|
|
// return record list
|
|
@@ -1637,6 +1643,29 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public void insertSyncDevices(List<SyncDevice> devices){
|
|
|
+ SQLiteDatabase db = this.getWritableDatabase();
|
|
|
+
|
|
|
+ db.beginTransaction();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (SyncDevice device : devices){
|
|
|
+ ContentValues recordValues = new ContentValues();
|
|
|
+ recordValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_ID, device.getDeviceID());
|
|
|
+ recordValues.put(SyncDeviceEntry.COLUMN_NAME_DEVICE_TIMESTAMP, device.getLast_sync_timestamp());
|
|
|
+ recordValues.put(SyncDeviceEntry.COLUMN_NAME_HIGHEST_ATTACK_ID, device.getHighest_attack_id());
|
|
|
+
|
|
|
+ // Inserting Rows
|
|
|
+ db.insert(SyncDeviceEntry.TABLE_NAME, null, recordValues);
|
|
|
+ }
|
|
|
+ db.setTransactionSuccessful();
|
|
|
+ } finally {
|
|
|
+ db.endTransaction();
|
|
|
+ }
|
|
|
+
|
|
|
+ db.close(); // Closing database connection
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/** Returns the color for the given index
|
|
|
* @return int color*/
|