Browse Source

Moved Strings from MainActivity to ressources
Resctructered Strings in ressources
Moved Methods to get and set connection Information from MainActivity to
HoneyService

Light indicator not correct anymore
HoneyHandler does not send broadcast when closed

Lars 10 years ago
parent
commit
ee92b061bc

+ 3 - 3
AndroidManifest.xml

@@ -53,15 +53,15 @@
         </activity>
         <activity
             android:name="de.tudarmstadt.informatik.hostage.ui.AboutActivity"
-            android:label="@string/action_about" >
+            android:label="@string/gui_action_about" >
         </activity>
         <activity
             android:name="de.tudarmstadt.informatik.hostage.ui.PlayGroundActivity"
-            android:label="@string/playground" >
+            android:label="@string/gui_playground" >
         </activity>
         <activity
             android:name="de.tudarmstadt.informatik.hostage.sync.NFCSync"
-            android:label="@string/playground" >
+            android:label="@string/gui_playground" >
             <intent-filter>
                 <action android:name="android.nfc.action.NDEF_DISCOVERED" />
 

+ 10 - 10
res/layout/activity_main.xml

@@ -23,7 +23,7 @@
                 android:layout_height="wrap_content"
                 android:layout_above="@+id/imageViewLight"
                 android:layout_centerHorizontal="true"
-                android:text="@string/status"
+                android:text="@string/gui_status"
                 android:textAppearance="?android:attr/textAppearanceLarge" />
 
             <ImageView
@@ -40,7 +40,7 @@
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true"
                 android:layout_alignParentLeft="true"
-                android:text="@string/paranoid" />
+                android:text="@string/gui_paranoid" />
 
             <ToggleButton
                 android:id="@+id/toggleButtonOnOff"
@@ -49,8 +49,8 @@
                 android:layout_alignParentBottom="true"
                 android:layout_alignParentRight="true"
                 android:onClick="buttonOnOffClick"
-                android:textOff="@string/capital_off"
-                android:textOn="@string/capital_on" />
+                android:textOff="@string/gui_capital_off"
+                android:textOn="@string/gui_capital_on" />
 
             <Button
                 android:id="@+id/buttonShowLog"
@@ -81,7 +81,7 @@
                 android:id="@+id/textViewDetails"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/details"
+                android:text="@string/gui_details"
                 android:textAppearance="?android:attr/textAppearanceLarge" />
 
             <LinearLayout
@@ -93,7 +93,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:paddingLeft="20dp"
-                    android:text="@string/ssid"
+                    android:text="@string/gui_ssid"
                     android:textAppearance="?android:attr/textAppearanceMedium" />
 
                 <TextView
@@ -114,7 +114,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:paddingLeft="20dp"
-                    android:text="@string/bssid"
+                    android:text="@string/gui_bssid"
                     android:textAppearance="?android:attr/textAppearanceMedium" />
 
                 <TextView
@@ -135,7 +135,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:paddingLeft="20dp"
-                    android:text="@string/internal_ip"
+                    android:text="@string/gui_internal_ip"
                     android:textAppearance="?android:attr/textAppearanceMedium" />
 
                 <TextView
@@ -156,7 +156,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:paddingLeft="20dp"
-                    android:text="@string/external_ip"
+                    android:text="@string/gui_external_ip"
                     android:textAppearance="?android:attr/textAppearanceMedium" />
 
                 <TextView
@@ -172,7 +172,7 @@
                 android:id="@+id/TextViewServices"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/services"
+                android:text="@string/gui_services"
                 android:textAppearance="?android:attr/textAppearanceLarge" />
 
             <ListView

+ 4 - 4
res/layout/activity_viewlog.xml

@@ -17,7 +17,7 @@
             android:id="@+id/textStatistics"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/statistics"
+            android:text="@string/gui_statistics"
             android:textAppearance="?android:attr/textAppearanceLarge" />
 
         <TableLayout
@@ -36,7 +36,7 @@
                 android:id="@+id/textFirstAttack"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/firstAttack"
+                android:text="@string/gui_firstAttack"
                 android:textAppearance="?android:attr/textAppearanceMedium" />
 
             <TextView
@@ -57,7 +57,7 @@
                 android:id="@+id/textLastAttack"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/lastAttack"
+                android:text="@string/gui_lastAttack"
                 android:textAppearance="?android:attr/textAppearanceMedium" />
 
             <TextView
