From 351644f0c83cb9489271156da9b1a692314d34af Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Date: Thu, 3 Jan 2019 16:40:19 +0100 Subject: wifi: Wait 10 seconds between scans for high-accuracy case Typically people can't go very far in 10 seconds so no need to scan continuously for even high-accuracy requests. Fixes #100. --- src/gclue-wifi.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/gclue-wifi.c b/src/gclue-wifi.c index 269984b..364cca9 100644 --- a/src/gclue-wifi.c +++ b/src/gclue-wifi.c @@ -28,10 +28,11 @@ #include "gclue-error.h" #include "gclue-mozilla.h" +#define WIFI_SCAN_TIMEOUT_HIGH_ACCURACY 10 /* Since this is only used for city-level accuracy, 5 minutes betweeen each * scan is more than enough. */ -#define WIFI_SCAN_TIMEOUT 300 +#define WIFI_SCAN_TIMEOUT_LOW_ACCURACY 300 /** * SECTION:gclue-wifi @@ -441,6 +442,7 @@ on_scan_done (WPAInterface *object, { GClueWifi *wifi = GCLUE_WIFI (user_data); GClueWifiPrivate *priv = wifi->priv; + guint timeout; if (!success) { g_warning ("WiFi scan failed"); @@ -455,17 +457,18 @@ on_scan_done (WPAInterface *object, g_debug ("Refreshing location.."); gclue_web_source_refresh (GCLUE_WEB_SOURCE (wifi)); + /* With high-enough accuracy requests, we need to scan more often since + * user's location can change quickly. With low accuracy, we don't since + * we wouldn't want to drain power unnecessarily. + */ if (priv->accuracy_level >= GCLUE_ACCURACY_LEVEL_STREET) - /* With high-enough accuracy requests, we need to continuously - * keep scanning since user's location can change quickly. With - * low accuracy, we don't since we wouldn't want to drain power - * unnecessarily. - */ - on_scan_timeout (wifi); + timeout = WIFI_SCAN_TIMEOUT_HIGH_ACCURACY; else - priv->scan_timeout = g_timeout_add_seconds (WIFI_SCAN_TIMEOUT, - on_scan_timeout, - wifi); + timeout = WIFI_SCAN_TIMEOUT_LOW_ACCURACY; + priv->scan_timeout = g_timeout_add_seconds (timeout, + on_scan_timeout, + wifi); + g_debug ("Next scan scheduled in %u seconds", timeout); } static void -- cgit v1.2.1