Browse Source

home and services fragment are now synched

Daniel Lazar 10 years ago
parent
commit
1b8e11aec2

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/net/MyServerSocketFactory.java

@@ -11,7 +11,7 @@ import java.net.SocketImpl;
 import javax.net.ServerSocketFactory;
 
 import de.tudarmstadt.informatik.hostage.system.P;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 /**
  * Server Socket Factory using file descriptors.

+ 13 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -154,6 +154,19 @@ public class HomeFragment extends Fragment {
 
 	    updateUI();
 
+		final String[] protocols = getResources().getStringArray(R.array.protocols);
+
+		if(MainActivity.getInstance().getHoneyService() == null){
+			// do nothing
+		}
+		else {
+			for(String protocol: protocols){
+				if (MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
+					setStateActive();
+				}
+			}
+		}
+
 	    mHomeSwitchConnection = (Switch) rootView.findViewById(R.id.home_switch_connection);
 
 	    if(switchChangeListener == null){
@@ -176,7 +189,6 @@ public class HomeFragment extends Fragment {
 					    setStateNotConnected();
 				    } else {
 					    if(isChecked){
-						    String[] protocols = getResources().getStringArray(R.array.protocols);
 						    for(String protocol: protocols){
 							    MainActivity.getInstance().getHoneyService().startListener(protocol);
 						    }

+ 27 - 7
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -15,14 +15,12 @@ import android.widget.TextView;
 
 import java.util.ArrayList;
 
-import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.protocol.FTP;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
-import static de.tudarmstadt.informatik.hostage.HoneyService.*;
 
 /**
  * Created by Daniel Lazar on 05.02.14.
@@ -37,6 +35,7 @@ public class ServicesFragment extends Fragment{
 	private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
 
 
+
 	private void assignViews(){
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 		mServicesTextName = (TextView) rootView.findViewById(R.id.services_text_name);
@@ -54,7 +53,7 @@ public class ServicesFragment extends Fragment{
 		}
 
 /*		//check if ftp monitoring is running
-		if(!HoneyService.isRunning(protocols[1])){
+		if(!MainActivity.getInstance().getHoneyService().isRunning(protocols[1])){
 			mServicesSwitchFTP.setOnCheckedChangeListener(null);
 		}
 		else {
@@ -74,16 +73,22 @@ public class ServicesFragment extends Fragment{
 		updateUI();
 
 		ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
-		String[] protocols = getResources().getStringArray(R.array.protocols);
+
+		final String[] protocols = getResources().getStringArray(R.array.protocols);
 		ArrayList<ServicesListItem> protocolList= new ArrayList<ServicesListItem>();
 
 		for(String protocol: protocols){
 			protocolList.add(new ServicesListItem(protocol));
+			if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
+				setStateActive();
+			}
 		}
 
 		ServicesListAdapter adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
 		list.setAdapter(adapter);
 
+		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
+
 		if(switchChangeListener == null){
 			switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
 				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -104,20 +109,34 @@ public class ServicesFragment extends Fragment{
 						setStateNotConnected();
 					} else {
 						if(isChecked){
+							for(String protocol: protocols){
+								if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
+
+								}
+								else{
+								MainActivity.getInstance().getHoneyService().startListener(protocol);
+								}
+							}
 							setStateActive();
 						} else {
+							MainActivity.getInstance().getHoneyService().stopListeners();
+							MainActivity.getInstance().stopAndUnbind();
 							setStateNotActive();
 						}
 					}
 				}
 			};
 		}
+		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
+
+
+
 		return rootView;
 
-	}
+	};
 
 	private void setStateActive() {
-
+		mServicesSwitchService.setChecked(true);
 	}
 
 	private void setStateNotConnected() {
@@ -125,6 +144,7 @@ public class ServicesFragment extends Fragment{
 	}
 
 	private void setStateNotActive() {
+		mServicesSwitchService.setChecked(false);
 
 	}