Selaa lähdekoodia

worked on bugs(honey service) in services view

Daniel Lazar 10 vuotta sitten
vanhempi
commit
e93c1f454d

+ 123 - 0
res/layout-land/fragment_services.xml

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="horizontal"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+    <ViewGroup
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content">
+            android:layout_weight="1">
+        <TextView
+                android:id="@+id/textView"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentEnd="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentRight="false"
+                android:layout_marginLeft="15dp"
+                android:layout_marginTop="20dp"
+                android:layout_weight="1"
+                android:text="@string/current_connection"
+                android:textSize="18dp"
+                android:textStyle="bold" />
+
+        <ImageView
+                android:id="@+id/services_button_connection_info"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentEnd="true"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentTop="true"
+                android:layout_marginTop="5dp"
+                android:layout_marginRight="12dp"
+                android:src="@android:drawable/ic_menu_info_details" />
+    </ViewGroup>
+
+    <ViewGroup android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1">
+    <View
+            android:layout_width="fill_parent"
+            android:layout_height="1dp"
+            android:layout_marginLeft="15dp"
+            android:layout_marginRight="15dp"
+            android:background="@android:color/darker_gray" />
+    <RelativeLayout
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content" >
+
+        <TextView
+                android:id="@+id/services_text_name"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentTop="true"
+                android:layout_centerHorizontal="true"
+                android:layout_gravity="center_horizontal"
+                android:layout_marginTop="21dp"
+                android:text="Eduroam"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:textSize="26sp" />
+
+    </RelativeLayout>
+
+    <RelativeLayout
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:baselineAligned="false"
+            android:orientation="horizontal"
+            android:weightSum="1" >
+
+        <TextView
+                android:id="@+id/textView"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentEnd="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentRight="false"
+                android:layout_marginLeft="15dp"
+                android:layout_marginTop="0dp"
+                android:layout_weight="1"
+                android:text="@string/monitor_services"
+                android:textStyle="bold"
+                android:textSize="20dp"/>
+
+        <Switch
+                android:id="@+id/service_switch_connection"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentBottom="false"
+                android:layout_alignParentEnd="false"
+                android:layout_alignParentLeft="false"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentTop="false"
+                android:layout_gravity="right"
+                android:layout_marginLeft="0dp"
+                android:layout_marginRight="15dp"
+                android:layout_marginTop="30dp"
+                android:layout_marginBottom="0dp"
+                android:layout_weight="1"
+                android:checked="false"
+                android:textSize="10dp" />
+
+    </RelativeLayout>
+
+    <View
+            android:layout_width="fill_parent"
+            android:layout_height="1dp"
+            android:layout_marginLeft="15dp"
+            android:layout_marginRight="15dp"
+            android:background="@android:color/darker_gray" />
+
+    <ListView android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:id="@+id/services_list_view"
+              android:layout_marginLeft="15dp"
+              android:layout_marginRight="15dp"
+            >
+
+
+    </ListView>
+    </ViewGroup>
+</LinearLayout>

+ 15 - 6
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -4,7 +4,6 @@ package de.tudarmstadt.informatik.hostage.ui2.adapter;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
-import android.content.SharedPreferences;
 import android.os.Build;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -19,7 +18,6 @@ import java.util.List;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
-import de.tudarmstadt.informatik.hostage.ui2.fragment.ServicesFragment;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
 /**
@@ -27,8 +25,6 @@ import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
  */
 public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 
-	private SharedPreferences mConnectionInfo;
-
 	private class ViewHolder {
 			public TextView protocolName;
 			public TextView recordedAttacks;
@@ -62,7 +58,7 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 		View rowView = convertView;
 
-		ViewHolder holder = null;
+		ViewHolder holder;
 
 		final ServicesListItem item = values.get(position);
 
@@ -70,6 +66,7 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 			rowView = inflater.inflate(R.layout.services_list_item, parent, false);
 
 			holder = new ViewHolder();
+			assert rowView != null;
 			holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
 			holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
 			holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
@@ -104,14 +101,22 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 
 					buttonView.setChecked(false);
 				} else {
+					//check if switch is set to ON and start the concrete listener for the protocol
 					if(isChecked){
 						if(!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
 							MainActivity.getInstance().getHoneyService().startListener(item.protocol);
+							System.out.println("Protokoll gestartet innerIFFFFF: ------------------------------" + item.protocol);
+
+							//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 if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
+							System.out.println("Protokoll ist bereits gestartet: ------------------------------" + item.protocol);
+							buttonView.setChecked(true);
 						}
-						buttonView.setChecked(true);
 					} else {
 						if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
 							MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
@@ -142,6 +147,10 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 				}
 			}
 		}
