|
@@ -1,5 +1,7 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui;
|
|
|
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.UnknownHostException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
|
|
@@ -12,6 +14,10 @@ import android.content.Context;
|
|
|
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;
|
|
@@ -28,6 +34,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListView;
|
|
|
+import android.widget.TextView;
|
|
|
import android.widget.ToggleButton;
|
|
|
import android.widget.ViewAnimator;
|
|
|
import de.tudarmstadt.informatik.hostage.HoneyListener;
|
|
@@ -78,6 +85,7 @@ public class MainActivity extends Activity {
|
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
|
registerReceiver();
|
|
|
+ registerNetReceiver();
|
|
|
if (isServiceRunning()) {
|
|
|
bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
|
|
|
}
|
|
@@ -85,11 +93,18 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
- super.onStop();
|
|
|
if (isServiceRunning()) {
|
|
|
unbindService(mConnection);
|
|
|
}
|
|
|
unregisterReceiver();
|
|
|
+ unregisterNetReceiver();
|
|
|
+ super.onStop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ updateWifiInfo();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -250,6 +265,15 @@ public class MainActivity extends Activity {
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
|
|
}
|
|
|
|
|
|
+ private void registerNetReceiver() {
|
|
|
+ LocalBroadcastManager.getInstance(this).registerReceiver(netReceiver,
|
|
|
+ new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void unregisterNetReceiver() {
|
|
|
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(netReceiver);
|
|
|
+ }
|
|
|
+
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
|
|
@Override
|
|
@@ -259,6 +283,15 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ private BroadcastReceiver netReceiver = new BroadcastReceiver() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ updateWifiInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
private void updateUI() {
|
|
|
boolean activeListeners = false;
|
|
|
boolean activeHandlers = false;
|
|
@@ -355,4 +388,43 @@ public class MainActivity extends Activity {
|
|
|
adapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
+ private void updateWifiInfo() {
|
|
|
+ ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
+ NetworkInfo info = manager.getActiveNetworkInfo();
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ ssidView.setText("-");
|
|
|
+ bssidView.setText("-");
|
|
|
+ ipView.setText("-");
|
|
|
+ }
|
|
|
+
|
|
|
+ ssidView.invalidate();
|
|
|
+ bssidView.invalidate();
|
|
|
+ ipView.invalidate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private byte[] unpackInetAddress(int bytes) {
|
|
|
+ return new byte[] { (byte) ((bytes) & 0xff),
|
|
|
+ (byte) ((bytes >>> 8) & 0xff), (byte) ((bytes >>> 16) & 0xff),
|
|
|
+ (byte) ((bytes >>> 24) & 0xff) };
|
|
|
+ }
|
|
|
+
|
|
|
}
|