Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Set latitude/longitude indepedently
Browse files Browse the repository at this point in the history
Refs #706
  • Loading branch information
M66B committed Nov 10, 2013
1 parent 575c9b7 commit 828be42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
24 changes: 15 additions & 9 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,22 +856,28 @@ public static Object getDefacedProp(int uid, String name) {
}

public static Location getDefacedLocation(int uid, Location location) {
String sLat = getSetting(null, null, uid, cSettingLatitude, "", true);
String sLon = getSetting(null, null, uid, cSettingLongitude, "", true);
String sLat = getSetting(null, null, uid, cSettingLatitude, null, true);
String sLon = getSetting(null, null, uid, cSettingLongitude, null, true);

if (cValueRandom.equals(sLat))
sLat = getRandomProp("LAT");
if (cValueRandom.equals(sLon))
sLon = getRandomProp("LON");
if (sLat.equals("") || sLon.equals("")) {
// Christmas Island

// 1 degree ~ 111111 m
// 1 m ~ 0,000009 degrees
// Christmas Island ~ -10.5 / 105.667

if (sLat == null)
location.setLatitude(-10.5);
location.setLongitude(105.667);
} else {
// 1 degree ~ 111111 m
// 1 m ~ 0,000009 degrees = 9e-6
else
location.setLatitude(Float.parseFloat(sLat) + (Math.random() * 2.0 - 1.0) * location.getAccuracy() * 9e-6);

if (sLon == null)
location.setLongitude(105.667);
else
location.setLongitude(Float.parseFloat(sLon) + (Math.random() * 2.0 - 1.0) * location.getAccuracy() * 9e-6);
}

return location;
}

Expand Down
19 changes: 12 additions & 7 deletions src/biz/bokhorst/xprivacy/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,26 @@ public void onClick(View view) {
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSerial,
cbSerial.isChecked() ? PrivacyManager.cValueRandom : etSerial.getText().toString());

// Set location
// Set latitude
try {
float lat = Float.parseFloat(etLat.getText().toString().replace(',', '.'));
float lon = Float.parseFloat(etLon.getText().toString().replace(',', '.'));
if (lat < -90 || lat > 90 || lon < -180 || lon > 180)
if (lat < -90 || lat > 90)
throw new InvalidParameterException();

PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude,
cbLat.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lat));
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude,
cbLon.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lon));

} catch (Throwable ex) {
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLatitude,
cbLat.isChecked() ? PrivacyManager.cValueRandom : "");
}

// Set longitude
try {
float lon = Float.parseFloat(etLon.getText().toString().replace(',', '.'));
if (lon < -180 || lon > 180)
throw new InvalidParameterException();
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude,
cbLon.isChecked() ? PrivacyManager.cValueRandom : Float.toString(lon));
} catch (Throwable ex) {
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingLongitude,
cbLon.isChecked() ? PrivacyManager.cValueRandom : "");
}
Expand Down

0 comments on commit 828be42

Please sign in to comment.