Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Julien Clauter 11 years ago
parent
commit
bacd45c332
35 changed files with 1369 additions and 289 deletions
  1. 1 1
      build.gradle
  2. 15 0
      res/drawable/panel_warning_bg.xml
  3. 10 0
      res/drawable/profile_protocol_badge.xml
  4. 134 0
      res/layout-land/fragment_services.xml
  5. 43 0
      res/layout/preference_warning.xml
  6. 50 2
      res/layout/profile_manager_list_item.xml
  7. 1 0
      res/values-de/strings.xml
  8. 14 0
      res/values/attrs.xml
  9. 11 0
      res/values/protocols.xml
  10. 2 0
      res/values/strings.xml
  11. 9 0
      res/values/styles.xml
  12. 11 1
      res/xml/profile_preferences.xml
  13. 26 1
      src/de/tudarmstadt/informatik/hostage/HoneyService.java
  14. 1 0
      src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java
  15. 146 45
      src/de/tudarmstadt/informatik/hostage/dao/ProfileManager.java
  16. 46 4
      src/de/tudarmstadt/informatik/hostage/model/Profile.java
  17. 13 0
      src/de/tudarmstadt/informatik/hostage/model/ProfilesHolder.java
  18. 101 40
      src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java
  19. 1 0
      src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java
  20. 76 65
      src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java
  21. 6 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/AboutFragment.java
  22. 30 13
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/ConnectionInfoDialogFragment.java
  23. 75 43
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java
  24. 19 0
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/PreferenceHostageFrament.java
  25. 41 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java
  26. 26 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java
  27. 72 55
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java
  28. 24 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java
  29. 2 1
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java
  30. 20 9
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/ThreatMapFragment.java
  31. 14 0
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/interfaces/UpNavigatible.java
  32. 2 2
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/opengl/HomeGLSurfaceView.java
  33. 0 1
      src/de/tudarmstadt/informatik/hostage/ui2/helper/ColorSequenceGenerator.java
  34. 326 0
      src/de/tudarmstadt/informatik/hostage/ui2/layouts/FlowLayout.java
  35. 1 2
      src/de/tudarmstadt/informatik/hostage/ui2/model/ServicesListItem.java

+ 1 - 1
build.gradle

@@ -3,7 +3,7 @@ buildscript {
         mavenCentral()
         mavenCentral()
     }
     }
     dependencies {
     dependencies {
-        classpath 'com.android.tools.build:gradle:0.8.+'
+        classpath 'com.android.tools.build:gradle:0.9.0'
     }
     }
 }
 }
 apply plugin: 'android'
 apply plugin: 'android'

+ 15 - 0
res/drawable/panel_warning_bg.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+	<!-- White Top color -->
+	<item android:bottom="4px">
+
+		<shape android:shape="rectangle">
+
+			<solid android:color="@color/holo_red" />
+			<corners android:radius="4dp" />
+
+		</shape>
+
+	</item>
+</selector>

+ 10 - 0
res/drawable/profile_protocol_badge.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+	<item android:bottom="4px">
+		<shape android:shape="rectangle">
+			<solid android:color="@color/light_grey" />
+			<corners android:radius="6dp" />
+		</shape>
+	</item>
+</selector>

+ 134 - 0
res/layout-land/fragment_services.xml

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="horizontal"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+    <RelativeLayout
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight="3">
+
+        <LinearLayout android:layout_width="fill_parent"
+                      android:layout_height="wrap_content"
+                      android:orientation="vertical">
+
+            <LinearLayout android:layout_width="fill_parent"
+                          android:layout_height="wrap_content"
+                          android:orientation="vertical"
+                          android:layout_weight="1"
+                          android:layout_marginTop="20dp"
+                          android:layout_marginLeft="15dp">
+                <ImageView
+                        android:id="@+id/services_button_connection_info"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:scaleType="fitEnd"
+                        android:src="@android:drawable/ic_menu_info_details"/>
+
+                <TextView
+                    android:id="@+id/textView"
+                    android:layout_width="fill_parent"
+                    android:layout_height="0dip"
+                    android:layout_marginLeft="15dp"
+                    android:layout_weight="1"
+                    android:layout_marginTop="0dp"
+                    android:text="@string/current_connection"
+                    android:textSize="18sp"
+                    android:textStyle="bold" />
+
+             </LinearLayout>
+             <RelativeLayout android:layout_width="fill_parent"
+                             android:layout_height="wrap_content"
+                            android:orientation="horizontal"
+                            android:layout_weight="1"
+                            android:layout_gravity="center_vertical"
+                            android:layout_marginLeft="15dp"
+                            android:layout_marginTop="5dp">
+                <View
+                        android:layout_width="fill_parent"
+                        android:layout_height="1dp"
+                        android:layout_weight="1"
+                        android:layout_marginLeft="15dp"
+                        android:layout_marginRight="15dp"
+                        android:background="@android:color/darker_gray" />
+
+                  <TextView
+                        android:id="@+id/services_text_name"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="10dp"
+                        android:layout_marginLeft="15dp"
+                        android:layout_marginRight="15dp"
+                        android:layout_alignParentTop="false"
+                        android:layout_centerHorizontal="true"
+                        android:layout_gravity="center_horizontal"
+                        android:text="Eduroam"
+                        android:textAppearance="?android:attr/textAppearanceLarge"
+                        android:textSize="26sp" />
+             </RelativeLayout>
+        </LinearLayout>
+    </RelativeLayout>
+
+    <LinearLayout android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="2"
+                    android:orientation="vertical">
+
+        <RelativeLayout
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:baselineAligned="false"
+                android:orientation="horizontal"
+                android:weightSum="1" >
+
+            <TextView
+                    android:id="@+id/textView"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentEnd="true"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentRight="false"
+                    android:layout_marginLeft="15dp"
+                    android:layout_marginTop="35dp"
+                    android:text="@string/monitor_services"
+                    android:textStyle="bold"
+                    android:textSize="20sp"/>
+
+            <Switch
+                    android:id="@+id/service_switch_connection"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentBottom="false"
+                    android:layout_alignParentEnd="false"
+                    android:layout_alignParentLeft="false"
+                    android:layout_alignParentRight="true"
+                    android:layout_alignParentTop="false"
+                    android:layout_gravity="right"
+                    android:layout_marginLeft="0dp"
+                    android:layout_marginRight="15dp"
+                    android:layout_marginTop="30dp"
+                    android:layout_marginBottom="0dp"
+                    android:checked="false"
+                    android:textSize="10sp" />
+
+        </RelativeLayout>
+        <View
+            android:layout_width="fill_parent"
+            android:layout_height="1dp"
+            android:layout_marginLeft="15dp"
+            android:layout_marginRight="15dp"
+            android:background="@android:color/darker_gray" />
+
+    <ListView android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:id="@+id/services_list_view"
+              android:layout_marginLeft="15dp"
+              android:layout_marginRight="15dp"
+            >
+
+
+    </ListView>
+    </LinearLayout>
+</LinearLayout>

+ 43 - 0
res/layout/preference_warning.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:gravity="center_vertical">
+
+	<LinearLayout android:layout_width="match_parent"
+	              android:layout_height="wrap_content"
+				  android:layout_marginTop="6dip"
+				  android:layout_marginBottom="6dip"
+				  android:minHeight="?android:attr/listPreferredItemHeight"
+				  android:background="@drawable/panel_warning_bg"
+				  android:paddingEnd="?android:attr/scrollbarSize">
+	<RelativeLayout
+			android:layout_width="wrap_content"
+			android:layout_height="wrap_content"
+			android:layout_marginStart="15dip"
+			android:layout_marginEnd="6dip"
+			android:layout_marginTop="6dip"
+			android:layout_marginBottom="6dip"
+			android:layout_weight="1">
+
+		<TextView android:id="@+android:id/title"
+		          android:layout_width="wrap_content"
+		          android:layout_height="wrap_content"
+		          android:singleLine="true"
+		          android:textAppearance="?android:attr/textAppearanceLarge"
+		          android:ellipsize="marquee"
+		          android:fadingEdge="horizontal" />
+
+		<TextView android:id="@+android:id/summary"
+		          android:layout_width="wrap_content"
+		          android:layout_height="wrap_content"
+		          android:layout_below="@android:id/title"
+		          android:layout_alignStart="@android:id/title"
+		          android:textAppearance="?android:attr/textAppearanceSmall"
+		          android:textColor="#FFFFFFFF"
+		          android:maxLines="4" />
+
+	</RelativeLayout>
+	</LinearLayout>
+</LinearLayout>

+ 50 - 2
res/layout/profile_manager_list_item.xml

@@ -103,7 +103,7 @@
 	        android:visibility="visible"
 	        android:visibility="visible"
 	        android:layout_marginLeft="20dp"/>
 	        android:layout_marginLeft="20dp"/>
 
 
-	    <ImageView
+		<ImageView
 	        android:layout_width="48dp"
 	        android:layout_width="48dp"
 	        android:layout_height="48dp"
 	        android:layout_height="48dp"
 	        android:id="@+id/profile_manager_item_image"
 	        android:id="@+id/profile_manager_item_image"
@@ -112,6 +112,54 @@
 	        android:layout_alignParentLeft="true"
 	        android:layout_alignParentLeft="true"
 	        android:layout_alignParentStart="true" android:scaleType="centerInside"/>
 	        android:layout_alignParentStart="true" android:scaleType="centerInside"/>
 
 
+		<de.tudarmstadt.informatik.hostage.ui2.layouts.FlowLayout
+				xmlns:f="http://schemas.android.com/apk/res/de.tudarmstadt.informatik.hostage"
+				android:orientation="horizontal"
+				android:layout_width="fill_parent"
+				android:layout_height="fill_parent"
+				android:layout_alignParentBottom="true"
+				android:layout_below="@+id/profile_manager_item_text"
+				android:padding="10dp"
+				f:horizontalSpacing="10dip"
+				f:verticalSpacing="10dip"
+				android:layout_alignRight="@+id/profile_manager_item_text" android:layout_alignEnd="@+id/profile_manager_item_text">
+			<TextView
+					android:layout_width="wrap_content"
+					android:layout_height="wrap_content"
+					android:textAppearance="?android:attr/textAppearanceSmall"
+					android:text="HTTP"
+					style="@style/ProfileManagerListBadge"
+					android:id="@+id/textView" android:layout_gravity="center_vertical" android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView2" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView11" android:layout_gravity="bottom"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView3" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView10" android:layout_gravity="bottom"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView4" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView5" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView9" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView8" android:layout_gravity="bottom"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView6" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+			<TextView style="@style/ProfileManagerListBadge" android:layout_width="wrap_content" android:layout_height="wrap_content"
+			          android:textAppearance="?android:attr/textAppearanceSmall" android:text="HTTP" android:id="@+id/textView7" android:layout_gravity="center_vertical"
+			          android:layout_marginLeft="10dp"/>
+		</de.tudarmstadt.informatik.hostage.ui2.layouts.FlowLayout>
 	</RelativeLayout>
 	</RelativeLayout>
-
 </FrameLayout>
 </FrameLayout>

+ 1 - 0
res/values-de/strings.xml

@@ -21,6 +21,7 @@
 
 
     <string name="information">Information</string>
     <string name="information">Information</string>
     <string name="wifi_not_connected_msg">Sie sind nicht mit einem WLAN Netzwerk verbunden. \n\nBitte verbinden sie sich mit einem, bevor sie HosTaGe starten.</string>
     <string name="wifi_not_connected_msg">Sie sind nicht mit einem WLAN Netzwerk verbunden. \n\nBitte verbinden sie sich mit einem, bevor sie HosTaGe starten.</string>
+	<string name="profile_no_services_msg">Das aktive Profil scheint keine Dienste zu überwachen.\n\nBitte aktivieren Sie Dienste in dem aktiven Profil.</string>
 
 
     <string name="monitor_current_connection">Überwache aktuelle Verbindung</string>
     <string name="monitor_current_connection">Überwache aktuelle Verbindung</string>
     <string name="active_profile">Aktives Profil: </string>
     <string name="active_profile">Aktives Profil: </string>

+ 14 - 0
res/values/attrs.xml

@@ -46,4 +46,18 @@
         <attr name="swipeDrawableUnchecked" format="reference"/>
         <attr name="swipeDrawableUnchecked" format="reference"/>
     </declare-styleable>
     </declare-styleable>
 
 
+	<declare-styleable name="FlowLayout">
+		<attr name="horizontalSpacing" format="dimension"/>
+		<attr name="verticalSpacing" format="dimension"/>
+		<attr name="orientation" format="enum">
+			<enum name="horizontal" value="0"/>
+			<enum name="vertical" value="1"/>
+		</attr>
+		<attr name="debugDraw" format="boolean" />
+	</declare-styleable>
+	<declare-styleable name="FlowLayout_LayoutParams">
+		<attr name="layout_newLine" format="boolean"/>
+		<attr name="layout_horizontalSpacing" format="dimension"/>
+		<attr name="layout_verticalSpacing" format="dimension"/>
+	</declare-styleable>
 </resources>
 </resources>

