summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-05 23:56:04 +0200
committerMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-06 00:10:45 +0200
commit80fe4e92d7df9819f49004a9780e4b895ceba0ce (patch)
tree35f6bcabf0deffd58711ee40ba4bed0041e36304
parent1d95627a96779f4b8a58e28ddbf8d0b190235deb (diff)
downloadgeoclue-80fe4e92d7df9819f49004a9780e4b895ceba0ce.tar.gz
location-source: Make location scrambling more fine-grained
Add a random gdouble distance between 0 km and 3 km to the latitude when scrambling a location instead of just one of two possible integer distances: 1 km or 2 km. If the location source is already pretty inaccurate do just a limited range scrambling (up to 1 km) - just to be sure.
-rw-r--r--src/gclue-location-source.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/gclue-location-source.c b/src/gclue-location-source.c
index 5d7347d..1179b8d 100644
--- a/src/gclue-location-source.c
+++ b/src/gclue-location-source.c
@@ -419,21 +419,30 @@ gclue_location_source_set_location (GClueLocationSource *source,
priv->location = gclue_location_duplicate (location);
if (priv->scramble_location) {
- gdouble latitude, distance, accuracy;
+ gdouble latitude, distance, accuracy, scramble_range;
latitude = gclue_location_get_latitude (priv->location);
accuracy = gclue_location_get_accuracy (priv->location);
+ scramble_range = GCLUE_LOCATION_ACCURACY_NEIGHBORHOOD;
+ if (accuracy >= scramble_range) {
+ /* If the location source is already pretty inaccurate
+ * do just a limited range scrambling to be sure.
+ */
+ scramble_range /= 3;
+ }
+
/* Randomization is needed to stop apps from calculationg the
* actual location.
*/
- distance = (gdouble) g_random_int_range (1, 3);
+ distance = g_random_double_range (0, scramble_range);
+ distance /= 1000;
if (g_random_boolean ())
latitude += distance * LATITUDE_IN_KM;
else
latitude -= distance * LATITUDE_IN_KM;
- accuracy += 3000;
+ accuracy += scramble_range;
g_object_set (G_OBJECT (priv->location),
"latitude", latitude,