|
@@ -4,13 +4,16 @@ import android.app.Fragment;
|
|
import android.graphics.Color;
|
|
import android.graphics.Color;
|
|
import android.location.Location;
|
|
import android.location.Location;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
-import android.util.Log;
|
|
|
|
import android.view.InflateException;
|
|
import android.view.InflateException;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
import com.google.android.gms.common.ConnectionResult;
|
|
import com.google.android.gms.common.ConnectionResult;
|
|
|
|
+import com.google.android.gms.common.GooglePlayServicesClient;
|
|
|
|
+import com.google.android.gms.location.LocationClient;
|
|
|
|
+import com.google.android.gms.location.LocationListener;
|
|
|
|
+import com.google.android.gms.location.LocationRequest;
|
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
|
import com.google.android.gms.maps.GoogleMap;
|
|
import com.google.android.gms.maps.GoogleMap;
|
|
import com.google.android.gms.maps.MapFragment;
|
|
import com.google.android.gms.maps.MapFragment;
|
|
@@ -35,12 +38,22 @@ import static com.google.android.gms.common.GooglePlayServicesUtil.*;
|
|
*
|
|
*
|
|
* Created by Fabio Arnold on 10.02.14.
|
|
* Created by Fabio Arnold on 10.02.14.
|
|
*/
|
|
*/
|
|
-public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindowClickListener {
|
|
|
|
- private GoogleMap mMap = null;
|
|
|
|
|
|
+public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindowClickListener,
|
|
|
|
+ GooglePlayServicesClient.ConnectionCallbacks,
|
|
|
|
+ GooglePlayServicesClient.OnConnectionFailedListener,
|
|
|
|
+ LocationListener {
|
|
|
|
+ private static GoogleMap sMap = null;
|
|
private static View sView = null;
|
|
private static View sView = null;
|
|
|
|
|
|
private HashMap<String, String> mMarkerIDToSSID = new HashMap<String, String>();
|
|
private HashMap<String, String> mMarkerIDToSSID = new HashMap<String, String>();
|
|
|
|
|
|
|
|
+ private LocationClient mLocationClient;
|
|
|
|
+ private static final LocationRequest REQUEST = LocationRequest.create()
|
|
|
|
+ .setExpirationDuration(5000) // 5 seconds
|
|
|
|
+ .setInterval(5000) // 5 seconds
|
|
|
|
+ .setFastestInterval(16) // 16ms = 60fps
|
|
|
|
+ .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* if google play services aren't available an error notification will be displayed
|
|
* if google play services aren't available an error notification will be displayed
|
|
*
|
|
*
|
|
@@ -71,6 +84,34 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * callbacks from LocationClient
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void onConnected(Bundle bundle) {
|
|
|
|
+ mLocationClient.requestLocationUpdates(REQUEST, this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDisconnected() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onLocationChanged(Location location) {
|
|
|
|
+ sMap.animateCamera(CameraUpdateFactory.newLatLng(
|
|
|
|
+ new LatLng(location.getLatitude(), location.getLongitude())));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * helper class
|
|
|
|
+ * easier to use than LatLng
|
|
|
|
+ */
|
|
private class Point {
|
|
private class Point {
|
|
public double x, y;
|
|
public double x, y;
|
|
public Point(double sx, double sy) {
|
|
public Point(double sx, double sy) {
|
|
@@ -79,6 +120,11 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * helper class
|
|
|
|
+ * contains heuristic to split SSIDs by location
|
|
|
|
+ * see MAX_DISTANCE
|
|
|
|
+ */
|
|
private class SSIDArea {
|
|
private class SSIDArea {
|
|
private Point mMinimum, mMaximum;
|
|
private Point mMinimum, mMaximum;
|
|
public int numPoints;
|
|
public int numPoints;
|
|
@@ -128,6 +174,9 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * fills the map with markers and circle representing SSIDs
|
|
|
|
+ */
|
|
private void populateMap() {
|
|
private void populateMap() {
|
|
UglyDbHelper dbh = new UglyDbHelper(getActivity());
|
|
UglyDbHelper dbh = new UglyDbHelper(getActivity());
|
|
ArrayList<Record> records = dbh.getAllRecords();
|
|
ArrayList<Record> records = dbh.getAllRecords();
|
|
@@ -135,8 +184,6 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
HashMap<String, ArrayList<SSIDArea>> threadAreas = new HashMap<String, ArrayList<SSIDArea>>();
|
|
HashMap<String, ArrayList<SSIDArea>> threadAreas = new HashMap<String, ArrayList<SSIDArea>>();
|
|
|
|
|
|
for (Record record : records) {
|
|
for (Record record : records) {
|
|
- Log.i("SSID", record.getSsid() + " bssid " + record.getBssid());
|
|
|
|
-
|
|
|
|
LatLng location = new LatLng(record.getLatitude(), record.getLongitude());
|
|
LatLng location = new LatLng(record.getLatitude(), record.getLongitude());
|
|
ArrayList<SSIDArea> areas;
|
|
ArrayList<SSIDArea> areas;
|
|
if (threadAreas.containsKey(record.getSsid())) {
|
|
if (threadAreas.containsKey(record.getSsid())) {
|
|
@@ -169,8 +216,8 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
LatLng center = area.calculateCenterLocation();
|
|
LatLng center = area.calculateCenterLocation();
|
|
float radius = area.calculateRadius();
|
|
float radius = area.calculateRadius();
|
|
|
|
|
|
- mMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
|
|
|
|
- Marker marker = mMap.addMarker(new MarkerOptions()
|
|
|
|
|
|
+ sMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
|
|
|
|
+ Marker marker = sMap.addMarker(new MarkerOptions()
|
|
.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? " attack"
|
|
.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? " attack"
|
|
: " attacks")).position(
|
|
: " attacks")).position(
|
|
center));
|
|
center));
|
|
@@ -179,16 +226,24 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mMap.setMyLocationEnabled(true);
|
|
|
|
- mMap.setOnInfoWindowClickListener(this);
|
|
|
|
-
|
|
|
|
- LatLng tudarmstadt = new LatLng(49.86923, 8.6632768);
|
|
|
|
- //LatLng mapCenter = new LatLng(41.889, -87.622);
|
|
|
|
|
|
+ sMap.setMyLocationEnabled(true);
|
|
|
|
+ sMap.setOnInfoWindowClickListener(this);
|
|
|
|
|
|
- //Location myLocation = map.getMyLocation();
|
|
|
|
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tudarmstadt, 13));
|
|
|
|
|
|
+ LatLng tudarmstadt = new LatLng(49.86923, 8.6632768); // default location
|
|
|
|
+ sMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tudarmstadt, 13));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * performs initialization
|
|
|
|
+ * checks if google play services are supported
|
|
|
|
+ * view must be removed if this object has been created once before
|
|
|
|
+ * that is why view is static
|
|
|
|
+ *
|
|
|
|
+ * @param inflater
|
|
|
|
+ * @param container
|
|
|
|
+ * @param savedInstanceState
|
|
|
|
+ * @return the view
|
|
|
|
+ */
|
|
@Override
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
Bundle savedInstanceState) {
|
|
Bundle savedInstanceState) {
|
|
@@ -203,15 +258,32 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
try {
|
|
try {
|
|
sView = inflater.inflate(R.layout.fragment_threatmap, container, false);
|
|
sView = inflater.inflate(R.layout.fragment_threatmap, container, false);
|
|
if (isGooglePlay()) {
|
|
if (isGooglePlay()) {
|
|
- mMap = ((MapFragment) getFragmentManager()
|
|
|
|
|
|
+ sMap = ((MapFragment) getFragmentManager()
|
|
.findFragmentById(R.id.threatmapfragment)).getMap();
|
|
.findFragmentById(R.id.threatmapfragment)).getMap();
|
|
populateMap();
|
|
populateMap();
|
|
}
|
|
}
|
|
} catch (InflateException e) {
|
|
} catch (InflateException e) {
|
|
// map already exists
|
|
// map already exists
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ //e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
return sView;
|
|
return sView;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onResume() {
|
|
|
|
+ super.onResume();
|
|
|
|
+ if (mLocationClient == null) {
|
|
|
|
+ mLocationClient = new LocationClient(MainActivity.getInstance().getApplicationContext(), this, this);
|
|
|
|
+ }
|
|
|
|
+ mLocationClient.connect();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onPause() {
|
|
|
|
+ super.onPause();
|
|
|
|
+ if (mLocationClient != null) {
|
|
|
|
+ mLocationClient.disconnect();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|