Bläddra i källkod

fixed last merge conflicts

Alexander Brakowski 10 år sedan
förälder
incheckning
32eb0ee049

+ 32 - 3
res/layout/fragment_about.xml

@@ -10,7 +10,6 @@
 			android:layout_height="match_parent"
 			android:id="@+id/imageView" android:src="@drawable/hostage_logo_tilted"
 			android:layout_weight="0.6" android:layout_margin="24dp"/>
-
 	<TextView
 			android:layout_width="wrap_content"
 			android:layout_height="wrap_content"
@@ -25,16 +24,18 @@
 			android:text="a low-interaction honeypot for mobile devices"
 			android:id="@+id/textView7" android:layout_gravity="center_horizontal"
 			/>
+
     <ScrollView android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="15dp"
                 android:layout_marginBottom="10dp"
                 android:layout_marginRight="15dp">
+
 	<RelativeLayout
 			android:orientation="horizontal"
 			android:layout_width="fill_parent"
 			android:layout_height="fill_parent" android:layout_weight="0.7"
-			android:paddingTop="20dp">
+			android:paddingTop="15dp">
 
 		<LinearLayout
 				android:orientation="vertical"
@@ -101,7 +102,7 @@
 			          android:textAlignment="center" android:layout_gravity="right"/>
 			<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
 			          android:textAppearance="?android:attr/textAppearanceMedium"
-			          android:text="Wulf Pfeiffer" android:id="@+id/record_conversation_type"
+			          android:text="Wulf Pfeiffer" 
 			          android:singleLine="false"
 			          android:autoText="false" android:layout_marginTop="4dp"
 			          android:textAlignment="center" android:layout_gravity="right"/>
@@ -114,4 +115,32 @@
 		</LinearLayout>
 	</RelativeLayout>
     </ScrollView>
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1"
+        android:paddingTop="5dp"
+        android:layout_marginBottom="5dp">
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/tud_logo"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp"
+            android:layout_weight="0.5"/>
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/cased_logo"
+            android:layout_marginRight="5dp"
+            android:layout_weight="0.5"/>
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/tk_logo"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp"
+            android:layout_weight="0.1"/>
+    </LinearLayout>
 </LinearLayout>

+ 179 - 141
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -2,7 +2,6 @@ package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
 import java.util.List;
 
-import android.annotation.TargetApi;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -20,146 +19,185 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
 /**
- * Created by Daniel Lazar on 06.02.14.
+ * @author Daniel Lazar
+ * @created 06.02.14.
+ * a list adapter for loading switches and service information asynchronously
  */
 public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
