diff options
author | Zeeshan Ali <zeenix@collabora.co.uk> | 2018-09-15 21:38:24 -0400 |
---|---|---|
committer | Zeeshan Ali <zeenix@collabora.co.uk> | 2018-09-17 11:16:26 +0200 |
commit | fcd237b6d6c38bc37d5721611d460e2dbdb9293d (patch) | |
tree | a2dc605162c91170d9085d1ef8d8adf98faafd3e | |
parent | f234563838854e7c290f518ba257e37b378b6303 (diff) | |
download | geoclue-fcd237b6d6c38bc37d5721611d460e2dbdb9293d.tar.gz |
wifi: Use WiFi-based geolocation for city level accuracy
Since GeoIP can be easily extremely inaccurate, let's use WiFi-geolocation
for city accuracy level. We scramble the location a bit so that apps
requesting city accuracy level don't end up getting user's street
location with 300 meters accuracy.
Fixes #64.
-rw-r--r-- | src/gclue-wifi.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/gclue-wifi.c b/src/gclue-wifi.c index 527bbbf..cf8b04e 100644 --- a/src/gclue-wifi.c +++ b/src/gclue-wifi.c @@ -24,6 +24,7 @@ #include <string.h> #include <config.h> #include "gclue-wifi.h" +#include "gclue-config.h" #include "gclue-error.h" #include "gclue-mozilla.h" @@ -458,9 +459,12 @@ static GClueAccuracyLevel gclue_wifi_get_available_accuracy_level (GClueWebSource *source, gboolean net_available) { + GClueWifiPrivate *priv = GCLUE_WIFI (source)->priv; + if (!net_available) return GCLUE_ACCURACY_LEVEL_NONE; - else if (GCLUE_WIFI (source)->priv->interface != NULL) + else if (priv->interface != NULL && + priv->accuracy_level != GCLUE_ACCURACY_LEVEL_CITY) return GCLUE_ACCURACY_LEVEL_STREET; else return GCLUE_ACCURACY_LEVEL_CITY; @@ -569,8 +573,12 @@ gclue_wifi_constructed (GObject *object) G_OBJECT_CLASS (gclue_wifi_parent_class)->constructed (object); - if (wifi->priv->accuracy_level == GCLUE_ACCURACY_LEVEL_CITY) - goto refresh_n_exit; + if (wifi->priv->accuracy_level == GCLUE_ACCURACY_LEVEL_CITY) { + GClueConfig *config = gclue_config_get_singleton (); + + if (!gclue_config_get_enable_wifi_source (config)) + goto refresh_n_exit; + } /* FIXME: We should be using async variant */ priv->supplicant = wpa_supplicant_proxy_new_for_bus_sync @@ -629,15 +637,26 @@ gclue_wifi_get_singleton (GClueAccuracyLevel level) { static GClueWifi *wifi[] = { NULL, NULL }; guint i; + gboolean scramble_location = FALSE; g_return_val_if_fail (level >= GCLUE_ACCURACY_LEVEL_CITY, NULL); if (level == GCLUE_ACCURACY_LEVEL_NEIGHBORHOOD) level = GCLUE_ACCURACY_LEVEL_CITY; - i = (level == GCLUE_ACCURACY_LEVEL_CITY)? 0 : 1; + if (level == GCLUE_ACCURACY_LEVEL_CITY) { + GClueConfig *config = gclue_config_get_singleton (); + + i = 0; + if (gclue_config_get_enable_wifi_source (config)) + scramble_location = TRUE; + } else { + i = 1; + } + if (wifi[i] == NULL) { wifi[i] = g_object_new (GCLUE_TYPE_WIFI, "accuracy-level", level, + "scramble-location", scramble_location, NULL); g_object_weak_ref (G_OBJECT (wifi[i]), on_wifi_destroyed, |