Browse Source

new db helper classes

Mihai Plasoianu 10 years ago
parent
commit
0722712d01

+ 35 - 78
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -37,8 +37,8 @@ import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
 import android.widget.Toast;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.MyLocationManager;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.protocol.HTTP;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.ui.MainActivity;
@@ -69,14 +69,12 @@ public class HoneyService extends Service {
 	private class QotdTask extends AsyncTask<String, Void, String> {
 		@Override
 		protected String doInBackground(String... unused) {
-			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com",
-					"alpha.mike-r.com", "electricbiscuit.org" };
+			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org" };
 			SecureRandom rndm = new SecureRandom();
 			StringBuffer sb = new StringBuffer();
 			try {
 				Socket client = new Socket(sources[rndm.nextInt(4)], 17);
-				BufferedReader in = new BufferedReader(new InputStreamReader(
-						client.getInputStream()));
+				BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
 				while (!in.ready())
 					;
 				while (in.ready()) {
@@ -126,11 +124,9 @@ public class HoneyService extends Service {
 
 		@Override
 		protected void onPostExecute(String result) {
-			connectionInfoEditor.putString(
-					getString(R.string.connection_info_external_ip), result);
+			connectionInfoEditor.putString(getString(R.string.connection_info_external_ip), result);
 			connectionInfoEditor.commit();
-			notifyUI(this.getClass().getName(),
-					new String[] { getString(R.string.broadcast_connectivity) });
+			notifyUI(this.getClass().getName(), new String[] { getString(R.string.broadcast_connectivity) });
 		}
 	}
 
@@ -164,16 +160,13 @@ public class HoneyService extends Service {
 	private BroadcastReceiver netReceiver = new BroadcastReceiver() {
 		@Override
 		public void onReceive(Context context, Intent intent) {
-			String bssid_old = connectionInfo.getString(
-					getString(R.string.connection_info_bssid), "");
+			String bssid_old = connectionInfo.getString(getString(R.string.connection_info_bssid), "");
 			String bssid_new = HelperUtils.getBSSID(context);
 			if (bssid_new == null || !bssid_new.equals(bssid_old)) {
 				deleteConnectionData();
 				updateConnectionInfo();
 				getLocationData();
-				notifyUI(
-						this.getClass().getName(),
-						new String[] { getString(R.string.broadcast_connectivity) });
+				notifyUI(this.getClass().getName(), new String[] { getString(R.string.broadcast_connectivity) });
 			}
 		}
 	};
@@ -207,8 +200,7 @@ public class HoneyService extends Service {
 	 */
 	public int getNumberOfActiveConnections(String protocolName, int port) {
 		for (HoneyListener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName)
-					&& listener.getPort() == port) {
+			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				return listener.getHandlerCount();
 			}
 		}
@@ -253,8 +245,7 @@ public class HoneyService extends Service {
 	 */
 	public boolean isRunning(String protocolName, int port) {
 		for (HoneyListener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName)
-					&& listener.getPort() == port) {
+			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				return listener.isRunning();
 			}
 		}
@@ -272,8 +263,7 @@ public class HoneyService extends Service {
 	public void notifyUI(String sender, String[] values) {
 		createNotification();
 		// Send Notification
-		if (sender.equals(HoneyHandler.class.getName())
-				&& values[0].equals(R.string.broadcast_started)) {
+		if (sender.equals(HoneyHandler.class.getName()) && values[0].equals(R.string.broadcast_started)) {
 			attackNotification();
 		}
 		// Inform UI of Preference Change
@@ -294,8 +284,7 @@ public class HoneyService extends Service {
 		super.onCreate();
 		HoneyService.context = getApplicationContext();
 		implementedProtocols = getImplementedProtocols();
-		connectionInfo = getSharedPreferences(
-				getString(R.string.connection_info), Context.MODE_PRIVATE);
+		connectionInfo = getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
 		connectionInfoEditor = connectionInfo.edit();
 		createNotification();
 		registerNetReceiver();
@@ -303,8 +292,7 @@ public class HoneyService extends Service {
 		getLocationData();
 
 		String sharedPreferencePath = getString(R.string.shared_preference_path);
-		boolean useQotd = getSharedPreferences(sharedPreferencePath,
-				MODE_PRIVATE).getBoolean("useQotd", true);
+		boolean useQotd = getSharedPreferences(sharedPreferencePath, MODE_PRIVATE).getBoolean("useQotd", true);
 		if (useQotd) {
 			new QotdTask().execute(new String[] {});
 		}
@@ -346,18 +334,13 @@ public class HoneyService extends Service {
 	 */
 	public boolean startListener(String protocolName, int port) {
 		for (HoneyListener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName)
-					&& listener.getPort() == port) {
+			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				if (!listener.isRunning()) {
 					if (listener.start()) {
-						Toast.makeText(getApplicationContext(),
-								protocolName + " SERVICE STARTED!",
-								Toast.LENGTH_SHORT).show();
+						Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
 						return true;
 					}
-					Toast.makeText(getApplicationContext(),
-							protocolName + " SERVICE COULD NOT BE STARTED!",
-							Toast.LENGTH_SHORT).show();
+					Toast.makeText(getApplicationContext(), protocolName + " SERVICE COULD NOT BE STARTED!", Toast.LENGTH_SHORT).show();
 					return false;
 				}
 
@@ -366,15 +349,11 @@ public class HoneyService extends Service {
 		HoneyListener listener = createListener(protocolName, port);
 		if (listener != null) {
 			if (listener.start()) {
-				Toast.makeText(getApplicationContext(),
-						protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT)
-						.show();
+				Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
 				return true;
 			}
 		}
-		Toast.makeText(getApplicationContext(),
-				protocolName + " SERVICE COULD NOT BE STARTED!",
-				Toast.LENGTH_SHORT).show();
+		Toast.makeText(getApplicationContext(), protocolName + " SERVICE COULD NOT BE STARTED!", Toast.LENGTH_SHORT).show();
 		return false;
 	}
 
@@ -387,8 +366,7 @@ public class HoneyService extends Service {
 				listener.start();
 			}
 		}
-		Toast.makeText(getApplicationContext(), "SERVICES STARTED!",
-				Toast.LENGTH_SHORT).show();
+		Toast.makeText(getApplicationContext(), "SERVICES STARTED!", Toast.LENGTH_SHORT).show();
 	}
 
 	/**
@@ -411,15 +389,13 @@ public class HoneyService extends Service {
 	 */
 	public void stopListener(String protocolName, int port) {
 		for (HoneyListener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName)
-					&& listener.getPort() == port) {
+			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				if (listener.isRunning()) {
 					listener.stop();
 				}
 			}
 		}
-		Toast.makeText(getApplicationContext(),
-				protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
+		Toast.makeText(getApplicationContext(), protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
 	}
 
 	/**
@@ -431,31 +407,22 @@ public class HoneyService extends Service {
 				listener.stop();
 			}
 		}
-		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!",
-				Toast.LENGTH_SHORT).show();
+		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!", Toast.LENGTH_SHORT).show();
 	}
 
 	/**
 	 * Updates the notification when a attack is registered.
 	 */
 	private void attackNotification() {
-		SharedPreferences defaultPref = PreferenceManager
-				.getDefaultSharedPreferences(this);
-		String strRingtonePreference = defaultPref.getString(
-				"pref_notification_sound",
-				"content://settings/system/notification_sound");
-		builder = new NotificationCompat.Builder(this)
-				.setContentTitle(getString(R.string.app_name))
-				.setTicker("Honeypot under attack!")
-				.setContentText("Honeypot under attack!")
-				.setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true)
-				.setWhen(System.currentTimeMillis())
+		SharedPreferences defaultPref = PreferenceManager.getDefaultSharedPreferences(this);
+		String strRingtonePreference = defaultPref.getString("pref_notification_sound", "content://settings/system/notification_sound");
+		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setTicker("Honeypot under attack!")
+				.setContentText("Honeypot under attack!").setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true).setWhen(System.currentTimeMillis())
 				.setSound(Uri.parse(strRingtonePreference));
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
 		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
-		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
-				PendingIntent.FLAG_UPDATE_CURRENT);
+		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		if (defaultPref.getBoolean("pref_vibration", false)) {
 			builder.setVibrate(new long[] { 100, 200, 100, 200 });
@@ -500,7 +467,7 @@ public class HoneyService extends Service {
 	 * Creates a Notification in the notification bar.
 	 */
 	private void createNotification() {
-		UglyDbHelper dbh = new UglyDbHelper(this);
+		HostageDbHelper dbh = new HostageDbHelper(this);
 		boolean activeHandlers = false;
 		boolean bssidSeen = false;
 		boolean listening = false;
@@ -511,14 +478,11 @@ public class HoneyService extends Service {
 			if (listener.getHandlerCount() > 0) {
 				activeHandlers = true;
 			}
-			if (dbh.bssidSeen(listener.getProtocolName(),
-					HelperUtils.getBSSID(getApplicationContext()))) {
+			if (dbh.bssidSeen(listener.getProtocolName(), HelperUtils.getBSSID(getApplicationContext()))) {
 				bssidSeen = true;
 			}
 		}
-		builder = new NotificationCompat.Builder(this).setContentTitle(
-				getString(R.string.app_name)).setWhen(
-				System.currentTimeMillis());
+		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setWhen(System.currentTimeMillis());
 		if (!listening) {
 			builder.setSmallIcon(R.drawable.ic_launcher);
 			builder.setContentText("HosTaGe is not active.");
@@ -535,8 +499,7 @@ public class HoneyService extends Service {
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
 		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
-		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
-				PendingIntent.FLAG_UPDATE_CURRENT);
+		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		builder.setOngoing(true);
 		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@@ -583,9 +546,7 @@ public class HoneyService extends Service {
 
 		for (String protocol : protocols) {
 			try {
-				implementedProtocols.add((Protocol) Class.forName(
-						String.format("%s.%s", packageName, protocol))
-						.newInstance());
+				implementedProtocols.add((Protocol) Class.forName(String.format("%s.%s", packageName, protocol)).newInstance());
 			} catch (Exception e) {
 				e.printStackTrace();
 			}
@@ -630,15 +591,11 @@ public class HoneyService extends Service {
 	 * @see MainActivity#CONNECTION_INFO
 	 */
 	private void updateConnectionInfo() {
-		SharedPreferences pref = context.getSharedPreferences(
-				getString(R.string.connection_info), Context.MODE_PRIVATE);
+		SharedPreferences pref = context.getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
 		Editor editor = pref.edit();
-		editor.putString(getString(R.string.connection_info_ssid),
-				HelperUtils.getSSID(context));
-		editor.putString(getString(R.string.connection_info_bssid),
-				HelperUtils.getBSSID(context));
-		editor.putString(getString(R.string.connection_info_internal_ip),
-				HelperUtils.getInternalIP(context));
+		editor.putString(getString(R.string.connection_info_ssid), HelperUtils.getSSID(context));
+		editor.putString(getString(R.string.connection_info_bssid), HelperUtils.getBSSID(context));
+		editor.putString(getString(R.string.connection_info_internal_ip), HelperUtils.getInternalIP(context));
 		editor.commit();
 		SetExternalIPTask async = new SetExternalIPTask();
 		async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });

+ 39 - 0
src/de/tudarmstadt/informatik/hostage/db/HostageDbContract.java

@@ -0,0 +1,39 @@
+package de.tudarmstadt.informatik.hostage.db;
+
+import android.provider.BaseColumns;
+
+public final class HostageDbContract {
+	public static abstract class NetworkEntry implements BaseColumns {
+		public static final String TABLE_NAME = "network";
+		public static final String COLUMN_NAME_BSSID = "_bssid";
+		public static final String COLUMN_NAME_SSID = "ssid";
+		public static final String COLUMN_NAME_LATITUDE = "latitude";
+		public static final String COLUMN_NAME_LONGITUDE = "longitude";
+		public static final String COLUMN_NAME_ACCURACY = "accuracy";
+		public static final String COLUMN_NAME_GEO_TIMESTAMP = "geo_timestamp";
+	}
+
+	public static abstract class AttackEntry implements BaseColumns {
+		public static final String TABLE_NAME = "attack";
+		public static final String COLUMN_NAME_ATTACK_ID = "_attack_id";
+		public static final String COLUMN_NAME_PROTOCOL = "protocol";
+		public static final String COLUMN_NAME_EXTERNAL_IP = "externalIP";
+		public static final String COLUMN_NAME_LOCAL_IP = "localIP";
+		public static final String COLUMN_NAME_LOCAL_HOST_NAME = "localHostName";
+		public static final String COLUMN_NAME_LOCAL_PORT = "localPort";
+		public static final String COLUMN_NAME_REMOTE_IP = "remoteIP";
+		public static final String COLUMN_NAME_REMOTE_HOST_NAME = "remoteHostName";
+		public static final String COLUMN_NAME_REMOTE_PORT = "remotePort";
+		public static final String COLUMN_NAME_BSSID = "_bssid";
+	}
+
+	public static abstract class PacketEntry implements BaseColumns {
+		public static final String TABLE_NAME = "packet";
+		public static final String COLUMN_NAME_ID = "_id";
+		public static final String COLUMN_NAME_ATTACK_ID = "_attack_id";
+		public static final String COLUMN_NAME_TYPE = "type";
+		public static final String COLUMN_NAME_PACKET_TIMESTAMP = "packet_timestamp";
+		public static final String COLUMN_NAME_PACKET = "packet";
+	}
+
+}

+ 609 - 666
src/de/tudarmstadt/informatik/hostage/logging/UglyDbHelper.java → src/de/tudarmstadt/informatik/hostage/db/HostageDbHelper.java

@@ -1,666 +1,609 @@
-package de.tudarmstadt.informatik.hostage.logging;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
-
-/**
- * This class creates SQL tables and handles all access to the database.<br>
- * It contains several methods with predefined queries to extract different
- * kinds of information from the database.<br>
- * The database contains two tables: {@link #TABLE_RECORDS} and
- * {@link #TABLE_BSSIDS}:<br>
- * {@link #TABLE_RECORDS} contains all logging information of a single message
- * record except the SSID.<br>
- * {@link #TABLE_BSSIDS} contains the BSSID of all recorded Networks and the
- * corresponding SSID.<br>
- * 
- * @author Lars Pandikow
- */
-public class UglyDbHelper extends SQLiteOpenHelper {
-
-	// All Static variables
-	// Database Version
-	private static final int DATABASE_VERSION = 1;
-
-	// Database Name
-	private static final String DATABASE_NAME = "recordManager";
-
-	// Contacts table names
-	private static final String TABLE_ATTACK_INFO = "attack_info";
-	private static final String TABLE_RECORDS = "records";
-	private static final String TABLE_BSSIDS = "bssids";
-
-	// Contacts Table Columns names
-	public static final String KEY_ID = "_id";
-	public static final String KEY_ATTACK_ID = "_attack_id";
-	public static final String KEY_TYPE = "type";
-	public static final String KEY_TIME = "timestamp";
-	public static final String KEY_PACKET = "packet";
-	public static final String KEY_PROTOCOL = "protocol";
-	public static final String KEY_EXTERNAL_IP = "externalIP";
-	public static final String KEY_LOCAL_IP = "localIP";
-	public static final String KEY_LOCAL_HOSTNAME = "localHostName";
-	public static final String KEY_LOCAL_PORT = "localPort";
-	public static final String KEY_REMOTE_IP = "remoteIP";
-	public static final String KEY_REMOTE_HOSTNAME = "remoteHostName";
-	public static final String KEY_REMOTE_PORT = "remotePort";
-	public static final String KEY_BSSID = "_bssid";
-	public static final String KEY_SSID = "ssid";
-	public static final String KEY_LATITUDE = "latitude";
-	public static final String KEY_LONGITUDE = "longitude";
-	public static final String KEY_ACCURACY = "accuracy";
-
-	// Database sql create statements
-	private static final String CREATE_RECORD_TABLE = "CREATE TABLE "
-			+ TABLE_RECORDS + "(" + KEY_ID + " INTEGER NOT NULL,"
-			+ KEY_ATTACK_ID + " INTEGER NOT NULL," + KEY_TYPE + " TEXT,"
-			+ KEY_TIME + " INTEGER," + KEY_PACKET + " TEXT," + "FOREIGN KEY("
-			+ KEY_ATTACK_ID + ") REFERENCES " + TABLE_ATTACK_INFO + "("
-			+ KEY_ATTACK_ID + ")," + "PRIMARY KEY(" + KEY_ID + ", "
-			+ KEY_ATTACK_ID + ")" + ")";
-
-	private static final String CREATE_ATTACK_INFO_TABLE = "CREATE TABLE "
-			+ TABLE_ATTACK_INFO + "(" + KEY_ATTACK_ID + " INTEGER PRIMARY KEY,"
-			+ KEY_PROTOCOL + " TEXT," + KEY_EXTERNAL_IP + " TEXT,"
-			+ KEY_LOCAL_IP + " BLOB," + KEY_LOCAL_HOSTNAME + " TEXT,"
-			+ KEY_LOCAL_PORT + " INTEGER," + KEY_REMOTE_IP + " BLOB,"
-			+ KEY_REMOTE_HOSTNAME + " TEXT," + KEY_REMOTE_PORT + " INTEGER,"
-			+ KEY_BSSID + " TEXT," + "FOREIGN KEY(" + KEY_BSSID
-			+ ") REFERENCES " + TABLE_BSSIDS + "(" + KEY_BSSID + ")" + ")";
-
-	private static final String CREATE_BSSID_TABLE = "CREATE TABLE "
-			+ TABLE_BSSIDS + "(" + KEY_BSSID + " TEXT PRIMARY KEY," + KEY_SSID
-			+ " TEXT," + KEY_LATITUDE + " INTEGER," + KEY_LONGITUDE
-			+ " INTEGER," + KEY_ACCURACY + " INTEGER," + KEY_TIME + " INTEGER"
-			+ ")";
-
-	public UglyDbHelper(Context context) {
-		super(context, DATABASE_NAME, null, DATABASE_VERSION);
-	}
-
-	/**
-	 * Adds a given {@link Record} to the database.
-	 * 
-	 * @param record
-	 *            The added {@link Record} .
-	 */
-	public void addRecord(Record record) {
-		SQLiteDatabase db = this.getWritableDatabase();
-
-		HashMap<String, Object> bssidValues = new HashMap<String, Object>();
-		bssidValues.put(KEY_BSSID, record.getBssid());
-		bssidValues.put(KEY_SSID, record.getSsid());
-		bssidValues.put(KEY_LATITUDE, record.getLatitude());
-		bssidValues.put(KEY_LONGITUDE, record.getLongitude());
-		bssidValues.put(KEY_ACCURACY, record.getAccuracy());
-		bssidValues.put(KEY_TIME, record.getTimestampLocation());
-
-		ContentValues attackValues = new ContentValues();
-		attackValues.put(KEY_ATTACK_ID, record.getAttack_id()); // Log Attack ID
-		attackValues.put(KEY_PROTOCOL, record.getProtocol().toString());
-		attackValues.put(KEY_EXTERNAL_IP, record.getExternalIP());
-		attackValues.put(KEY_LOCAL_IP, record.getLocalIP()); // Log Local IP
-		attackValues.put(KEY_LOCAL_HOSTNAME, record.getLocalHost());
-		attackValues.put(KEY_LOCAL_PORT, record.getLocalPort());
-		attackValues.put(KEY_REMOTE_IP, record.getRemoteIP()); // Log Remote IP
-		attackValues.put(KEY_REMOTE_HOSTNAME, record.getRemoteHost());
-		attackValues.put(KEY_REMOTE_PORT, record.getRemotePort()); // Log Remote
-																	// Port
-		attackValues.put(KEY_BSSID, record.getBssid());
-
-		ContentValues recordValues = new ContentValues();
-		recordValues.put(KEY_ID, record.getId()); // Log Message Number
-		recordValues.put(KEY_ATTACK_ID, record.getAttack_id()); // Log Attack ID
-		recordValues.put(KEY_TYPE, record.getType().name()); // Log Type
-		recordValues.put(KEY_TIME, record.getTimestamp()); // Log Timestamp
-		recordValues.put(KEY_PACKET, record.getPacket()); // Log Packet
-
-		// Inserting Rows
-		db.insertWithOnConflict(TABLE_ATTACK_INFO, null, attackValues,
-				SQLiteDatabase.CONFLICT_REPLACE);
-		db.insert(TABLE_RECORDS, null, recordValues);
-		db.close(); // Closing database connection
-		// Update Network Information
-		updateNetworkInformation(bssidValues);
-	}
-
-	/**
-	 * Determines if a network with given BSSID has already been recorded as
-	 * malicious.
-	 * 
-	 * @param BSSID
-	 *            The BSSID of the network.
-	 * @return True if an attack has been recorded in a network with the given
-	 *         BSSID, else false.
-	 */
-	public boolean bssidSeen(String BSSID) {
-		String countQuery = "SELECT  * FROM " + TABLE_BSSIDS + " WHERE "
-				+ KEY_BSSID + " = " + "'" + BSSID + "'";
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
-		cursor.close();
-		db.close();
-		return result > 0;
-	}
-
-	/**
-	 * Determines if an attack has been recorded on a specific protocol in a
-	 * network with a given BSSID.
-	 * 
-	 * @param protocol
-	 *            The
-	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
-	 *            Protocol} to inspect.
-	 * @param BSSID
-	 *            The BSSID of the network.
-	 * @return True if an attack on the given protocol has been recorded in a
-	 *         network with the given BSSID, else false.
-	 */
-	public boolean bssidSeen(String protocol, String BSSID) {
-		String countQuery = "SELECT  * FROM " + TABLE_ATTACK_INFO
-				+ " NATURAL JOIN " + TABLE_BSSIDS + " WHERE " + KEY_PROTOCOL
-				+ " = " + "'" + protocol + "'" + " AND " + KEY_BSSID + " = "
-				+ "'" + BSSID + "'";
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
-		cursor.close();
-		db.close();
-		return result > 0;
-	}
-
-	/**
-	 * Deletes all records from {@link #TABLE_RECORDS}.
-	 */
-	public void clearData() {
-		SQLiteDatabase db = this.getReadableDatabase();
-		db.delete(TABLE_RECORDS, null, null);
-		db.delete(TABLE_ATTACK_INFO, null, null);
-		db.close();
-	}
-
-	/**
-	 * Deletes all records from {@link #TABLE_RECORDS} with a specific BSSID.
-	 * 
-	 * @param bssid
-	 *            The BSSID to match against.
-	 */
-	public void deleteByBSSID(String bssid) {
-		SQLiteDatabase db = this.getReadableDatabase();
-		db.delete(TABLE_RECORDS, KEY_BSSID + " = ?", new String[] { bssid });
-		db.delete(TABLE_ATTACK_INFO, KEY_BSSID + " = ?", new String[] { bssid });
-		db.close();
-	}
-
-	// TODO Delete statement �berarbeiten
-	/**
-	 * Deletes all records from {@link #TABLE_RECORDS} with a time stamp smaller
-	 * then the given
-	 * 
-	 * @param date
-	 *            A Date represented in milliseconds.
-	 */
-	public void deleteByDate(long date) {
-		SQLiteDatabase db = this.getReadableDatabase();
-		String deleteQuery = "DELETE  FROM " + TABLE_RECORDS + " WHERE "
-				+ KEY_TIME + " < " + date;
-		// TODO Delete statement �berarbeiten
-		// String deleteQuery2 = "DELETE "
-		db.execSQL(deleteQuery);
-		db.close();
-	}
-
-	/**
-	 * Returns a String array with all BSSIDs stored in the database.
-	 * 
-	 * @return String[] of all recorded BSSIDs.
-	 */
-	public String[] getAllBSSIDS() {
-		String selectQuery = "SELECT  * FROM " + TABLE_BSSIDS;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		String[] bssidList = new String[cursor.getCount()];
-		int counter = 0;
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				bssidList[counter] = cursor.getString(0);
-				counter++;
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
-		db.close();
-		return bssidList;
-	}
-
-	/**
-	 * Gets all received {@link Record Records} for every attack identified by
-	 * its attack id and ordered by date.
-	 * 
-	 * @return A ArrayList with all received {@link Record Records} for each
-	 *         attack id in the Database.
-	 */
-	public ArrayList<Record> getAllReceivedRecordsOfEachAttack() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN "
-				+ TABLE_BSSIDS + " WHERE " + KEY_TYPE + "='RECEIVE'"
-				+ " ORDER BY " + KEY_TIME;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
-
-		// return record list
-		db.close();
-		return recordList;
-	}
-
-	/**
-	 * Gets all {@link Record Records} saved in the database.
-	 * 
-	 * @return A ArrayList of all the {@link Record Records} in the Database.
-	 */
-	public ArrayList<Record> getAllRecords() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		// Select All Query
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " JOIN "
-				+ TABLE_BSSIDS + " USING (_bssid)";
-
-		SQLiteDatabase db = this.getWritableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		Log.i("Database", "Start loop");
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Log.i("Database", "Add Record");
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
-		db.close();
-		// return record list
-		return recordList;
-	}
-
-	/**
-	 * Determines the number of different attack_ids in the database.
-	 * 
-	 * @return The number of different attack_ids in the database.
-	 */
-	public int getAttackCount() {
-		String countQuery = "SELECT  * FROM " + TABLE_ATTACK_INFO;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
-		cursor.close();
-
-		// return count
-		db.close();
-		return result;
-	}
-
-	/**
-	 * Determines the number of different attack_ids for a specific protocol in
-	 * the database.
-	 * 
-	 * @param protocol
-	 *            The String representation of the
-	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
-	 *            Protocol}
-	 * @return The number of different attack_ids in the database.
-	 */
-	public int getAttackPerProtocolCount(String protocol) {
-		String countQuery = "SELECT  * FROM " + TABLE_ATTACK_INFO + " WHERE "
-				+ KEY_PROTOCOL + " = " + "'" + protocol + "'";
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
-		cursor.close();
-
-		// return count
-		db.close();
-		return result;
-	}
-
-	/**
-	 * Determines the highest attack id stored in the database.
-	 * 
-	 * @return The highest attack id stored in the database.
-	 */
-	public long getHighestAttackId() {
-		String selectQuery = "SELECT MAX(" + KEY_ATTACK_ID + ") FROM "
-				+ TABLE_ATTACK_INFO;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		int result;
-
-		if (cursor.moveToFirst()) {
-			result = cursor.getInt(0);
-		} else {
-			result = -1;
-		}
-		cursor.close();
-		db.close();
-		return result;
-	}
-
-	public ArrayList<HashMap<String, Object>> getNetworkInformation() {
-		String selectQuery = "SELECT  * FROM " + TABLE_BSSIDS;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		ArrayList<HashMap<String, Object>> networkInformation = new ArrayList<HashMap<String, Object>>();
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				HashMap<String, Object> values = new HashMap<String, Object>();
-				values.put(KEY_BSSID, cursor.getString(0));
-				values.put(KEY_SSID, cursor.getString(1));
-				values.put(KEY_LATITUDE,
-						Double.parseDouble(cursor.getString(2)));
-				values.put(KEY_LONGITUDE,
-						Double.parseDouble(cursor.getString(3)));
-				values.put(KEY_ACCURACY, Float.parseFloat(cursor.getString(4)));
-				values.put(KEY_TIME, cursor.getLong(5));
-				networkInformation.add(values);
-			} while (cursor.moveToNext());
-		}
-
-		cursor.close();
-		db.close();
-		return networkInformation;
-	}
-
-	/**
-	 * Gets a single {@link Record} with the given ID from the database.
-	 * 
-	 * @param id
-	 *            The ID of the {@link Record};
-	 * @return The {@link Record}.
-	 */
-	public Record getRecord(int id) {
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN "
-				+ TABLE_BSSIDS + " WHERE " + KEY_ID + " = " + id;
-		SQLiteDatabase db = this.getReadableDatabase();
-
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		Record record = null;
-		if (cursor.moveToFirst()) {
-			record = createRecord(cursor);
-		}
-
-		cursor.close();
-		db.close();
-		// return contact
-		return record;
-	}
-
-	/**
-	 * Determines the number of {@link Record Records} in the database.
-	 * 
-	 * @return The number of {@link Record Records} in the database.
-	 */
-	public int getRecordCount() {
-		String countQuery = "SELECT  * FROM " + TABLE_RECORDS;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
-		cursor.close();
-
-		// return count
-		db.close();
-		return result;
-	}
-
-	/**
-	 * Gets a single {@link Record} with the given attack id from the database.
-	 * 
-	 * @param attack_id
-	 *            The attack id of the {@link Record};
-	 * @return The {@link Record}.
-	 */
-	public Record getRecordOfAttackId(long attack_id) {
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN "
-				+ TABLE_BSSIDS + " WHERE " + KEY_ATTACK_ID + " = " + attack_id
-				+ " GROUP BY " + KEY_ATTACK_ID;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		Record record = null;
-
-		if (cursor.moveToFirst()) {
-			record = createRecord(cursor);
-		}
-		cursor.close();
-
-		// return record list
-		db.close();
-		return record;
-	}
-
-	/**
-	 * Gets a representative {@link Record} for every attack identified by its
-	 * attack id.
-	 * 
-	 * @return A ArrayList with one {@link Record Records} for each attack id in
-	 *         the Database.
-	 */
-	public ArrayList<Record> getRecordOfEachAttack() {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN "
-				+ TABLE_BSSIDS + " GROUP BY " + KEY_ATTACK_ID;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
-
-		// return record list
-		db.close();
-		return recordList;
-	}
-
-	/**
-	 * Gets a representative {@link Record} for every attack with a higher
-	 * attack id than the specified.
-	 * 
-	 * @param attack_id
-	 *            The attack id to match the query against.
-	 * @return A ArrayList with one {@link Record Records} for each attack id
-	 *         higher than the given.
-	 */
-	public ArrayList<Record> getRecordOfEachAttack(long attack_id) {
-		ArrayList<Record> recordList = new ArrayList<Record>();
-		String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
-				+ " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN "
-				+ TABLE_BSSIDS + " WHERE " + KEY_ATTACK_ID + " > " + attack_id
-				+ " GROUP BY " + KEY_ATTACK_ID;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-
-		// looping through all rows and adding to list
-		if (cursor.moveToFirst()) {
-			do {
-				Record record = createRecord(cursor);
-				// Adding record to list
-				recordList.add(record);
-			} while (cursor.moveToNext());
-		}
-		cursor.close();
-
-		// return count
-		db.close();
-		return recordList;
-	}
-
-	/**
-	 * Determines the smallest attack id stored in the database.
-	 * 
-	 * @return The smallest attack id stored in the database.
-	 */
-	public long getSmallestAttackId() {
-		String selectQuery = "SELECT MIN(" + KEY_ATTACK_ID + ") FROM "
-				+ TABLE_ATTACK_INFO;
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		int result;
-
-		if (cursor.moveToFirst()) {
-			result = cursor.getInt(0);
-		} else {
-			result = -1;
-		}
-		cursor.close();
-		db.close();
-		return result;
-	}
-
-	/**
-	 * Gets the last recorded SSID to a given BSSID.
-	 * 
-	 * @param bssid
-	 *            The BSSID to match against.
-	 * @return A String of the last SSID or null if the BSSID is not in the
-	 *         database.
-	 */
-	public String getSSID(String bssid) {
-		String selectQuery = "SELECT " + KEY_SSID + " FROM " + TABLE_BSSIDS
-				+ " WHERE " + KEY_BSSID + " = " + "'" + bssid + "'";
-		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(selectQuery, null);
-		String ssid = null;
-		if (cursor.moveToFirst()) {
-			ssid = cursor.getString(0);
-		}
-		cursor.close();
-		db.close();
-		return ssid;
-	}
-
-	// Creating Tables
-	@Override
-	public void onCreate(SQLiteDatabase db) {
-		db.execSQL(CREATE_BSSID_TABLE);
-		db.execSQL(CREATE_ATTACK_INFO_TABLE);
-		db.execSQL(CREATE_RECORD_TABLE);
-	}
-
-	// Upgrading database
-	@Override
-	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-		// Drop older table if existed
-		db.execSQL("DROP TABLE IF EXISTS " + TABLE_RECORDS);
-		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ATTACK_INFO);
-		db.execSQL("DROP TABLE IF EXISTS " + TABLE_BSSIDS);
-
-		// Create tables again
-		onCreate(db);
-	}
-
-	public void updateNetworkInformation(
-			ArrayList<HashMap<String, Object>> networkInformation) {
-		Log.i("DatabaseHandler", "Starte updating");
-		for (HashMap<String, Object> values : networkInformation) {
-			updateNetworkInformation(values);
-		}
-	}
-
-	public void updateNetworkInformation(
-			HashMap<String, Object> networkInformation) {
-		SQLiteDatabase db = this.getReadableDatabase();
-		String bssid = (String) networkInformation.get(KEY_BSSID);
-		String bssidQuery = "SELECT  * FROM " + TABLE_BSSIDS + " WHERE "
-				+ KEY_BSSID + " = " + "'" + bssid + "'";
-		Cursor cursor = db.rawQuery(bssidQuery, null);
-		int result = cursor.getCount();
-		if (cursor != null
-				&& cursor.moveToFirst()
-				&& (result <= 0 || cursor.getLong(5) < (Long) networkInformation
-						.get(KEY_TIME)))
-			;
-		{
-			ContentValues bssidValues = new ContentValues();
-			bssidValues.put(KEY_BSSID, bssid);
-			bssidValues
-					.put(KEY_SSID, (String) networkInformation.get(KEY_SSID));
-			bssidValues.put(KEY_LATITUDE,
-					(double) (Double) networkInformation.get(KEY_LATITUDE));
-			bssidValues.put(KEY_LONGITUDE,
-					(double) (Double) networkInformation.get(KEY_LONGITUDE));
-			bssidValues.put(KEY_ACCURACY,
-					(float) (Float) networkInformation.get(KEY_ACCURACY));
-			bssidValues.put(KEY_TIME, (Long) networkInformation.get(KEY_TIME));
-			db.insertWithOnConflict(TABLE_BSSIDS, null, bssidValues,
-					SQLiteDatabase.CONFLICT_REPLACE);
-		}
-		cursor.close();
-		db.close();
-	}
-
-	/**
-	 * Creates a {@link Record} from a Cursor. If the cursor does not show to a
-	 * valid data structure a runtime exception is thrown.
-	 * 
-	 * @param cursor
-	 * @return Returns the created {@link Record} .
-	 */
-	private Record createRecord(Cursor cursor) {
-		Record record = new Record();
-		record.setId(Integer.parseInt(cursor.getString(0)));
-		record.setAttack_id(cursor.getLong(1));
-		record.setType(TYPE.valueOf(cursor.getString(2)));
-		record.setTimestamp(cursor.getLong(3));
-		record.setPacket(cursor.getString(4));
-		record.setProtocol(cursor.getString(5));
-		record.setExternalIP(cursor.getString(6));
-
-		record.setLocalIP(cursor.getString(7));
-		record.setLocalHost(cursor.getString(8));
-		record.setLocalPort(Integer.parseInt(cursor.getString(9)));
-
-		record.setRemoteIP(cursor.getString(10));
-		record.setRemoteHost(cursor.getString(11));
-		record.setRemotePort(Integer.parseInt(cursor.getString(12)));
-
-		record.setBssid(cursor.getString(13));
-		record.setSsid(cursor.getString(14));
-		record.setLatitude(Double.parseDouble(cursor.getString(15)));
-		record.setLongitude(Double.parseDouble(cursor.getString(16)));
-		record.setAccuracy(Float.parseFloat(cursor.getString(17)));
-		record.setTimestampLocation(cursor.getLong(18));
-
-		return record;
-	}
-}
+package de.tudarmstadt.informatik.hostage.db;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+import de.tudarmstadt.informatik.hostage.db.HostageDbContract.AttackEntry;
+import de.tudarmstadt.informatik.hostage.db.HostageDbContract.NetworkEntry;
+import de.tudarmstadt.informatik.hostage.db.HostageDbContract.PacketEntry;
+import de.tudarmstadt.informatik.hostage.logging.Record;
+import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
+
+public class HostageDbHelper extends SQLiteOpenHelper {
+
+	private static final String DATABASE_NAME = "hostage.db";
+	private static final int DATABASE_VERSION = 1;
+
+	private static final String SQL_CREATE_PACKET_ENTRIES = "CREATE TABLE " + PacketEntry.TABLE_NAME + "(" + PacketEntry.COLUMN_NAME_ID + " INTEGER NOT NULL,"
+			+ PacketEntry.COLUMN_NAME_ATTACK_ID + " INTEGER NOT NULL," + PacketEntry.COLUMN_NAME_TYPE + " TEXT," + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP
+			+ " INTEGER," + PacketEntry.COLUMN_NAME_PACKET + " TEXT," + "FOREIGN KEY(" + PacketEntry.COLUMN_NAME_ATTACK_ID + ") REFERENCES "
+			+ AttackEntry.TABLE_NAME + "(" + PacketEntry.COLUMN_NAME_ATTACK_ID + ")," + "PRIMARY KEY(" + PacketEntry.COLUMN_NAME_ID + ", "
+			+ PacketEntry.COLUMN_NAME_ATTACK_ID + ")" + ")";
+
+	private static final String SQL_CREATE_ATTACK_ENTRIES = "CREATE TABLE " + AttackEntry.TABLE_NAME + "(" + AttackEntry.COLUMN_NAME_ATTACK_ID
+			+ " INTEGER PRIMARY KEY," + AttackEntry.COLUMN_NAME_PROTOCOL + " TEXT," + AttackEntry.COLUMN_NAME_EXTERNAL_IP + " TEXT,"
+			+ AttackEntry.COLUMN_NAME_LOCAL_IP + " BLOB," + AttackEntry.COLUMN_NAME_LOCAL_HOST_NAME + " TEXT," + AttackEntry.COLUMN_NAME_LOCAL_PORT
+			+ " INTEGER," + AttackEntry.COLUMN_NAME_REMOTE_IP + " BLOB," + AttackEntry.COLUMN_NAME_REMOTE_HOST_NAME + " TEXT,"
+			+ AttackEntry.COLUMN_NAME_REMOTE_PORT + " INTEGER," + AttackEntry.COLUMN_NAME_BSSID + " TEXT," + "FOREIGN KEY(" + AttackEntry.COLUMN_NAME_BSSID
+			+ ") REFERENCES " + NetworkEntry.TABLE_NAME + "(" + NetworkEntry.COLUMN_NAME_BSSID + ")" + ")";
+
+	private static final String SQL_CREATE_NETWORK_ENTRIES = "CREATE TABLE " + NetworkEntry.TABLE_NAME + "(" + NetworkEntry.COLUMN_NAME_BSSID
+			+ " TEXT PRIMARY KEY," + NetworkEntry.COLUMN_NAME_SSID + " TEXT," + NetworkEntry.COLUMN_NAME_LATITUDE + " INTEGER,"
+			+ NetworkEntry.COLUMN_NAME_LONGITUDE + " INTEGER," + NetworkEntry.COLUMN_NAME_ACCURACY + " INTEGER," + NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP
+			+ " INTEGER" + ")";
+
+	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;
+
+	public HostageDbHelper(Context context) {
+		super(context, DATABASE_NAME, null, DATABASE_VERSION);
+	}
+
+	@Override
+	public void onCreate(SQLiteDatabase db) {
+		db.execSQL(SQL_CREATE_PACKET_ENTRIES);
+		db.execSQL(SQL_CREATE_ATTACK_ENTRIES);
+		db.execSQL(SQL_CREATE_NETWORK_ENTRIES);
+	}
+
+	@Override
+	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+		db.execSQL(SQL_DELETE_PACKET_ENTRIES);
+		db.execSQL(SQL_DELETE_ATTACK_ENTRIES);
+		db.execSQL(SQL_DELETE_NETWORK_ENTRIES);
+		onCreate(db);
+	}
+
+	/**
+	 * Adds a given {@link Record} to the database.
+	 * 
+	 * @param record
+	 *            The added {@link Record} .
+	 */
+	public void addRecord(Record record) {
+		SQLiteDatabase db = this.getWritableDatabase();
+
+		HashMap<String, Object> bssidValues = new HashMap<String, Object>();
+		bssidValues.put(NetworkEntry.COLUMN_NAME_BSSID, record.getBssid());
+		bssidValues.put(NetworkEntry.COLUMN_NAME_SSID, record.getSsid());
+		bssidValues.put(NetworkEntry.COLUMN_NAME_LATITUDE, record.getLatitude());
+		bssidValues.put(NetworkEntry.COLUMN_NAME_LONGITUDE, record.getLongitude());
+		bssidValues.put(NetworkEntry.COLUMN_NAME_ACCURACY, record.getAccuracy());
+		bssidValues.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, record.getTimestampLocation());
+
+		ContentValues attackValues = new ContentValues();
+		attackValues.put(AttackEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log
+																					// Attack
+																					// ID
+		attackValues.put(AttackEntry.COLUMN_NAME_PROTOCOL, record.getProtocol().toString());
+		attackValues.put(AttackEntry.COLUMN_NAME_EXTERNAL_IP, record.getExternalIP());
+		attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_IP, record.getLocalIP()); // Log
+																					// Local
+																					// IP
+		attackValues.put(AttackEntry.COLUMN_NAME_LOCAL_HOST_NAME, record.getLocalHost());
+		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_HOST_NAME, record.getRemoteHost());
+		attackValues.put(AttackEntry.COLUMN_NAME_REMOTE_PORT, record.getRemotePort()); // Log
+																						// Remote
+																						// Port
+		attackValues.put(AttackEntry.COLUMN_NAME_BSSID, record.getBssid());
+
+		ContentValues recordValues = new ContentValues();
+		recordValues.put(PacketEntry.COLUMN_NAME_ID, record.getId()); // Log
+																		// Message
+																		// Number
+		recordValues.put(PacketEntry.COLUMN_NAME_ATTACK_ID, record.getAttack_id()); // Log
+																					// Attack
+																					// ID
+		recordValues.put(PacketEntry.COLUMN_NAME_TYPE, record.getType().name()); // Log
+																					// Type
+		recordValues.put(PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP, record.getTimestamp()); // Log
+																							// Timestamp
+		recordValues.put(PacketEntry.COLUMN_NAME_PACKET, record.getPacket()); // Log
+																				// Packet
+
+		// Inserting Rows
+		db.insertWithOnConflict(AttackEntry.TABLE_NAME, null, attackValues, SQLiteDatabase.CONFLICT_REPLACE);
+		db.insert(PacketEntry.TABLE_NAME, null, recordValues);
+		db.close(); // Closing database connection
+		// Update Network Information
+		updateNetworkInformation(bssidValues);
+	}
+
+	/**
+	 * Determines if a network with given BSSID has already been recorded as
+	 * malicious.
+	 * 
+	 * @param BSSID
+	 *            The BSSID of the network.
+	 * @return True if an attack has been recorded in a network with the given
+	 *         BSSID, else false.
+	 */
+	public boolean bssidSeen(String BSSID) {
+		String countQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(countQuery, null);
+		int result = cursor.getCount();
+		cursor.close();
+		db.close();
+		return result > 0;
+	}
+
+	/**
+	 * Determines if an attack has been recorded on a specific protocol in a
+	 * network with a given BSSID.
+	 * 
+	 * @param protocol
+	 *            The
+	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
+	 *            Protocol} to inspect.
+	 * @param BSSID
+	 *            The BSSID of the network.
+	 * @return True if an attack on the given protocol has been recorded in a
+	 *         network with the given BSSID, else false.
+	 */
+	public boolean bssidSeen(String protocol, String BSSID) {
+		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " NATURAL JOIN " + NetworkEntry.TABLE_NAME + " WHERE "
+				+ AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'" + " AND " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(countQuery, null);
+		int result = cursor.getCount();
+		cursor.close();
+		db.close();
+		return result > 0;
+	}
+
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME}.
+	 */
+	public void clearData() {
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(PacketEntry.TABLE_NAME, null, null);
+		db.delete(AttackEntry.TABLE_NAME, null, null);
+		db.close();
+	}
+
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a specific BSSID.
+	 * 
+	 * @param bssid
+	 *            The BSSID to match against.
+	 */
+	public void deleteByBSSID(String bssid) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		db.delete(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
+		db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_BSSID + " = ?", new String[] { bssid });
+		db.close();
+	}
+
+	// TODO Delete statement �berarbeiten
+	/**
+	 * Deletes all records from {@link #PacketEntry.TABLE_NAME} with a time stamp smaller
+	 * then the given
+	 * 
+	 * @param date
+	 *            A Date represented in milliseconds.
+	 */
+	public void deleteByDate(long date) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		String deleteQuery = "DELETE  FROM " + PacketEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP + " < " + date;
+		// TODO Delete statement überarbeiten
+		// String deleteQuery2 = "DELETE "
+		db.execSQL(deleteQuery);
+		db.close();
+	}
+
+	/**
+	 * Returns a String array with all BSSIDs stored in the database.
+	 * 
+	 * @return String[] of all recorded BSSIDs.
+	 */
+	public String[] getAllBSSIDS() {
+		String selectQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		String[] bssidList = new String[cursor.getCount()];
+		int counter = 0;
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				bssidList[counter] = cursor.getString(0);
+				counter++;
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+		db.close();
+		return bssidList;
+	}
+
+	/**
+	 * Gets all received {@link Record Records} for every attack identified by
+	 * its attack id and ordered by date.
+	 * 
+	 * @return A ArrayList with all received {@link Record Records} for each
+	 *         attack id in the Database.
+	 */
+	public ArrayList<Record> getAllReceivedRecordsOfEachAttack() {
+		ArrayList<Record> recordList = new ArrayList<Record>();
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
+				+ NetworkEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_TYPE + "='RECEIVE'" + " ORDER BY " + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				Record record = createRecord(cursor);
+				// Adding record to list
+				recordList.add(record);
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+
+		// return record list
+		db.close();
+		return recordList;
+	}
+
+	/**
+	 * Gets all {@link Record Records} saved in the database.
+	 * 
+	 * @return A ArrayList of all the {@link Record Records} in the Database.
+	 */
+	public ArrayList<Record> getAllRecords() {
+		ArrayList<Record> recordList = new ArrayList<Record>();
+		// Select All Query
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME
+				+ " USING (_bssid)";
+
+		SQLiteDatabase db = this.getWritableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		Log.i("Database", "Start loop");
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				Log.i("Database", "Add Record");
+				Record record = createRecord(cursor);
+				// Adding record to list
+				recordList.add(record);
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+		db.close();
+		// return record list
+		return recordList;
+	}
+
+	/**
+	 * Determines the number of different attack_ids in the database.
+	 * 
+	 * @return The number of different attack_ids in the database.
+	 */
+	public int getAttackCount() {
+		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(countQuery, null);
+		int result = cursor.getCount();
+		cursor.close();
+
+		// return count
+		db.close();
+		return result;
+	}
+
+	/**
+	 * Determines the number of different attack_ids for a specific protocol in
+	 * the database.
+	 * 
+	 * @param protocol
+	 *            The String representation of the
+	 *            {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
+	 *            Protocol}
+	 * @return The number of different attack_ids in the database.
+	 */
+	public int getAttackPerProtocolCount(String protocol) {
+		String countQuery = "SELECT  * FROM " + AttackEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'";
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(countQuery, null);
+		int result = cursor.getCount();
+		cursor.close();
+
+		// return count
+		db.close();
+		return result;
+	}
+
+	/**
+	 * Determines the highest attack id stored in the database.
+	 * 
+	 * @return The highest attack id stored in the database.
+	 */
+	public long getHighestAttackId() {
+		String selectQuery = "SELECT MAX(" + AttackEntry.COLUMN_NAME_ATTACK_ID + ") FROM " + AttackEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		int result;
+
+		if (cursor.moveToFirst()) {
+			result = cursor.getInt(0);
+		} else {
+			result = -1;
+		}
+		cursor.close();
+		db.close();
+		return result;
+	}
+
+	public ArrayList<HashMap<String, Object>> getNetworkInformation() {
+		String selectQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		ArrayList<HashMap<String, Object>> networkInformation = new ArrayList<HashMap<String, Object>>();
+
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				HashMap<String, Object> values = new HashMap<String, Object>();
+				values.put(NetworkEntry.COLUMN_NAME_BSSID, cursor.getString(0));
+				values.put(NetworkEntry.COLUMN_NAME_SSID, cursor.getString(1));
+				values.put(NetworkEntry.COLUMN_NAME_LATITUDE, Double.parseDouble(cursor.getString(2)));
+				values.put(NetworkEntry.COLUMN_NAME_LONGITUDE, Double.parseDouble(cursor.getString(3)));
+				values.put(NetworkEntry.COLUMN_NAME_ACCURACY, Float.parseFloat(cursor.getString(4)));
+				values.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, cursor.getLong(5));
+				networkInformation.add(values);
+			} while (cursor.moveToNext());
+		}
+
+		cursor.close();
+		db.close();
+		return networkInformation;
+	}
+
+	/**
+	 * Gets a single {@link Record} with the given ID from the database.
+	 * 
+	 * @param id
+	 *            The ID of the {@link Record};
+	 * @return The {@link Record}.
+	 */
+	public Record getRecord(int id) {
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
+				+ NetworkEntry.TABLE_NAME + " WHERE " + PacketEntry.COLUMN_NAME_ID + " = " + id;
+		SQLiteDatabase db = this.getReadableDatabase();
+
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		Record record = null;
+		if (cursor.moveToFirst()) {
+			record = createRecord(cursor);
+		}
+
+		cursor.close();
+		db.close();
+		// return contact
+		return record;
+	}
+
+	/**
+	 * Determines the number of {@link Record Records} in the database.
+	 * 
+	 * @return The number of {@link Record Records} in the database.
+	 */
+	public int getRecordCount() {
+		String countQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(countQuery, null);
+		int result = cursor.getCount();
+		cursor.close();
+
+		// return count
+		db.close();
+		return result;
+	}
+
+	/**
+	 * Gets a single {@link Record} with the given attack id from the database.
+	 * 
+	 * @param attack_id
+	 *            The attack id of the {@link Record};
+	 * @return The {@link Record}.
+	 */
+	public Record getRecordOfAttackId(long attack_id) {
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
+				+ NetworkEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id + " GROUP BY "
+				+ AttackEntry.COLUMN_NAME_ATTACK_ID;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		Record record = null;
+
+		if (cursor.moveToFirst()) {
+			record = createRecord(cursor);
+		}
+		cursor.close();
+
+		// return record list
+		db.close();
+		return record;
+	}
+
+	/**
+	 * Gets a representative {@link Record} for every attack identified by its
+	 * attack id.
+	 * 
+	 * @return A ArrayList with one {@link Record Records} for each attack id in
+	 *         the Database.
+	 */
+	public ArrayList<Record> getRecordOfEachAttack() {
+		ArrayList<Record> recordList = new ArrayList<Record>();
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
+				+ NetworkEntry.TABLE_NAME + " GROUP BY " + AttackEntry.COLUMN_NAME_ATTACK_ID;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				Record record = createRecord(cursor);
+				// Adding record to list
+				recordList.add(record);
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+
+		// return record list
+		db.close();
+		return recordList;
+	}
+
+	/**
+	 * Gets a representative {@link Record} for every attack with a higher
+	 * attack id than the specified.
+	 * 
+	 * @param attack_id
+	 *            The attack id to match the query against.
+	 * @return A ArrayList with one {@link Record Records} for each attack id
+	 *         higher than the given.
+	 */
+	public ArrayList<Record> getRecordOfEachAttack(long attack_id) {
+		ArrayList<Record> recordList = new ArrayList<Record>();
+		String selectQuery = "SELECT  * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " NATURAL JOIN "
+				+ NetworkEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " > " + attack_id + " GROUP BY "
+				+ AttackEntry.COLUMN_NAME_ATTACK_ID;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+
+		// looping through all rows and adding to list
+		if (cursor.moveToFirst()) {
+			do {
+				Record record = createRecord(cursor);
+				// Adding record to list
+				recordList.add(record);
+			} while (cursor.moveToNext());
+		}
+		cursor.close();
+
+		// return count
+		db.close();
+		return recordList;
+	}
+
+	/**
+	 * Determines the smallest attack id stored in the database.
+	 * 
+	 * @return The smallest attack id stored in the database.
+	 */
+	public long getSmallestAttackId() {
+		String selectQuery = "SELECT MIN(" + AttackEntry.COLUMN_NAME_ATTACK_ID + ") FROM " + AttackEntry.TABLE_NAME;
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		int result;
+
+		if (cursor.moveToFirst()) {
+			result = cursor.getInt(0);
+		} else {
+			result = -1;
+		}
+		cursor.close();
+		db.close();
+		return result;
+	}
+
+	/**
+	 * Gets the last recorded SSID to a given BSSID.
+	 * 
+	 * @param bssid
+	 *            The BSSID to match against.
+	 * @return A String of the last SSID or null if the BSSID is not in the
+	 *         database.
+	 */
+	public String getSSID(String bssid) {
+		String selectQuery = "SELECT " + NetworkEntry.COLUMN_NAME_SSID + " FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID
+				+ " = " + "'" + bssid + "'";
+		SQLiteDatabase db = this.getReadableDatabase();
+		Cursor cursor = db.rawQuery(selectQuery, null);
+		String ssid = null;
+		if (cursor.moveToFirst()) {
+			ssid = cursor.getString(0);
+		}
+		cursor.close();
+		db.close();
+		return ssid;
+	}
+
+	public void updateNetworkInformation(ArrayList<HashMap<String, Object>> networkInformation) {
+		Log.i("DatabaseHandler", "Starte updating");
+		for (HashMap<String, Object> values : networkInformation) {
+			updateNetworkInformation(values);
+		}
+	}
+
+	public void updateNetworkInformation(HashMap<String, Object> networkInformation) {
+		SQLiteDatabase db = this.getReadableDatabase();
+		String bssid = (String) networkInformation.get(NetworkEntry.COLUMN_NAME_BSSID);
+		String bssidQuery = "SELECT  * FROM " + NetworkEntry.TABLE_NAME + " WHERE " + NetworkEntry.COLUMN_NAME_BSSID + " = " + "'" + bssid + "'";
+		Cursor cursor = db.rawQuery(bssidQuery, null);
+		int result = cursor.getCount();
+		if (cursor != null && cursor.moveToFirst()
+				&& (result <= 0 || cursor.getLong(5) < (Long) networkInformation.get(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP)))
+			;
+		{
+			ContentValues bssidValues = new ContentValues();
+			bssidValues.put(NetworkEntry.COLUMN_NAME_BSSID, bssid);
+			bssidValues.put(NetworkEntry.COLUMN_NAME_SSID, (String) networkInformation.get(NetworkEntry.COLUMN_NAME_SSID));
+			bssidValues.put(NetworkEntry.COLUMN_NAME_LATITUDE, (double) (Double) networkInformation.get(NetworkEntry.COLUMN_NAME_LATITUDE));
+			bssidValues.put(NetworkEntry.COLUMN_NAME_LONGITUDE, (double) (Double) networkInformation.get(NetworkEntry.COLUMN_NAME_LONGITUDE));
+			bssidValues.put(NetworkEntry.COLUMN_NAME_ACCURACY, (float) (Float) networkInformation.get(NetworkEntry.COLUMN_NAME_ACCURACY));
+			bssidValues.put(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, (Long) networkInformation.get(NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP));
+			db.insertWithOnConflict(NetworkEntry.TABLE_NAME, null, bssidValues, SQLiteDatabase.CONFLICT_REPLACE);
+		}
+		cursor.close();
+		db.close();
+	}
+
+	/**
+	 * Creates a {@link Record} from a Cursor. If the cursor does not show to a
+	 * valid data structure a runtime exception is thrown.
+	 * 
+	 * @param cursor
+	 * @return Returns the created {@link Record} .
+	 */
+	private Record createRecord(Cursor cursor) {
+		Record record = new Record();
+		record.setId(Integer.parseInt(cursor.getString(0)));
+		record.setAttack_id(cursor.getLong(1));
+		record.setType(TYPE.valueOf(cursor.getString(2)));
+		record.setTimestamp(cursor.getLong(3));
+		record.setPacket(cursor.getString(4));
+		record.setProtocol(cursor.getString(5));
+		record.setExternalIP(cursor.getString(6));
+
+		record.setLocalIP(cursor.getString(7));
+		record.setLocalHost(cursor.getString(8));
+		record.setLocalPort(Integer.parseInt(cursor.getString(9)));
+
+		record.setRemoteIP(cursor.getString(10));
+		record.setRemoteHost(cursor.getString(11));
+		record.setRemotePort(Integer.parseInt(cursor.getString(12)));
+
+		record.setBssid(cursor.getString(13));
+		record.setSsid(cursor.getString(14));
+		record.setLatitude(Double.parseDouble(cursor.getString(15)));
+		record.setLongitude(Double.parseDouble(cursor.getString(16)));
+		record.setAccuracy(Float.parseFloat(cursor.getString(17)));
+		record.setTimestampLocation(cursor.getLong(18));
+
+		return record;
+	}
+
+}

