Parcourir la source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Alexander Brakowski il y a 10 ans
Parent
commit
4a055198e7

BIN
res/drawable/hostage_logo_big.png


BIN
res/drawable/hostage_logo_tilted.png


+ 41 - 0
res/layout/fragment_about.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout
+		android:orientation="vertical"
+		android:layout_width="fill_parent"
+		android:layout_height="fill_parent"
+		xmlns:android="http://schemas.android.com/apk/res/android">
+	<ImageView
+			android:layout_width="match_parent"
+			android:layout_height="match_parent"
+			android:id="@+id/imageView" android:src="@drawable/hostage_logo_tilted"
+			android:layout_weight="0.4" android:layout_margin="24dp"/>
+
+	<LinearLayout
+			android:orientation="vertical"
+			android:layout_width="match_parent"
+			android:layout_height="match_parent"
+			android:layout_weight="0.6">
+		<TextView
+				android:layout_width="wrap_content"
+				android:layout_height="wrap_content"
+				android:textAppearance="?android:attr/textAppearanceLarge"
+				android:text="HosTaGe"
+				android:id="@+id/textView" android:layout_gravity="center_horizontal"
+				android:textStyle="bold"/>
+		<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
+				  android:textAppearance="?android:attr/textAppearanceMedium"
+				  android:text="UI designed by:"
+				  android:id="@+id/textView4" android:layout_gravity="center_horizontal"
+				  android:singleLine="false" android:autoText="false"
+				  android:layout_marginTop="8dp"/>
+		<TextView
+				android:layout_width="wrap_content"
+				android:layout_height="wrap_content"
+				android:textAppearance="?android:attr/textAppearanceMedium"
+				android:text="Fabio Arnold\nAlexander Bra\nJulien Clauter\nDaniel Lazar"
+				android:id="@+id/textView2"
+				android:layout_gravity="center_horizontal"
+				android:singleLine="false" android:autoText="false" android:layout_marginTop="4dp"/>
+	</LinearLayout>
+</LinearLayout>

+ 4 - 0
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -30,6 +30,7 @@ import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.ui.LogFilter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.DrawerListAdapter;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.AboutFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.HomeFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ProfileManagerFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.RecordOverviewFragment;
@@ -317,6 +318,9 @@ public class MainActivity extends Activity {
 			case SETTINGS:
 				fragment = new SettingsFragment();
 				break;
+			case APPLICATION_INFO:
+				fragment = new AboutFragment();
+				break;
 			default:
 				break;
 		}

+ 77 - 10
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -1,11 +1,14 @@
 package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
+import android.app.AlertDialog;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.os.Build;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
+import android.widget.CompoundButton;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.ListView;
@@ -13,30 +16,35 @@ import android.widget.Switch;
 import android.widget.TextView;
 import android.widget.ViewSwitcher;
 
+import java.util.HashMap;
 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;
 
 /**
  * Created by Daniel Lazar on 06.02.14.
  */
 public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