@@ -73,7 +73,7 @@
             android:id="@+id/textLogFile"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/log_actions"
+            android:text="@string/gui_log_actions"
             android:textAppearance="?android:attr/textAppearanceLarge" />
 
         <LinearLayout

+ 1 - 1
res/layout/list_view_protocols_row.xml

@@ -30,7 +30,7 @@
                 android:id="@+id/textViewConnections"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/connections"
+                android:text="@string/gui_connections"
                 android:textAppearance="?android:attr/textAppearanceSmall" />
 
             <TextView

+ 2 - 2
res/menu/main.xml

@@ -4,12 +4,12 @@
         android:id="@+id/action_settings"
         android:orderInCategory="100"
         android:showAsAction="never"
-        android:title="@string/action_settings"/>
+        android:title="@string/gui_action_settings"/>
     
     <item
         android:id="@+id/action_about"
         android:orderInCategory="100"
         android:showAsAction="never"
-        android:title="@string/action_about"/>
+        android:title="@string/gui_action_about"/>
 
 </menu>

+ 0 - 26
res/values/strings.xml

@@ -1,34 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 
-    <string name="action_about">About</string>
-    <string name="action_settings">Settings</string>
     <string name="app_name">HosTaGe</string>
-    <string name="bssid">BSSID:</string>
-    <string name="cancel">Cancel</string>
-    <string name="capital_off">ON</string>
-    <string name="capital_on">OFF</string>
-    <string name="clear">Clear</string>
-    <string name="connections">Recorded connections:</string>
-    <string name="database">Database</string>
-    <string name="delete">Delete</string>
-    <string name="delete_dialog_title">Delete data sets by:</string>
-    <string name="details">Connection info</string>
-    <string name="dialog_clear_database">Clear all data?</string>
-    <string name="dialog_clear_database_date">Delete all data before:</string>
-    <string name="export_dialog_title">Choose Export Format</string>
-    <string name="external_ip">External IP:</string>
-    <string name="firstAttack">First Attack:</string>
-    <string name="internal_ip">Internal IP:</string>
-    <string name="lastAttack">Last Attack:</string>
-    <string name="log_actions">Actions</string>
-    <string name="paranoid">Paranoid Mode</string>
-    <string name="playground">Playground</string>
-    <string name="services">Services</string>
     <string name="shared_preference_path">de.tudarmstadt.informatik.hostage.preferences</string>
-    <string name="ssid">SSID:</string>
-    <string name="statistics">Statistics</string>
-    <string name="status">Status</string>
     <string name="UUID">9fc4f490-659e-11e3-949a-0800200c9a66</string>
     
 </resources>

+ 11 - 0
res/values/strings_broadcast.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    
+    <string name="broadcast">de.tudarmstadt.informatik.hostage.BROADCAST</string>    
+    <string name="broadcast_connectivity">de.tudarmstadt.informatik.hostage.BROADCAST.CONNECTIVITY_CHANGE</string>
+    <string name="broadcast_started">de.tudarmstadt.informatik.hostage.BROADCAST.STARTED</string>
+    <string name="broadcast_stopped">de.tudarmstadt.informatik.hostage.BROADCAST.STOPPED</string>
+
+    
+</resources>

+ 13 - 0
res/values/strings_connection_info.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    
+   
+    <string name="connection_info">de.tudarmstadt.informatik.hostage.CONNECTION_INFO</string>
+    <string name="connection_info_bssid">de.tudarmstadt.informatik.hostage.CONNECTION_INFO.BSSID</string>
+    <string name="connection_info_ssid">de.tudarmstadt.informatik.hostage.CONNECTION_INFO.SSID</string>
+    <string name="connection_info_internal_ip">de.tudarmstadt.informatik.hostage.CONNECTION_INFO.INTERNAL_IP</string>
+ 	<string name="connection_info_external_ip">de.tudarmstadt.informatik.hostage.CONNECTION_INFO.EXTERNAL_IP</string>  
+
+    
+</resources>