+ 11 - 0
res/values/protocols.xml

@@ -13,4 +13,15 @@
         <item>TELNET</item>
         <item>TELNET</item>
     </string-array>
     </string-array>
 
 
+	<string-array name="protocols_description">
+		<item>A service for testing and measurement of round-trip times in IP networks</item>
+		<item>A protocol used to transfer files from one host to another host</item>
+		<item>A protocol mirrors an incoming connection back to the attacker on the same port, that it is running on</item>
+		<item>A protocol to exchange or transfer hypertext. It is the foundation of data communication for the World Wide Web</item>
+		<item>The same as HTTP, but using a secure connections based on SSL/TLS</item>
+		<item>The world\'s second most widely used relational database management system</item>
+		<item>A protocol used for providing shared access to files, printers, serial ports, and miscellaneous communications between nodes on a network</item>
+		<item>A network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream</item>
+		<item>A network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection</item>
+	</string-array>
 </resources>
 </resources>

+ 2 - 0
res/values/strings.xml

@@ -21,6 +21,7 @@
 
 
     <string name="information">Information</string>
     <string name="information">Information</string>
     <string name="wifi_not_connected_msg">You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
     <string name="wifi_not_connected_msg">You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.</string>
+	<string name="profile_no_services_msg">The current active protocol does not seem to monitor any services.\n\nPlease activate some services to monitor in the profile.</string>
 
 
     <string name="monitor_current_connection">Monitor current connection</string>
     <string name="monitor_current_connection">Monitor current connection</string>
     <string name="active_profile">Active profile: </string>
     <string name="active_profile">Active profile: </string>
@@ -96,4 +97,5 @@
     <string name="delete_profile">Delete profile</string>
     <string name="delete_profile">Delete profile</string>
     <string name="discard">Discard</string>
     <string name="discard">Discard</string>
     <string name="save">Save</string>
     <string name="save">Save</string>
+	<string name="really_want_delete_profiel">Do you really want to delete this profile?</string>
 </resources>
 </resources>

+ 9 - 0
res/values/styles.xml

@@ -42,4 +42,13 @@
 		<item name="android:ellipsize">none</item>
 		<item name="android:ellipsize">none</item>
 		<item name="android:padding">4dp</item>
 		<item name="android:padding">4dp</item>
 	</style>
 	</style>
+
+	<style name="ProfileManagerListBadge">
+		<item name="android:paddingTop">4dp</item>
+		<item name="android:paddingBottom">4dp</item>
+		<item name="android:paddingLeft">4dp</item>
+		<item name="android:paddingRight">4dp</item>
+		<item name="android:background">@drawable/profile_protocol_badge</item>
+		<item name="android:textColor">#FFFFFFFF</item>
+	</style>
 </resources>
 </resources>

+ 11 - 1
res/xml/profile_preferences.xml

@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+	<Preference android:summary="Please note, that this profile can't be edited. If you make any changes to this profile, a new profile will be created."
+				android:layout="@layout/preference_warning"
+				android:key="pref_profile_warning"
+				android:enabled="false" />
+
 	<PreferenceCategory android:title="@string/general"
 	<PreferenceCategory android:title="@string/general"
 	                    android:key="pref_profile_general_settings">
 	                    android:key="pref_profile_general_settings">
 		<EditTextPreference android:key="pref_profile_general_name"
 		<EditTextPreference android:key="pref_profile_general_name"
@@ -17,4 +22,9 @@
 		            android:title="Icon"
 		            android:title="Icon"
 		            android:summary="@string/change_icon_of_profile" />
 		            android:summary="@string/change_icon_of_profile" />
 	</PreferenceCategory>
 	</PreferenceCategory>
-</PreferenceScreen>
+
+	<PreferenceCategory android:title="Montior protocols"
+	                    android:key="pref_profile_protocols_settings">
+		<Preference android:summary="Activate the protocols that should be monitored by HosTaGe" />
+	</PreferenceCategory>
+</PreferenceScreen>

+ 26 - 1
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -5,6 +5,7 @@ import java.io.InputStreamReader;
 import java.net.Socket;
 import java.net.Socket;
 import java.security.SecureRandom;
 import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
 
 
