diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index a0997db41..615f9142b 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -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; } diff --git a/src/biz/bokhorst/xprivacy/SettingsDialog.java b/src/biz/bokhorst/xprivacy/SettingsDialog.java index 716faa672..6d15da806 100644 --- a/src/biz/bokhorst/xprivacy/SettingsDialog.java +++ b/src/biz/bokhorst/xprivacy/SettingsDialog.java @@ -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 : ""); }