+ 31 - 0
res/values/strings_gui.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="gui_action_about">About</string>
+    <string name="gui_action_settings">Settings</string>
+    <string name="gui_bssid">BSSID:</string>
+    <string name="gui_cancel">Cancel</string>
+    <string name="gui_capital_off">ON</string>
+    <string name="gui_capital_on">OFF</string>
+    <string name="gui_clear">Clear</string>
+    <string name="gui_connections">Recorded connections:</string>
+    <string name="gui_database">Database</string>
+    <string name="gui_delete">Delete</string>
+    <string name="gui_delete_dialog_title">Delete data sets by:</string>
+    <string name="gui_details">Connection info</string>
+    <string name="gui_dialog_clear_database">Clear all data?</string>
+    <string name="gui_dialog_clear_database_date">Delete all data before:</string>
+    <string name="gui_export_dialog_title">Choose Export Format</string>
+    <string name="gui_external_ip">External IP:</string>
+    <string name="gui_firstAttack">First Attack:</string>
+    <string name="gui_internal_ip">Internal IP:</string>
+    <string name="gui_lastAttack">Last Attack:</string>
+    <string name="gui_log_actions">Actions</string>
+    <string name="gui_paranoid">Paranoid Mode</string>
+    <string name="gui_playground">Playground</string>
+    <string name="gui_services">Services</string>
+    <string name="gui_ssid">SSID:</string>
+    <string name="gui_statistics">Statistics</string>
+    <string name="gui_status">Status</string>
+    
+</resources>

+ 6 - 1
res/values/strings_preferences.xml

@@ -14,12 +14,17 @@
 	<string name="pref_vibration_summ">Enable Vibration</string>
 	<string name="pref_upload">Upload of Records</string>	
 	<string name="pref_upload_server">Server address</string>	
+	<string name="pref_connection_settings">Connection Settings</string>
 	<string name="pref_max_connections">Max Connections</string>	
 	<string name="pref_max_connections_default">5</string>	
 	<string name="pref_timeout">SocketTimeout(in seconds)</string>	
 	<string name="pref_timeout_default">30</string>	
 	<string name="pref_sleeptime">Stream Sleeptime(in mseconds)</string>
 	<string name="pref_sleeptime_default">500</string>
-	<string name="pref_connection_settings">Connection Settings</string>
+	<string name="pref_location_settings">Location Settings</string>
+	<string name="pref_location_time">Time to get Location Data(in mseconds)</string>
+	<string name="pref_location_time_default">60000</string>
+	<string name="pref_location_retries">Retries</string>
+	<string name="pref_location_retries_default">3</string>
 	
 </resources>

+ 13 - 1
res/xml/preferences.xml

@@ -11,7 +11,7 @@
         <EditTextPreference
             android:key="pref_external_location"
             android:dependency="pref_external_storage"
-            android:defaultValue="/HOsTaGe/LogFiles/"
+            android:defaultValue="/HosTaGe/LogFiles/"
             android:title="@string/pref_external_location_title"
             />
         
@@ -55,6 +55,18 @@
             android:defaultValue="@string/pref_sleeptime_default"
             android:title="@string/pref_sleeptime" />
     </PreferenceCategory>
+        <PreferenceCategory android:title="@string/pref_location_settings" >
+        <EditTextPreference
+            android:key="pref_location_time"
+            android:defaultValue="@string/pref_location_time_default"
+            android:title="@string/pref_location_time" />
+               
+          <EditTextPreference
+            android:key="pref_location_retries"
+            android:defaultValue="@string/pref_location_retries_default"
+            android:title="@string/pref_location_retries" />
+          
+    </PreferenceCategory>
 
 
 </PreferenceScreen>

+ 10 - 6
src/de/tudarmstadt/informatik/hostage/HoneyHandler.java

@@ -20,7 +20,6 @@ import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
@@ -39,6 +38,7 @@ public class HoneyHandler implements Runnable {
 	 */
 	private int SLEEPTIME;
 
+	private HoneyService service;
 	protected Protocol protocol;
 	private Socket client;
 	protected Thread thread;
@@ -70,15 +70,16 @@ public class HoneyHandler implements Runnable {
 		this.protocol = protocol;
 		this.client = client;
 		this.thread = new Thread(this);
+		service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_started), protocol.toString(), Integer.toString(listener.getPort())});
 		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(service);
 		SLEEPTIME = pref.getInt("sleeptime", 1); // 1 ms already removes ressource leak
 		TIMEOUT = pref.getInt("timeout", 30) * 1000;
 		// TODO ThreadSicher?
 		getAndIncrementAttackID(pref);