@@ -55,6 +56,8 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  */
  */
 public class HoneyService extends Service {
 public class HoneyService extends Service {
 
 
+	private HashMap<String, Boolean> mProtocolActiveAttacks;
+
 	public class LocalBinder extends Binder {
 	public class LocalBinder extends Binder {
 		public HoneyService getService() {
 		public HoneyService getService() {
 			return HoneyService.this;
 			return HoneyService.this;
@@ -273,7 +276,9 @@ public class HoneyService extends Service {
 		createNotification();
 		createNotification();
 		// Send Notification
 		// Send Notification
 		if (sender.equals(HoneyHandler.class.getName())
 		if (sender.equals(HoneyHandler.class.getName())
-				&& values[0].equals(R.string.broadcast_started)) {
+				&& values[0].equals(getString(R.string.broadcast_started))) {
+			this.mProtocolActiveAttacks.put(values[1], true);
+
 			attackNotification();
 			attackNotification();
 		}
 		}
 		// Inform UI of Preference Change
 		// Inform UI of Preference Change
@@ -297,6 +302,9 @@ public class HoneyService extends Service {
 		connectionInfo = getSharedPreferences(
 		connectionInfo = getSharedPreferences(
 				getString(R.string.connection_info), Context.MODE_PRIVATE);
 				getString(R.string.connection_info), Context.MODE_PRIVATE);
 		connectionInfoEditor = connectionInfo.edit();
 		connectionInfoEditor = connectionInfo.edit();
+
+		mProtocolActiveAttacks = new HashMap<String, Boolean>();
+
 		createNotification();
 		createNotification();
 		registerNetReceiver();
 		registerNetReceiver();
 		updateConnectionInfo();
 		updateConnectionInfo();
@@ -363,6 +371,7 @@ public class HoneyService extends Service {
 
 
 			}
 			}
 		}
 		}
+
 		HoneyListener listener = createListener(protocolName, port);
 		HoneyListener listener = createListener(protocolName, port);
 		if (listener != null) {
 		if (listener != null) {
 			if (listener.start()) {
 			if (listener.start()) {
@@ -415,6 +424,7 @@ public class HoneyService extends Service {
 					&& listener.getPort() == port) {
 					&& listener.getPort() == port) {
 				if (listener.isRunning()) {
 				if (listener.isRunning()) {
 					listener.stop();
 					listener.stop();
+					mProtocolActiveAttacks.remove(protocolName);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -429,6 +439,7 @@ public class HoneyService extends Service {
 		for (HoneyListener listener : listeners) {
 		for (HoneyListener listener : listeners) {
 			if (listener.isRunning()) {
 			if (listener.isRunning()) {
 				listener.stop();
 				listener.stop();
+				mProtocolActiveAttacks.remove(listener.getProtocolName());
 			}
 			}
 		}
 		}
 		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!",
 		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!",
@@ -621,6 +632,18 @@ public class HoneyService extends Service {
 		unregisterReceiver(netReceiver);
 		unregisterReceiver(netReceiver);
 	}
 	}
 
 
+	public boolean hasProtocolActiveAttacks(String protocol){
+		if(!mProtocolActiveAttacks.containsKey(protocol)) return false;
+		return mProtocolActiveAttacks.get(protocol);
+	}
+
+	public boolean hasActiveAttacks(){
+		for(boolean b: mProtocolActiveAttacks.values()){
+			if(b) return true;
+		}
+
+		return false;
+	}
 	/**
 	/**
 	 * Updates the connection info and saves them in the the SharedPreferences
 	 * Updates the connection info and saves them in the the SharedPreferences
 	 * for session data.
 	 * for session data.
@@ -642,6 +665,8 @@ public class HoneyService extends Service {
 		editor.commit();
 		editor.commit();
 		SetExternalIPTask async = new SetExternalIPTask();
 		SetExternalIPTask async = new SetExternalIPTask();
 		async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });
 		async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });
+
+		this.mProtocolActiveAttacks.clear();
 	}
 	}
 
 
 }
 }

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -392,6 +392,7 @@ public final class HelperUtils {
 	}
 	}
 
 
 	public static boolean isWifiConnected(Context context){
 	public static boolean isWifiConnected(Context context){
+		if(context == null) return false;
 		ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
 		ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
 		NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
 		NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
 
 

+ 146 - 45
src/de/tudarmstadt/informatik/hostage/dao/ProfileManager.java

@@ -1,5 +1,15 @@
 package de.tudarmstadt.informatik.hostage.dao;
 package de.tudarmstadt.informatik.hostage.dao;
 
 
+import android.content.Context;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.io.StreamCorruptedException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashMap;
@@ -7,8 +17,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.model.ProfilesHolder;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ProfileManagerListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ProfileManagerListAdapter;
 
 
@@ -19,44 +29,87 @@ import de.tudarmstadt.informatik.hostage.ui2.adapter.ProfileManagerListAdapter;
 public class ProfileManager {
 public class ProfileManager {
 	private static ProfileManager INSTANCE = null;
 	private static ProfileManager INSTANCE = null;
 
 
-	private Map<Integer, Profile> mProfiles;
 	private ProfileManagerListAdapter mProfileListAdapter = null;
 	private ProfileManagerListAdapter mProfileListAdapter = null;
-
-	private int mProfileId = 0;
 	private Profile mCurrentActivatedProfile = null;
 	private Profile mCurrentActivatedProfile = null;
+	private Profile mRandomProfile = null;
+
+	private static final String PERSIST_FILENAME = "hostage_profiles.dat";
 
 
-	private UglyDbHelper dbh;
+	private ProfilesHolder holder;
 
 
 	public static ProfileManager getInstance(){
 	public static ProfileManager getInstance(){
 		if(INSTANCE == null){
 		if(INSTANCE == null){
 			INSTANCE = new ProfileManager();
 			INSTANCE = new ProfileManager();
 		}
 		}
 
 
+		if(INSTANCE.getNumberOfProfiles() == 0){
+			INSTANCE.loadData();
+		}
+
 		return INSTANCE;
 		return INSTANCE;
 	}
 	}
 
 
 	private ProfileManager(){
 	private ProfileManager(){
-		this.mProfiles = new HashMap<Integer, Profile>();
-		this.dbh = new UglyDbHelper(MainActivity.getContext());
+		holder = new ProfilesHolder();
+		holder.mProfiles = new HashMap<Integer, Profile>();
 	}
 	}
 
 
 	public void loadData(){
 	public void loadData(){
-		Collection<Profile> profiles = this.dbh.getAllProfiles();
+		try {
+			FileInputStream fin = MainActivity.getContext().openFileInput(PERSIST_FILENAME);
+			ObjectInputStream ois = new ObjectInputStream(fin);
+
+			Object obj = ois.readObject();
+			ois.close();
+			fin.close();
+
+			if(obj != null && obj instanceof ProfilesHolder){
+				this.holder = (ProfilesHolder) obj;
+
+				for(Map.Entry<Integer, Profile> entry: holder.mProfiles.entrySet()){
+					if(entry.getValue().mActivated){
+						this.mCurrentActivatedProfile = entry.getValue();
+					}
+
+					if(entry.getValue().mIsRandom){
+						this.mRandomProfile = entry.getValue();
+					}
+				}
+			}
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (StreamCorruptedException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		} finally {
+			if(holder.mProfiles.size() == 0){
+				this.fillWithSampleData();
+				loadData();
+			}
 
 
-		if(profiles.size() == 0){
-			this.fillWithSampleData();
-			profiles = this.dbh.getAllProfiles();
+			if(this.mRandomProfile != null){
+				randomizeProtocols(mRandomProfile);
+			}
 		}
 		}
+	}
 
 
-		this.mProfiles.clear();
-
-		for(Profile p: profiles){
-			this.mProfiles.put(p.mId, p);
-
-			if(p.mActivated){
-				this.mCurrentActivatedProfile = p;
-			}
+	public void persistData(){
+		try {
+			FileOutputStream fout = MainActivity.getContext().openFileOutput(PERSIST_FILENAME, Context.MODE_PRIVATE);
+			ObjectOutputStream oos = new ObjectOutputStream(fout);
+
+			oos.writeObject(holder);
+			oos.close();
+			fout.close();
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
 		}
 		}
+
 	}
 	}
 
 
 	public List<Profile> getProfilesList(){
 	public List<Profile> getProfilesList(){
@@ -64,45 +117,75 @@ public class ProfileManager {
 	}
 	}
 
 
 	public Collection<Profile> getProfilesCollection(){
 	public Collection<Profile> getProfilesCollection(){
-		if(mProfiles.size() == 0 || mProfiles == null){
+		if(holder.mProfiles.size() == 0 || holder.mProfiles == null){
 			this.loadData();
 			this.loadData();
 		}
 		}
 
 
-		return mProfiles.values();
+		return holder.mProfiles.values();
 	}
 	}
 
 
 	public Map<Integer, Profile> getMapProfiles(){
 	public Map<Integer, Profile> getMapProfiles(){
-		return mProfiles;
+		return holder.mProfiles;
 	}
 	}
 
 
-	public long persistProfile(Profile profile){
-		int id = (int) this.dbh.persistProfile(profile);
+	public void randomizeProtocols(Profile profile){
+		for(String protocol: MainActivity.getContext().getResources().getStringArray(R.array.protocols)){
+			double rand = Math.random();
+
+			if(rand > 0.4){
+				profile.mActiveProtocols.put(protocol, true);
+			} else {
+				profile.mActiveProtocols.put(protocol, false);
+			}
+		}
+
+		persistData();
+	}
 
 
-		if(profile.mId != id){
-			profile.mId = id;
+	public long persistProfile(Profile profile){
+		if(profile.mId == -1){
+			profile.mId = ++holder.mIncrementValue;
 		}
 		}
 
 
-		this.mProfiles.put(id, profile);
+		holder.mProfiles.put(profile.mId, profile);
+
+		this.persistData();
 
 
-		return id;
+		if(this.mProfileListAdapter != null){
+			this.mProfileListAdapter.notifyDataSetChanged();
+		}
+
+		return profile.mId;
 	}
 	}
 
 
 	public Profile getProfile(int id){
 	public Profile getProfile(int id){
-		if(this.mProfiles.containsKey(id)){
-			return this.mProfiles.get(id);
+		if(holder.mProfiles.size() == 0){
+			loadData();
 		}
 		}
 
 
-		Profile profile = this.dbh.getProfile(id);
-		if(profile != null) return profile;
+		if(this.holder.mProfiles.containsKey(id)){
+			return this.holder.mProfiles.get(id);
+		}
 
 
 		return null;
 		return null;
 	}
 	}
 
 
 	public void addProfile(Profile profile){
 	public void addProfile(Profile profile){
-		int id = (int) this.dbh.persistProfile(profile);
-		profile.mId = id;
+		this.addProfile(profile, true);
+	}
+
+	public void addProfile(Profile profile, boolean persist){
+
+		if(profile.mId == -1){
+			profile.mId = ++holder.mIncrementValue;
+		}
+
+		holder.mProfiles.put(profile.mId, profile);
+
+		if(persist){
+			persistData();
+		}
 
 
-		this.mProfiles.put(id, profile);
 		if(this.mProfileListAdapter != null){
 		if(this.mProfileListAdapter != null){
 			this.mProfileListAdapter.add(profile);
 			this.mProfileListAdapter.add(profile);
 			this.mProfileListAdapter.notifyDataSetChanged();
 			this.mProfileListAdapter.notifyDataSetChanged();
@@ -110,9 +193,10 @@ public class ProfileManager {
 	}
 	}
 
 
 	public void deleteProfile(Profile profile){
 	public void deleteProfile(Profile profile){
-		if(this.mProfiles.containsKey(profile.mId)){
-			this.mProfiles.remove(profile.mId);
-			this.dbh.deleteProfile(profile.mId);
+		if(this.holder.mProfiles.containsKey(profile.mId)){
+			this.holder.mProfiles.remove(profile.mId);
+			this.persistData();
+			//this.dbh.deleteProfile(profile.mId);
 
 
 			if(this.mProfileListAdapter != null){
 			if(this.mProfileListAdapter != null){
 				this.mProfileListAdapter.remove(profile);
 				this.mProfileListAdapter.remove(profile);
@@ -121,6 +205,11 @@ public class ProfileManager {
 		}
 		}
 	}
 	}
 
 
+	public void clearProfiles(){
+		holder.mProfiles.clear();
+		persistData();
+	}
+
 	public void activateProfile(Profile profile){
 	public void activateProfile(Profile profile){
 		if(profile.equals(this.mCurrentActivatedProfile)) return;
 		if(profile.equals(this.mCurrentActivatedProfile)) return;
 
 
@@ -131,7 +220,8 @@ public class ProfileManager {
 
 
 		profile.mActivated = true;
 		profile.mActivated = true;
 		this.mCurrentActivatedProfile = profile;
 		this.mCurrentActivatedProfile = profile;
-		this.dbh.persistProfile(profile);
+		this.holder.mProfiles.put(profile.mId, profile);
+		persistData();
 	}
 	}
 
 
 	public Profile getCurrentActivatedProfile(){
 	public Profile getCurrentActivatedProfile(){
@@ -147,6 +237,10 @@ public class ProfileManager {
 		return this.mProfileListAdapter;
 		return this.mProfileListAdapter;
 	}
 	}
 
 
+	public int getNumberOfProfiles(){
+		return holder.mProfiles.size();
+	}
+
 	public void fillWithSampleData(){
 	public void fillWithSampleData(){
 		this.addProfile(new Profile(
 		this.addProfile(new Profile(
 				0,
 				0,
@@ -154,7 +248,7 @@ public class ProfileManager {
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				R.drawable.ic_profile_vista,
 				R.drawable.ic_profile_vista,
 				false
 				false
-		));
+		), false);
 
 
 		this.addProfile(new Profile(
 		this.addProfile(new Profile(
 				1,
 				1,
@@ -162,7 +256,7 @@ public class ProfileManager {
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				R.drawable.ic_profile_w7,
 				R.drawable.ic_profile_w7,
 				false
 				false
-		));
+		), false);
 
 
 		this.addProfile(new Profile(
 		this.addProfile(new Profile(
 				2,
 				2,
@@ -170,15 +264,19 @@ public class ProfileManager {
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				R.drawable.ic_profile_unix,
 				R.drawable.ic_profile_unix,
 				false
 				false
-		));
+		), false);
 
 
-		this.addProfile(new Profile(
+		Profile randomProfile = new Profile(
 				3,
 				3,
 				"Random",
 				"Random",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				R.drawable.ic_service_green,
 				R.drawable.ic_service_green,
 				false
 				false
-		));
+		);
+
+		randomProfile.mIsRandom = true;
+
+		this.addProfile(randomProfile, false);
 
 
 		this.addProfile(new Profile(
 		this.addProfile(new Profile(
 				4,
 				4,
@@ -186,6 +284,9 @@ public class ProfileManager {
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
 				R.drawable.ic_service_green,
 				R.drawable.ic_service_green,
 				false
 				false
-		));
+		), false);
+
+		holder.mIncrementValue = 4;
+		persistData();
 	}
 	}
 }
 }

+ 46 - 4
src/de/tudarmstadt/informatik/hostage/model/Profile.java

@@ -1,9 +1,20 @@
 package de.tudarmstadt.informatik.hostage.model;
 package de.tudarmstadt.informatik.hostage.model;
 
 
+import android.content.Context;
+import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 
 
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 
@@ -11,19 +22,22 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  * @author Alexander Brakowski
  * @author Alexander Brakowski
  * @created 14.01.14 18:04
  * @created 14.01.14 18:04
  */
  */
-public class Profile {
+public class Profile implements Serializable {
 	public String mText;
 	public String mText;
 	public String mLabel;
 	public String mLabel;
 	public int mId;
 	public int mId;
 	public boolean mActivated;
 	public boolean mActivated;
-	public Bitmap mIcon;
-	public int mIconId;
+	transient public Bitmap mIcon;
+	transient public int mIconId;
 	public String mIconName;
 	public String mIconName;
 
 
 	public String mIconPath;
 	public String mIconPath;
 
 
 	public boolean mIsBackVisible = false;
 	public boolean mIsBackVisible = false;
 	public boolean mEditable = false;
 	public boolean mEditable = false;
+	public boolean mIsRandom = false;
+
+	public HashMap<String, Boolean> mActiveProtocols = new HashMap<String, Boolean>();
 
 
 	public Profile(){
 	public Profile(){
 		this.mEditable = true;
 		this.mEditable = true;
@@ -55,6 +69,18 @@ public class Profile {
 		this.mEditable = editable;
 		this.mEditable = editable;
 	}
 	}
 
 
+	public Profile(Parcel in) {
+		mText = in.readString();
+		mLabel = in.readString();
+		mId = in.readInt();
+		mActivated = in.readInt() == 1;
+		mIconId = in.readInt();
+		mIconName = in.readString();
+		mIconPath = in.readString();
+		mEditable = in.readInt() == 1;
+		mActiveProtocols = (HashMap<String,Boolean>) in.readSerializable();
+	}
+
 	public void setIcon(Bitmap bitmap){
 	public void setIcon(Bitmap bitmap){
 		this.mIcon = bitmap;
 		this.mIcon = bitmap;
 	}
 	}
@@ -90,8 +116,24 @@ public class Profile {
 		return null;
 		return null;
 	}
 	}
 
 
+	public boolean isProtocolActive(String protocol){
+		if(!mActiveProtocols.containsKey(protocol)) return false;
+		return mActiveProtocols.get(protocol);
+	}
+
+	public List<String> getActiveProtocols(){
+		List<String> list = new LinkedList<String>();
+		for(Map.Entry<String, Boolean> entry: this.mActiveProtocols.entrySet()){
+			if(entry.getValue()){
+				list.add(entry.getKey());
+			}
+		}
+
+		return list;
+	}
+
 	public Drawable getIconDrawable(){
 	public Drawable getIconDrawable(){
-		return new BitmapDrawable(getIconBitmap());
+		return new BitmapDrawable(MainActivity.context.getResources(), getIconBitmap());
 	}
 	}
 
 
 	public boolean isEditable(){
 	public boolean isEditable(){

+ 13 - 0
src/de/tudarmstadt/informatik/hostage/model/ProfilesHolder.java

@@ -0,0 +1,13 @@
+package de.tudarmstadt.informatik.hostage.model;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+/**
+ * @author Alexander Brakowski
+ * @created 07.03.14 00:23
+ */
+public class ProfilesHolder implements Serializable {
+	public int mIncrementValue = 1;
+	public HashMap<Integer, Profile> mProfiles;
+}

+ 101 - 40
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -45,8 +45,10 @@ import de.tudarmstadt.informatik.hostage.ui2.fragment.ServicesFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.SettingsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.SettingsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.StatisticsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.StatisticsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ThreatMapFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ThreatMapFragment;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.interfaces.UpNavigatible;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRenderer;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRenderer;
 import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
 import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
+import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
 
 /**
 /**
  * @author Alexander Brakowski
  * @author Alexander Brakowski
@@ -298,13 +300,32 @@ public class MainActivity extends Activity {
 
 
 		if(item.getItemId() == android.R.id.home){
 		if(item.getItemId() == android.R.id.home){
 			if(!mDrawerToggle.isDrawerIndicatorEnabled()){
 			if(!mDrawerToggle.isDrawerIndicatorEnabled()){
-				if(getFragmentManager().getBackStackEntryCount() > 0) {
-					getFragmentManager().popBackStackImmediate();
-					this.mDisplayedFragment = getFragmentManager().findFragmentById(R.id.content_frame);
-					this.mInvalidMenuItem = true;
+				if(!(this.mDisplayedFragment instanceof UpNavigatible)) {
+					mDrawerToggle.setDrawerIndicatorEnabled(true);
+					return true;
+				}
+
+				UpNavigatible upNav = (UpNavigatible) this.mDisplayedFragment;
+
+				getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+				Fragment frag = null;
+
+				try{
+					frag = (Fragment) upNav.getUpFragment().newInstance();
+				} catch (InstantiationException e) {
+					Log.i(null, "Could not create new instance of fragment");
+				} catch (IllegalAccessException e) {
+					Log.i(null, "Could not create new instance of fragment");
+				}
+
+				if(frag != null) this.injectFragment(frag);
+
+				if(!(this.mDisplayedFragment instanceof UpNavigatible) || !((UpNavigatible) this.mDisplayedFragment).isUpNavigatible()){
+					mDrawerToggle.setDrawerIndicatorEnabled(true);
+				} else {
+					mDrawerToggle.setDrawerIndicatorEnabled(false);
 				}
 				}
 
 
-				if(getCurrentFragment().getTag() != null) mDrawerToggle.setDrawerIndicatorEnabled(true);
 				return true;
 				return true;
 			}
 			}
 		}
 		}
@@ -341,27 +362,30 @@ public class MainActivity extends Activity {
 		return this.mDisplayedFragment;
 		return this.mDisplayedFragment;
 	}
 	}
 
 
+	public void setDrawerIndicatorEnabled(boolean val){
+		mDrawerToggle.setDrawerIndicatorEnabled(val);
+	}
+
 	public void displayView(int position) {
 	public void displayView(int position) {
-		if(mSelectedMenuItem != null && position == mSelectedMenuItem.value && !mInvalidMenuItem) {
+		MainMenuItem menuItemPosition = MainMenuItem.create(position);
+
+		if(this.mDisplayedFragment != null && this.mDisplayedFragment.getClass() == menuItemPosition.getKlass()) {
 			mDrawerLayout.closeDrawer(mDrawerList);
 			mDrawerLayout.closeDrawer(mDrawerList);
 			return;
 			return;
 		}
 		}
 
 
-        // DONT OPEN SAME VIEW AGAIN
-		mInvalidMenuItem = false;
-		MainMenuItem menuItemPosition = mSelectedMenuItem = MainMenuItem.create(position);
-
         Fragment fragment = null;
         Fragment fragment = null;
 
 
-		// set orientation fixed to portrait in home fragment
-		if(menuItemPosition == MainMenuItem.HOME){
-			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
-		} else {
-			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+		try {
+			fragment = (Fragment) menuItemPosition.getKlass().newInstance();
+		} catch (InstantiationException e) {
+			Log.i(menuItemPosition.getKlass().toString(), "Could not create new instance of fragment");
+		} catch (IllegalAccessException e) {
+			Log.i(menuItemPosition.getKlass().toString(), "Could not create new instance of fragment");
 		}
 		}
 
 
-        // update the main content by replacing fragments
-		switch (menuItemPosition) {
+		// update the main content by replacing fragments
+		/*switch (menuItemPosition) {
 			case HOME:
 			case HOME:
 				fragment = new HomeFragment();
 				fragment = new HomeFragment();
 				break;
 				break;
@@ -394,11 +418,11 @@ public class MainActivity extends Activity {
 				break;
 				break;
 			default:
 			default:
 				break;
 				break;
-		}
+		}*/
 
 
 		if (fragment != null) {
 		if (fragment != null) {
 			// update selected item and title, then close the drawer if needed
 			// update selected item and title, then close the drawer if needed
-            injectFragment(fragment, false, menuItemPosition);
+            injectFragment(fragment);//, false, menuItemPosition);
 
 
 		    mDrawerList.setItemChecked(position, true);
 		    mDrawerList.setItemChecked(position, true);
 		    mDrawerList.setSelection(position);
 		    mDrawerList.setSelection(position);
@@ -409,29 +433,53 @@ public class MainActivity extends Activity {
 	}
 	}
 
 
 	public void injectFragment(Fragment fragment, boolean enableBack){
 	public void injectFragment(Fragment fragment, boolean enableBack){
-		injectFragment(fragment, enableBack, null);
+		injectFragment(fragment);
 	}
 	}
 
 
-	public void injectFragment(Fragment fragment, boolean enableBack, Object tagObj){
-		if(enableBack){
-			mDrawerToggle.setDrawerIndicatorEnabled(false);
+	public void injectFragment(Fragment fragment){
+		// set orientation fixed to portrait in home fragment
+		if(fragment instanceof UpNavigatible){
+			UpNavigatible upFrag = (UpNavigatible) fragment;
+			if(upFrag.getUpFragment() == null){
+				upFrag.setUpFragment(this.mDisplayedFragment.getClass());
+			}
+			if(upFrag.isUpNavigatible()){
+				mDrawerToggle.setDrawerIndicatorEnabled(false);
+			}
 		}
 		}
 
 
-		String tag = (tagObj == null ? null : tagObj.toString());
+		configureFragment(fragment);
 
 
 		FragmentManager fragmentManager = getFragmentManager();
 		FragmentManager fragmentManager = getFragmentManager();
 		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
 		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-		fragmentTransaction.replace(R.id.content_frame, fragment, tag);
+		fragmentTransaction.replace(R.id.content_frame, fragment, fragment.getClass().getName());
 
 
-		fragmentTransaction.addToBackStack(tag);
+		fragmentTransaction.addToBackStack(fragment.getClass().getName());
 
 
 		fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
 		fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
 		fragmentTransaction.commit();
 		fragmentTransaction.commit();
 
 
 		this.mDisplayedFragment = fragment;
 		this.mDisplayedFragment = fragment;
-		
-		if(tagObj == null){
-			this.mInvalidMenuItem = true;
+	}
+
+	private void configureFragment(){
+		configureFragment(this.mDisplayedFragment);
+	}
+
+	private void configureFragment(Fragment fragment){
+		if(fragment == null) return;
+
+		if(fragment instanceof HomeFragment){
+			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
+		} else {
+			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+		}
+
+		if(fragment instanceof StatisticsFragment ||
+				fragment instanceof RecordOverviewFragment){
+
+			Intent intent = this.getIntent();
+			intent.removeExtra(LogFilter.LOG_FILTER_INTENT_KEY);
 		}
 		}
 	}
 	}
 
 
@@ -442,8 +490,13 @@ public class MainActivity extends Activity {
 		} else {
 		} else {
 			super.onBackPressed();
 			super.onBackPressed();
 			this.mDisplayedFragment = getFragmentManager().findFragmentById(R.id.content_frame);
 			this.mDisplayedFragment = getFragmentManager().findFragmentById(R.id.content_frame);
-			this.mInvalidMenuItem = true;
-			if(getCurrentFragment().getTag() != null) mDrawerToggle.setDrawerIndicatorEnabled(true);
+			configureFragment();
+
+			if(!(this.mDisplayedFragment instanceof UpNavigatible) || !((UpNavigatible) this.mDisplayedFragment).isUpNavigatible()){
+				mDrawerToggle.setDrawerIndicatorEnabled(true);
+			} else {
+				mDrawerToggle.setDrawerIndicatorEnabled(false);
+			}
 		}
 		}
 	}
 	}
 
 
@@ -520,27 +573,35 @@ public class MainActivity extends Activity {
 	}
 	}
 
 
 	public enum MainMenuItem {
 	public enum MainMenuItem {
-        HOME(0),
-        THREAT_MAP(1),
-        RECORDS(2),
-		STATISTICS(3),
-        SERVICES(4),
-        PROFILE_MANAGER(5),
-        SETTINGS(6),
-        APPLICATION_INFO(7);
+        HOME(0, HomeFragment.class),
+        THREAT_MAP(1, ThreatMapFragment.class),
+        RECORDS(2, RecordOverviewFragment.class),
+		STATISTICS(3, StatisticsFragment.class),
+        SERVICES(4, ServicesFragment.class),
+        PROFILE_MANAGER(5, ProfileManagerFragment.class),
+        SETTINGS(6, SettingsFragment.class),
+        APPLICATION_INFO(7, AboutFragment.class);
 
 
         private int value;
         private int value;
+		private Class<?> klass;
 
 
-        private MainMenuItem(int value) {
+        private MainMenuItem(int value, Class<?> klass) {
             this.value = value;
             this.value = value;
+            this.klass = klass;
         }
         }
+
         static public MainMenuItem create(int value){
         static public MainMenuItem create(int value){
             if (value < 0 || value  >= MainMenuItem.values().length) return MainMenuItem.HOME;
             if (value < 0 || value  >= MainMenuItem.values().length) return MainMenuItem.HOME;
             return  MainMenuItem.values()[value];
             return  MainMenuItem.values()[value];
         }
         }
+
 		public int getValue() {
 		public int getValue() {
 			return value;
 			return value;
 		}
 		}
+
+		public Class<?> getKlass(){
+			return this.klass;
+		}
     }
     }
 
 
 	private class DrawerItemClickListener implements ListView.OnItemClickListener {
 	private class DrawerItemClickListener implements ListView.OnItemClickListener {

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -93,6 +93,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 				Intent intent = new Intent(context, ProfileEditActivity.class);
 				Intent intent = new Intent(context, ProfileEditActivity.class);
 				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 				intent.putExtra("profile_id", item.mId);
 				intent.putExtra("profile_id", item.mId);
+				//intent.putExtra("profile", item);
 				context.startActivity(intent);
 				context.startActivity(intent);
 			}
 			}
 		});
 		});

+ 76 - 65
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -1,10 +1,10 @@
 package de.tudarmstadt.informatik.hostage.ui2.adapter;
 package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
 
 
 
+import android.annotation.TargetApi;
 import android.app.AlertDialog;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface;
-import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Build;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
@@ -19,7 +19,6 @@ import java.util.List;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
-import de.tudarmstadt.informatik.hostage.ui2.fragment.ServicesFragment;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
 
 /**
 /**
@@ -27,23 +26,30 @@ import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
  */
  */
 public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 
 
-	private SharedPreferences mConnectionInfo;
-
 	private class ViewHolder {
 	private class ViewHolder {
-			public TextView protocolName;
-			public TextView recordedAttacks;
-			public Switch activated;
-			public View circle;
-		}
+
+		public TextView protocolName;
+
+		public TextView recordedAttacks;
+
+		public Switch activated;
+
+		public View circle;
+	}
 
 
 	private Context mActivity;
 	private Context mActivity;
+
 	private Switch mServicesSwitch;
 	private Switch mServicesSwitch;
+
 	private CompoundButton.OnCheckedChangeListener mListener;
 	private CompoundButton.OnCheckedChangeListener mListener;
+
 	private final Context context;
 	private final Context context;
+
 	private final List<ServicesListItem> values;
 	private final List<ServicesListItem> values;
+
 	int sdk = Build.VERSION.SDK_INT;
 	int sdk = Build.VERSION.SDK_INT;
 
 
-	public ServicesListAdapter(Context context, List<ServicesListItem> objects){
+	public ServicesListAdapter(Context context, List<ServicesListItem> objects) {
 		super(context, R.layout.services_list_item, objects);
 		super(context, R.layout.services_list_item, objects);
 
 
 		this.context = context;
 		this.context = context;
@@ -62,20 +68,20 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 		View rowView = convertView;
 		View rowView = convertView;
 
 
-		ViewHolder holder = null;
+		ViewHolder holder;
 
 
 		final ServicesListItem item = values.get(position);
 		final ServicesListItem item = values.get(position);
 
 
-		if(rowView == null){
+		if (rowView == null) {
 			rowView = inflater.inflate(R.layout.services_list_item, parent, false);
 			rowView = inflater.inflate(R.layout.services_list_item, parent, false);
 
 
 			holder = new ViewHolder();
 			holder = new ViewHolder();
+			assert rowView != null;
 			holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
 			holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
 			holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
 			holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
 			holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
 			holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
 			holder.circle = rowView.findViewById(R.id.services_circle);
 			holder.circle = rowView.findViewById(R.id.services_circle);
 			rowView.setTag(holder);
 			rowView.setTag(holder);
-
 		} else {
 		} else {
 			holder = (ViewHolder) rowView.getTag();
 			holder = (ViewHolder) rowView.getTag();
 		}
 		}
@@ -85,77 +91,82 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 
 
 		this.updateStatus(item, holder);
 		this.updateStatus(item, holder);
 
 
-			holder.activated.setOnCheckedChangeListener(
-					new CompoundButton.OnCheckedChangeListener() {
-						public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-							ServicesListItem item = (ServicesListItem) buttonView.getTag();
-				if(!HelperUtils.isWifiConnected(mActivity)){
-					new AlertDialog.Builder(mActivity)
-							.setTitle(R.string.information)
-							.setMessage(R.string.wifi_not_connected_msg)
-							.setPositiveButton(android.R.string.ok,
-									new DialogInterface.OnClickListener() {
-										public void onClick(DialogInterface dialog, int which) {
-										}
-									})
-							.setIcon(android.R.drawable.ic_dialog_info)
-							.show();
-
-
-					buttonView.setChecked(false);
-				} else {
-					if(isChecked){
-						if(!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
-							MainActivity.getInstance().getHoneyService().startListener(item.protocol);
-							mServicesSwitch.setOnCheckedChangeListener(null);
-							mServicesSwitch.setChecked(true);
-							mServicesSwitch.setOnCheckedChangeListener(mListener);
-						}
-						buttonView.setChecked(true);
-					} else {
-						if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
-							MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
+		holder.activated.setOnCheckedChangeListener(
+				new CompoundButton.OnCheckedChangeListener() {
+					public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+						ServicesListItem item = (ServicesListItem) buttonView.getTag();
+
+						if (!HelperUtils.isWifiConnected(mActivity)) {
+							new AlertDialog.Builder(mActivity)
+									.setTitle(R.string.information)
+									.setMessage(R.string.wifi_not_connected_msg)
+									.setPositiveButton(android.R.string.ok,
+											new DialogInterface.OnClickListener() {
+												public void onClick(DialogInterface dialog,
+														int which) {
+												}
+											})
+									.setIcon(android.R.drawable.ic_dialog_info).show();
+
+							buttonView.setChecked(false);
+						} else {
+							//check if switch is set to ON and start the concrete listener for the protocol
+							if (isChecked) {
+								if (!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
+									MainActivity.getInstance().getHoneyService().startListener(item.protocol);
+
+									//set the main switch to null, so that he won't react and starts all protocols
+									mServicesSwitch.setOnCheckedChangeListener(null);
+									mServicesSwitch.setChecked(true);
+									mServicesSwitch.setOnCheckedChangeListener(mListener);
+									buttonView.setChecked(true);
+								} else if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
+									buttonView.setChecked(true);
+								}
+							} else {
+								if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
+									MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
+								}
+								buttonView.setChecked(false);
+							}
 						}
 						}
-						buttonView.setChecked(false);
 					}
 					}
-				}
-						}
-					});
+				});
 		return rowView;
 		return rowView;
 	}
 	}
 
 
-	private void updateStatus(ServicesListItem item, ViewHolder holder){
-		if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
+	private void updateStatus(ServicesListItem item, ViewHolder holder) {
+		if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
 			holder.activated.setChecked(true);
 			holder.activated.setChecked(true);
-			if(!MainActivity.getInstance().hasProtocolAttacks(item.protocol)){
-				if(Integer.valueOf(item.attacks) > 0) {
+			if (!MainActivity.getInstance().getHoneyService().hasProtocolActiveAttacks(item.protocol)) {
+				if (item.attacks > 0) {
 					setBackground(holder, R.drawable.services_circle_yellow);
 					setBackground(holder, R.drawable.services_circle_yellow);
-				}
-				else {
+				} else {
 					setBackground(holder, R.drawable.services_circle_green);
 					setBackground(holder, R.drawable.services_circle_green);
 				}
 				}
 
 
-			}
-			else {
-				if(MainActivity.getInstance().hasProtocolAttacks(item.protocol)){
+			} else {
+				if (MainActivity.getInstance().getHoneyService().hasProtocolActiveAttacks(item.protocol)) {
 					setBackground(holder, R.drawable.services_circle_red);
 					setBackground(holder, R.drawable.services_circle_red);
 				}
 				}
 			}
 			}
-		}
-		else {
+		} else if (item.attacks > 0) {
+			holder.activated.setChecked(false);
+			setBackground(holder, R.drawable.services_circle_yellow);
+		} else {
 			holder.activated.setChecked(false);
 			holder.activated.setChecked(false);
 			setBackground(holder, R.drawable.services_circle);
 			setBackground(holder, R.drawable.services_circle);
 		}
 		}
-		holder.recordedAttacks.setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + "  %d", Integer.valueOf(item.attacks)));
+		holder.recordedAttacks
+				.setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + "  %d", Integer.valueOf(item.attacks)));
 	}
 	}
 
 