-		private class ViewHolder {
+
+
+	private class ViewHolder {
 			public TextView protocolName;
 			public TextView recordedAttacks;
 			public Switch activated;
 			public View circle;
 		}
 
+	private Context mActivity;
+	private Switch mServicesSwitch;
+	private CompoundButton.OnCheckedChangeListener mListener;
 	private final Context context;
 	private final List<ServicesListItem> values;
 	int sdk = Build.VERSION.SDK_INT;
 
-	ViewHolder holder = null;
-	private ServicesListItem item;
-
 	public ServicesListAdapter(Context context, List<ServicesListItem> objects){
 		super(context, R.layout.services_list_item, objects);
 
@@ -44,14 +52,21 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 		this.values = objects;
 	}
 
+	public void setActivity(Context activity, Switch servicesSwitch, CompoundButton.OnCheckedChangeListener mainListener) {
+		mActivity = activity;
+		mServicesSwitch = servicesSwitch;
+		mListener = mainListener;
+	}
+
 	@Override
 	public View getView(final int position, View convertView, ViewGroup parent) {
 		LayoutInflater inflater = (LayoutInflater) context
 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
 		View rowView = convertView;
 
-		item = values.get(position);
+		ViewHolder holder = null;
+
+		final ServicesListItem item = values.get(position);
 
 		if(rowView == null){
 			rowView = inflater.inflate(R.layout.services_list_item, parent, false);
@@ -60,20 +75,62 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 			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);
-			holder.circle = (View) rowView.findViewById(R.id.services_circle);
-			this.notifyDataSetChanged();
+			holder.circle = rowView.findViewById(R.id.services_circle);
 			rowView.setTag(holder);
+
+
 		} else {
 			holder = (ViewHolder) rowView.getTag();
 		}
 
 		holder.protocolName.setText(item.protocol);
+		holder.activated.setTag(item);
+
+		this.updateStatus(item, holder);
+
+			holder.activated.setOnCheckedChangeListener(
+					new CompoundButton.OnCheckedChangeListener() {
+						public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+							ServicesListItem item = (ServicesListItem) buttonView.getTag();
+									System.out
+											.println("Protokoll: " + item.protocol);
+							System.out.println("Position: " + position);
+				if(!HelperUtils.isWifiConnected(mActivity)){
+					new AlertDialog.Builder(mActivity)
+							.setTitle("Information")
+							.setMessage("You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.")
+							.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+								public void onClick(DialogInterface dialog, int which) {
+								}
+							})
+							.setIcon(android.R.drawable.ic_dialog_info)
+							.show();
+
+
+					buttonView.setChecked(false);
+				} else {
+					if(isChecked){
+						if(!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
+							MainActivity.getInstance().getHoneyService().startListener(item.protocol);
+							mServicesSwitch.setOnCheckedChangeListener(null);
+							mServicesSwitch.setChecked(true);
+							mServicesSwitch.setOnCheckedChangeListener(mListener);
+						}
+						buttonView.setChecked(true);
+					} else {
+						if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
+							MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
+						}
+						buttonView.setChecked(false);
+					}
+				}
+						}
+					});
 
 		return rowView;
 	}
 
-	@Override
-	public void notifyDataSetChanged(){
+	private void updateStatus(ServicesListItem item, ViewHolder holder){
 		if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
 			holder.activated.setChecked(true);
 			if(sdk < Build.VERSION_CODES.JELLY_BEAN){
@@ -94,4 +151,14 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
 		}
 	}
 
+	/*private void updateProtocolConnections(int connections, String protocolName, ServicesListAdapter adapter) {
+		for (int i = 0; i < adapter.getCount(); ++i) {
+			HashMap<String, String> d = ((HashMap<String, String>) adapter
+					.getItem(i));
+			if (d.get("protocol").equals(protocolName)) {
+				d.put("connections", String.valueOf(connections));
+			}
+		}
+		adapter.notifyDataSetChanged();
+	}*/
 }

+ 19 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/AboutFragment.java

@@ -0,0 +1,19 @@
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import de.tudarmstadt.informatik.hostage.R;
+
+/**
+ * Created by Fabio Arnold on 25.02.14.
+ */
+public class AboutFragment extends Fragment {
+	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
+		super.onCreateView(inflater, container, savedInstanceState);
+		return inflater.inflate(R.layout.fragment_about, container, false);
+	}
+}

+ 34 - 21
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -2,9 +2,14 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 
 import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.support.v4.content.LocalBroadcastManager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -17,6 +22,7 @@ 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.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
@@ -34,6 +40,9 @@ public class ServicesFragment extends Fragment{
 
 	private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
 
+	private BroadcastReceiver mReceiver;
+
+	private ServicesListAdapter adapter;
 
 
 	private void assignViews(){
@@ -52,16 +61,21 @@ public class ServicesFragment extends Fragment{
 			mServicesTextName.setText(HelperUtils.getSSID(getActivity()));
 		}
 
-/*		//check if ftp monitoring is running
-		if(!MainActivity.getInstance().getHoneyService().isRunning(protocols[1])){
-			mServicesSwitchFTP.setOnCheckedChangeListener(null);
-		}
-		else {
-			mServicesSwitchFTP.setChecked(true);
-		}*/
 	}
 	public ServicesFragment(){}
 
+	private void registerBroadcastReceiver(){
+		mReceiver = new BroadcastReceiver() {
+			@Override
+			public void onReceive(Context context, Intent intent) {
+				adapter.notifyDataSetChanged();
+			}
+		};
+
+		LocalBroadcastManager
+				.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
+	}
+
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 
@@ -84,9 +98,12 @@ public class ServicesFragment extends Fragment{
 			}
 		}
 
-		final ServicesListAdapter adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
+		adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
+		adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
 		list.setAdapter(adapter);
 