+		else if(Integer.valueOf(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);

+ 29 - 23
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -23,7 +23,6 @@ import java.util.ArrayList;
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
 import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
@@ -54,6 +53,8 @@ public class ServicesFragment extends Fragment{
 
 	private SharedPreferences mConnectionInfo;
 
+	private boolean mReceiverRegistered = false;
+
 
 	private void assignViews(){
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
@@ -83,6 +84,7 @@ public class ServicesFragment extends Fragment{
 	public ServicesFragment(){}
 
 	private void registerBroadcastReceiver(){
+		if(!mReceiverRegistered){
 		mReceiver = new BroadcastReceiver() {
 			@Override
 			public void onReceive(Context context, Intent intent) {
@@ -99,6 +101,8 @@ public class ServicesFragment extends Fragment{
 
 		LocalBroadcastManager
 				.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
+			this.mReceiverRegistered = true;
+		}
 	}
 
 	@Override
@@ -117,18 +121,16 @@ public class ServicesFragment extends Fragment{
 		ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
 
 		protocolList= new ArrayList<ServicesListItem>();
-
+		int i=0;
 		for(String protocol: protocols){
 			protocolList.add(new ServicesListItem(protocol));
+			protocolList.get(i).attacks = String.valueOf(dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null)));
+			i++;
 			if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
 				setStateActive();
 			}
 		}
-		for(int i=0; i < protocols.length; i++){
 
-			protocolList.get(i).attacks = String.valueOf(dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null)));
-		//	protocolList.get(i).initialValue = Integer.valueOf(protocolList.get(i).attacks);
-		}
 		adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
 		adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
 		list.setAdapter(adapter);
@@ -156,18 +158,21 @@ public class ServicesFragment extends Fragment{
 						setStateNotActive();
 						setStateNotConnected();
 					} else {
-						if(isChecked){
-							for(String protocol: protocols){
-								if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
-									MainActivity.getInstance().getHoneyService().startListener(protocol);
-								}
+						if(MainActivity.getInstance().isServiceBound()) {
+							if(isChecked){
+									for(String protocol: protocols){
+										if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
+											System.out.println("SERVICESFRAGMENT starts LISTENER for PROTO:" + protocol);
+											MainActivity.getInstance().getHoneyService().startListener(protocol);
+										}
+									}
+									setStateActive();
 							}
-							setStateActive();
-						} else {
-							MainActivity.getInstance().getHoneyService().stopListeners();
-							MainActivity.getInstance().stopAndUnbind();
-
-							setStateNotActive();
+							else {
+								MainActivity.getInstance().getHoneyService().stopListeners();
+								MainActivity.getInstance().stopAndUnbind();
+								setStateNotActive();
+								}
 						}
 					}
 				}
@@ -176,27 +181,28 @@ public class ServicesFragment extends Fragment{
 		}
 		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
 
-
-
 		return rootView;
 
 	};
 
 	@Override
 	public void onStart(){
-		super.onStart();
 		registerBroadcastReceiver();
+		super.onStart();
 	}
 
 	@Override
 	public void onStop(){
-		super.onStop();
 		unregisterBroadcastReceiver();
+		super.onStop();
 
 	}
 
 	private void unregisterBroadcastReceiver(){
-		LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+		if(mReceiverRegistered){
+			LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+			this.mReceiverRegistered = false;
+		}
 	}
 
 	private void setStateActive() {
@@ -214,8 +220,8 @@ public class ServicesFragment extends Fragment{
 
 	@Override
 	public void onDestroy(){
+		unregisterBroadcastReceiver();
 		super.onDestroy();
-		LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
 	}
 
 }