-	private void setBackground(ViewHolder holder, int drawable){
-		if(sdk < Build.VERSION_CODES.JELLY_BEAN){
+	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+	private void setBackground(ViewHolder holder, int drawable) {
+		if (sdk < Build.VERSION_CODES.JELLY_BEAN) {
 			holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
 			holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
-		}
-		else {
-			holder.circle.setBackground(MainActivity.getInstance().getResources()
-					.getDrawable(drawable));
+		} else {
+			holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(drawable));
 		}
 		}
 	}
 	}
 }
 }

+ 6 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/AboutFragment.java

@@ -1,5 +1,6 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 
+import android.app.Activity;
 import android.app.Fragment;
 import android.app.Fragment;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
@@ -10,12 +11,16 @@ import de.tudarmstadt.informatik.hostage.R;
 
 
 /**
 /**
  * Created by Fabio Arnold on 25.02.14.
  * Created by Fabio Arnold on 25.02.14.
+ * displays credits for the app
  */
  */
 public class AboutFragment extends Fragment {
 public class AboutFragment extends Fragment {
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 		super.onCreateView(inflater, container, savedInstanceState);
 		super.onCreateView(inflater, container, savedInstanceState);
 
 
-		getActivity().setTitle(getResources().getString(R.string.drawer_app_info));
+		final Activity activity = getActivity();
+		if (activity != null) {
+			activity.setTitle(getResources().getString(R.string.drawer_app_info));
+		}
 
 
 		return inflater.inflate(R.layout.fragment_about, container, false);
 		return inflater.inflate(R.layout.fragment_about, container, false);
 	}
 	}

