|
@@ -1,7 +1,5 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui;
|
|
|
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.UnknownHostException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
|
|
@@ -15,9 +13,6 @@ import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
|
import android.net.ConnectivityManager;
|
|
|
-import android.net.NetworkInfo;
|
|
|
-import android.net.wifi.WifiInfo;
|
|
|
-import android.net.wifi.WifiManager;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
@@ -41,6 +36,7 @@ import de.tudarmstadt.informatik.hostage.HoneyListener;
|
|
|
import de.tudarmstadt.informatik.hostage.HoneyService;
|
|
|
import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
|
|
|
public class MainActivity extends Activity {
|
|
|
|
|
@@ -63,8 +59,8 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
private ListView listView;
|
|
|
private ListViewAdapter adapter;
|
|
|
-
|
|
|
- private boolean running;
|
|
|
+
|
|
|
+ private String protocolClicked;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -104,20 +100,21 @@ public class MainActivity extends Activity {
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
- updateWifiInfo();
|
|
|
+ updateConnectionInfo();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onTouchEvent(MotionEvent event) {
|
|
|
- return gestureDetector.onTouchEvent(event);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
public void buttonOnOffClick(View view) {
|
|
|
if (((ToggleButton) view).isChecked()) {
|
|
|
+ if (isParanoid()) {
|
|
|
+ protocolClicked = "PANIC";
|
|
|
+ } else {
|
|
|
+ protocolClicked = "SMB";
|
|
|
+ }
|
|
|
startAndBind();
|
|
|
} else {
|
|
|
stopAndUnbind();
|
|
|
- running = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -131,23 +128,34 @@ public class MainActivity extends Activity {
|
|
|
unbindService(mConnection);
|
|
|
stopService(getServiceIntent());
|
|
|
}
|
|
|
+
|
|
|
+ private ServiceConnection mConnection = new ServiceConnection() {
|
|
|
|
|
|
- private boolean isParanoid() {
|
|
|
- return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
+ mService = ((LocalBinder) service).getService();
|
|
|
+ if(protocolClicked != null && protocolClicked.equals("PANIC")){
|
|
|
+ mService.startListeners();
|
|
|
+ }else{
|
|
|
+ mService.toggleListener(protocolClicked);
|
|
|
+ }
|
|
|
+ protocolClicked = null;
|
|
|
+ updateUI();
|
|
|
+ }
|
|
|
|
|
|
- private void initViewAnimator() {
|
|
|
- viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
|
|
|
- gestureDetector = new GestureDetector(this, simpleOnGestureListener);
|
|
|
+ @Override
|
|
|
+ public void onServiceDisconnected(ComponentName name) {
|
|
|
+ mService = null;
|
|
|
+ }
|
|
|
|
|
|
- animFlipInLR = AnimationUtils.loadAnimation(this,
|
|
|
- R.anim.in_left_to_right);
|
|
|
- animFlipOutLR = AnimationUtils.loadAnimation(this,
|
|
|
- R.anim.out_left_to_right);
|
|
|
- animFlipInRL = AnimationUtils.loadAnimation(this,
|
|
|
- R.anim.in_right_to_left);
|
|
|
- animFlipOutRL = AnimationUtils.loadAnimation(this,
|
|
|
- R.anim.out_right_to_left);
|
|
|
+ };
|
|
|
+
|
|
|
+ private Intent getServiceIntent() {
|
|
|
+ return new Intent(this, HoneyService.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isParanoid() {
|
|
|
+ return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
|
|
|
}
|
|
|
|
|
|
private void initListView() {
|
|
@@ -177,84 +185,30 @@ public class MainActivity extends Activity {
|
|
|
int position, long id) {
|
|
|
String protocolName = (String) ((HashMap<?, ?>) adapter
|
|
|
.getItem(position)).get("protocol");
|
|
|
- if (!isServiceRunning()) {
|
|
|
+ if (isServiceRunning()) {
|
|
|
+ mService.toggleListener(protocolName);
|
|
|
+ if(!mService.hasRunningListeners())
|
|
|
+ stopAndUnbind();
|
|
|
+ }else{
|
|
|
+ protocolClicked = protocolName;
|
|
|
startAndBind();
|
|
|
- }
|
|
|
- mService.toggleListener(protocolName);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void swipeRightToLeft() {
|
|
|
- if (viewAnimator.getDisplayedChild() == 0) {
|
|
|
- viewAnimator.setInAnimation(animFlipInRL);
|
|
|
- viewAnimator.setOutAnimation(animFlipOutRL);
|
|
|
- viewAnimator.setDisplayedChild(1);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private void swipeLeftToRight() {
|
|
|
- if (viewAnimator.getDisplayedChild() == 1) {
|
|
|
- viewAnimator.setInAnimation(animFlipInLR);
|
|
|
- viewAnimator.setOutAnimation(animFlipOutLR);
|
|
|
- viewAnimator.setDisplayedChild(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {
|
|
|
- @Override
|
|
|
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
|
|
- float velocityY) {
|
|
|
- float sensitvity = 50;
|
|
|
- if ((e1.getX() - e2.getX()) > sensitvity) {
|
|
|
- swipeRightToLeft();
|
|
|
- } else if ((e2.getX() - e1.getX()) > sensitvity) {
|
|
|
- swipeLeftToRight();
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
private boolean isServiceRunning() {
|
|
|
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
- for (RunningServiceInfo service : manager
|
|
|
- .getRunningServices(Integer.MAX_VALUE)) {
|
|
|
- if (service.service.getClassName().equals(
|
|
|
- HoneyService.class.getName())) {
|
|
|
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
|
+ if (service.service.getClassName().equals(HoneyService.class.getName())) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private Intent getServiceIntent() {
|
|
|
- return new Intent(this, HoneyService.class);
|
|
|
- }
|
|
|
-
|
|
|
- private ServiceConnection mConnection = new ServiceConnection() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
- mService = ((LocalBinder) service).getService();
|
|
|
- if (!running) {
|
|
|
- if (isParanoid()) {
|
|
|
- mService.startListeners();
|
|
|
- } else {
|
|
|
- mService.startListener("SMB");
|
|
|
- }
|
|
|
- }
|
|
|
- running = true;
|
|
|
- updateUI();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onServiceDisconnected(ComponentName name) {
|
|
|
- mService = null;
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
|
|
|
private void registerReceiver() {
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
|
|
@@ -287,7 +241,7 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
- updateWifiInfo();
|
|
|
+ updateConnectionInfo();
|
|
|
}
|
|
|
|
|
|
};
|
|
@@ -296,6 +250,7 @@ public class MainActivity extends Activity {
|
|
|
boolean activeListeners = false;
|
|
|
boolean activeHandlers = false;
|
|
|
|
|
|
+ if(mService != null){
|
|
|
for (HoneyListener listener : mService.getListeners()) {
|
|
|
if (listener.isRunning()) {
|
|
|
activeListeners = true;
|
|
@@ -311,6 +266,7 @@ public class MainActivity extends Activity {
|
|
|
updateProtocolLight(LIGHT_GREY, listener.getProtocolName());
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
if (activeListeners) {
|
|
|
if (activeHandlers) {
|
|
@@ -388,43 +344,93 @@ public class MainActivity extends Activity {
|
|
|
adapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
- private void updateWifiInfo() {
|
|
|
- ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
- NetworkInfo info = manager.getActiveNetworkInfo();
|
|
|
-
|
|
|
+ private void updateConnectionInfo() {
|
|
|
TextView ssidView = (TextView) findViewById(R.id.textViewSSIDValue);
|
|
|
TextView bssidView = (TextView) findViewById(R.id.textViewBSSIDValue);
|
|
|
- TextView ipView = (TextView) findViewById(R.id.textViewIPValue);
|
|
|
-
|
|
|
- if (info != null && info.isConnectedOrConnecting()
|
|
|
- && info.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
|
-
|
|
|
- WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
|
|
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
|
- ssidView.setText(wifiInfo.getSSID());
|
|
|
- bssidView.setText(wifiInfo.getBSSID());
|
|
|
- try {
|
|
|
- String ip = InetAddress.getByAddress(
|
|
|
- unpackInetAddress(wifiInfo.getIpAddress()))
|
|
|
- .getHostAddress();
|
|
|
- ipView.setText(ip);
|
|
|
- } catch (UnknownHostException e) {
|
|
|
- }
|
|
|
- } else {
|
|
|
+ TextView internalIPView = (TextView) findViewById(R.id.textViewInternalIPValue);
|
|
|
+ TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
|
|
|
+
|
|
|
+ String ssid = HelperUtils.getSSID(getApplicationContext());
|
|
|
+ String bssid = HelperUtils.getBSSID(getApplicationContext());
|
|
|
+ String internalIP = HelperUtils.getInternalIP(getApplicationContext());
|
|
|
+ String externalIP = HelperUtils.getExternalIP(getApplicationContext());
|
|
|
+
|
|
|
+ if (ssid != null)
|
|
|
+ ssidView.setText(ssid);
|
|
|
+ else
|
|
|
ssidView.setText("-");
|
|
|
+
|
|
|
+ if (bssid != null)
|
|
|
+ bssidView.setText(bssid);
|
|
|
+ else
|
|
|
bssidView.setText("-");
|
|
|
- ipView.setText("-");
|
|
|
- }
|
|
|
+
|
|
|
+ if (internalIP != null)
|
|
|
+ internalIPView.setText(internalIP);
|
|
|
+ else
|
|
|
+ internalIPView.setText("-");
|
|
|
+
|
|
|
+ if (externalIP != null)
|
|
|
+ externalIPView.setText(externalIP);
|
|
|
+ else
|
|
|
+ externalIPView.setText("-");
|
|
|
|
|
|
ssidView.invalidate();
|
|
|
bssidView.invalidate();
|
|
|
- ipView.invalidate();
|
|
|
+ internalIPView.invalidate();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*############# AB HIER KOMMEN HILFSFUNKTIONEN FÜR GESTEN ##################*/
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onTouchEvent(MotionEvent event) {
|
|
|
+ return gestureDetector.onTouchEvent(event);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initViewAnimator() {
|
|
|
+ viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
|
|
|
+ gestureDetector = new GestureDetector(this, simpleOnGestureListener);
|
|
|
+
|
|
|
+ animFlipInLR = AnimationUtils.loadAnimation(this,
|
|
|
+ R.anim.in_left_to_right);
|
|
|
+ animFlipOutLR = AnimationUtils.loadAnimation(this,
|
|
|
+ R.anim.out_left_to_right);
|
|
|
+ animFlipInRL = AnimationUtils.loadAnimation(this,
|
|
|
+ R.anim.in_right_to_left);
|
|
|
+ animFlipOutRL = AnimationUtils.loadAnimation(this,
|
|
|
+ R.anim.out_right_to_left);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void swipeRightToLeft() {
|
|
|
+ if (viewAnimator.getDisplayedChild() == 0) {
|
|
|
+ viewAnimator.setInAnimation(animFlipInRL);
|
|
|
+ viewAnimator.setOutAnimation(animFlipOutRL);
|
|
|
+ viewAnimator.setDisplayedChild(1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private byte[] unpackInetAddress(int bytes) {
|
|
|
- return new byte[] { (byte) ((bytes) & 0xff),
|
|
|
- (byte) ((bytes >>> 8) & 0xff), (byte) ((bytes >>> 16) & 0xff),
|
|
|
- (byte) ((bytes >>> 24) & 0xff) };
|
|
|
+ private void swipeLeftToRight() {
|
|
|
+ if (viewAnimator.getDisplayedChild() == 1) {
|
|
|
+ viewAnimator.setInAnimation(animFlipInLR);
|
|
|
+ viewAnimator.setOutAnimation(animFlipOutLR);
|
|
|
+ viewAnimator.setDisplayedChild(0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
|
|
+ float velocityY) {
|
|
|
+ float sensitvity = 50;
|
|
|
+ if ((e1.getX() - e2.getX()) > sensitvity) {
|
|
|
+ swipeRightToLeft();
|
|
|
+ } else if ((e2.getX() - e1.getX()) > sensitvity) {
|
|
|
+ swipeLeftToRight();
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
}
|