|
@@ -23,7 +23,6 @@ import java.util.ArrayList;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
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.logging.UglyDbHelper;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
|
|
import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
|
|
@@ -54,6 +53,8 @@ public class ServicesFragment extends Fragment{
|
|
|
|
|
|
private SharedPreferences mConnectionInfo;
|
|
private SharedPreferences mConnectionInfo;
|
|
|
|
|
|
|
|
+ private boolean mReceiverRegistered = false;
|
|
|
|
+
|
|
|
|
|
|
private void assignViews(){
|
|
private void assignViews(){
|
|
mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
|
|
mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
|
|
@@ -83,6 +84,7 @@ public class ServicesFragment extends Fragment{
|
|
public ServicesFragment(){}
|
|
public ServicesFragment(){}
|
|
|
|
|
|
private void registerBroadcastReceiver(){
|
|
private void registerBroadcastReceiver(){
|
|
|
|
+ if(!mReceiverRegistered){
|
|
mReceiver = new BroadcastReceiver() {
|
|
mReceiver = new BroadcastReceiver() {
|
|
@Override
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
public void onReceive(Context context, Intent intent) {
|
|
@@ -99,6 +101,8 @@ public class ServicesFragment extends Fragment{
|
|
|
|
|
|
LocalBroadcastManager
|
|
LocalBroadcastManager
|
|
.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
|
|
.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
|
|
|
|
+ this.mReceiverRegistered = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -117,18 +121,16 @@ public class ServicesFragment extends Fragment{
|
|
ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
|
|
ListView list = (ListView) rootView.findViewById(R.id.services_list_view);
|
|
|
|
|
|
protocolList= new ArrayList<ServicesListItem>();
|
|
protocolList= new ArrayList<ServicesListItem>();
|
|
-
|
|
|
|
|
|
+ int i=0;
|
|
for(String protocol: protocols){
|
|
for(String protocol: protocols){
|
|
protocolList.add(new ServicesListItem(protocol));
|
|
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)){
|
|
if(MainActivity.getInstance().getHoneyService().isRunning(protocol)){
|
|
setStateActive();
|
|
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 = new ServicesListAdapter(getActivity().getBaseContext(), protocolList);
|
|
adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
|
|
adapter.setActivity(this.getActivity(), this.mServicesSwitchService, this.switchChangeListener);
|
|
list.setAdapter(adapter);
|
|
list.setAdapter(adapter);
|
|
@@ -156,18 +158,21 @@ public class ServicesFragment extends Fragment{
|
|
setStateNotActive();
|
|
setStateNotActive();
|
|
setStateNotConnected();
|
|
setStateNotConnected();
|
|
} else {
|
|
} 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);
|
|
mServicesSwitchService.setOnCheckedChangeListener(switchChangeListener);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
return rootView;
|
|
return rootView;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onStart(){
|
|
public void onStart(){
|
|
- super.onStart();
|
|
|
|
registerBroadcastReceiver();
|
|
registerBroadcastReceiver();
|
|
|
|
+ super.onStart();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onStop(){
|
|
public void onStop(){
|
|
- super.onStop();
|
|
|
|
unregisterBroadcastReceiver();
|
|
unregisterBroadcastReceiver();
|
|
|
|
+ super.onStop();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void unregisterBroadcastReceiver(){
|
|
private void unregisterBroadcastReceiver(){
|
|
- LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
|
|
|
|
|
+ if(mReceiverRegistered){
|
|
|
|
+ LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
|
|
|
+ this.mReceiverRegistered = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void setStateActive() {
|
|
private void setStateActive() {
|
|
@@ -214,8 +220,8 @@ public class ServicesFragment extends Fragment{
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onDestroy(){
|
|
public void onDestroy(){
|
|
|
|
+ unregisterBroadcastReceiver();
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
- LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|