+ 30 - 13
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ConnectionInfoDialogFragment.java

@@ -1,5 +1,6 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.app.DialogFragment;
@@ -20,15 +21,25 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 
 /**
 /**
  * Created by Fabio Arnold on 03.03.14.
  * Created by Fabio Arnold on 03.03.14.
+ * displays details about the current connection
  */
  */
 public class ConnectionInfoDialogFragment extends DialogFragment {
 public class ConnectionInfoDialogFragment extends DialogFragment {
 	public Dialog onCreateDialog(Bundle savedInstance) {
 	public Dialog onCreateDialog(Bundle savedInstance) {
-		// get connection infos
-		SharedPreferences sharedPreferences = getActivity().getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
-		final String ssid = sharedPreferences.getString(getString(R.string.connection_info_ssid), "");
-		String bssid = sharedPreferences.getString(getString(R.string.connection_info_bssid), "");
-		String internalIP = sharedPreferences.getString(getString(R.string.connection_info_internal_ip), "");
-		String externalIP = sharedPreferences.getString(getString(R.string.connection_info_external_ip), "");
+		// the data we want to display
+		String ssid = "undefined";
+		String bssid = "undefined";
+		String internalIP = "undefined";
+		String externalIP = "undefined";
+
+		// get infos about the current connection using SharedPreferences
+		final Activity activity = getActivity();
+		if (activity != null) {
+			SharedPreferences sharedPreferences = activity.getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
+			ssid = sharedPreferences.getString(getString(R.string.connection_info_ssid), "");
+			bssid = sharedPreferences.getString(getString(R.string.connection_info_bssid), "");
+			internalIP = sharedPreferences.getString(getString(R.string.connection_info_internal_ip), "");
+			externalIP = sharedPreferences.getString(getString(R.string.connection_info_external_ip), "");
+		}
 
 
 		// inflate the layout with a dark theme
 		// inflate the layout with a dark theme
 		Context context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo);
 		Context context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo);
@@ -36,12 +47,17 @@ public class ConnectionInfoDialogFragment extends DialogFragment {
 		View view = localInflater.inflate(R.layout.fragment_connectioninfo_dialog, null);
 		View view = localInflater.inflate(R.layout.fragment_connectioninfo_dialog, null);
 
 
 		// assign values in layout
 		// assign values in layout
-		((TextView)view.findViewById(R.id.connectioninfo_ssid_value)).setText(ssid);
-		((TextView)view.findViewById(R.id.connectioninfo_bssid_value)).setText(bssid);
-		((TextView)view.findViewById(R.id.connectioninfo_internalip_value)).setText(internalIP);
-		((TextView)view.findViewById(R.id.connectioninfo_externalip_value)).setText(externalIP);
+		if (view != null) {
+			((TextView)view.findViewById(R.id.connectioninfo_ssid_value)).setText(ssid);
+			((TextView)view.findViewById(R.id.connectioninfo_bssid_value)).setText(bssid);
+			((TextView)view.findViewById(R.id.connectioninfo_internalip_value)).setText(internalIP);
+			((TextView)view.findViewById(R.id.connectioninfo_externalip_value)).setText(externalIP);
+		}
+
+		// capture the SSID for the button action
+		final String filterSSID = ssid;
 
 
-		// build the dialog
+		// build the actual dialog
 		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
 		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
 		builder.setView(view);
 		builder.setView(view);
 		builder.setTitle(R.string.title_connection_info);
 		builder.setTitle(R.string.title_connection_info);
@@ -50,7 +66,7 @@ public class ConnectionInfoDialogFragment extends DialogFragment {
 			@Override
 			@Override
 			public void onClick(DialogInterface dialog, int which) {
 			public void onClick(DialogInterface dialog, int which) {
 				ArrayList<String> ssids = new ArrayList<String>();
 				ArrayList<String> ssids = new ArrayList<String>();
-				ssids.add(ssid);
+				ssids.add(filterSSID);
 
 
 				LogFilter filter = new LogFilter();
 				LogFilter filter = new LogFilter();
 				filter.setESSIDs(ssids);
 				filter.setESSIDs(ssids);
@@ -58,8 +74,9 @@ public class ConnectionInfoDialogFragment extends DialogFragment {
 				RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
 				RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
 				recordOverviewFragment.setFilter(filter);
 				recordOverviewFragment.setFilter(filter);
 				recordOverviewFragment.setGroupKey("ESSID");
 				recordOverviewFragment.setGroupKey("ESSID");
+				recordOverviewFragment.setUpNavigatible(true);
 
 
-				MainActivity.getInstance().injectFragment(recordOverviewFragment, false, MainActivity.MainMenuItem.RECORDS);
+				MainActivity.getInstance().injectFragment(recordOverviewFragment);
 			}
 			}
 		});
 		});
 		builder.setNegativeButton(R.string.close, null);
 		builder.setNegativeButton(R.string.close, null);

+ 75 - 43
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -1,4 +1,5 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.AlertDialog;
 import android.app.Fragment;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentManager;
@@ -10,7 +11,6 @@ import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.content.LocalBroadcastManager;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewGroup;
@@ -153,38 +153,26 @@ public class HomeFragment extends Fragment {
 
 
 		boolean hasActiveListeners = false;
 		boolean hasActiveListeners = false;
 		int totalAttacks = dbh.numBssidSeen(mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
 		int totalAttacks = dbh.numBssidSeen(mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
-		int totalLogged = 0;
-
-		if(MainActivity.getInstance().isServiceBound()){
-			for(String protocol: getResources().getStringArray(R.array.protocols)){
-				if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
-					hasActiveListeners = true;
-
-					boolean attackRegistered = MainActivity.getInstance().hasProtocolAttacks(protocol);
-
-					if(!attackRegistered){
-						if(totalAttacks > 0){
-							if(THREAT_LEVEL != ThreatIndicatorGLRenderer.ThreatLevel.LIVE_THREAT){
-								THREAT_LEVEL = ThreatIndicatorGLRenderer.ThreatLevel.PAST_THREAT;
-							}
-						} else {
-							if(THREAT_LEVEL != ThreatIndicatorGLRenderer.ThreatLevel.LIVE_THREAT && THREAT_LEVEL != ThreatIndicatorGLRenderer.ThreatLevel.PAST_THREAT){
-								THREAT_LEVEL = ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT;
-							}
-						}
-					} else {
-						THREAT_LEVEL = ThreatIndicatorGLRenderer.ThreatLevel.LIVE_THREAT;
-					}
+		ThreatIndicatorGLRenderer.ThreatLevel threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NOT_MONITORING;
+
+		if(MainActivity.getInstance().getHoneyService() != null){
+			if(MainActivity.getInstance().getHoneyService().hasRunningListeners()){
+				hasActiveListeners = true;
+
+				if(MainActivity.getInstance().getHoneyService().hasActiveAttacks() && totalAttacks > 0){
+					threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.LIVE_THREAT;
+				} else if(totalAttacks > 0){
+					threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.PAST_THREAT;
+				} else {
+					threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT;
 				}
 				}
 			}
 			}
 		}
 		}
 
 
-
-
 		if(hasActiveListeners){
 		if(hasActiveListeners){
 			setStateActive(true);
 			setStateActive(true);
 
 
-			switch(THREAT_LEVEL){
+			switch(threatLevel){
 				case NO_THREAT:
 				case NO_THREAT:
 					mHomeTextAttacks.setText(R.string.zero_attacks);
 					mHomeTextAttacks.setText(R.string.zero_attacks);
 					mHomeTextSecurity.setText(R.string.secure);
 					mHomeTextSecurity.setText(R.string.secure);
@@ -205,17 +193,13 @@ public class HomeFragment extends Fragment {
 					break;
 					break;
 			}
 			}
 
 
-			ThreatIndicatorGLRenderer.setThreatLevel(THREAT_LEVEL);
+			ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
 		} else {
 		} else {
-			mHomeSwitchConnection.setOnCheckedChangeListener(null);
 			setStateNotActive();
 			setStateNotActive();
-			THREAT_LEVEL = ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT;
 
 
 			if(!HelperUtils.isWifiConnected(getActivity())){
 			if(!HelperUtils.isWifiConnected(getActivity())){
 				setStateNotConnected();
 				setStateNotConnected();
 			}
 			}
-
-			mHomeSwitchConnection.setOnCheckedChangeListener(switchChangeListener);
 		}
 		}
 	}
 	}
 
 
@@ -225,7 +209,10 @@ public class HomeFragment extends Fragment {
 
 
 	    super.onCreateView(inflater, container, savedInstanceState);
 	    super.onCreateView(inflater, container, savedInstanceState);
 
 
-	    getActivity().setTitle(getResources().getString(R.string.drawer_overview));
+		final Activity activity = getActivity();
+		if (activity != null) {
+			activity.setTitle(getResources().getString(R.string.drawer_overview));
+		}
 
 
 	    dbh = new UglyDbHelper(getActivity());
 	    dbh = new UglyDbHelper(getActivity());
 
 
@@ -239,8 +226,11 @@ public class HomeFragment extends Fragment {
 		mHomeConnectionInfoButton.setOnClickListener(new View.OnClickListener() {
 		mHomeConnectionInfoButton.setOnClickListener(new View.OnClickListener() {
 			@Override
 			@Override
 			public void onClick(View v) {
 			public void onClick(View v) {
-				ConnectionInfoDialogFragment connectionInfoDialogFragment = new ConnectionInfoDialogFragment();
-				connectionInfoDialogFragment.show(getFragmentManager().beginTransaction(), connectionInfoDialogFragment.getTag());
+				final FragmentManager fragmentManager = getFragmentManager();
+				if (fragmentManager != null) {
+					ConnectionInfoDialogFragment connectionInfoDialogFragment = new ConnectionInfoDialogFragment();
+					connectionInfoDialogFragment.show(fragmentManager.beginTransaction(), connectionInfoDialogFragment.getTag());
+				}
 			}
 			}
 		});
 		});
 
 
@@ -259,8 +249,6 @@ public class HomeFragment extends Fragment {
 
 
 	    updateUI();
 	    updateUI();
 
 
-		final String[] protocols = getResources().getStringArray(R.array.protocols);
-
 	    mHomeSwitchConnection = (Switch) rootView.findViewById(R.id.home_switch_connection);
 	    mHomeSwitchConnection = (Switch) rootView.findViewById(R.id.home_switch_connection);
 
 
 	    if(switchChangeListener == null){
 	    if(switchChangeListener == null){
@@ -278,19 +266,48 @@ public class HomeFragment extends Fragment {
 							    .setIcon(android.R.drawable.ic_dialog_info)
 							    .setIcon(android.R.drawable.ic_dialog_info)
 							    .show();
 							    .show();
 
 
-
 					    setStateNotActive();
 					    setStateNotActive();
 					    setStateNotConnected();
 					    setStateNotConnected();
 				    } else {
 				    } else {
 					    if(isChecked){
 					    if(isChecked){
-						    for(String protocol: protocols){
-							    if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) MainActivity.getInstance().getHoneyService().startListener(protocol);
+						    boolean protocolActivated = false;
+						    if(ProfileManager.getInstance().getCurrentActivatedProfile() == null){
+							    for(String protocol: getResources().getStringArray(R.array.protocols)){
+								    if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)){
+									    MainActivity.getInstance().getHoneyService().startListener(protocol);
+									    protocolActivated = true;
+								    }
+							    }
+						    } else {
+							    for(String protocol: ProfileManager.getInstance().getCurrentActivatedProfile().getActiveProtocols()){
+								    if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
+									    MainActivity.getInstance().getHoneyService().startListener(protocol);
+									    protocolActivated = true;
+								    }
+							    }
 						    }
 						    }
 
 
-						    setStateActive();
+						    if(protocolActivated){
+						        setStateActive();
+						    } else {
+							    new AlertDialog.Builder(getActivity())
+									    .setTitle(R.string.information)
+									    .setMessage(R.string.profile_no_services_msg)
+									    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+										    public void onClick(DialogInterface dialog, int which) {
+
+										    }
+									    })
+									    .setIcon(android.R.drawable.ic_dialog_info)
+									    .show();
+
+							    setStateNotActive();
+						    }
 					    } else {
 					    } else {
-						    MainActivity.getInstance().getHoneyService().stopListeners();
-						    MainActivity.getInstance().stopAndUnbind();
+						    if(MainActivity.getInstance().getHoneyService() != null && MainActivity.getInstance().isServiceRunning()){
+							    MainActivity.getInstance().getHoneyService().stopListeners();
+							    MainActivity.getInstance().stopAndUnbind();
+						    }
 						    setStateNotActive();
 						    setStateNotActive();
 					    }
 					    }
 				    }
 				    }
