Merge lp:~mardy/location-service/old-location-1551686 into lp:location-service/trunk

Proposed by Alberto Mardegan on 2016-04-27
Status: Needs review
Proposed branch: lp:~mardy/location-service/old-location-1551686
Merge into: lp:location-service/trunk
Diff against target: 431 lines (+273/-8)
9 files modified
src/location_service/com/ubuntu/location/CMakeLists.txt (+1/-0)
src/location_service/com/ubuntu/location/service/daemon.cpp (+2/-1)
src/location_service/com/ubuntu/location/service/implementation.cpp (+2/-0)
src/location_service/com/ubuntu/location/service/implementation.h (+5/-0)
src/location_service/com/ubuntu/location/service/position_obfuscator.cpp (+68/-0)
src/location_service/com/ubuntu/location/service/position_obfuscator.h (+74/-0)
tests/CMakeLists.txt (+1/-0)
tests/acceptance_tests.cpp (+19/-7)
tests/obfuscator_test.cpp (+101/-0)
To merge this branch: bzr merge lp:~mardy/location-service/old-location-1551686
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2016-04-27
Ubuntu Phablet Team 2016-04-27 Pending
Review via email: mp+293075@code.launchpad.net

Commit message

Decrease accuracy according to the update's age

Description of the change

Decrease accuracy according to the update's age

Unmerged revisions

222. By Alberto Mardegan on 2016-04-27

Merge trunk

* Small fixes around provider loading added: tests/mock_engine.h
* Use a fusion engine provider to generate higher quality position
  updates added:
  include/location_service/com/ubuntu/location/fusion_provider.h
  include/location_service/com/ubuntu/location/fusion_provider_selecti
  on_policy.h
  include/location_service/com/ubuntu/location/newer_or_more_accurate_
  update_selector.h
  include/location_service/com/ubuntu/location/newer_update_selector.h
  include/location_service/com/ubuntu/location/update_selector.h
  src/location_service/com/ubuntu/location/fusion_provider.cpp
  src/location_service/com/ubuntu/location/fusion_provider_selection_p
  olicy.cpp
* Enable dual landings according to https://wiki.ubuntu.com/citrain/LandingProcess#Dual-landing_for_stable_and_devel:
  * Both vivid+overlay and xenial packages are built from the same
    source.
  * To account for differences in major revisions (necessary to handle
    the g++ 5 ABI break), we generate install files on the fly.
* Lower number of concurrent clients to stabilize acceptance test on
  loaded builders.
* No change rebuild.
* No change rebuild.
* libubuntu-location-service3: Replaces libubuntu-location-service2,
  config file /etc/gps.conf in both packages.