-		SharedPreferences sessionPref = service.getSharedPreferences(MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
-		BSSID = sessionPref.getString(MainActivity.BSSID, null);
-		SSID = sessionPref.getString(MainActivity.SSID, null);
-		externalIP = sessionPref.getString(MainActivity.EXTERNAL_IP, null);
+		SharedPreferences connInfo = service.getSharedPreferences(service.getString(R.string.connection_info), Context.MODE_PRIVATE);
+		BSSID = connInfo.getString(service.getString(R.string.connection_info_bssid), null);
+		SSID = connInfo.getString(service.getString(R.string.connection_info_ssid), null);
+		externalIP = connInfo.getString(service.getString(R.string.connection_info_external_ip), null);
 		setSoTimeout(client);
 		thread.start();
 	}
@@ -114,7 +115,6 @@ public class HoneyHandler implements Runnable {
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		Log.i("HoneyHandler", "Connection closed, close Socket and kill Thread");
 		kill();
 	}
 
@@ -122,12 +122,16 @@ public class HoneyHandler implements Runnable {
 	 * Sets the interrupt flag of the thread and tries to close the socket.
 	 */
 	public void kill() {
+		//TODO FIX NullPointer Exception
+		//service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_started),protocol.toString() ,Integer.toString(listener.getPort())});
 		thread.interrupt();
 		try {
 			client.close();
 			Log.i("HoneyHandler", "Socket closed: " + client.isClosed());
 		} catch (Exception e) {
 			e.printStackTrace();
+		} finally {
+
 		}
 		listener.refreshHandlers();
 	}

+ 3 - 7
src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -12,7 +12,6 @@ import javax.net.ssl.SSLSocketFactory;
 import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 
 /**
  * Protocol listener class:<br>
@@ -75,7 +74,6 @@ public class HoneyListener implements Runnable {
 		this.service = service;
 		this.protocol = protocol;
 		this.port = port;
-
 		conReg = new ConnectionRegister(service);
 	}
 
@@ -96,9 +94,9 @@ public class HoneyListener implements Runnable {
 		try {
 			server = new MyServerSocketFactory().createServerSocket(port);
 			if(server == null) return false;
-			(this.thread = new Thread(this)).start();
-			service.notifyUI(this.getClass().getName(), protocol.toString() + MainActivity.LISTENER);
+			(this.thread = new Thread(this)).start();			
 			running = true;
+			service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_started), protocol.toString(), Integer.toString(port)});
 			return true;
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -114,8 +112,8 @@ public class HoneyListener implements Runnable {
 		try {
 			server.close();
 			thread.interrupt();
-			service.notifyUI(this.getClass().getName(), protocol.toString() + MainActivity.LISTENER);
 			running = false;
+			service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_stopped), protocol.toString(), Integer.toString(port)});
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -149,7 +147,6 @@ public class HoneyListener implements Runnable {
 			if (handler.isTerminated()) {
 				conReg.closeConnection();
 				iterator.remove();
-				service.notifyUI(this.getClass().getName(), protocol.toString() + MainActivity.HANDLER_COUNT);
 			}
 		}
 	}
@@ -168,7 +165,6 @@ public class HoneyListener implements Runnable {
 				} else {
 					startHandler(client);
 				}
-				service.notifyUI(this.getClass().getName(), protocol.toString() + MainActivity.HANDLER_COUNT);
 			} catch (Exception e) {
 				e.printStackTrace();
 			}

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

@@ -94,7 +94,7 @@ public class HoneyService extends Service {
 		super.onCreate();
 		HoneyService.context = getApplicationContext();
 		implementedProtocols = getImplementedProtocols();
-		connectionInfo = getSharedPreferences(MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
+		connectionInfo = getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
 		connectionInfoEditor = connectionInfo.edit();
 		createNotification();
 		registerNetReceiver();
@@ -127,7 +127,6 @@ public class HoneyService extends Service {
 	 * class.
 	 */
 	private void getLocationData() {
-		// TODO Put time and attempts in settings
 		MyLocationManager locationManager = new MyLocationManager(this);
 		locationManager.getUpdates(60 * 1000, 3);
 	}
@@ -165,13 +164,13 @@ public class HoneyService extends Service {
 	private BroadcastReceiver netReceiver = new BroadcastReceiver() {
 		@Override
 		public void onReceive(Context context, Intent intent) {
-			String bssid_old = connectionInfo.getString(MainActivity.BSSID, "");
+			String bssid_old = connectionInfo.getString(getString(R.string.connection_info_bssid), "");
 			String bssid_new = HelperUtils.getBSSID(context);
 			if (bssid_new == null || !bssid_new.equals(bssid_old)) {
 				deleteConnectionData();
 				updateConnectionInfo();
 				getLocationData();
-				notifyUI(this.getClass().getName(), "CONNECTIVITY_CHANGE");
+				notifyUI(this.getClass().getName(), new String[]{getString(R.string.broadcast_connectivity)});
 			}
 		}
 	};
@@ -180,21 +179,22 @@ public class HoneyService extends Service {
 	/**
 	 * Notifies the GUI about a event.
 	 * 
-	 * @param protocol
-	 *            The protocol where the event happened.
+	 * @param sender
+	 *            Source where the event took place.
 	 * @param key
-	 *            The key for the event.
+	 *            Detailed information about the event.
 	 */
-	public void notifyUI(String sender, String key) {
+	public void notifyUI(String sender, String[] values) {
+		createNotification();
 		// Send Notification
-		if (key.equals(MainActivity.HANDLER_COUNT)) {
+		if (sender.equals(HoneyHandler.class.getName())) {
 			updateNotification();
 		}
-		Log.i("HoneyService", sender + key);
 		// Inform UI of Preference Change
-		Intent intent = new Intent(MainActivity.BROADCAST);
+		Intent intent = new Intent(getString(R.string.broadcast));
 		intent.putExtra("SENDER", sender);
-		intent.putExtra("KEY", key);
+		intent.putExtra("VALUES", values);
+		Log.i("Sender" ,sender);
 		LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
 	}
 	
@@ -237,7 +237,7 @@ public class HoneyService extends Service {
 	}
 
 	/**
-	 * Determines if there are running listeners.
+	 * Determines if there any listener is currently running.
 	 * 
 	 * @return True if there is a running listener, else false.
 	 */
@@ -256,8 +256,7 @@ public class HoneyService extends Service {
 	 */
 	public boolean isRunning(String protocolName){
 		int port = getDefaultPort(protocolName);
-		if(port >= 0) return isRunning(protocolName, port);
-		return false;
+		return isRunning(protocolName, port);
 	}
 	
 	/**
@@ -278,27 +277,26 @@ public class HoneyService extends Service {
 	/**
 	 * Determines the number of active connections for a protocol running on its default port.
 	 * @param protocolName The protocol name
-	 * @return Number of active connections if protocol is implemented, else -1.
+	 * @return Number of active connections
 	 */
-	public int getHandlerCount(String protocolName){
+	public int getNumberOfActiveConnections(String protocolName){
 		int port = getDefaultPort(protocolName);
-		if(port >= 0) return getHandlerCount(protocolName, port);
-		return -1;
+		return getNumberOfActiveConnections(protocolName, port);
 	}
 	
 	/**
 	 * Determines the number of active connections for a protocol running on the given port.
 	 * @param protocolName The protocol name
 	 * @param port Specific port
-	 * @return Number of active connections if protocol is implemented, else -1.
+	 * @return Number of active connections
 	 */
-	public int getHandlerCount(String protocolName, int port){
+	public int getNumberOfActiveConnections(String protocolName, int port){
 		for (HoneyListener listener : listeners) {
 			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
 				return listener.getHandlerCount();
 			}
 		}	
-		return -1;
+		return 0;
 	}
 
 	/**
@@ -355,9 +353,7 @@ public class HoneyService extends Service {
 	 *            Name of the protocol that should be started.
 	 */
 	public boolean startListener(String protocolName) {
-		int port = getDefaultPort(protocolName);
-		if(port >= 0) return startListener(protocolName, port);
-		return false;
+		return startListener(protocolName, getDefaultPort(protocolName));
 	}
 	
 	/**
@@ -400,8 +396,7 @@ public class HoneyService extends Service {
 	 *            Name of the protocol that should be stopped.
 	 */
 	public void stopListener(String protocolName) {
-		int port = getDefaultPort(protocolName);
-		if(port >= 0) stopListener(protocolName, port);
+		stopListener(protocolName, getDefaultPort(protocolName));
 	}
 	
 	/**
@@ -468,11 +463,11 @@ public class HoneyService extends Service {
 	 */
 	private void updateConnectionInfo() {
 		SharedPreferences pref = context.getSharedPreferences(
-				MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
+				getString(R.string.connection_info), Context.MODE_PRIVATE);
 		Editor editor = pref.edit();
-		editor.putString(MainActivity.SSID, HelperUtils.getSSID(context));
-		editor.putString(MainActivity.BSSID, HelperUtils.getBSSID(context));
-		editor.putString(MainActivity.INTERNAL_IP,
+		editor.putString(getString(R.string.connection_info_ssid), HelperUtils.getSSID(context));
+		editor.putString(getString(R.string.connection_info_bssid), HelperUtils.getBSSID(context));
+		editor.putString(getString(R.string.connection_info_internal_ip),
 				HelperUtils.getInternalIP(context));
 		editor.commit();
 		SetExternalIPTask async = new SetExternalIPTask();
@@ -508,9 +503,9 @@ public class HoneyService extends Service {
 
 		@Override
 		protected void onPostExecute(String result) {
-			connectionInfoEditor.putString(MainActivity.EXTERNAL_IP, result);
+			connectionInfoEditor.putString(getString(R.string.connection_info_external_ip), result);
 			connectionInfoEditor.commit();
-			notifyUI(this.getClass().getName(), MainActivity.EXTERNAL_IP);
+			notifyUI(this.getClass().getName(), new String[]{getString(R.string.broadcast_connectivity)});
 		}
 	};
 	
@@ -523,9 +518,11 @@ public class HoneyService extends Service {
 		UglyDbHelper dbh = new UglyDbHelper(this);
 		boolean activeHandlers = false;
 		boolean bssidSeen = false;
+		boolean listening = false;
 
 		for (HoneyListener listener : listeners) {
 			if(listener.isRunning())
+				listening = true;
 			if (listener.getHandlerCount() > 0) {
 				activeHandlers = true;
 			}
@@ -542,9 +539,12 @@ public class HoneyService extends Service {
 		} else if (bssidSeen) {
 			builder.setSmallIcon(R.drawable.ic_service_yellow);
 			builder.setContentText("Network has been infected in previous session!");
-		} else {
+		} else if(listening){
 			builder.setSmallIcon(R.drawable.ic_service_green);
 			builder.setContentText("Everything looks fine!");
+		} else{
+			builder.setSmallIcon(R.drawable.ic_launcher);
+			builder.setContentText("HosTaGe is not active.");
 		}
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
@@ -552,6 +552,7 @@ public class HoneyService extends Service {
 		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
 				PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
+		builder.setOngoing(true);
 		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 		mNotificationManager.notify(1, builder.build());
 	}

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/sync/BluetoothSync.java

@@ -114,7 +114,8 @@ public class BluetoothSync{
 	
 	private void deviceDialog() {
 		AlertDialog.Builder builder = new AlertDialog.Builder(context);
-		builder.setTitle(R.string.delete_dialog_title);
+		//TODO in resources auslagern
+		builder.setTitle("Choose Device");
 		builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
 			public void onClick(DialogInterface dialog, int position) {
 				String deviceInfo = arrayAdapter.getItem(position);

+ 14 - 42
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -3,18 +3,7 @@ package de.tudarmstadt.informatik.hostage.ui;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
-import java.util.LinkedList;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.json.JSONObject;
-
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.ActivityManager.RunningServiceInfo;
@@ -25,9 +14,6 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.net.ConnectivityManager;
-import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -57,6 +43,7 @@ import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
 import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver.Receiver;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
+import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 
 /**
  * MainActivity is the central activity for the GUI of the application.
@@ -72,24 +59,6 @@ import de.tudarmstadt.informatik.hostage.logging.Logger;
  * @author Wulf Pfeiffer
  */
 public class MainActivity extends Activity implements Receiver {
-	// String constants for whole application
-	/**
-	 * Used for Broadcast between service and GUI. String:
-	 * "de.tudarmstadt.informatik.hostage.BROADCAST"
-	 */
-	public static final String BROADCAST = "de.tudarmstadt.informatik.hostage.BROADCAST";
-	/**
-	 * Used to store session related data in a SharedPrefereces. String:
-	 * "de.tudarmstadt.informatik.hostage.SESSION_DATA"
-	 */
-	public static final String CONNECTION_INFO = "de.tudarmstadt.informatik.hostage.CONNECTION_INFO";
-	public static final String LISTENER = "_LISTENER";
-	public static final String HANDLER_COUNT = "_HANDLER_COUNT";
-	public static final String SSID = "SSID";
-	public static final String BSSID = "BSSID";
-	public static final String INTERNAL_IP = "INTERNAL_IP";
-	public static final String EXTERNAL_IP = "EXTERNAL_IP";
-
 	/**
 	 * Flag for root acces. True if phone has root acces, else false.
 	 */
@@ -140,7 +109,7 @@ public class MainActivity extends Activity implements Receiver {
 		super.onCreate(savedInstanceState);
 		logResultReceiver = new LogResultReceiver(new Handler());
 		setContentView(R.layout.activity_main);
-		connectionInfo = getSharedPreferences(MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
+		connectionInfo = getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
 		
 		// Create dynamic view elements
 		initViewAnimator();
@@ -217,7 +186,9 @@ public class MainActivity extends Activity implements Receiver {
 		if (((ToggleButton) view).isChecked()) {
 			if (isParanoid()) {
 				String[] protocols = getResources().getStringArray(R.array.protocols);
-//				startListener((LinkedList<String>) Arrays.asList(protocols));				
+				for(String protocol: protocols){
+					mService.startListener(protocol);	
+				}						
 			} else {
 				if(mService.isRunning("SMB")){
 					mService.stopListener("SMB");
@@ -441,7 +412,7 @@ public class MainActivity extends Activity implements Receiver {
 	 */
 	private void registerReceiver() {
 		LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
-				new IntentFilter(BROADCAST));
+				new IntentFilter(getString(R.string.broadcast)));
 	}
 
 	/**
@@ -483,19 +454,20 @@ public class MainActivity extends Activity implements Receiver {
 				// Check if protocol is active
 				if (mService.isRunning(protocol)) {
 					activeListeners = true;
-					int handlerCount = mService.getHandlerCount(protocol);
+					int handlerCount = mService.getNumberOfActiveConnections(protocol);
 					// Check if attacks have been recorded in this session.
 					if (handlerCount > 0) {
 						activeHandlers = true;
 						updateProtocolLight(LIGHT_RED, protocol);
 						updateProtocolConnections(handlerCount, protocol);
-				} else {
+					} else {
 						// Check if the bssid of the wireless network has already
 						// been recorded as infected.
 						Logger.isBssidSeen(getApplicationContext(), protocol,
 								HelperUtils.getBSSID(getApplicationContext()),
 								logResultReceiver);
-						if (isBssidSeen) {
+						UglyDbHelper dbh = new UglyDbHelper(this);
+						if (dbh.bssidSeen(protocol, connectionInfo.getString(getString(R.string.connection_info_bssid), null))) {
 							updateProtocolLight(LIGHT_YELLOW, protocol);
 							yellowLight = true;
 						} else {
@@ -628,10 +600,10 @@ public class MainActivity extends Activity implements Receiver {
 //		externalIPView.setText("Loading...");
 
 		// Get connection information
-		String ssid = connectionInfo.getString(SSID, null);
-		String bssid = connectionInfo.getString(BSSID, null);
-		String internalIP = connectionInfo.getString(INTERNAL_IP, null);
-		String externalIP = connectionInfo.getString(EXTERNAL_IP, null);
+		String ssid = connectionInfo.getString(getString(R.string.connection_info_ssid), null);
+		String bssid = connectionInfo.getString(getString(R.string.connection_info_bssid), null);
+		String internalIP = connectionInfo.getString(getString(R.string.connection_info_internal_ip), null);
+		String externalIP = connectionInfo.getString(getString(R.string.connection_info_external_ip), null);
 
 		// Set text fields
 		if (ssid != null)

+ 34 - 0
src/de/tudarmstadt/informatik/hostage/ui/SettingsActivity.java

@@ -45,7 +45,19 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
         pref = findPreference("pref_sleeptime");
         etp = (EditTextPreference) pref;
         defaultPref.edit().putInt("sleeptime", Integer.valueOf(etp.getText()).intValue()).commit();
+        pref.setSummary(etp.getText());
+        
+        //Set the value of the preference as the summary for the preference
+        pref = findPreference("pref_location_time");
+        etp = (EditTextPreference) pref;
+        defaultPref.edit().putInt("location_time", Integer.valueOf(etp.getText()).intValue()).commit();
+        pref.setSummary(etp.getText());
         
+        //Set the value of the preference as the summary for the preference
+        pref = findPreference("pref_location_retries");
+        etp = (EditTextPreference) pref;
+        defaultPref.edit().putInt("location_retries", Integer.valueOf(etp.getText()).intValue()).commit();
+        pref.setSummary(etp.getText());
     }    
 
     protected void onResume() {
@@ -118,6 +130,28 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
         	sharedPreferences.edit().putInt("sleeptime", Integer.valueOf(value).intValue()).commit();
     		pref.setSummary(value);
     	}
+    	else if(key.equals("pref_location_time")){
+    		Preference pref = findPreference(key);
+    		EditTextPreference etp = (EditTextPreference) pref;
+    		String value = etp.getText();
+    		if(!value.matches("([0-9])+")){
+    			Toast.makeText(getApplicationContext(), "Enter a valid number.", Toast.LENGTH_SHORT).show();
+    			value = getResources().getString(R.string.pref_location_time_default);
+    		}
+        	sharedPreferences.edit().putInt("location_time", Integer.valueOf(value).intValue()).commit();
+    		pref.setSummary(value);
+    	}
+    	else if(key.equals("pref_location_retries")){
+    		Preference pref = findPreference(key);
+    		EditTextPreference etp = (EditTextPreference) pref;
+    		String value = etp.getText();
+    		if(!value.matches("([0-9])+")){
+    			Toast.makeText(getApplicationContext(), "Enter a valid number.", Toast.LENGTH_SHORT).show();
+    			value = getResources().getString(R.string.pref_location_retries_default);
+    		}
+        	sharedPreferences.edit().putInt("location_retries", Integer.valueOf(value).intValue()).commit();
+    		pref.setSummary(value);
+    	}
     	 
     }
 }

+ 9 - 9
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -100,7 +100,7 @@ public class ViewLog extends Activity {
 	 */
 	public void exportDatabase(View view) {
 		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.export_dialog_title);
+		builder.setTitle(R.string.gui_export_dialog_title);
 		builder.setItems(R.array.format, new DialogInterface.OnClickListener() {
 			public void onClick(DialogInterface dialog, int position) {
 				exportDatabase(position);
@@ -289,7 +289,7 @@ public class ViewLog extends Activity {
 	 */
 	public void deleteLog(View view) {
 		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.delete_dialog_title);
+		builder.setTitle(R.string.gui_delete_dialog_title);
 		builder.setItems(R.array.delete_criteria,
 				new DialogInterface.OnClickListener() {
 					public void onClick(DialogInterface dialog, int position) {
@@ -324,7 +324,7 @@ public class ViewLog extends Activity {
 			strings[i] = bssidArray[i] + " (" // + logger.getSSID(bssidArray[i])
 					+ ")";
 		}
-		builder.setTitle(R.string.delete_dialog_title);
+		builder.setTitle(R.string.gui_delete_dialog_title);
 		builder.setItems(strings, new DialogInterface.OnClickListener() {
 			@SuppressLint("NewApi")
 			public void onClick(DialogInterface dialog, int position) {
@@ -391,9 +391,9 @@ public class ViewLog extends Activity {
 		calendar.set(year, monthOfYear, dayOfMonth,
 				timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
 		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.dialog_clear_database_date)
+		builder.setTitle(R.string.gui_dialog_clear_database_date)
 				.setMessage(sdf.format(calendar.getTime()))
-				.setPositiveButton(R.string.delete,
+				.setPositiveButton(R.string.gui_delete,
 						new DialogInterface.OnClickListener() {
 							@SuppressLint("NewApi")
 							public void onClick(DialogInterface dialog, int id) {
@@ -413,7 +413,7 @@ public class ViewLog extends Activity {
 								}
 							}
 						})
-				.setNegativeButton(R.string.cancel,
+				.setNegativeButton(R.string.gui_cancel,
 						new DialogInterface.OnClickListener() {
 							public void onClick(DialogInterface dialog, int id) {
 								// User cancelled the dialog
@@ -432,8 +432,8 @@ public class ViewLog extends Activity {
 	 */
 	private void deleteAll() {
 		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setMessage(R.string.dialog_clear_database)
-				.setPositiveButton(R.string.clear,
+		builder.setMessage(R.string.gui_dialog_clear_database)
+				.setPositiveButton(R.string.gui_clear,
 						new DialogInterface.OnClickListener() {
 							@SuppressLint("NewApi")
 							public void onClick(DialogInterface dialog, int id) {
@@ -455,7 +455,7 @@ public class ViewLog extends Activity {
 								}
 							}
 						})
-				.setNegativeButton(R.string.cancel,
+				.setNegativeButton(R.string.gui_cancel,
 						new DialogInterface.OnClickListener() {
 							public void onClick(DialogInterface dialog, int id) {
 								// User cancelled the dialog