@@ -311,10 +328,25 @@ public class HomeFragment extends Fragment {
         return rootView;
         return rootView;
     }
     }
 
 
+	@Override
+	public void onStop(){
+		super.onStop();
+
+		unregisterBroadcastReceiver();
+		//mHomeSwitchConnection.setOnCheckedChangeListener(null);
+	}
+
+	@Override
+	public void onStart(){
+		super.onStart();
+		registerBroadcastReceiver();
+		updateUI();
+		//mHomeSwitchConnection.setOnCheckedChangeListener(switchChangeListener);
+	}
 
 
 	@Override
 	@Override
 	public void onDestroy(){
 	public void onDestroy(){
-		unregisterBroadcastReceiver();
 		super.onDestroy();
 		super.onDestroy();
+		unregisterBroadcastReceiver();
 	}
 	}
 }
 }

+ 19 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/PreferenceHostageFrament.java

@@ -5,10 +5,13 @@ import android.os.Bundle;
 import android.preference.EditTextPreference;
 import android.preference.EditTextPreference;
 import android.preference.Preference;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
 
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.interfaces.UpNavigatible;
 
 
 /**
 /**
  * @author Alexander Brakowski
  * @author Alexander Brakowski
@@ -71,6 +74,22 @@ public class PreferenceHostageFrament extends PreferenceFragment implements Shar
 		super.onPause();
 		super.onPause();
 	}
 	}
 
 
+/*	@Override
+	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+		super.onPreferenceTreeClick(preferenceScreen, preference);
+
+		if (preference instanceof PreferenceScreen) {
+			if(MainActivity.getInstance().mDisplayedFragment != null && MainActivity.getInstance().mDisplayedFragment instanceof UpNavigatible){
+				((UpNavigatible) MainActivity.getInstance().mDisplayedFragment).setUpNavigatible(true);
+				((UpNavigatible) MainActivity.getInstance().mDisplayedFragment).setUpFragment(SettingsFragment.class);
+				MainActivity.getInstance().setDrawerIndicatorEnabled(false);
+				return true;
+			}
+		}
+
+		return false;
+	}*/
+
 	@Override
 	@Override
 	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
 	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
 		updatePreferenceSummary(key);
 		updatePreferenceSummary(key);

+ 41 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java

@@ -11,15 +11,21 @@ import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Bundle;
+import android.preference.CheckBoxPreference;
 import android.preference.EditTextPreference;
 import android.preference.EditTextPreference;
+import android.preference.MultiSelectListPreference;
 import android.preference.Preference;
 import android.preference.Preference;
+import android.preference.PreferenceCategory;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
 import android.provider.MediaStore;
 import android.provider.MediaStore;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.LinearLayout;
 
 
+import java.util.HashMap;
+
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
 import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
 import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.model.Profile;
@@ -34,6 +40,8 @@ public class ProfileEditFragment extends PreferenceFragment implements
 	private LayoutInflater mInflater;
 	private LayoutInflater mInflater;
 	private SharedPreferences.Editor prefs;
 	private SharedPreferences.Editor prefs;
 
 
+	private HashMap<String, Boolean> profileProtocols;
+
 	@Override
 	@Override
 	public void onCreate(Bundle savedInstanceState){
 	public void onCreate(Bundle savedInstanceState){
 		getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
 		getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
@@ -71,11 +79,14 @@ public class ProfileEditFragment extends PreferenceFragment implements
 				profile.mLabel = prefs.getString("pref_profile_general_name", profile.mLabel);
 				profile.mLabel = prefs.getString("pref_profile_general_name", profile.mLabel);
 				profile.mIconPath = prefs.getString("pref_profile_general_image", profile.mIconPath);
 				profile.mIconPath = prefs.getString("pref_profile_general_image", profile.mIconPath);
 				profile.mText = prefs.getString("pref_profile_general_description", profile.mText);
 				profile.mText = prefs.getString("pref_profile_general_description", profile.mText);
+				profile.mActiveProtocols = new HashMap<String, Boolean>(profileProtocols);
 
 
 				if(createNew){
 				if(createNew){
 					profile.mId = -1;
 					profile.mId = -1;
 					profile.mIconId = 0;
 					profile.mIconId = 0;
 					profile.mIconName = "";
 					profile.mIconName = "";
+					profile.mIsRandom = false;
+					profile.mIcon = null;
 					pmanager.addProfile(profile);
 					pmanager.addProfile(profile);
 				} else {
 				} else {
 					pmanager.persistProfile(profile);
 					pmanager.persistProfile(profile);
@@ -96,7 +107,7 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
 		prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
 
 
 		String pname = "",
 		String pname = "",
-			   pimage = "",
+			   pimage = null,
 			   pdesc = "";
 			   pdesc = "";
 
 
 		if(profile != null){
 		if(profile != null){
@@ -119,6 +130,9 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 
 		if(profile != null){
 		if(profile != null){
 			pref.setIcon(profile.getIconDrawable());
 			pref.setIcon(profile.getIconDrawable());
+			profileProtocols = new HashMap<String, Boolean>(profile.mActiveProtocols);
+		} else {
+			profileProtocols = new HashMap<String, Boolean>();
 		}
 		}
 
 
 		pref.setOnPreferenceClickListener(
 		pref.setOnPreferenceClickListener(
@@ -139,12 +153,35 @@ public class ProfileEditFragment extends PreferenceFragment implements
 			findPreference("pref_profile_general_name").setSummary(profile.mLabel);
 			findPreference("pref_profile_general_name").setSummary(profile.mLabel);
 			findPreference("pref_profile_general_description").setSummary(profile.mText);
 			findPreference("pref_profile_general_description").setSummary(profile.mText);
 		}
 		}
+
+		if(profile == null || profile.isEditable()){
+			getPreferenceScreen().removePreference(findPreference("pref_profile_warning"));
+		}
+
+		PreferenceCategory protocolsCategory = (PreferenceCategory) findPreference("pref_profile_protocols_settings");
+		String[] protocols = getResources().getStringArray(R.array.protocols);
+		String[] protocols_summary = getResources().getStringArray(R.array.protocols_description);
+
+		for(int i = 0; i<protocols.length; i++){
+			prefs.putBoolean("pref_profile_protocol_" + protocols[i], profile != null && profile.isProtocolActive(protocols[i]));
+			prefs.commit();
+
+			CheckBoxPreference check = new CheckBoxPreference(getActivity());
+			check.setTitle(protocols[i]);
+			check.setKey("pref_profile_protocol_" + protocols[i]);
+			check.setSummary(protocols_summary[i]);
+			//check.setChecked(profile != null && profile.isProtocolActive(protocols[i]));
+			//System.out.println("-----------------_> " + profile.isProtocolActive(protocols[i]) + " :: " + protocols[i]);
+			protocolsCategory.addPreference(check);
+		}
 	}
 	}
 
 
 	public Profile getProfile(){
 	public Profile getProfile(){
 		ProfileManager pmanager = ProfileManager.getInstance();
 		ProfileManager pmanager = ProfileManager.getInstance();
 
 
 		Intent intent = getActivity().getIntent();
 		Intent intent = getActivity().getIntent();
+		//Profile profile = (Profile) intent.getSerializableExtra("profile");
+
 		int profile_id = intent.getIntExtra("profile_id", -1);
 		int profile_id = intent.getIntExtra("profile_id", -1);
 
 
 		if(profile_id != -1){
 		if(profile_id != -1){
@@ -182,6 +219,9 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 
 		if(p instanceof EditTextPreference){
 		if(p instanceof EditTextPreference){
 			p.setSummary(sharedPreferences.getString(key, ""));
 			p.setSummary(sharedPreferences.getString(key, ""));
+		} else if(p instanceof CheckBoxPreference){
+			profileProtocols.put(p.getTitle().toString(), ((CheckBoxPreference) p).isChecked());
+			//System.out.println("------------------------------- P: " + ((CheckBoxPreference) p).isChecked());
 		}
 		}
 	}
 	}
 
 

+ 26 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -38,6 +38,7 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.interfaces.UpNavigatible;
 import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
 import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
@@ -45,7 +46,8 @@ import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
 
 
-public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
+public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener,
+		UpNavigatible {
 	static final String SELECTED_KEY = "Selected";
 	static final String SELECTED_KEY = "Selected";
 	static final String OTHERS_KEY = "Other";
 	static final String OTHERS_KEY = "Other";
 
 
@@ -788,4 +790,27 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
         }
         }
 
 
     }
     }
+
+	private Class<?> upFragment;
+	private boolean isUpNavigatible = false;
+
+	@Override
+	public Class<?> getUpFragment() {
+		return upFragment;
+	}
+
+	@Override
+	public void setUpFragment( Class<?> upFragment) {
+		this.upFragment = upFragment;
+	}
+
+	@Override
+	public boolean isUpNavigatible() {
+		return isUpNavigatible;
+	}
+
+	@Override
+	public void setUpNavigatible(boolean isUpNavigatible) {
+		this.isUpNavigatible = isUpNavigatible;
+	}
 }
 }

+ 72 - 55
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -20,10 +20,11 @@ import android.widget.Switch;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 
+import de.tudarmstadt.informatik.hostage.HoneyHandler;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
 import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
@@ -54,6 +55,8 @@ public class ServicesFragment extends Fragment{
 
 
 	private SharedPreferences mConnectionInfo;
 	private SharedPreferences mConnectionInfo;
 
 
+	private boolean mReceiverRegistered = false;
+
 
 
 	private void assignViews(){
 	private void assignViews(){
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
@@ -76,6 +79,10 @@ public class ServicesFragment extends Fragment{
 			mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 			mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 		}
 		}
 		else {
 		else {
+			if(MainActivity.getInstance().getHoneyService().hasRunningListeners()){
+				setStateActive();
+			}
+
 			mServicesTextName.setText(HelperUtils.getSSID(getActivity()));
 			mServicesTextName.setText(HelperUtils.getSSID(getActivity()));
 		}
 		}
 
 
@@ -83,22 +90,34 @@ public class ServicesFragment extends Fragment{
 	public ServicesFragment(){}
 	public ServicesFragment(){}
 
 
 	private void registerBroadcastReceiver(){
 	private void registerBroadcastReceiver(){
-		mReceiver = new BroadcastReceiver() {
-			@Override
-			public void onReceive(Context context, Intent intent) {
+		if(!mReceiverRegistered){
+			mReceiver = new BroadcastReceiver() {
+				@Override
+				public void onReceive(Context context, Intent intent) {
+					String sender = intent.getStringExtra("SENDER");
+					String[] values = intent.getStringArrayExtra("VALUES");
+
+					if(sender.equals(HoneyHandler.class.getName()) && values[0].equals(getString(R.string.broadcast_started))){
+						for(ServicesListItem item: protocolList){
+							if(item.protocol.equals(values[1])){
+								item.attacks = dbh.numBssidSeen(item.protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
+							}
+						}
+					}
 
 
-				for(int i = 0; i < protocols.length; i++ ){
-					protocolList.get(i).attacks = String.valueOf(dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null)));
-				}
-				if (!MainActivity.getInstance().getHoneyService().hasRunningListeners()) {
-					setStateNotActive();
+					if (!MainActivity.getInstance().getHoneyService().hasRunningListeners()) {
+						setStateNotActive();
+					} else {
+						setStateActive();
+					}
+
+					adapter.notifyDataSetChanged();
 				}
 				}
-				adapter.notifyDataSetChanged();
-			}
-		};
+			};
 
 
-		LocalBroadcastManager
-				.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
+			LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
+			this.mReceiverRegistered = true;
+		}
 	}
 	}
 
 
 	@Override
 	@Override
@@ -117,57 +136,50 @@ public class ServicesFragment extends Fragment{
 		ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
 		ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
 
 
 		protocolList= new ArrayList<ServicesListItem>();
 		protocolList= new ArrayList<ServicesListItem>();
-
+		int i=0;
 		for(String protocol: protocols){
 		for(String protocol: protocols){
 			protocolList.add(new ServicesListItem(protocol));
 			protocolList.add(new ServicesListItem(protocol));
-			if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
-				setStateActive();
-			}
+			protocolList.get(i).attacks = dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
+			i++;
 		}
 		}
-		for(int i=0; i < protocols.length; i++){
-
-			protocolList.get(i).attacks = String.valueOf(dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null)));
-		//	protocolList.get(i).initialValue = Integer.valueOf(protocolList.get(i).attacks);
-		}
-		adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
-		adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
-		list.setAdapter(adapter);
-
-		registerBroadcastReceiver();
 
 
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 
 
-		if(switchChangeListener == null){
+		if (switchChangeListener == null) {
 			switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
 			switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
 				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-					if(!HelperUtils.isWifiConnected(getActivity())){
+					if (!HelperUtils.isWifiConnected(getActivity())) {
 						new AlertDialog.Builder(getActivity())
 						new AlertDialog.Builder(getActivity())
 								.setTitle(R.string.information)
 								.setTitle(R.string.information)
 								.setMessage(R.string.wifi_not_connected_msg)
 								.setMessage(R.string.wifi_not_connected_msg)
-								.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-									public void onClick(DialogInterface dialog, int which) {
+								.setPositiveButton(android.R.string.ok,
+										new DialogInterface.OnClickListener() {
+											public void onClick(DialogInterface dialog, int which) {
 
 
-									}
-								})
+											}
+										})
 								.setIcon(android.R.drawable.ic_dialog_info)
 								.setIcon(android.R.drawable.ic_dialog_info)
 								.show();
 								.show();
 
 
-
 						setStateNotActive();
 						setStateNotActive();
 						setStateNotConnected();
 						setStateNotConnected();
 					} else {
 					} else {
-						if(isChecked){
-							for(String protocol: protocols){
-								if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
-									MainActivity.getInstance().getHoneyService().startListener(protocol);
+						if (MainActivity.getInstance().isServiceBound()) {
+							if (isChecked) {
+								for (String protocol : protocols) {
+									if (!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
+										System.out.println(
+												"SERVICESFRAGMENT starts LISTENER for PROTO:"
+														+ protocol);
+										MainActivity.getInstance().getHoneyService().startListener(protocol);
+									}
 								}
 								}
+								setStateActive();
+							} else {
+								MainActivity.getInstance().getHoneyService().stopListeners();
+								MainActivity.getInstance().stopAndUnbind();
+								setStateNotActive();
 							}
 							}
-							setStateActive();
-						} else {
-							MainActivity.getInstance().getHoneyService().stopListeners();
-							MainActivity.getInstance().stopAndUnbind();
-
-							setStateNotActive();
 						}
 						}
 					}
 					}
 				}
 				}