-
-	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;
-
-	public ServicesListAdapter(Context context, List<ServicesListItem> objects) {
-		super(context, R.layout.services_list_item, objects);
-
-		this.context = context;
-		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;
-
-		ViewHolder holder;
-
-		final ServicesListItem item = values.get(position);
-
-		if (rowView == null) {
-			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);
-			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();
-
-				if (!HelperUtils.isWifiConnected(mActivity)) {
-					new AlertDialog.Builder(mActivity).setTitle(R.string.information).setMessage(R.string.wifi_not_connected_msg)
-							.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 {
-					// check if switch is set to ON and start the concrete
-					// listener for the protocol
-					if (isChecked) {
-						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
-							mServicesSwitch.setOnCheckedChangeListener(null);
-							mServicesSwitch.setChecked(true);
-							mServicesSwitch.setOnCheckedChangeListener(mListener);
-							buttonView.setChecked(true);
-						} else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-							buttonView.setChecked(true);
-						}
-					} else {
-						if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-							MainActivity.getInstance().getHostageService().stopListener(item.protocol);
-						}
-						buttonView.setChecked(false);
-					}
-				}
-			}
-		});
-		return rowView;
-	}
-
-	private void updateStatus(ServicesListItem item, ViewHolder holder) {
-		if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-			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().getNumberOfActiveConnections(item.protocol) > 0) {
-					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);
-		}
-		holder.recordedAttacks.setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + "  %d",
-				Integer.valueOf(item.attacks)));
-	}
-
-	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
-	private void setBackground(ViewHolder holder, int drawable) {
-		if (sdk < Build.VERSION_CODES.JELLY_BEAN) {
-			holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
-		} else {
-			holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(drawable));
-		}
-	}
+    private final Context context;
+    private final List<ServicesListItem> values;
+    int sdk = Build.VERSION.SDK_INT;
+    private Context mActivity;
+    private Switch mServicesSwitch;
+    private CompoundButton.OnCheckedChangeListener mListener;
+
+    /**
+     * constructor
+     *
+     * @param context Context of the current activity
+     * @param objects List of ServicesListItem which contains all the protocols
+     */
+    public ServicesListAdapter(Context context, List<ServicesListItem> objects) {
+        super(context, R.layout.services_list_item, objects);
+
+        this.context = context;
+        this.values = objects;
+    }
+
+    /**
+     * method to save important information from parent fragment
+     *
+     * @param activity       activicty from parent fragment
+     * @param servicesSwitch the switch from parent fragment
+     * @param mainListener   Listener from parent fragment
+     */
+    public void setActivity(Context activity, Switch servicesSwitch, CompoundButton.OnCheckedChangeListener mainListener) {
+        mActivity = activity;
+        mServicesSwitch = servicesSwitch;
+        mListener = mainListener;
+    }
+
+    /**
+     * main method of ServicesListAdapter which initializes the holder if null
+     * Also activates protocols and switches
+     *
+     * @param position    current position in list
+     * @param convertView
+     * @param parent
+     * @return
+     */
+    @Override
+    public View getView(final int position, View convertView, ViewGroup parent) {
+        LayoutInflater inflater = (LayoutInflater) context
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        View rowView = convertView;
+
+        ViewHolder holder;
+
+        final ServicesListItem item = values.get(position);
+
+        if (rowView == null) {
+            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);
+            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();
+
+                        if (!HelperUtils.isWifiConnected(mActivity)) {
+                            new AlertDialog.Builder(mActivity)
+                                    .setTitle(R.string.information)
+                                    .setMessage(R.string.wifi_not_connected_msg)
+                                    .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 {
+                            //check if switch is set to ON and start the concrete listener for the protocol
+                            if (isChecked) {
+                                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
+                                    mServicesSwitch.setOnCheckedChangeListener(null);
+                                    mServicesSwitch.setChecked(true);
+                                    mServicesSwitch.setOnCheckedChangeListener(mListener);
+                                    buttonView.setChecked(true);
+                                } else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                    buttonView.setChecked(true);
+                                }
+                            } else {
+                                if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                    MainActivity.getInstance().getHostageService().stopListener(item.protocol);
+                                }
+                                buttonView.setChecked(false);
+                            }
+                        }
+                    }
+                }
+        );
+        return rowView;
+    }
+
+    /**
+     * method to update the current status, which includes changing the attack indication circle and the number of attacks
+     *
+     * @param item   ServiceListItem which has information about current item, e.g. protocol, activated, attacks
+     * @param holder ViewHolder which represents the item in the View
+     */
+    private void updateStatus(ServicesListItem item, ViewHolder holder) {
+        if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+            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);
+        }
+        holder.recordedAttacks
+                .setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + "  %d", Integer.valueOf(item.attacks)));
+    }
+
+    /**
+     * changes the indicator circle of a service
+     *
+     * @param holder   ViewHolder which represents the item in the View
+     * @param drawable int which represents the ID of the drawable we want to display, e.g. on a present attack it should be R.drawable.services_circle_red
+     */
+    private void setBackground(ViewHolder holder, int drawable) {
+        if (sdk < Build.VERSION_CODES.JELLY_BEAN) {
+            holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
+        } else {
+            holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(drawable));
+        }
+    }
+
+    /**
+     * ViewHolder stands for a row in the view
+     */
+    private class ViewHolder {
+
+        public TextView protocolName;
+
+        public TextView recordedAttacks;
+
+        public Switch activated;
+
+        public View circle;
+    }
 }