+		registerBroadcastReceiver();
+
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 
 		if(switchChangeListener == null){
@@ -110,25 +127,15 @@ public class ServicesFragment extends Fragment{
 					} else {
 						if(isChecked){
 							for(String protocol: protocols){
-								if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
-									adapter.notifyDataSetChanged();
-								}
-								else{
+								if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
 									MainActivity.getInstance().getHoneyService().startListener(protocol);
-									adapter.notifyDataSetChanged();
 								}
 							}
 							setStateActive();
 						} else {
-							for(String protocol: protocols){
-								if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
-									MainActivity.getInstance().getHoneyService().stopListener(protocol);
-									/*MainActivity.getInstance().stopAndUnbind();*/
-									adapter.notifyDataSetChanged();
+							MainActivity.getInstance().getHoneyService().stopListeners();
+							MainActivity.getInstance().stopAndUnbind();
 
-								}
-							}
-//							adapter.notifyDataSetChanged();
 							setStateNotActive();
 						}
 					}
@@ -157,4 +164,10 @@ public class ServicesFragment extends Fragment{
 
 	}
 
+	@Override
+	public void onDestroy(){
+		super.onDestroy();
+		LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+	}
+
 }

+ 6 - 44
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -38,6 +38,7 @@ import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.ui.LogFilter;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.StatisticListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
+import de.tudarmstadt.informatik.hostage.ui2.helper.ColorSequenceGenerator;
 import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
 import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
@@ -935,50 +936,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
 
     public int getOtherColor(){
-        return Color.argb(255,0,0,0);
-    }
-
-     public ArrayList<Integer> getColorList(){
-        if (this.colorList == null){
-            this.colorList = new ArrayList<Integer>();
-            for (int i =0; i < 255; i++){
-                Integer color = this.generateColorForIndex(i);
-                this.colorList.add(color);
-            }
-        }
-        return this.colorList;
-    }
-
-    public Integer getColor(int index){
-        if (this.colorList == null) this.colorList = new ArrayList<Integer>();
-        if (index >= this.colorList.size()) {
-            for (int i = this.colorList.size(); i<= index; i++){
-                Integer color = this.generateColorForIndex(i);
-                this.colorList.add(color);
-            }
-            return this.generateColorForIndex(index);
-        }
-        return this.colorList.get(index);
-    }
-
-    public Integer generateColorForIndex(int index){
-        int r[] = new int[]{0,0,1,1,0,1,1};
-        int g[] = new int[]{0,1,0,0,1,1,1};
-        int b[] = new int[]{1,0,0,1,1,0,1};
-
-        int a = (index / 7);
-        int n = index % 7;
-
-        int q = Math.max(1, 2 * (a / 7));
-        int multiplier = 16 / (q);
-
-        int sub = (Math.min(((Math.max(0,(a ))) * multiplier), 16));
-
-        int R = Math.max( (r[n] * 255) - sub, 0);
-        int G = Math.max( (g[n] * 255) - sub, 0);
-        int B = Math.max( (b[n] * 255) - sub, 0);
-
-        return Color.argb(255,R,G,B);
+        return Color.argb(255, 80, 80, 80); // grey
+	}
+	
+    public Integer getColor(int index) {
+		return ColorSequenceGenerator.getColorForIndex(index);
     }
 
 

+ 27 - 0
src/de/tudarmstadt/informatik/hostage/ui2/helper/ColorSequenceGenerator.java

@@ -0,0 +1,27 @@
+package de.tudarmstadt.informatik.hostage.ui2.helper;
+
+import android.graphics.Color;
+
+/**
+ * Idea from http://ridiculousfish.com/blog/posts/colors.html
+ * Created by Fabio Arnold on 25.02.14.
+ */
+public class ColorSequenceGenerator {
+	private static final int BIT_COUNT = 31; // sadly there is no unsigned type in java
+	public static int getColorForIndex(int index) {
+		int reverseIndex = 0;
+		for (int i = 0; i  < BIT_COUNT; i++) {
+			reverseIndex = (reverseIndex << 1) | (index & 1);
+			index >>= 1;
+		}
+		float hue = ((float)reverseIndex / (float)(1 << BIT_COUNT) + 0.6f) % 1.0f;
+
+
+		float[] hsv = new float[3];
+		hsv[0] = 360.0f * hue;
+		hsv[1] = 0.7f; // not fully saturated
+		hsv[2] = 1.0f;
+
+		return Color.HSVToColor(hsv);
+	}
+}