@@ -176,7 +188,11 @@ public class ServicesFragment extends Fragment{
 		}
 		}
 		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 
 
+		adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
+		adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
+		list.setAdapter(adapter);
 
 
+		registerBroadcastReceiver();
 
 
 		return rootView;
 		return rootView;
 
 
@@ -186,17 +202,14 @@ public class ServicesFragment extends Fragment{
 	public void onStart(){
 	public void onStart(){
 		super.onStart();
 		super.onStart();
 		registerBroadcastReceiver();
 		registerBroadcastReceiver();
-	}
-
-	@Override
-	public void onStop(){
-		super.onStop();
-		unregisterBroadcastReceiver();
-
+		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 	}
 	}
 
 
 	private void unregisterBroadcastReceiver(){
 	private void unregisterBroadcastReceiver(){
-		LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+		if(mReceiverRegistered){
+			LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+			this.mReceiverRegistered = false;
+		}
 	}
 	}
 
 
 	private void setStateActive() {
 	private void setStateActive() {
@@ -209,13 +222,17 @@ public class ServicesFragment extends Fragment{
 
 
 	private void setStateNotActive() {
 	private void setStateNotActive() {
 		mServicesSwitchService.setChecked(false);
 		mServicesSwitchService.setChecked(false);
-
 	}
 	}
 
 
+	@Override
+	public void onStop(){
+		super.onStop();
+		mServicesSwitchService.setOnCheckedChangeListener(null);
+	}
 	@Override
 	@Override
 	public void onDestroy(){
 	public void onDestroy(){
 		super.onDestroy();
 		super.onDestroy();
-		LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+		unregisterBroadcastReceiver();
 	}
 	}
 
 
 }
 }

+ 24 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java

@@ -10,12 +10,13 @@ import android.widget.TextView;
 
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.interfaces.UpNavigatible;
 
 
 /**
 /**
  * @author Alexander Brakowski
  * @author Alexander Brakowski
  * @created 24.02.14 23:37
  * @created 24.02.14 23:37
  */
  */
-public class SettingsFragment extends Fragment {
+public class SettingsFragment extends Fragment implements UpNavigatible {
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 		super.onCreateView(inflater, container, savedInstanceState);
 		super.onCreateView(inflater, container, savedInstanceState);
 		getActivity().setTitle(getResources().getString(R.string.drawer_settings));
 		getActivity().setTitle(getResources().getString(R.string.drawer_settings));
@@ -49,4 +50,26 @@ public class SettingsFragment extends Fragment {
 		FragmentManager manager = this.getFragmentManager();
 		FragmentManager manager = this.getFragmentManager();
 		manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit();
 		manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit();
 	}
 	}
+
+	private Class<?> upFrag;
+	private boolean isUpNav = false;
+	@Override
+	public Class<?> getUpFragment() {
+		return upFrag;
+	}
+
+	@Override
+	public void setUpFragment(Class<?> upFragment) {
+		this.upFrag = upFragment;
+	}
+
+	@Override
+	public boolean isUpNavigatible() {
+		return isUpNav;
+	}
+
+	@Override
+	public void setUpNavigatible(boolean isUpNavigatible) {
+		isUpNav = isUpNavigatible;
+	}
 }
 }

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -1450,11 +1450,12 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
 
         if (fm != null){
         if (fm != null){
             RecordOverviewFragment newFragment = new RecordOverviewFragment();
             RecordOverviewFragment newFragment = new RecordOverviewFragment();
+	        newFragment.setUpNavigatible(true);
             newFragment.setFilter(filter);
             newFragment.setFilter(filter);
 
 
             if (sortKey != null && sortKey.length() != 0) newFragment.setGroupKey(sortKey);
             if (sortKey != null && sortKey.length() != 0) newFragment.setGroupKey(sortKey);
 
 
-            MainActivity.getInstance().injectFragment(newFragment, true, MainActivity.MainMenuItem.RECORDS);
+            MainActivity.getInstance().injectFragment(newFragment);
 
 
         }
         }
 
 

+ 20 - 9
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ThreatMapFragment.java

@@ -1,6 +1,8 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 
+import android.app.Activity;
 import android.app.Fragment;
 import android.app.Fragment;
+import android.app.FragmentManager;
 import android.graphics.Color;
 import android.graphics.Color;
 import android.location.Location;
 import android.location.Location;
 import android.os.Bundle;
 import android.os.Bundle;
@@ -231,8 +233,8 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 
 
 				sMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
 				sMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
 				Marker marker = sMap.addMarker(new MarkerOptions()
 				Marker marker = sMap.addMarker(new MarkerOptions()
-						.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? " attack"
-								: " attacks")).position(
+						.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? getResources().getString(R.string.attack)
+								: getResources().getString(R.string.attacks))).position(
 								center));
 								center));
 
 
 				sMarkerIDToSSID.put(marker.getId(), ssid);
 				sMarkerIDToSSID.put(marker.getId(), ssid);
@@ -251,9 +253,9 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 	 * view must be removed if this object has been created once before
 	 * view must be removed if this object has been created once before
 	 * that is why view is static
 	 * that is why view is static
 	 *
 	 *
-	 * @param inflater
-	 * @param container
-	 * @param savedInstanceState
+	 * @param inflater the inflater
+	 * @param container the container
+	 * @param savedInstanceState the savedInstanceState
 	 * @return the view
 	 * @return the view
 	 */
 	 */
 	@Override
 	@Override