* Bump major revision and fix LP:#1478750 to account for toolchain update.
* Log to stderr by default, relying on upstart to rotate logs
  appropriately. (LP: #1447110)
* Add SntpClient for querying reference time information.

221. By Alberto Mardegan on 2016-03-18

Add tests

220. By Alberto Mardegan on 2016-03-17

Fix tests

219. By Alberto Mardegan on 2016-03-17

Move aging function into new obfuscator class

218. By Alberto Mardegan on 2016-03-14

WIP first draft

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/location_service/com/ubuntu/location/CMakeLists.txt'
2--- src/location_service/com/ubuntu/location/CMakeLists.txt 2016-04-05 21:26:06 +0000
3+++ src/location_service/com/ubuntu/location/CMakeLists.txt 2016-04-27 10:14:29 +0000
4@@ -53,6 +53,7 @@
5 service/trust_store_permission_manager.cpp
6
7 service/implementation.cpp
8+ service/position_obfuscator.cpp
9 service/skeleton.cpp
10 service/stub.cpp
11
12
13=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
14--- src/location_service/com/ubuntu/location/service/daemon.cpp 2016-03-31 20:31:05 +0000
15+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2016-04-27 10:14:29 +0000
16@@ -246,7 +246,8 @@
17 {
18 std::make_shared<dummy::ConnectivityManager>(),
19 std::make_shared<NullReporter>()
20- }
21+ },
22+ location::service::PositionObfuscator::Configuration(),
23 };
24
25 auto location_service = std::make_shared<location::service::Implementation>(configuration);
26
27=== modified file 'src/location_service/com/ubuntu/location/service/implementation.cpp'
28--- src/location_service/com/ubuntu/location/service/implementation.cpp 2015-12-09 15:18:14 +0000
29+++ src/location_service/com/ubuntu/location/service/implementation.cpp 2016-04-27 10:14:29 +0000
30@@ -64,6 +64,7 @@
31 },
32 configuration(config),
33 harvester(config.harvester),
34+ obfuscator(config.obfuscator),
35 connections
36 {
37 is_online().changed().connect(
38@@ -157,6 +158,7 @@
39 session_iface->updates().position_status.changed().connect([this, session_weak](const session::Interface::Updates::Status& status)
40 {
41 cul::Optional<cul::Update<cul::Position>> last_known_position = configuration.engine->updates.last_known_location.get();
42+ obfuscator.apply_age(last_known_position);
43 bool has_last_known_position = last_known_position ? true : false;
44 bool is_session_enabled = status == culs::session::Interface::Updates::Status::enabled;
45 bool is_session_on_or_active = configuration.engine->configuration.engine_state != Engine::Status::off;
46
47=== modified file 'src/location_service/com/ubuntu/location/service/implementation.h'
48--- src/location_service/com/ubuntu/location/service/implementation.h 2014-08-01 12:51:25 +0000
49+++ src/location_service/com/ubuntu/location/service/implementation.h 2016-04-27 10:14:29 +0000
50@@ -21,6 +21,7 @@
51 #include <com/ubuntu/location/engine.h>
52 #include <com/ubuntu/location/connectivity/manager.h>
53 #include <com/ubuntu/location/service/harvester.h>
54+#include <com/ubuntu/location/service/position_obfuscator.h>
55 #include <com/ubuntu/location/service/skeleton.h>
56
57 #include <memory>
58@@ -53,6 +54,8 @@
59 PermissionManager::Ptr permission_manager;
60 // All harvesting specific options.
61 Harvester::Configuration harvester;
62+ // Options for the position obfuscator.
63+ PositionObfuscator::Configuration obfuscator;
64 };
65
66 // Creates a new instance of the service with the given configuration.
67@@ -67,6 +70,8 @@
68 Configuration configuration;
69 // The harvester instance.
70 Harvester harvester;
71+ // The position obfuscator
72+ PositionObfuscator obfuscator;
73 // All event connections are automatically cut on destruction.
74 struct
75 {
76
77=== added file 'src/location_service/com/ubuntu/location/service/position_obfuscator.cpp'
78--- src/location_service/com/ubuntu/location/service/position_obfuscator.cpp 1970-01-01 00:00:00 +0000
79+++ src/location_service/com/ubuntu/location/service/position_obfuscator.cpp 2016-04-27 10:14:29 +0000
80@@ -0,0 +1,68 @@
81+/*
82+ * Copyright © 2016 Canonical Ltd.
83+ *
84+ * This program is free software: you can redistribute it and/or modify it
85+ * under the terms of the GNU Lesser General Public License version 3,
86+ * as published by the Free Software Foundation.
87+ *
88+ * This program is distributed in the hope that it will be useful,
89+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
90+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91+ * GNU Lesser General Public License for more details.
92+ *
93+ * You should have received a copy of the GNU Lesser General Public License
94+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
95+ *
96+ * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
97+ */
98+
99+#include <com/ubuntu/location/service/position_obfuscator.h>
100+
101+#include <com/ubuntu/location/logging.h>
102+
103+namespace cul = com::ubuntu::location;
104+namespace culs = com::ubuntu::location::service;
105+
106+culs::PositionObfuscator::PositionObfuscator(const culs::PositionObfuscator::Configuration& configuration)
107+ : config(configuration)
108+{
109+}
110+
111+culs::PositionObfuscator::~PositionObfuscator()
112+{
113+}
114+
115+void culs::PositionObfuscator::apply_age(cul::Optional<cul::Update<cul::Position>>& optional_update) const
116+{
117+ if (!optional_update) return;
118+
119+ auto update = optional_update.get();
120+ auto aged_update = cul::Update<cul::Position>(update.value);
121+
122+ std::chrono::duration<double> age = aged_update.when - update.when;
123+ double meters_covered = age.count() * config.moving_speed;
124+ double final_accuracy = meters_covered +
125+ (update.value.accuracy.horizontal ? update.value.accuracy.horizontal.get().value() : 0);
126+ if (final_accuracy > config.minimum_accuracy)
127+ {
128+ // this would be a meaningless update, let's just skip it
129+ VLOG(10) << "Discarding update due to low accuracy after aging: " << update;
130+ optional_update = cul::Optional<cul::Update<cul::Position>>{};
131+ return;
132+ }
133+
134+ aged_update.value.accuracy.horizontal =
135+ cul::Position::Accuracy::Horizontal(final_accuracy * cul::units::Meters);
136+
137+ // similar treatment for vertical accuracy
138+ if (update.value.altitude)
139+ {
140+ final_accuracy = meters_covered +
141+ (update.value.accuracy.vertical ? update.value.accuracy.vertical.get().value() : 0);
142+ aged_update.value.accuracy.vertical =
143+ cul::Position::Accuracy::Vertical(final_accuracy * cul::units::Meters);
144+
145+ }
146+
147+ optional_update = aged_update;
148+}
149
150=== added file 'src/location_service/com/ubuntu/location/service/position_obfuscator.h'
151--- src/location_service/com/ubuntu/location/service/position_obfuscator.h 1970-01-01 00:00:00 +0000
152+++ src/location_service/com/ubuntu/location/service/position_obfuscator.h 2016-04-27 10:14:29 +0000
153@@ -0,0 +1,74 @@
154+/*
155+ * Copyright © 2016 Canonical Ltd.
156+ *
157+ * This program is free software: you can redistribute it and/or modify it
158+ * under the terms of the GNU Lesser General Public License version 3,
159+ * as published by the Free Software Foundation.
160+ *
161+ * This program is distributed in the hope that it will be useful,
162+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
163+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
164+ * GNU Lesser General Public License for more details.
165+ *
166+ * You should have received a copy of the GNU Lesser General Public License
167+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
168+ *
169+ * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
170+ */
171+
172+#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
173+#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
174+
175+#include <com/ubuntu/location/optional.h>
176+#include <com/ubuntu/location/position.h>
177+#include <com/ubuntu/location/update.h>
178+
179+namespace com
180+{
181+namespace ubuntu
182+{
183+namespace location
184+{
185+namespace service
186+{
187+/** @brief Tranform location updates based on age and client's permissions.
188+ *
189+ * @note Obfuscating the user location based on the client's permissions
190+ * is not currently implemented.
191+ */
192+class PositionObfuscator
193+{
194+public:
195+
196+ /** @brief Configuration encapsulates all creation time options of class Harvester */
197+ struct Configuration
198+ {
199+ /** Estimated speed, in m/s; the accuracy of a position update will be
200+ * decreased according to this speed.
201+ */
202+ double moving_speed { 250 }; /* 900km/h, cruising speed of a plane */
203+
204+ /** Minimum accuracy, in metres: if the accuracy falls below this value,
205+ * no position update will be reported.
206+ */
207+ int minimum_accuracy { 5000 * 1000 }; /* 5000 km */
208+ };
209+
210+ /** @brief Creates a new instance based on the given configuration. */
211+ PositionObfuscator(const Configuration& configuration);
212+
213+ /** @brief Frees all resources held by the instance. */
214+ virtual ~PositionObfuscator();
215+
216+ /** @brief Decrease the accuracy of the given update based on its age. */
217+ void apply_age(Optional<Update<Position>>& optional_update) const;
218+
219+private:
220+ Configuration config;
221+};
222+}
223+}
224+}
225+}
226+
227+#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
228
229=== modified file 'tests/CMakeLists.txt'
230--- tests/CMakeLists.txt 2016-03-31 10:15:53 +0000
231+++ tests/CMakeLists.txt 2016-04-27 10:14:29 +0000
232@@ -79,6 +79,7 @@
233 LOCATION_SERVICE_ADD_TEST(default_permission_manager_test default_permission_manager_test.cpp)
234 LOCATION_SERVICE_ADD_TEST(engine_test engine_test.cpp)
235 LOCATION_SERVICE_ADD_TEST(harvester_test harvester_test.cpp)
236+LOCATION_SERVICE_ADD_TEST(obfuscator_test obfuscator_test.cpp)
237 LOCATION_SERVICE_ADD_TEST(demultiplexing_reporter_test demultiplexing_reporter_test.cpp)
238 LOCATION_SERVICE_ADD_TEST(time_based_update_policy_test time_based_update_policy_test.cpp)
239
240
241=== modified file 'tests/acceptance_tests.cpp'
242--- tests/acceptance_tests.cpp 2016-03-11 13:51:03 +0000
243+++ tests/acceptance_tests.cpp 2016-04-27 10:14:29 +0000
244@@ -206,6 +206,8 @@
245 {120. * cul::units::Degrees},
246 timestamp
247 };
248+
249+culs::PositionObfuscator::Configuration obfuscator_config;
250 } // namespace
251
252 TEST_F(LocationServiceStandalone, SessionsReceiveUpdatesViaDBus)
253@@ -248,7 +250,8 @@
254 {
255 cul::connectivity::platform_default_manager(),
256 std::make_shared<NullReporter>()
257- }
258+ },
259+ obfuscator_config,
260 };
261 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
262
263@@ -370,7 +373,8 @@
264 {
265 cul::connectivity::platform_default_manager(),
266 std::make_shared<NullReporter>()
267- }
268+ },
269+ obfuscator_config,
270 };
271 configuration.engine->configuration.engine_state = cul::Engine::Status::on;
272 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
273@@ -451,7 +455,8 @@
274 {
275 cul::connectivity::platform_default_manager(),
276 std::make_shared<NullReporter>()
277- }
278+ },
279+ obfuscator_config,
280 };
281 configuration.engine->configuration.satellite_based_positioning_state.set(cul::SatelliteBasedPositioningState::on);
282 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
283@@ -531,7 +536,8 @@
284 {
285 cul::connectivity::platform_default_manager(),
286 std::make_shared<NullReporter>()
287- }
288+ },
289+ obfuscator_config,
290 };
291 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
292
293@@ -619,7 +625,8 @@
294 {
295 cul::connectivity::platform_default_manager(),
296 std::make_shared<NullReporter>()
297- }
298+ },
299+ obfuscator_config,
300 };
301 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
302
303@@ -699,7 +706,8 @@
304 {
305 cul::connectivity::platform_default_manager(),
306 std::make_shared<NullReporter>()
307- }
308+ },
309+ obfuscator_config,
310 };
311 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
312
313@@ -761,7 +769,11 @@
314 if (t.joinable())
315 t.join();
316
317- EXPECT_EQ(reference_position_update, position);
318+ EXPECT_TRUE(position.when >= reference_position_update.when);
319+ /* Clear the accuracy, since it has been altered by the obfuscator. */
320+ cul::Position expectedPosition = reference_position_update.value;
321+ expectedPosition.accuracy = position.value.accuracy = cul::Position::Accuracy();
322+ EXPECT_EQ(expectedPosition, position.value);
323
324 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
325 };
326
327=== added file 'tests/obfuscator_test.cpp'
328--- tests/obfuscator_test.cpp 1970-01-01 00:00:00 +0000
329+++ tests/obfuscator_test.cpp 2016-04-27 10:14:29 +0000
330@@ -0,0 +1,101 @@
331+/*
332+ * Copyright © 2016 Canonical Ltd.
333+ *
334+ * This program is free software: you can redistribute it and/or modify it
335+ * under the terms of the GNU Lesser General Public License version 3,
336+ * as published by the Free Software Foundation.
337+ *
338+ * This program is distributed in the hope that it will be useful,
339+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
340+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
341+ * GNU Lesser General Public License for more details.
342+ *
343+ * You should have received a copy of the GNU Lesser General Public License
344+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
345+ *
346+ * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
347+ */
348+
349+#include <com/ubuntu/location/service/position_obfuscator.h>
350+
351+#include <gtest/gtest.h>
352+
353+namespace cul = com::ubuntu::location;
354+namespace culs = com::ubuntu::location::service;
355+typedef cul::Optional<cul::Update<cul::Position>> OptionalUpdate;
356+
357+TEST(Obfuscator, aging_no_update)
358+{
359+ using namespace ::testing;
360+
361+ culs::PositionObfuscator::Configuration config;
362+ culs::PositionObfuscator obfuscator(config);
363+
364+ OptionalUpdate empty_update;
365+ EXPECT_FALSE(empty_update);
366+
367+ obfuscator.apply_age(empty_update);
368+ EXPECT_FALSE(empty_update);
369+}
370+
371+TEST(Obfuscator, aging_still_valid)
372+{
373+ using namespace ::testing;
374+
375+ culs::PositionObfuscator::Configuration config;
376+ config.moving_speed = 10.0;
377+ config.minimum_accuracy = 10000;
378+
379+ culs::PositionObfuscator obfuscator(config);
380+
381+ auto test_time = cul::Clock::now();
382+ cul::Update<cul::Position> update
383+ {
384+ {
385+ cul::wgs84::Latitude{9. * cul::units::Degrees},
386+ cul::wgs84::Longitude{53. * cul::units::Degrees},
387+ cul::wgs84::Altitude{-2. * cul::units::Meters},
388+ 12 * cul::units::Meters,
389+ 9 * cul::units::Meters
390+ },
391+ test_time - std::chrono::seconds(100),
392+ };
393+
394+ OptionalUpdate optional = update;
395+ obfuscator.apply_age(optional);
396+
397+ EXPECT_TRUE(bool(optional));
398+ cul::Update<cul::Position> aged_update = optional.get();
399+
400+ /* Make sure that the time has been updated since the original update */
401+ EXPECT_TRUE(aged_update.when >= test_time);
402+
403+ /* Check that the accuracy is the one we would expect */
404+ EXPECT_EQ(1012, int(aged_update.value.accuracy.horizontal.get() / cul::units::Meters));
405+ EXPECT_EQ(1009, int(aged_update.value.accuracy.vertical.get() / cul::units::Meters));
406+}
407+
408+TEST(Obfuscator, aging_too_inaccurate)
409+{
410+ using namespace ::testing;
411+
412+ culs::PositionObfuscator::Configuration config;
413+ config.moving_speed = 1000.1;
414+ config.minimum_accuracy = 100000;
415+
416+ culs::PositionObfuscator obfuscator(config);
417+
418+ cul::Update<cul::Position> update
419+ {
420+ {
421+ cul::wgs84::Latitude{9. * cul::units::Degrees},
422+ cul::wgs84::Longitude{53. * cul::units::Degrees},
423+ cul::wgs84::Altitude{-2. * cul::units::Meters}
424+ },
425+ cul::Clock::now() - std::chrono::seconds(100),
426+ };
427+
428+ OptionalUpdate optional = update;
429+ obfuscator.apply_age(optional);
430+ EXPECT_FALSE(optional);
431+}

Subscribers

People subscribed via source and target branches