|
@@ -15,6 +15,8 @@ import android.widget.Switch;
|
|
|
import android.widget.TextView;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
+import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
|
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
|
|
|
@@ -30,6 +32,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
private Context mActivity;
|
|
|
private Switch mServicesSwitch;
|
|
|
private CompoundButton.OnCheckedChangeListener mListener;
|
|
|
+ private Profile mProfile;
|
|
|
+ private Integer[] mGhostPorts;
|
|
|
|
|
|
/**
|
|
|
* constructor
|
|
@@ -99,7 +103,7 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
new CompoundButton.OnCheckedChangeListener() {
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
ServicesListItem item = (ServicesListItem) buttonView.getTag();
|
|
|
-
|
|
|
+ mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
|
|
|
if (!HelperUtils.isWifiConnected(mActivity)) {
|
|
|
new AlertDialog.Builder(mActivity)
|
|
|
.setTitle(R.string.information)
|
|
@@ -117,7 +121,29 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
} else {
|
|
|
//check if switch is set to ON and start the concrete listener for the protocol
|
|
|
if (isChecked) {
|
|
|
- if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
+ if(item.protocol.equals("GHOST")){
|
|
|
+ if(mProfile.mGhostActive){
|
|
|
+ mGhostPorts = mProfile.getGhostPorts();
|
|
|
+
|
|
|
+ if(mGhostPorts.length != 0) {
|
|
|
+ for(Integer port: mGhostPorts){
|
|
|
+ if(!MainActivity.getInstance().getHostageService().isRunning(item.protocol, port)) {
|
|
|
+ MainActivity.getInstance().getHostageService().startListener(item.protocol, port);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //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 {
|
|
|
+ buttonView.setChecked(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
MainActivity.getInstance().getHostageService().startListener(item.protocol);
|
|
|
|
|
|
//set the main switch to null, so that he won't react and starts all protocols
|
|
@@ -125,14 +151,23 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
mServicesSwitch.setChecked(true);
|
|
|
mServicesSwitch.setOnCheckedChangeListener(mListener);
|
|
|
buttonView.setChecked(true);
|
|
|
- } else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
+ } else {
|
|
|
buttonView.setChecked(true);
|
|
|
}
|
|
|
} else {
|
|
|
- if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
- MainActivity.getInstance().getHostageService().stopListener(item.protocol);
|
|
|
- }
|
|
|
- buttonView.setChecked(false);
|
|
|
+ if(item.protocol.equals("GHOST")) {
|
|
|
+ mGhostPorts = mProfile.getGhostPorts();
|
|
|
+ for(Integer port: mGhostPorts){
|
|
|
+ if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
|
|
|
+ MainActivity.getInstance().getHostageService().stopListener("GHOST", port);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buttonView.setChecked(false);
|
|
|
+ }
|
|
|
+ else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
+ MainActivity.getInstance().getHostageService().stopListener(item.protocol);
|
|
|
+ }
|
|
|
+ buttonView.setChecked(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -148,7 +183,46 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
* @param holder ViewHolder which represents the item in the View
|
|
|
*/
|
|
|
private void updateStatus(ServicesListItem item, ViewHolder holder) {
|
|
|
- if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
+ if(item.protocol.equals("GHOST")){
|
|
|
+ mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
|
|
|
+ mGhostPorts = mProfile.getGhostPorts();
|
|
|
+
|
|
|
+ boolean ghostActive = false;
|
|
|
+
|
|
|
+ for(Integer port: mGhostPorts){
|
|
|
+ if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
|
|
|
+ ghostActive = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ghostActive){
|
|
|
+ holder.activated.setChecked(true);
|
|
|
+
|
|
|
+ if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
|
|
|
+ if (item.attacks > 0) {
|
|
|
+ setBackground(holder, R.drawable.services_circle_yellow);
|
|
|
+ } else {
|
|
|
+ setBackground(holder, R.drawable.services_circle_green);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
|
|
|
+ setBackground(holder, R.drawable.services_circle_red);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (item.attacks > 0) {
|
|
|
+ holder.activated.setChecked(false);
|
|
|
+ setBackground(holder, R.drawable.services_circle_yellow);
|
|
|
+ } else {
|
|
|
+ holder.activated.setChecked(false);
|
|
|
+ setBackground(holder, R.drawable.services_circle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
|
|
|
holder.activated.setChecked(true);
|
|
|
if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
|
|
|
if (item.attacks > 0) {
|