+ 248 - 195
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -28,202 +28,255 @@ import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
 /**
- * Created by Daniel Lazar on 05.02.14.
+ * @author Daniel Lazar
+ * @created 05.02.14
+ * Fragment that displays a switch for every protocol.
+ * Also it can de-/activate every protocol by using this switch.
  */
 public class ServicesFragment extends Fragment {
-
-	private Switch mServicesSwitchService;
-	private TextView mServicesTextName;
-
-	private View rootView;
-
-	private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
-
-	private BroadcastReceiver mReceiver;
-
-	private ServicesListAdapter adapter;
-
-	private ArrayList<ServicesListItem> protocolList;
-
-	private UglyDbHelper dbh = new UglyDbHelper(MainActivity.getContext());
-
-	private String[] protocols;
-
-	private SharedPreferences mConnectionInfo;
-
-	private boolean mReceiverRegistered = false;
-
-	private void assignViews() {
-		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
-		mServicesTextName = (TextView) rootView.findViewById(R.id.services_text_name);
-
-		rootView.findViewById(R.id.services_button_connection_info).setOnClickListener(new View.OnClickListener() {
-			@Override
-			public void onClick(View v) {
-				ConnectionInfoDialogFragment connectionInfoDialogFragment = new ConnectionInfoDialogFragment();
-				connectionInfoDialogFragment.show(getFragmentManager().beginTransaction(), connectionInfoDialogFragment.getTag());
-			}
-		});
-
-	}
-
-	public void updateUI() {
-		if (!HelperUtils.isWifiConnected(getActivity())) {
-			mServicesSwitchService.setOnCheckedChangeListener(null);
-			setStateNotConnected();
-			setStateNotActive();
-			mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
-		} else {
-			if (MainActivity.getInstance().getHostageService().hasRunningListeners()) {
-				setStateActive();
-			}
-
-			mServicesTextName.setText(HelperUtils.getSSID(getActivity()));
-		}
-
-	}
-
-	public ServicesFragment() {
-	}
-
-	private void registerBroadcastReceiver() {
-		if (!mReceiverRegistered) {
-			mReceiver = new BroadcastReceiver() {
-				@Override
-				public void onReceive(Context context, Intent intent) {
-					String sender = intent.getStringExtra("SENDER");
-					String[] values = intent.getStringArrayExtra("VALUES");
-
-					if (sender.equals(Handler.class.getName()) && values[0].equals(getString(R.string.broadcast_started))) {
-						for (ServicesListItem item : protocolList) {
-							if (item.protocol.equals(values[1])) {
-								item.attacks = dbh.numBssidSeen(item.protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
-							}
-						}
-					}
-
-					if (!MainActivity.getInstance().getHostageService().hasRunningListeners()) {
-						setStateNotActive();
-					} else {
-						setStateActive();
-					}
-
-					adapter.notifyDataSetChanged();
-				}
-			};
-
-			LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
-			this.mReceiverRegistered = true;
-		}
-	}
-
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
-		super.onCreateView(inflater, container, savedInstanceState);
-
-		rootView = inflater.inflate(R.layout.fragment_services, container, false);
-		assignViews();
-
-		protocols = getResources().getStringArray(R.array.protocols);
-		mConnectionInfo = getActivity().getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
-
-		updateUI();
-
-		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 = dbh.numBssidSeen(protocolList.get(i).protocol,
-					mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
-			i++;
-		}
-
-		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
-
-		if (switchChangeListener == null) {
-			switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
-				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-					if (!HelperUtils.isWifiConnected(getActivity())) {
-						new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.wifi_not_connected_msg)
-								.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-									public void onClick(DialogInterface dialog, int which) {
-
-									}
-								}).setIcon(android.R.drawable.ic_dialog_info).show();
-
-						setStateNotActive();
-						setStateNotConnected();
-					} else {
-						if (MainActivity.getInstance().isServiceBound()) {
-							if (isChecked) {
-								for (String protocol : protocols) {
-									if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
-										MainActivity.getInstance().getHostageService().startListener(protocol);
-									}
-								}
-								setStateActive();
-							} else {
-								MainActivity.getInstance().getHostageService().stopListeners();
-								MainActivity.getInstance().stopAndUnbind();
-								setStateNotActive();
-							}
-						}
-					}
-				}
-
-			};
-		}
-		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
-
-		adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
-		adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
-		list.setAdapter(adapter);
-
-		registerBroadcastReceiver();
-
-		return rootView;
-
-	};
-
-	@Override
-	public void onStart() {
-		super.onStart();
-		registerBroadcastReceiver();
-		mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
-	}
-
-	private void unregisterBroadcastReceiver() {
-		if (mReceiverRegistered) {
-			LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
-			this.mReceiverRegistered = false;
-		}
-	}
-
-	private void setStateActive() {
-		mServicesSwitchService.setChecked(true);
-	}
-
-	private void setStateNotConnected() {
-		mServicesTextName.setText(R.string.not_connected);
-	}
-
-	private void setStateNotActive() {
-		mServicesSwitchService.setChecked(false);
-	}
-
-	@Override
-	public void onStop() {
-		super.onStop();
-		mServicesSwitchService.setOnCheckedChangeListener(null);
-	}
-
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		unregisterBroadcastReceiver();
-	}
+    private Switch mServicesSwitchService;
+    private TextView mServicesTextName;
+
+    private View rootView;
+
+    private CompoundButton.OnCheckedChangeListener switchChangeListener = null;
+
+    private BroadcastReceiver mReceiver;
+
+    private ServicesListAdapter adapter;
+
+    private ArrayList<ServicesListItem> protocolList;
+
+    private UglyDbHelper dbh = new UglyDbHelper(MainActivity.getContext());
+
+    private String[] protocols;
+
+    private SharedPreferences mConnectionInfo;
+
+    private boolean mReceiverRegistered = false;
+
+    public ServicesFragment() {
+    }
+
+    /**
+     * assign views which are not asynchronously loaded
+     */
+    private void assignViews() {
+        mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
+        mServicesTextName = (TextView) rootView.findViewById(R.id.services_text_name);
+
+        rootView.findViewById(R.id.services_button_connection_info).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ConnectionInfoDialogFragment connectionInfoDialogFragment = new ConnectionInfoDialogFragment();
+                connectionInfoDialogFragment.show(getFragmentManager().beginTransaction(), connectionInfoDialogFragment.getTag());
+            }
+        });
+
+    }
+
+    /**
+     * updates the user interface
+     * in detail: the main switch and the textField mServicesTextName
+     */
+    public void updateUI() {
+        if (!HelperUtils.isWifiConnected(getActivity())) {
+            mServicesSwitchService.setOnCheckedChangeListener(null);
+            setStateNotConnected();
+            setStateNotActive();
+            mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
+        } else {
+            if (MainActivity.getInstance().getHostageService().hasRunningListeners()) {
+                setStateActive();
+            }
+
+            mServicesTextName.setText(HelperUtils.getSSID(getActivity()));
+        }
+
+    }
+
+    /**
+     * register a broadcast receiver if not already registered
+     * and also update the number of attacks per protocol
+     */
+    private void registerBroadcastReceiver() {
+        if (!mReceiverRegistered) {
+            mReceiver = new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    String sender = intent.getStringExtra("SENDER");
+                    String[] values = intent.getStringArrayExtra("VALUES");
+
+                    if (sender.equals(Handler.class.getName()) && values[0].equals(getString(R.string.broadcast_started))) {
+                        for (ServicesListItem item : protocolList) {
+                            if (item.protocol.equals(values[1])) {
+                                item.attacks = dbh.numBssidSeen(item.protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
+                            }
+                        }
+                    }
+
+                    if (!MainActivity.getInstance().getHostageService().hasRunningListeners()) {
+                        setStateNotActive();
+                    } else {
+                        setStateActive();
+                    }
+
+                    adapter.notifyDataSetChanged();
+                }
+            };
+
+            LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
+            this.mReceiverRegistered = true;
+        }
+    }
+
+
+    /**
+     * most important method of this class
+     *
+     * @param inflater
+     * @param container
+     * @param savedInstanceState
+     * @return rootView
+     */
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+        super.onCreateView(inflater, container, savedInstanceState);
+
+        rootView = inflater.inflate(R.layout.fragment_services, container, false);
+        assignViews();
+
+        protocols = getResources().getStringArray(R.array.protocols);
+        mConnectionInfo = getActivity().getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
+
+        updateUI();
+
+        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 = dbh.numBssidSeen(protocolList.get(i).protocol, mConnectionInfo.getString(getString(R.string.connection_info_bssid), null));
+            i++;
+        }
+
+        mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
+
+        if (switchChangeListener == null) {
+            switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
+                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                    if (!HelperUtils.isWifiConnected(getActivity())) {
+                        new AlertDialog.Builder(getActivity())
+                                .setTitle(R.string.information)
+                                .setMessage(R.string.wifi_not_connected_msg)
+                                .setPositiveButton(android.R.string.ok,
+                                        new DialogInterface.OnClickListener() {
+                                            public void onClick(DialogInterface dialog, int which) {
+
+                                            }
+                                        }
+                                )
+                                .setIcon(android.R.drawable.ic_dialog_info)
+                                .show();
+
+                        setStateNotActive();
+                        setStateNotConnected();
+                    } else {
+                        if (MainActivity.getInstance().isServiceBound()) {
+                            if (isChecked) {
+                                for (String protocol : protocols) {
+                                    if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
+                                        MainActivity.getInstance().getHostageService().startListener(protocol);
+                                    }
+                                }
+                                setStateActive();
+                            } else {
+                                MainActivity.getInstance().getHostageService().stopListeners();
+                                MainActivity.getInstance().stopAndUnbind();
+                                setStateNotActive();
+                            }
+                        }
+                    }
+                }
+
+            };
+        }
+        mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
+
+        adapter = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
+        adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
+        list.setAdapter(adapter);
+
+        registerBroadcastReceiver();
+
+        return rootView;
+
+    }
+
+    ;
+
+    /**
+     * called on start of this fragment.
+     * registers broadcast receiver and binds change listener to main switch
+     */
+    @Override
+    public void onStart() {
+        super.onStart();
+        registerBroadcastReceiver();
+        mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
+    }
+
+    /**
+     * unregister the broadcast receiver if a receiver is already registered
+     */
+    private void unregisterBroadcastReceiver() {
+        if (mReceiverRegistered) {
+            LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
+            this.mReceiverRegistered = false;
+        }
+    }
+
+    /**
+     * sets main switch to true
+     */
+    private void setStateActive() {
+        mServicesSwitchService.setChecked(true);
+    }
+
+    /**
+     * sets text of text field to not connected, if the device is not connected to a network
+     */
+    private void setStateNotConnected() {
+        mServicesTextName.setText(R.string.not_connected);
+    }
+
+    /**
+     * sets main switch to false
+     */
+    private void setStateNotActive() {
+        mServicesSwitchService.setChecked(false);
+    }
+
+    /**
+     * overrides onStop
+     * unloads the ChangeListener
+     */
+    @Override
+    public void onStop() {
+        super.onStop();
+        mServicesSwitchService.setOnCheckedChangeListener(null);
+    }
+
+    /**
+     * overrides onDestroy
+     * unregisters broadcast receiver, when destroyed
+     */
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        unregisterBroadcastReceiver();
+    }
 
 }

+ 3 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/opengl/AnimatedMesh.java

@@ -62,10 +62,13 @@ public class AnimatedMesh {
 	public boolean isActionDone() {
 		if (currentAction == null)
 			return true;
+		return currentFrame <= 1 || currentFrame >= currentAction.numFrames - 1;
+		/*
 		if (reverseAction)
 			return currentFrame <= 0;
 		else
 			return currentFrame >= currentAction.numFrames - 1;
+			*/
 	}
 	
 	private class Bone {

+ 9 - 1
src/de/tudarmstadt/informatik/hostage/ui2/model/ServicesListItem.java

@@ -1,7 +1,10 @@
 package de.tudarmstadt.informatik.hostage.ui2.model;
 
 /**
- * Created by Daniel Lazar on 06.02.14.
+ * @author Daniel Lazar
+ * @created 06.02.14
+ *
+ * defines a service list item
  */
 public class ServicesListItem {
 	public String protocol;
@@ -9,6 +12,11 @@ public class ServicesListItem {
 
 	public boolean activated;
 
+    /**
+     * constructor of a service list item
+     *
+     * @param protocol protocol of this item, e.g. ftp
+     */
 	public ServicesListItem(String protocol){
 		this.protocol = protocol;
 		this.activated = false;