Skip to content

Commit

Permalink
Passive data disclosure work
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Jan 16, 2017
1 parent e07ab9b commit 70e5e3e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion res/values/generators.xml
Expand Up @@ -65,7 +65,7 @@
<string name="message_location_accuracy_disabled">This app will not use your location, but use an placeholder instead.</string>

<string name="title_location_accuracy_randomized">Locally Randomized</string>
<string name="message_location_accuracy_randomized">Please enter the random distance (miles/kilometers)to use to obfuscate your exact location:</string>
<string name="message_location_accuracy_randomized">Please enter the random distance (kilometers) to use to obfuscate your exact location:</string>

<string name="title_location_accuracy_user">User Provided</string>
<string name="message_location_accuracy_user">Please enter a postal code or city and province to use as your location:</string>
Expand Down
Expand Up @@ -67,8 +67,10 @@

import java.io.File;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@SuppressWarnings("unused")
public class Location extends Generator implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
Expand Down Expand Up @@ -312,13 +314,42 @@ public void onConnectionFailed(ConnectionResult connectionResult) {

@Override
public void onLocationChanged(android.location.Location location) {
Log.e("PDK", "LOCATION CHANGED");

if (location == null)
return;

long now = System.currentTimeMillis();

final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.mContext);
int selected = prefs.getInt(Location.ACCURACY_MODE, Location.ACCURACY_BEST);

if (selected == Location.ACCURACY_RANDOMIZED) {
// http://gis.stackexchange.com/a/68275/10230

double latitude = location.getLatitude();
double longitude = location.getLongitude();

double radius = prefs.getLong(Location.ACCURACY_MODE_RANDOMIZED_RANGE, Location.ACCURACY_MODE_RANDOMIZED_RANGE_DEFAULT);

double radiusInDegrees = radius / 111000;

Random r = new SecureRandom();

double u = r.nextDouble();
double v = r.nextDouble();

double w = radiusInDegrees * Math.sqrt(u);
double t = 2 * Math.PI * v;
double x = w * Math.cos(t);
double y = w * Math.sin(t);

// Adjust the x-coordinate for the shrinking of the east-west distances
longitude = longitude + (x / Math.cos(latitude));
latitude = y + latitude;

location.setLongitude(longitude);
location.setLatitude(latitude);
}

ContentValues values = new ContentValues();
values.put(Location.HISTORY_OBSERVED, System.currentTimeMillis());
values.put(Location.HISTORY_LATITUDE, location.getLatitude());
Expand Down Expand Up @@ -913,6 +944,34 @@ public android.location.Location getLastKnownLocation() {
}
}

if (selected == Location.ACCURACY_RANDOMIZED) {
// http://gis.stackexchange.com/a/68275/10230

double latitude = last.getLatitude();
double longitude = last.getLongitude();

double radius = prefs.getLong(Location.ACCURACY_MODE_RANDOMIZED_RANGE, Location.ACCURACY_MODE_RANDOMIZED_RANGE_DEFAULT);

double radiusInDegrees = radius / 111000;

Random r = new SecureRandom();

double u = r.nextDouble();
double v = r.nextDouble();

double w = radiusInDegrees * Math.sqrt(u);
double t = 2 * Math.PI * v;
double x = w * Math.cos(t);
double y = w * Math.sin(t);

// Adjust the x-coordinate for the shrinking of the east-west distances
longitude = longitude + (x / Math.cos(latitude));
latitude = y + latitude;

last.setLongitude(longitude);
last.setLatitude(latitude);
}

return last;
}

Expand Down

0 comments on commit 70e5e3e

Please sign in to comment.