@@ -261,7 +263,10 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 	                         Bundle savedInstanceState) {
 	                         Bundle savedInstanceState) {
 		super.onCreateView(inflater, container, savedInstanceState);
 		super.onCreateView(inflater, container, savedInstanceState);
 
 
-		getActivity().setTitle(getResources().getString(R.string.drawer_threat_map));
+		final Activity activity = getActivity();
+		if (activity != null) {
+			activity.setTitle(getResources().getString(R.string.drawer_threat_map));
+		}
 
 
 		if (sView != null) {
 		if (sView != null) {
 			ViewGroup parent = (ViewGroup) sView.getParent();
 			ViewGroup parent = (ViewGroup) sView.getParent();
@@ -272,9 +277,15 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 		try {
 		try {
 			sView = inflater.inflate(R.layout.fragment_threatmap, container, false);
 			sView = inflater.inflate(R.layout.fragment_threatmap, container, false);
 			if (isGooglePlay()) {
 			if (isGooglePlay()) {
-				sMap = ((MapFragment) getFragmentManager()
-						.findFragmentById(R.id.threatmapfragment)).getMap();
-				populateMap();
+				final FragmentManager fragmentManager = getFragmentManager();
+				if (fragmentManager != null) {
+					final MapFragment mapFragment = (MapFragment) getFragmentManager()
+							.findFragmentById(R.id.threatmapfragment);
+					if (mapFragment != null) {
+						sMap = mapFragment.getMap();
+						populateMap();
+					}
+				}
 			}
 			}
 		} catch (InflateException e) {
 		} catch (InflateException e) {
         	// map already exists
         	// map already exists

+ 14 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/interfaces/UpNavigatible.java

@@ -0,0 +1,14 @@
+package de.tudarmstadt.informatik.hostage.ui2.fragment.interfaces;
+
+import android.app.Fragment;
+
+/**
+ * @author Alexander Brakowski
+ * @created 12.03.14 16:20
+ */
+public interface UpNavigatible {
+	public Class<?> getUpFragment();
+	public void setUpFragment(Class<?> upFragment);
+	public boolean isUpNavigatible();
+	public void setUpNavigatible(boolean isUpNavigatible);
+}

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/opengl/HomeGLSurfaceView.java

@@ -24,7 +24,7 @@ public class HomeGLSurfaceView extends GLSurfaceView {
 	}
 	}
 	
 	
 	// TODO: just for testing -> remove this eventually
 	// TODO: just for testing -> remove this eventually
-	@Override
+	/*@Override
 	public boolean onTouchEvent(MotionEvent event) {
 	public boolean onTouchEvent(MotionEvent event) {
 		if (event.getAction() == MotionEvent.ACTION_DOWN) {
 		if (event.getAction() == MotionEvent.ACTION_DOWN) {
 			ThreatIndicatorGLRenderer.ThreatLevel threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT;
 			ThreatIndicatorGLRenderer.ThreatLevel threatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT;
@@ -33,5 +33,5 @@ public class HomeGLSurfaceView extends GLSurfaceView {
 			ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
 			ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
 		}
 		}
 		return false;
 		return false;
-	}
+	}*/
 }
 }

+ 0 - 1
src/de/tudarmstadt/informatik/hostage/ui2/helper/ColorSequenceGenerator.java

@@ -1,7 +1,6 @@
 package de.tudarmstadt.informatik.hostage.ui2.helper;
 package de.tudarmstadt.informatik.hostage.ui2.helper;
 
 
 import android.graphics.Color;
 import android.graphics.Color;
-import android.util.Log;
 
 
 /**
 /**
  * Idea from http://ridiculousfish.com/blog/posts/colors.html
  * Idea from http://ridiculousfish.com/blog/posts/colors.html

+ 326 - 0
src/de/tudarmstadt/informatik/hostage/ui2/layouts/FlowLayout.java

@@ -0,0 +1,326 @@
+package de.tudarmstadt.informatik.hostage.ui2.layouts;
+
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import de.tudarmstadt.informatik.hostage.R;
+
+public class FlowLayout extends ViewGroup {
+	public static final int HORIZONTAL = 0;
+	public static final int VERTICAL = 1;
+	private int horizontalSpacing = 0;
+	private int verticalSpacing = 0;
+	private int orientation = 0;
+	private boolean debugDraw = false;
+
+	public FlowLayout(Context context) {
+		super(context);
+
+		this.readStyleParameters(context, null);
+	}
+
+	public FlowLayout(Context context, AttributeSet attributeSet) {
+		super(context, attributeSet);
+
+		this.readStyleParameters(context, attributeSet);
+	}
+
+	public FlowLayout(Context context, AttributeSet attributeSet, int defStyle) {
+		super(context, attributeSet, defStyle);
+
+		this.readStyleParameters(context, attributeSet);
+	}
+
+	@Override
+	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+		int sizeWidth = MeasureSpec.getSize(widthMeasureSpec) - this.getPaddingRight() - this.getPaddingLeft();
+		int sizeHeight = MeasureSpec.getSize(heightMeasureSpec) - this.getPaddingTop() - this.getPaddingBottom();
+
+		int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
+		int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
+
+		int size;
+		int mode;
+
+		if (orientation == HORIZONTAL) {
+			size = sizeWidth;
+			mode = modeWidth;
+		} else {
+			size = sizeHeight;
+			mode = modeHeight;
+		}
+
+		int lineThicknessWithSpacing = 0;
+		int lineThickness = 0;
+		int lineLengthWithSpacing = 0;
+		int lineLength;
+
+		int prevLinePosition = 0;
+
+		int controlMaxLength = 0;
+		int controlMaxThickness = 0;
+
+		final int count = getChildCount();
+		for (int i = 0; i < count; i++) {
+			final View child = getChildAt(i);
+			if (child.getVisibility() == GONE) {
+				continue;
+			}
+
+			LayoutParams lp = (LayoutParams) child.getLayoutParams();
+
+			child.measure(
+					getChildMeasureSpec(widthMeasureSpec, this.getPaddingLeft() + this.getPaddingRight(), lp.width),
+					getChildMeasureSpec(heightMeasureSpec, this.getPaddingTop() + this.getPaddingBottom(), lp.height)
+			);
+
+			int hSpacing = this.getHorizontalSpacing(lp);
+			int vSpacing = this.getVerticalSpacing(lp);
+
+			int childWidth = child.getMeasuredWidth();
+			int childHeight = child.getMeasuredHeight();
+
+			int childLength;
+			int childThickness;
+			int spacingLength;
+			int spacingThickness;
+
+			if (orientation == HORIZONTAL) {
+				childLength = childWidth;
+				childThickness = childHeight;
+				spacingLength = hSpacing;
+				spacingThickness = vSpacing;
+			} else {
+				childLength = childHeight;
+				childThickness = childWidth;
+				spacingLength = vSpacing;
+				spacingThickness = hSpacing;
+			}
+
+			lineLength = lineLengthWithSpacing + childLength;
+			lineLengthWithSpacing = lineLength + spacingLength;
+
+			boolean newLine = lp.newLine || (mode != MeasureSpec.UNSPECIFIED && lineLength > size);
+			if (newLine) {
+				prevLinePosition = prevLinePosition + lineThicknessWithSpacing;
+
+				lineThickness = childThickness;
+				lineLength = childLength;
+				lineThicknessWithSpacing = childThickness + spacingThickness;
+				lineLengthWithSpacing = lineLength + spacingLength;
+			}
+
+			lineThicknessWithSpacing = Math.max(lineThicknessWithSpacing, childThickness + spacingThickness);
+			lineThickness = Math.max(lineThickness, childThickness);
+
+			int posX;
+			int posY;
+			if (orientation == HORIZONTAL) {
+				posX = getPaddingLeft() + lineLength - childLength;
+				posY = getPaddingTop() + prevLinePosition;
+			} else {
+				posX = getPaddingLeft() + prevLinePosition;
+				posY = getPaddingTop() + lineLength - childHeight;
+			}
+			lp.setPosition(posX, posY);
+
+			controlMaxLength = Math.max(controlMaxLength, lineLength);
+			controlMaxThickness = prevLinePosition + lineThickness;
+		}
+
+        /* need to take paddings into account */
+		if (orientation == HORIZONTAL) {
+			controlMaxLength += getPaddingLeft() + getPaddingRight();
+			controlMaxThickness += getPaddingBottom() + getPaddingTop();
+		} else {
+			controlMaxLength += getPaddingBottom() + getPaddingTop();
+			controlMaxThickness += getPaddingLeft() + getPaddingRight();
+		}
+
+		if (orientation == HORIZONTAL) {
+			this.setMeasuredDimension(resolveSize(controlMaxLength, widthMeasureSpec), resolveSize(controlMaxThickness, heightMeasureSpec));
+		} else {
+			this.setMeasuredDimension(resolveSize(controlMaxThickness, widthMeasureSpec), resolveSize(controlMaxLength, heightMeasureSpec));
+		}
+	}
+
+	private int getVerticalSpacing(LayoutParams lp) {
+		int vSpacing;
+		if (lp.verticalSpacingSpecified()) {
+			vSpacing = lp.verticalSpacing;
+		} else {
+			vSpacing = this.verticalSpacing;
+		}
+		return vSpacing;
+	}
+
+	private int getHorizontalSpacing(LayoutParams lp) {
+		int hSpacing;
+		if (lp.horizontalSpacingSpecified()) {
+			hSpacing = lp.horizontalSpacing;
+		} else {
+			hSpacing = this.horizontalSpacing;
+		}
+		return hSpacing;
+	}
+
+	@Override
+	protected void onLayout(boolean changed, int l, int t, int r, int b) {
+		final int count = getChildCount();
+		for (int i = 0; i < count; i++) {
+			View child = getChildAt(i);
+			LayoutParams lp = (LayoutParams) child.getLayoutParams();
+			child.layout(lp.x, lp.y, lp.x + child.getMeasuredWidth(), lp.y + child.getMeasuredHeight());
+		}
+	}
+
+	@Override
+	protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
+		boolean more = super.drawChild(canvas, child, drawingTime);
+		this.drawDebugInfo(canvas, child);
+		return more;
+	}
+
+	@Override
+	protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
+		return p instanceof LayoutParams;
+	}
+
+	@Override
+	protected LayoutParams generateDefaultLayoutParams() {
+		return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+	}
+
+	@Override
+	public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
+		return new LayoutParams(getContext(), attributeSet);
+	}
+
+	@Override
+	protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
+		return new LayoutParams(p);
+	}
+
+	private void readStyleParameters(Context context, AttributeSet attributeSet) {
+		TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout);
+		try {
+			horizontalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_horizontalSpacing, 0);
+			verticalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_verticalSpacing, 0);
+			orientation = a.getInteger(R.styleable.FlowLayout_orientation, HORIZONTAL);
+			debugDraw = a.getBoolean(R.styleable.FlowLayout_debugDraw, false);
+		} finally {
+			a.recycle();
+		}
+	}
+
+	private void drawDebugInfo(Canvas canvas, View child) {
+		if (!debugDraw) {
+			return;
+		}
+
+		Paint childPaint = this.createPaint(0xffffff00);
+		Paint layoutPaint = this.createPaint(0xff00ff00);
+		Paint newLinePaint = this.createPaint(0xffff0000);
+
+		LayoutParams lp = (LayoutParams) child.getLayoutParams();
+
+		if (lp.horizontalSpacing > 0) {
+			float x = child.getRight();
+			float y = child.getTop() + child.getHeight() / 2.0f;
+			canvas.drawLine(x, y, x + lp.horizontalSpacing, y, childPaint);
+			canvas.drawLine(x + lp.horizontalSpacing - 4.0f, y - 4.0f, x + lp.horizontalSpacing, y, childPaint);
+			canvas.drawLine(x + lp.horizontalSpacing - 4.0f, y + 4.0f, x + lp.horizontalSpacing, y, childPaint);
+		} else if (this.horizontalSpacing > 0) {
+			float x = child.getRight();
+			float y = child.getTop() + child.getHeight() / 2.0f;
+			canvas.drawLine(x, y, x + this.horizontalSpacing, y, layoutPaint);
+			canvas.drawLine(x + this.horizontalSpacing - 4.0f, y - 4.0f, x + this.horizontalSpacing, y, layoutPaint);
+			canvas.drawLine(x + this.horizontalSpacing - 4.0f, y + 4.0f, x + this.horizontalSpacing, y, layoutPaint);
+		}
+
+		if (lp.verticalSpacing > 0) {
+			float x = child.getLeft() + child.getWidth() / 2.0f;
+			float y = child.getBottom();
+			canvas.drawLine(x, y, x, y + lp.verticalSpacing, childPaint);
+			canvas.drawLine(x - 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
+			canvas.drawLine(x + 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
+		} else if (this.verticalSpacing > 0) {
+			float x = child.getLeft() + child.getWidth() / 2.0f;
+			float y = child.getBottom();
+			canvas.drawLine(x, y, x, y + this.verticalSpacing, layoutPaint);
+			canvas.drawLine(x - 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
+			canvas.drawLine(x + 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
+		}
+
+		if (lp.newLine) {
+			if (orientation == HORIZONTAL) {
+				float x = child.getLeft();
+				float y = child.getTop() + child.getHeight() / 2.0f;
+				canvas.drawLine(x, y - 6.0f, x, y + 6.0f, newLinePaint);
+			} else {
+				float x = child.getLeft() + child.getWidth() / 2.0f;
+				float y = child.getTop();
+				canvas.drawLine(x - 6.0f, y, x + 6.0f, y, newLinePaint);
+			}
+		}
+	}
+
+	private Paint createPaint(int color) {
+		Paint paint = new Paint();
+		paint.setAntiAlias(true);
+		paint.setColor(color);
+		paint.setStrokeWidth(2.0f);
+		return paint;
+	}
+
+	public static class LayoutParams extends ViewGroup.LayoutParams {
+		private static int NO_SPACING = -1;
+		private int x;
+		private int y;
+		private int horizontalSpacing = NO_SPACING;
+		private int verticalSpacing = NO_SPACING;
+		private boolean newLine = false;
+
+		public LayoutParams(Context context, AttributeSet attributeSet) {
+			super(context, attributeSet);
+			this.readStyleParameters(context, attributeSet);
+		}
+
+		public LayoutParams(int width, int height) {
+			super(width, height);
+		}
+
+		public LayoutParams(ViewGroup.LayoutParams layoutParams) {
+			super(layoutParams);
+		}
+
+		public boolean horizontalSpacingSpecified() {
+			return horizontalSpacing != NO_SPACING;
+		}
+
+		public boolean verticalSpacingSpecified() {
+			return verticalSpacing != NO_SPACING;
+		}
+
+		public void setPosition(int x, int y) {
+			this.x = x;
+			this.y = y;
+		}
+
+		private void readStyleParameters(Context context, AttributeSet attributeSet) {
+			TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout_LayoutParams);
+			try {
+				horizontalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_LayoutParams_layout_horizontalSpacing, NO_SPACING);
+				verticalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_LayoutParams_layout_verticalSpacing, NO_SPACING);
+				newLine = a.getBoolean(R.styleable.FlowLayout_LayoutParams_layout_newLine, false);
+			} finally {
+				a.recycle();
+			}
+		}
+	}
+}

+ 1 - 2
src/de/tudarmstadt/informatik/hostage/ui2/model/ServicesListItem.java

@@ -5,8 +5,7 @@ package de.tudarmstadt.informatik.hostage.ui2.model;
  */
  */
 public class ServicesListItem {
 public class ServicesListItem {
 	public String protocol;
 	public String protocol;
-	public String attacks;
-	public static int initialValue;
+	public int attacks;
 
 
 	public boolean activated;
 	public boolean activated;