Browse Source

Minor bug fixes

Lars 9 years ago
parent
commit
e8d61ae5dd

+ 3 - 3
src/de/tudarmstadt/informatik/hostage/HoneyHandler.java

@@ -66,11 +66,11 @@ public class HoneyHandler implements Runnable {
 	 */
 	public HoneyHandler(HoneyService service, HoneyListener listener,
 			Protocol protocol, Socket client) {
+		this.service = service;
 		this.listener = listener;
 		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;
@@ -106,6 +106,7 @@ public class HoneyHandler implements Runnable {
 	 */
 	@Override
 	public void run() {
+		service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_started), protocol.toString(), Integer.toString(listener.getPort())});
 		InputStream in;
 		OutputStream out;
 		try {
@@ -122,8 +123,7 @@ 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())});
+		service.notifyUI(this.getClass().getName(), new String[]{service.getString(R.string.broadcast_started),protocol.toString() ,Integer.toString(listener.getPort())});
 		thread.interrupt();
 		try {
 			client.close();

+ 11 - 11
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -187,8 +187,8 @@ public class HoneyService extends Service {
 	public void notifyUI(String sender, String[] values) {
 		createNotification();
 		// Send Notification
-		if (sender.equals(HoneyHandler.class.getName())) {
-			updateNotification();
+		if (sender.equals(HoneyHandler.class.getName()) && values[0].equals(R.string.broadcast_started)) {
+			attackNotification();
 		}
 		// Inform UI of Preference Change
 		Intent intent = new Intent(getString(R.string.broadcast));
@@ -533,19 +533,19 @@ public class HoneyService extends Service {
 		builder = new NotificationCompat.Builder(this).setContentTitle(
 				getString(R.string.app_name)).setWhen(
 				System.currentTimeMillis());
-		if (activeHandlers) {
+		if(!listening){
+			builder.setSmallIcon(R.drawable.ic_launcher);
+			builder.setContentText("HosTaGe is not active.");
+		} else if (activeHandlers) {
 			builder.setSmallIcon(R.drawable.ic_service_red);
 			builder.setContentText("Network is infected!");
 		} else if (bssidSeen) {
 			builder.setSmallIcon(R.drawable.ic_service_yellow);
 			builder.setContentText("Network has been infected in previous session!");
-		} else if(listening){
+		} else{
 			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);
 		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
@@ -560,7 +560,7 @@ public class HoneyService extends Service {
 	/**
 	 * Updates the notification when a attack is registered.
 	 */
-	private void updateNotification() {
+	private void attackNotification() {
 		SharedPreferences defaultPref = PreferenceManager
 				.getDefaultSharedPreferences(this);
 		String strRingtonePreference = defaultPref.getString(
@@ -569,7 +569,7 @@ public class HoneyService extends Service {
 		builder = new NotificationCompat.Builder(this)
 				.setContentTitle(getString(R.string.app_name))
 				.setTicker("Honeypot under attack!")
-				.setContentText("Network is infected!")
+				.setContentText("Honeypot under attack!")
 				.setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true)
 				.setWhen(System.currentTimeMillis())
 				.setSound(Uri.parse(strRingtonePreference));
@@ -584,7 +584,7 @@ public class HoneyService extends Service {
 		}
 
 		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-		mNotificationManager.notify(1, builder.build());
+		mNotificationManager.notify(2, builder.build());
 	}
 
 	/**