|
@@ -12,7 +12,6 @@ import javax.net.ssl.SSLSocketFactory;
|
|
|
import android.content.Context;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.content.SharedPreferences.Editor;
|
|
|
-import android.util.Log;
|
|
|
import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
|
|
|
import de.tudarmstadt.informatik.hostage.protocol.Protocol;
|
|
|
import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
|
|
@@ -47,11 +46,11 @@ public class HoneyListener implements Runnable {
|
|
|
|
|
|
private HoneyService service;
|
|
|
// Shared Preferences
|
|
|
- private SharedPreferences pref;
|
|
|
+ private SharedPreferences sessionPref;
|
|
|
private ConnectionRegister conReg;
|
|
|
|
|
|
// Editor for Shared preferences
|
|
|
- private Editor editor;
|
|
|
+ private Editor sessionEditor;
|
|
|
|
|
|
private boolean running = false;
|
|
|
|
|
@@ -75,9 +74,8 @@ public class HoneyListener implements Runnable {
|
|
|
public HoneyListener(HoneyService service, Protocol protocol) {
|
|
|
this.service = service;
|
|
|
this.protocol = protocol;
|
|
|
- pref = service.getApplicationContext().getSharedPreferences(
|
|
|
- MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
- editor = pref.edit();
|
|
|
+ sessionPref = service.getApplicationContext().getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
+ sessionEditor = sessionPref.edit();
|
|
|
conReg = new ConnectionRegister(service);
|
|
|
}
|
|
|
|
|
@@ -99,9 +97,8 @@ public class HoneyListener implements Runnable {
|
|
|
server = new MyServerSocketFactory().createServerSocket(protocol
|
|
|
.getPort());
|
|
|
(this.thread = new Thread(this)).start();
|
|
|
- Log.i("BugSearch", "Open ServerSocket - ServerSocket is: " + ((server == null) ? "null" : "not null"));
|
|
|
- editor.putBoolean(protocol + MainActivity.LISTENER, true);
|
|
|
- editor.commit();
|
|
|
+ sessionEditor.putBoolean(protocol + MainActivity.LISTENER, true);
|
|
|
+ sessionEditor.commit();
|
|
|
service.notifyUI(protocol.toString(), MainActivity.LISTENER);
|
|
|
running = true;
|
|
|
} catch (Exception e) {
|
|
@@ -115,11 +112,10 @@ public class HoneyListener implements Runnable {
|
|
|
*/
|
|
|
public void stop() {
|
|
|
try {
|
|
|
- Log.i("BugSearch", "Closing ServerSocket - ServerSocket is: " + ((server == null) ? "null" : "not null"));
|
|
|
server.close();
|
|
|
thread.interrupt();
|
|
|
- editor.putBoolean(protocol + MainActivity.LISTENER, false);
|
|
|
- editor.commit();
|
|
|
+ sessionEditor.putBoolean(protocol + MainActivity.LISTENER, false);
|
|
|
+ sessionEditor.commit();
|
|
|
service.notifyUI(protocol.toString(), MainActivity.LISTENER);
|
|
|
running = false;
|
|
|
} catch (Exception e) {
|
|
@@ -146,6 +142,10 @@ public class HoneyListener implements Runnable {
|
|
|
if (handler.isTerminated()) {
|
|
|
conReg.closeConnection();
|
|
|
iterator.remove();
|
|
|
+ int handlerCount = sessionPref.getInt(protocol + MainActivity.HANDLER_COUNT, 0);
|
|
|
+ sessionEditor.putInt(protocol + MainActivity.HANDLER_COUNT, handlerCount - 1);
|
|
|
+ sessionEditor.commit();
|
|
|
+ service.notifyUI(protocol.toString(), MainActivity.HANDLER_COUNT);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -164,11 +164,9 @@ public class HoneyListener implements Runnable {
|
|
|
} else {
|
|
|
startHandler(client);
|
|
|
}
|
|
|
- int handlerCount = pref.getInt(protocol
|
|
|
- + MainActivity.HANDLER_COUNT, 0);
|
|
|
- editor.putInt(protocol + MainActivity.HANDLER_COUNT,
|
|
|
- handlerCount + 1);
|
|
|
- editor.commit();
|
|
|
+ int handlerCount = sessionPref.getInt(protocol + MainActivity.HANDLER_COUNT, 0);
|
|
|
+ sessionEditor.putInt(protocol + MainActivity.HANDLER_COUNT, handlerCount + 1);
|
|
|
+ sessionEditor.commit();
|
|
|
service.notifyUI(protocol.toString(),
|
|
|
MainActivity.HANDLER_COUNT);
|
|
|
} catch (Exception e) {
|