|
@@ -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());
|
|
|
}
|