+ 20 - 36
src/de/tudarmstadt/informatik/hostage/logging/Logger.java

@@ -7,6 +7,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.ResultReceiver;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 
 /**
  * An {@link IntentService} subclass for handling asynchronous task requests in
@@ -79,8 +80,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	public static void getAttackPerProtocolCount(Context context,
-			String protocol, ResultReceiver receiver) {
+	public static void getAttackPerProtocolCount(Context context, String protocol, ResultReceiver receiver) {
 		Intent intent = new Intent(context, Logger.class);
 		intent.setAction(ACTION_GET_COUNT_PROTOCOL);
 		intent.putExtra(EXTRA_PROTOCOL, protocol);
@@ -102,8 +102,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	public static void getRecordOfAttackId(Context context, long attack_id,
-			ResultReceiver receiver) {
+	public static void getRecordOfAttackId(Context context, long attack_id, ResultReceiver receiver) {
 		Intent intent = new Intent(context, Logger.class);
 		intent.setAction(ACTION_GET_RECORD_ID);
 		intent.putExtra(EXTRA_PRIMITIVE, attack_id);
@@ -111,8 +110,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	public static void getRecordOfEachAttack(Context context,
-			int lastUploadedAttackId, ResultReceiver receiver) {
+	public static void getRecordOfEachAttack(Context context, int lastUploadedAttackId, ResultReceiver receiver) {
 		Intent intent = new Intent(context, Logger.class);
 		intent.setAction(ACTION_GET_RECORD_EACH);
 		intent.putExtra(EXTRA_PRIMITIVE, lastUploadedAttackId);
@@ -120,8 +118,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	public static void getSsid(Context context, String bssid,
-			ResultReceiver receiver) {
+	public static void getSsid(Context context, String bssid, ResultReceiver receiver) {
 		Intent intent = new Intent(context, Logger.class);
 		intent.setAction(ACTION_GET_SSID_BSSID);
 		intent.putExtra(EXTRA_BSSID, bssid);
@@ -129,8 +126,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	public static void isBssidSeen(Context context, String protocol,
-			String bssid, ResultReceiver receiver) {
+	public static void isBssidSeen(Context context, String protocol, String bssid, ResultReceiver receiver) {
 		Intent intent = new Intent(context, Logger.class);
 		intent.setAction(ACTION_IS_BSSID_SEEN);
 		intent.putExtra(EXTRA_PROTOCOL, protocol);
@@ -146,7 +142,7 @@ public class Logger extends IntentService {
 		context.startService(intent);
 	}
 
-	private UglyDbHelper mDbHelper;
+	private HostageDbHelper mDbHelper;
 
 	public Logger() {
 		super("Logger");
@@ -155,7 +151,7 @@ public class Logger extends IntentService {
 	@Override
 	public void onCreate() {
 		super.onCreate();
-		mDbHelper = new UglyDbHelper(getApplicationContext());
+		mDbHelper = new HostageDbHelper(getApplicationContext());
 	}
 
 	private boolean handleActionBssidSeen(String protocol, String bssid) {
@@ -205,8 +201,7 @@ public class Logger extends IntentService {
 		return mDbHelper.getRecordOfAttackId(attack_id);
 	}
 
-	private ArrayList<Record> handleActionGetRecordOfEachAttack(
-			int lastUploadedAttackId) {
+	private ArrayList<Record> handleActionGetRecordOfEachAttack(int lastUploadedAttackId) {
 		return mDbHelper.getRecordOfEachAttack(lastUploadedAttackId);
 	}
 
@@ -229,55 +224,47 @@ public class Logger extends IntentService {
 				final Record record = intent.getParcelableExtra(EXTRA_RECORD);
 				handleActionLog(record);
 			} else if (ACTION_GET_RECORD_ALL.equals(action)) {
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				ArrayList<Record> r = handleActionGetAllRecords();
 				Bundle result = new Bundle();
 				result.putParcelableArrayList("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_RECORD_EACH.equals(action)) {
-				final int lastUploadedAttackId = intent.getIntExtra(
-						EXTRA_PRIMITIVE, -1);
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				final int lastUploadedAttackId = intent.getIntExtra(EXTRA_PRIMITIVE, -1);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				ArrayList<Record> r = handleActionGetRecordOfEachAttack(lastUploadedAttackId);
 				Bundle result = new Bundle();
 				result.putParcelableArrayList("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_RECORD_ID.equals(action)) {
 				final int attack_id = intent.getIntExtra(EXTRA_PRIMITIVE, -1);
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				Record r = handleActionGetRecordOfAttackId(attack_id);
 				Bundle result = new Bundle();
 				result.putParcelable("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_COUNT_ALL.equals(action)) {
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				int r = handleActionGetAttackCount();
 				Bundle result = new Bundle();
 				result.putInt("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_COUNT_PROTOCOL.equals(action)) {
 				final String protocol = intent.getStringExtra(EXTRA_PROTOCOL);
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				int r = handleActionGetAttackPerProtocolCount(protocol);
 				Bundle result = new Bundle();
 				result.putInt("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_ATTACK_MIN.equals(action)) {
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				long r = handleActionGetMinAttackId();
 				Bundle result = new Bundle();
 				result.putLong("result", r);
 				receiver.send(0, result);
 				handleActionGetMinAttackId();
 			} else if (ACTION_GET_ATTACK_MAX.equals(action)) {
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				long r = handleActionGetMaxAttackId();
 				Bundle result = new Bundle();
 				result.putLong("result", r);
@@ -285,23 +272,20 @@ public class Logger extends IntentService {
 			} else if (ACTION_IS_BSSID_SEEN.equals(action)) {
 				final String protocol = intent.getStringExtra(EXTRA_PROTOCOL);
 				final String bssid = intent.getStringExtra(EXTRA_BSSID);
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				boolean r = handleActionBssidSeen(protocol, bssid);
 				Bundle result = new Bundle();
 				result.putBoolean("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_BSSID_ALL.equals(action)) {
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				String[] r = handleActionGetAllBssids();
 				Bundle result = new Bundle();
 				result.putStringArray("result", r);
 				receiver.send(0, result);
 			} else if (ACTION_GET_SSID_BSSID.equals(action)) {
 				final String bssid = intent.getStringExtra(EXTRA_BSSID);
-				ResultReceiver receiver = intent
-						.getParcelableExtra(RESULT_RECEIVER);
+				ResultReceiver receiver = intent.getParcelableExtra(RESULT_RECEIVER);
 				String r = handleActionGetSsid(bssid);
 				Bundle result = new Bundle();
 				result.putString("result", r);

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/logging/Record.java

@@ -35,7 +35,7 @@ public class Record implements Parcelable {
 	private String localHost;
 	private int localPort;
 	private String remoteIP;
-	private String remoteHost;
+	private String remoteHost; //TODO remove host
 	private int remotePort;
 	private String externalIP;
 	private String bssid;

+ 14 - 27
src/de/tudarmstadt/informatik/hostage/sync/BluetoothSync.java

@@ -19,7 +19,7 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.widget.ArrayAdapter;
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 
 public class BluetoothSync {
 
@@ -100,21 +100,18 @@ public class BluetoothSync {
 			// while (true) {
 			try {
 				// TODO Ersetze dbh mit Logger
-				UglyDbHelper dbh = new UglyDbHelper(context);
-				ArrayList<HashMap<String, Object>> localNetworkInformation = dbh
-						.getNetworkInformation();
+				HostageDbHelper dbh = new HostageDbHelper(context);
+				ArrayList<HashMap<String, Object>> localNetworkInformation = dbh.getNetworkInformation();
 				if (identifier == SERVER) {
 					// Read from the InputStream
-					ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) objectInput
-							.readObject();
+					ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) objectInput.readObject();
 					;
 					dbh.updateNetworkInformation(remoteNetworkInformation);
 					objectOuput.writeObject(localNetworkInformation);
 				} else {
 					objectOuput.writeObject(localNetworkInformation);
 					// Read from the InputStream
-					ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) objectInput
-							.readObject();
+					ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) objectInput.readObject();
 					dbh.updateNetworkInformation(remoteNetworkInformation);
 					mmSocket.close();
 				}
@@ -142,9 +139,7 @@ public class BluetoothSync {
 		public ServerThread() {
 			BluetoothServerSocket tmp = null;
 			try {
-				tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(
-						context.getResources().getString(R.string.app_name),
-						serviceUUID);
+				tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(context.getResources().getString(R.string.app_name), serviceUUID);
 			} catch (IOException e) {
 			}
 			serverSocket = tmp;
@@ -204,8 +199,7 @@ public class BluetoothSync {
 			// When discovery finds a device
 			if (BluetoothDevice.ACTION_FOUND.equals(action)) {
 				// Get the BluetoothDevice object from the Intent
-				BluetoothDevice device = intent
-						.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+				BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
 				// Add the name and address to an array adapter to show in a
 				// ListView
 				arrayAdapter.add(device.getName() + "\n" + device.getAddress());
@@ -216,8 +210,7 @@ public class BluetoothSync {
 
 	public BluetoothSync(Context context) {
 		this.context = context;
-		serviceUUID = UUID.fromString(context.getResources().getString(
-				R.string.UUID));
+		serviceUUID = UUID.fromString(context.getResources().getString(R.string.UUID));
 		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
 	}
 
@@ -234,8 +227,7 @@ public class BluetoothSync {
 			return false;
 		}
 		if (!mBluetoothAdapter.isEnabled()) {
-			Intent enableBtIntent = new Intent(
-					BluetoothAdapter.ACTION_REQUEST_ENABLE);
+			Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
 			context.startActivity(enableBtIntent);
 			return false;
 		}
@@ -251,8 +243,7 @@ public class BluetoothSync {
 			public void onClick(DialogInterface dialog, int position) {
 				String deviceInfo = arrayAdapter.getItem(position);
 				String mac = deviceInfo.substring(deviceInfo.indexOf("\n") + 1);
-				ClientThread clientThread = new ClientThread(mBluetoothAdapter
-						.getRemoteDevice(mac));
+				ClientThread clientThread = new ClientThread(mBluetoothAdapter.getRemoteDevice(mac));
 				clientThread.start();
 			}
 		});
@@ -266,8 +257,7 @@ public class BluetoothSync {
 		}
 		mBluetoothAdapter.cancelDiscovery();
 		context.unregisterReceiver(mReceiver);
-		CommunicationThread commThread = new CommunicationThread(socket,
-				identifier);
+		CommunicationThread commThread = new CommunicationThread(socket, identifier);
 		commThread.start();
 	}
 
@@ -281,8 +271,7 @@ public class BluetoothSync {
 
 	private boolean syncDataActive() {
 		registerBroadcastReceiver();
-		arrayAdapter = new ArrayAdapter<String>(context,
-				android.R.layout.simple_list_item_1);
+		arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
 		// Start scanning for devices
 		if (!mBluetoothAdapter.startDiscovery())
 			return false;
@@ -292,10 +281,8 @@ public class BluetoothSync {
 	}
 
 	private void syncDataPassive() {
-		Intent discoverableIntent = new Intent(
-				BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
-		discoverableIntent.putExtra(
-				BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
+		Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
+		discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
 		context.startActivity(discoverableIntent);
 
 		serverThread = new ServerThread();

+ 9 - 16
src/de/tudarmstadt/informatik/hostage/sync/NFCSync.java

@@ -42,17 +42,15 @@ import android.util.Log;
 import android.widget.TextView;
 import android.widget.Toast;
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
-public class NFCSync extends Activity implements CreateNdefMessageCallback,
-		OnNdefPushCompleteCallback {
+public class NFCSync extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback {
 	NfcAdapter mNfcAdapter;
 	TextView mInfoText;
 	private static final int MESSAGE_SENT = 1;
 
-	public static Object deserialize(byte[] data) throws IOException,
-			ClassNotFoundException {
+	public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
 		ByteArrayInputStream in = new ByteArrayInputStream(data);
 		ObjectInputStream is = new ObjectInputStream(in);
 		return is.readObject();
@@ -71,8 +69,7 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback,
 		public void handleMessage(Message msg) {
 			switch (msg.what) {
 			case MESSAGE_SENT:
-				Toast.makeText(getApplicationContext(), "Message sent!",
-						Toast.LENGTH_LONG).show();
+				Toast.makeText(getApplicationContext(), "Message sent!", Toast.LENGTH_LONG).show();
 				Log.i("NFC", "Message sent!");
 				break;
 			}
@@ -85,15 +82,12 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback,
 	@Override
 	public NdefMessage createNdefMessage(NfcEvent event) {
 		// Get Networkdata
-		UglyDbHelper dbh = new UglyDbHelper(this);
-		ArrayList<HashMap<String, Object>> localNetworkInformation = dbh
-				.getNetworkInformation();
+		HostageDbHelper dbh = new HostageDbHelper(this);
+		ArrayList<HashMap<String, Object>> localNetworkInformation = dbh.getNetworkInformation();
 		Log.i("NFC", "Creating Message");
 		NdefMessage msg = null;
 		try {
-			msg = new NdefMessage(NdefRecord.createMime(
-					"application/de.tudarmstadt.informatik.hostage",
-					serialize(localNetworkInformation))
+			msg = new NdefMessage(NdefRecord.createMime("application/de.tudarmstadt.informatik.hostage", serialize(localNetworkInformation))
 			/**
 			 * The Android Application Record (AAR) is commented out. When a
 			 * device receives a push with an AAR in it, the application
@@ -161,8 +155,7 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback,
 	 * Parses the NDEF Message from the intent and prints to the TextView
 	 */
 	void processIntent(Intent intent) {
-		Parcelable[] rawMsgs = intent
-				.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+		Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
 		// only one message sent during the beam
 		NdefMessage msg = (NdefMessage) rawMsgs[0];
 		// record 0 contains the MIME type, record 1 is the AAR, if present
@@ -171,7 +164,7 @@ public class NFCSync extends Activity implements CreateNdefMessageCallback,
 		try {
 			object = deserialize(msg.getRecords()[0].getPayload());
 			ArrayList<HashMap<String, Object>> remoteNetworkInformation = (ArrayList<HashMap<String, Object>>) object;
-			UglyDbHelper dbh = new UglyDbHelper(this);
+			HostageDbHelper dbh = new HostageDbHelper(this);
 			dbh.updateNetworkInformation(remoteNetworkInformation);
 		} catch (ClassNotFoundException e) {
 			// TODO Auto-generated catch block

+ 32 - 67
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -41,10 +41,10 @@ import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
 import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver.Receiver;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 
 /**
  * MainActivity is the central activity for the GUI of the application.
@@ -153,8 +153,7 @@ public class MainActivity extends Activity implements Receiver {
 
 	SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {
 		@Override
-		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
-				float velocityY) {
+		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
 			float sensitvity = 50;
 			if ((e1.getX() - e2.getX()) > sensitvity) {
 				swipeRightToLeft();
@@ -174,8 +173,7 @@ public class MainActivity extends Activity implements Receiver {
 	public void buttonOnOffClick(View view) {
 		if (((ToggleButton) view).isChecked()) {
 			if (isParanoid()) {
-				String[] protocols = getResources().getStringArray(
-						R.array.protocols);
+				String[] protocols = getResources().getStringArray(R.array.protocols);
 				for (String protocol : protocols) {
 					mService.startListener(protocol);
 				}
@@ -258,11 +256,9 @@ public class MainActivity extends Activity implements Receiver {
 		try {
 			String found = "Found";
 			String notFound = "Not found";
-			String command = "[ -f /data/local/p ] && echo " + found
-					+ " || echo " + notFound;
+			String command = "[ -f /data/local/p ] && echo " + found + " || echo " + notFound;
 			p = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
-			BufferedReader in = new BufferedReader(new InputStreamReader(
-					p.getInputStream()));
+			BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
 			/*
 			 * int av = byte[] b = new byte[av]; if (av != 0) { in.read(b); }
 			 */
@@ -277,8 +273,7 @@ public class MainActivity extends Activity implements Receiver {
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		Log.i("MainAc", "Rooted: " + isRooted + " Porthack: "
-				+ porthackInstalled);
+		Log.i("MainAc", "Rooted: " + isRooted + " Porthack: " + porthackInstalled);
 	}
 
 	/**
@@ -317,10 +312,8 @@ public class MainActivity extends Activity implements Receiver {
 		listView.setOnItemClickListener(new OnItemClickListener() {
 
 			@Override
-			public void onItemClick(AdapterView<?> parent, View view,
-					int position, long id) {
-				String protocolName = (String) ((HashMap<?, ?>) adapter
-						.getItem(position)).get("protocol");
+			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+				String protocolName = (String) ((HashMap<?, ?>) adapter.getItem(position)).get("protocol");
 				if (mService.isRunning(protocolName)) {
 					mService.stopListener(protocolName);
 				} else {
@@ -337,14 +330,10 @@ public class MainActivity extends Activity implements Receiver {
 		viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
 		gestureDetector = new GestureDetector(this, simpleOnGestureListener);
 
-		animFlipInLR = AnimationUtils.loadAnimation(this,
-				R.anim.in_left_to_right);
-		animFlipOutLR = AnimationUtils.loadAnimation(this,
-				R.anim.out_left_to_right);
-		animFlipInRL = AnimationUtils.loadAnimation(this,
-				R.anim.in_right_to_left);
-		animFlipOutRL = AnimationUtils.loadAnimation(this,
-				R.anim.out_right_to_left);
+		animFlipInLR = AnimationUtils.loadAnimation(this, R.anim.in_left_to_right);
+		animFlipOutLR = AnimationUtils.loadAnimation(this, R.anim.out_left_to_right);
+		animFlipInRL = AnimationUtils.loadAnimation(this, R.anim.in_right_to_left);
+		animFlipOutRL = AnimationUtils.loadAnimation(this, R.anim.out_right_to_left);
 	}
 
 	/**
@@ -372,10 +361,8 @@ public class MainActivity extends Activity implements Receiver {
 	 */
 	private boolean isServiceRunning() {
 		ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
-		for (RunningServiceInfo service : manager
-				.getRunningServices(Integer.MAX_VALUE)) {
-			if (service.service.getClassName().equals(
-					HoneyService.class.getName())) {
+		for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+			if (service.service.getClassName().equals(HoneyService.class.getName())) {
 				return true;
 			}
 		}
@@ -388,8 +375,7 @@ public class MainActivity extends Activity implements Receiver {
 	 * @see #BROADCAST
 	 */
 	private void registerReceiver() {
-		LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
-				new IntentFilter(getString(R.string.broadcast)));
+		LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
 	}
 
 	/**
@@ -464,14 +450,10 @@ public class MainActivity extends Activity implements Receiver {
 		// externalIPView.setText("Loading...");
 
 		// Get connection information
-		String ssid = connectionInfo.getString(
-				getString(R.string.connection_info_ssid), null);
-		String bssid = connectionInfo.getString(
-				getString(R.string.connection_info_bssid), null);
-		String internalIP = connectionInfo.getString(
-				getString(R.string.connection_info_internal_ip), null);
-		String externalIP = connectionInfo.getString(
-				getString(R.string.connection_info_external_ip), null);
+		String ssid = connectionInfo.getString(getString(R.string.connection_info_ssid), null);
+		String bssid = connectionInfo.getString(getString(R.string.connection_info_bssid), null);
+		String internalIP = connectionInfo.getString(getString(R.string.connection_info_internal_ip), null);
+		String externalIP = connectionInfo.getString(getString(R.string.connection_info_external_ip), null);
 
 		// Set text fields
 		if (ssid != null)
@@ -505,8 +487,7 @@ public class MainActivity extends Activity implements Receiver {
 	 */
 	private void updateProtocolConnections(int connections, String protocolName) {
 		for (int i = 0; i < adapter.getCount(); ++i) {
-			HashMap<String, String> d = ((HashMap<String, String>) adapter
-					.getItem(i));
+			HashMap<String, String> d = ((HashMap<String, String>) adapter.getItem(i));
 			if (d.get("protocol").equals(protocolName)) {
 				d.put("connections", String.valueOf(connections));
 			}
@@ -524,8 +505,7 @@ public class MainActivity extends Activity implements Receiver {
 	 */
 	private void updateProtocolLight(int light, String protocolName) {
 		for (int i = 0; i < adapter.getCount(); ++i) {
-			HashMap<String, String> d = (HashMap<String, String>) adapter
-					.getItem(i);
+			HashMap<String, String> d = (HashMap<String, String>) adapter.getItem(i);
 			if (d.get("protocol").equals(protocolName)) {
 				switch (light) {
 				case LIGHT_GREY:
@@ -560,20 +540,16 @@ public class MainActivity extends Activity implements Receiver {
 	private void updateStatusLight(int light) {
 		switch (light) {
 		case LIGHT_GREY:
-			((ImageView) findViewById(R.id.imageViewLight))
-					.setImageResource(R.drawable.light_grey_large);
+			((ImageView) findViewById(R.id.imageViewLight)).setImageResource(R.drawable.light_grey_large);
 			break;
 		case LIGHT_GREEN:
-			((ImageView) findViewById(R.id.imageViewLight))
-					.setImageResource(R.drawable.light_green_large);
+			((ImageView) findViewById(R.id.imageViewLight)).setImageResource(R.drawable.light_green_large);
 			break;
 		case LIGHT_RED:
-			((ImageView) findViewById(R.id.imageViewLight))
-					.setImageResource(R.drawable.light_red_large);
+			((ImageView) findViewById(R.id.imageViewLight)).setImageResource(R.drawable.light_red_large);
 			break;
 		case LIGHT_YELLOW:
-			((ImageView) findViewById(R.id.imageViewLight))
-					.setImageResource(R.drawable.light_yellow_large);
+			((ImageView) findViewById(R.id.imageViewLight)).setImageResource(R.drawable.light_yellow_large);
 			break;
 		}
 	}
@@ -596,8 +572,7 @@ public class MainActivity extends Activity implements Receiver {
 				// Check if protocol is active
 				if (mService.isRunning(protocol)) {
 					activeListeners = true;
-					int handlerCount = mService
-							.getNumberOfActiveConnections(protocol);
+					int handlerCount = mService.getNumberOfActiveConnections(protocol);
 					// Check if attacks have been recorded in this session.
 					if (handlerCount > 0) {
 						activeHandlers = true;
@@ -607,16 +582,9 @@ public class MainActivity extends Activity implements Receiver {
 						// Check if the bssid of the wireless network has
 						// already
 						// been recorded as infected.
-						Logger.isBssidSeen(getApplicationContext(), protocol,
-								HelperUtils.getBSSID(getApplicationContext()),
-								logResultReceiver);
-						UglyDbHelper dbh = new UglyDbHelper(this);
-						if (dbh.bssidSeen(
-								protocol,
-								connectionInfo
-										.getString(
-												getString(R.string.connection_info_bssid),
-												null))) {
+						Logger.isBssidSeen(getApplicationContext(), protocol, HelperUtils.getBSSID(getApplicationContext()), logResultReceiver);
+						HostageDbHelper dbh = new HostageDbHelper(this);
+						if (dbh.bssidSeen(protocol, connectionInfo.getString(getString(R.string.connection_info_bssid), null))) {
 							updateProtocolLight(LIGHT_YELLOW, protocol);
 							yellowLight = true;
 						} else {
@@ -643,13 +611,11 @@ public class MainActivity extends Activity implements Receiver {
 					updateStatusLight(LIGHT_GREEN);
 				}
 			}
-			((ToggleButton) findViewById(R.id.toggleButtonOnOff))
-					.setChecked(true);
+			((ToggleButton) findViewById(R.id.toggleButtonOnOff)).setChecked(true);
 			findViewById(R.id.checkBoxParanoid).setEnabled(false);
 		} else {
 			updateStatusLight(LIGHT_GREY);
-			((ToggleButton) findViewById(R.id.toggleButtonOnOff))
-					.setChecked(false);
+			((ToggleButton) findViewById(R.id.toggleButtonOnOff)).setChecked(false);
 			findViewById(R.id.checkBoxParanoid).setEnabled(true);
 		}
 	}
@@ -659,8 +625,7 @@ public class MainActivity extends Activity implements Receiver {
 		super.onCreate(savedInstanceState);
 		logResultReceiver = new LogResultReceiver(new Handler());
 		setContentView(R.layout.activity_main);
-		connectionInfo = getSharedPreferences(
-				getString(R.string.connection_info), Context.MODE_PRIVATE);
+		connectionInfo = getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
 
 		// Create dynamic view elements
 		initViewAnimator();

+ 17 - 18
src/de/tudarmstadt/informatik/hostage/ui/PlayGroundActivity.java

@@ -12,7 +12,8 @@ import android.view.Menu;
 import android.view.View;
 import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
+import de.tudarmstadt.informatik.hostage.db.HostageDbContract;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 import de.tudarmstadt.informatik.hostage.sync.BluetoothSync;
 import de.tudarmstadt.informatik.hostage.sync.NFCSync;
 
@@ -25,18 +26,17 @@ public class PlayGroundActivity extends Activity {
 		ArrayList<HashMap<String, Object>> fakeNetInfo = new ArrayList<HashMap<String, Object>>();
 		for (int i = 0; i < 25; i++) {
 			HashMap<String, Object> network = new HashMap<String, Object>();
-			network.put(UglyDbHelper.KEY_BSSID, createRandomBSSID());
-			network.put(UglyDbHelper.KEY_SSID,
-					new BigInteger(130, rnd).toString(32));
-			network.put(UglyDbHelper.KEY_LATITUDE, rnd.nextDouble() * 360);
-			network.put(UglyDbHelper.KEY_LONGITUDE, rnd.nextDouble() * 360);
-			network.put(UglyDbHelper.KEY_ACCURACY, rnd.nextFloat());
-			network.put(UglyDbHelper.KEY_TIME, System.currentTimeMillis());
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_BSSID, createRandomBSSID());
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_SSID, new BigInteger(130, rnd).toString(32));
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_LATITUDE, rnd.nextDouble() * 360);
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_LONGITUDE, rnd.nextDouble() * 360);
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_ACCURACY, rnd.nextFloat());
+			network.put(HostageDbContract.NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP, System.currentTimeMillis());
 			fakeNetInfo.add(network);
 		}
 
 		setNetworkInfoText();
-		new UglyDbHelper(this).updateNetworkInformation(fakeNetInfo);
+		new HostageDbHelper(this).updateNetworkInformation(fakeNetInfo);
 	}
 
 	@Override
@@ -73,18 +73,17 @@ public class PlayGroundActivity extends Activity {
 	}
 
 	private void setNetworkInfoText() {
-		UglyDbHelper dbh = new UglyDbHelper(this);
+		HostageDbHelper dbh = new HostageDbHelper(this);
 		TextView bssids = (TextView) findViewById(R.id.textView1);
 		String text = "";
-		ArrayList<HashMap<String, Object>> netInfo = dbh
-				.getNetworkInformation();
+		ArrayList<HashMap<String, Object>> netInfo = dbh.getNetworkInformation();
 		for (HashMap<String, Object> network : netInfo) {
-			text = text + (String) network.get(UglyDbHelper.KEY_BSSID) + "\n"
-					+ (String) network.get(UglyDbHelper.KEY_SSID) + "\n"
-					+ network.get(UglyDbHelper.KEY_LATITUDE) + "\n"
-					+ network.get(UglyDbHelper.KEY_LONGITUDE) + "\n"
-					+ network.get(UglyDbHelper.KEY_ACCURACY) + "\n"
-					+ network.get(UglyDbHelper.KEY_TIME) + "\n\n";
+			text = text + (String) network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_BSSID) + "\n"
+					+ (String) network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_SSID) + "\n"
+					+ network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_LATITUDE) + "\n"
+					+ network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_LONGITUDE) + "\n"
+					+ network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_ACCURACY) + "\n"
+					+ network.get(HostageDbContract.NetworkEntry.COLUMN_NAME_GEO_TIMESTAMP) + "\n\n";
 		}
 		bssids.setText(text);
 	}

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

@@ -4,8 +4,8 @@ import android.app.Activity;
 import android.os.Bundle;
 import android.widget.ScrollView;
 import android.widget.TextView;
+import de.tudarmstadt.informatik.hostage.db.HostageDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 
 /**
  * Creates a simple log view. Shows the Information for every attack. The format
@@ -19,7 +19,7 @@ public class ViewLogTable extends Activity {
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
-		UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
+		HostageDbHelper dbh = new HostageDbHelper(getBaseContext());
 		StringBuffer log = new StringBuffer();
 		// Create a log entry for every attack in the Database
 		for (Record record : dbh.getAllRecords()) {