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
=== modified file 'src/location_service/com/ubuntu/location/CMakeLists.txt'
--- src/location_service/com/ubuntu/location/CMakeLists.txt 2016-04-05 21:26:06 +0000
+++ src/location_service/com/ubuntu/location/CMakeLists.txt 2016-04-27 10:14:29 +0000
@@ -53,6 +53,7 @@
53 service/trust_store_permission_manager.cpp53 service/trust_store_permission_manager.cpp
5454
55 service/implementation.cpp55 service/implementation.cpp
56 service/position_obfuscator.cpp
56 service/skeleton.cpp57 service/skeleton.cpp
57 service/stub.cpp58 service/stub.cpp
5859
5960
=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
--- src/location_service/com/ubuntu/location/service/daemon.cpp 2016-03-31 20:31:05 +0000
+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2016-04-27 10:14:29 +0000
@@ -246,7 +246,8 @@
246 {246 {
247 std::make_shared<dummy::ConnectivityManager>(),247 std::make_shared<dummy::ConnectivityManager>(),
248 std::make_shared<NullReporter>()248 std::make_shared<NullReporter>()
249 }249 },
250 location::service::PositionObfuscator::Configuration(),
250 };251 };
251252
252 auto location_service = std::make_shared<location::service::Implementation>(configuration);253 auto location_service = std::make_shared<location::service::Implementation>(configuration);
253254
=== modified file 'src/location_service/com/ubuntu/location/service/implementation.cpp'
--- src/location_service/com/ubuntu/location/service/implementation.cpp 2015-12-09 15:18:14 +0000
+++ src/location_service/com/ubuntu/location/service/implementation.cpp 2016-04-27 10:14:29 +0000
@@ -64,6 +64,7 @@
64 },64 },
65 configuration(config),65 configuration(config),
66 harvester(config.harvester),66 harvester(config.harvester),
67 obfuscator(config.obfuscator),
67 connections68 connections
68 {69 {
69 is_online().changed().connect(70 is_online().changed().connect(
@@ -157,6 +158,7 @@
157 session_iface->updates().position_status.changed().connect([this, session_weak](const session::Interface::Updates::Status& status)158 session_iface->updates().position_status.changed().connect([this, session_weak](const session::Interface::Updates::Status& status)
158 {159 {
159 cul::Optional<cul::Update<cul::Position>> last_known_position = configuration.engine->updates.last_known_location.get();160 cul::Optional<cul::Update<cul::Position>> last_known_position = configuration.engine->updates.last_known_location.get();
161 obfuscator.apply_age(last_known_position);
160 bool has_last_known_position = last_known_position ? true : false;162 bool has_last_known_position = last_known_position ? true : false;
161 bool is_session_enabled = status == culs::session::Interface::Updates::Status::enabled;163 bool is_session_enabled = status == culs::session::Interface::Updates::Status::enabled;
162 bool is_session_on_or_active = configuration.engine->configuration.engine_state != Engine::Status::off;164 bool is_session_on_or_active = configuration.engine->configuration.engine_state != Engine::Status::off;
163165
=== modified file 'src/location_service/com/ubuntu/location/service/implementation.h'
--- src/location_service/com/ubuntu/location/service/implementation.h 2014-08-01 12:51:25 +0000
+++ src/location_service/com/ubuntu/location/service/implementation.h 2016-04-27 10:14:29 +0000
@@ -21,6 +21,7 @@
21#include <com/ubuntu/location/engine.h>21#include <com/ubuntu/location/engine.h>
22#include <com/ubuntu/location/connectivity/manager.h>22#include <com/ubuntu/location/connectivity/manager.h>
23#include <com/ubuntu/location/service/harvester.h>23#include <com/ubuntu/location/service/harvester.h>
24#include <com/ubuntu/location/service/position_obfuscator.h>
24#include <com/ubuntu/location/service/skeleton.h>25#include <com/ubuntu/location/service/skeleton.h>
2526
26#include <memory>27#include <memory>
@@ -53,6 +54,8 @@
53 PermissionManager::Ptr permission_manager;54 PermissionManager::Ptr permission_manager;
54 // All harvesting specific options.55 // All harvesting specific options.
55 Harvester::Configuration harvester;56 Harvester::Configuration harvester;
57 // Options for the position obfuscator.
58 PositionObfuscator::Configuration obfuscator;
56 };59 };
5760
58 // Creates a new instance of the service with the given configuration.61 // Creates a new instance of the service with the given configuration.
@@ -67,6 +70,8 @@
67 Configuration configuration;70 Configuration configuration;
68 // The harvester instance.71 // The harvester instance.
69 Harvester harvester;72 Harvester harvester;
73 // The position obfuscator
74 PositionObfuscator obfuscator;
70 // All event connections are automatically cut on destruction.75 // All event connections are automatically cut on destruction.
71 struct76 struct
72 {77 {
7378
=== added file 'src/location_service/com/ubuntu/location/service/position_obfuscator.cpp'
--- src/location_service/com/ubuntu/location/service/position_obfuscator.cpp 1970-01-01 00:00:00 +0000
+++ src/location_service/com/ubuntu/location/service/position_obfuscator.cpp 2016-04-27 10:14:29 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
17 */
18
19#include <com/ubuntu/location/service/position_obfuscator.h>
20
21#include <com/ubuntu/location/logging.h>
22
23namespace cul = com::ubuntu::location;
24namespace culs = com::ubuntu::location::service;
25
26culs::PositionObfuscator::PositionObfuscator(const culs::PositionObfuscator::Configuration& configuration)
27 : config(configuration)
28{
29}
30
31culs::PositionObfuscator::~PositionObfuscator()
32{
33}
34
35void culs::PositionObfuscator::apply_age(cul::Optional<cul::Update<cul::Position>>& optional_update) const
36{
37 if (!optional_update) return;
38
39 auto update = optional_update.get();
40 auto aged_update = cul::Update<cul::Position>(update.value);
41
42 std::chrono::duration<double> age = aged_update.when - update.when;
43 double meters_covered = age.count() * config.moving_speed;
44 double final_accuracy = meters_covered +
45 (update.value.accuracy.horizontal ? update.value.accuracy.horizontal.get().value() : 0);
46 if (final_accuracy > config.minimum_accuracy)
47 {
48 // this would be a meaningless update, let's just skip it
49 VLOG(10) << "Discarding update due to low accuracy after aging: " << update;
50 optional_update = cul::Optional<cul::Update<cul::Position>>{};
51 return;
52 }
53
54 aged_update.value.accuracy.horizontal =
55 cul::Position::Accuracy::Horizontal(final_accuracy * cul::units::Meters);
56
57 // similar treatment for vertical accuracy
58 if (update.value.altitude)
59 {
60 final_accuracy = meters_covered +
61 (update.value.accuracy.vertical ? update.value.accuracy.vertical.get().value() : 0);
62 aged_update.value.accuracy.vertical =
63 cul::Position::Accuracy::Vertical(final_accuracy * cul::units::Meters);
64
65 }
66
67 optional_update = aged_update;
68}
069
=== added file 'src/location_service/com/ubuntu/location/service/position_obfuscator.h'
--- src/location_service/com/ubuntu/location/service/position_obfuscator.h 1970-01-01 00:00:00 +0000
+++ src/location_service/com/ubuntu/location/service/position_obfuscator.h 2016-04-27 10:14:29 +0000
@@ -0,0 +1,74 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
17 */
18
19#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
20#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
21
22#include <com/ubuntu/location/optional.h>
23#include <com/ubuntu/location/position.h>
24#include <com/ubuntu/location/update.h>
25
26namespace com
27{
28namespace ubuntu
29{
30namespace location
31{
32namespace service
33{
34/** @brief Tranform location updates based on age and client's permissions.
35 *
36 * @note Obfuscating the user location based on the client's permissions
37 * is not currently implemented.
38 */
39class PositionObfuscator
40{
41public:
42
43 /** @brief Configuration encapsulates all creation time options of class Harvester */
44 struct Configuration
45 {
46 /** Estimated speed, in m/s; the accuracy of a position update will be
47 * decreased according to this speed.
48 */
49 double moving_speed { 250 }; /* 900km/h, cruising speed of a plane */
50
51 /** Minimum accuracy, in metres: if the accuracy falls below this value,
52 * no position update will be reported.
53 */
54 int minimum_accuracy { 5000 * 1000 }; /* 5000 km */
55 };
56
57 /** @brief Creates a new instance based on the given configuration. */
58 PositionObfuscator(const Configuration& configuration);
59
60 /** @brief Frees all resources held by the instance. */
61 virtual ~PositionObfuscator();
62
63 /** @brief Decrease the accuracy of the given update based on its age. */
64 void apply_age(Optional<Update<Position>>& optional_update) const;
65
66private:
67 Configuration config;
68};
69}
70}
71}
72}
73
74#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_POSITION_OBFUSCATOR_H_
075
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2016-03-31 10:15:53 +0000
+++ tests/CMakeLists.txt 2016-04-27 10:14:29 +0000
@@ -79,6 +79,7 @@
79LOCATION_SERVICE_ADD_TEST(default_permission_manager_test default_permission_manager_test.cpp)79LOCATION_SERVICE_ADD_TEST(default_permission_manager_test default_permission_manager_test.cpp)
80LOCATION_SERVICE_ADD_TEST(engine_test engine_test.cpp)80LOCATION_SERVICE_ADD_TEST(engine_test engine_test.cpp)
81LOCATION_SERVICE_ADD_TEST(harvester_test harvester_test.cpp)81LOCATION_SERVICE_ADD_TEST(harvester_test harvester_test.cpp)
82LOCATION_SERVICE_ADD_TEST(obfuscator_test obfuscator_test.cpp)
82LOCATION_SERVICE_ADD_TEST(demultiplexing_reporter_test demultiplexing_reporter_test.cpp)83LOCATION_SERVICE_ADD_TEST(demultiplexing_reporter_test demultiplexing_reporter_test.cpp)
83LOCATION_SERVICE_ADD_TEST(time_based_update_policy_test time_based_update_policy_test.cpp)84LOCATION_SERVICE_ADD_TEST(time_based_update_policy_test time_based_update_policy_test.cpp)
8485
8586
=== modified file 'tests/acceptance_tests.cpp'
--- tests/acceptance_tests.cpp 2016-03-11 13:51:03 +0000
+++ tests/acceptance_tests.cpp 2016-04-27 10:14:29 +0000
@@ -206,6 +206,8 @@
206 {120. * cul::units::Degrees},206 {120. * cul::units::Degrees},
207 timestamp207 timestamp
208};208};
209
210culs::PositionObfuscator::Configuration obfuscator_config;
209} // namespace211} // namespace
210212
211TEST_F(LocationServiceStandalone, SessionsReceiveUpdatesViaDBus)213TEST_F(LocationServiceStandalone, SessionsReceiveUpdatesViaDBus)
@@ -248,7 +250,8 @@
248 {250 {
249 cul::connectivity::platform_default_manager(),251 cul::connectivity::platform_default_manager(),
250 std::make_shared<NullReporter>()252 std::make_shared<NullReporter>()
251 }253 },
254 obfuscator_config,
252 };255 };
253 auto location_service = std::make_shared<cul::service::Implementation>(configuration);256 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
254257
@@ -370,7 +373,8 @@
370 {373 {
371 cul::connectivity::platform_default_manager(),374 cul::connectivity::platform_default_manager(),
372 std::make_shared<NullReporter>()375 std::make_shared<NullReporter>()
373 }376 },
377 obfuscator_config,
374 };378 };
375 configuration.engine->configuration.engine_state = cul::Engine::Status::on;379 configuration.engine->configuration.engine_state = cul::Engine::Status::on;
376 auto location_service = std::make_shared<cul::service::Implementation>(configuration);380 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
@@ -451,7 +455,8 @@
451 {455 {
452 cul::connectivity::platform_default_manager(),456 cul::connectivity::platform_default_manager(),
453 std::make_shared<NullReporter>()457 std::make_shared<NullReporter>()
454 }458 },
459 obfuscator_config,
455 };460 };
456 configuration.engine->configuration.satellite_based_positioning_state.set(cul::SatelliteBasedPositioningState::on);461 configuration.engine->configuration.satellite_based_positioning_state.set(cul::SatelliteBasedPositioningState::on);
457 auto location_service = std::make_shared<cul::service::Implementation>(configuration);462 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
@@ -531,7 +536,8 @@
531 {536 {
532 cul::connectivity::platform_default_manager(),537 cul::connectivity::platform_default_manager(),
533 std::make_shared<NullReporter>()538 std::make_shared<NullReporter>()
534 }539 },
540 obfuscator_config,
535 };541 };
536 auto location_service = std::make_shared<cul::service::Implementation>(configuration);542 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
537543
@@ -619,7 +625,8 @@
619 {625 {
620 cul::connectivity::platform_default_manager(),626 cul::connectivity::platform_default_manager(),
621 std::make_shared<NullReporter>()627 std::make_shared<NullReporter>()
622 }628 },
629 obfuscator_config,
623 };630 };
624 auto location_service = std::make_shared<cul::service::Implementation>(configuration);631 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
625632
@@ -699,7 +706,8 @@
699 {706 {
700 cul::connectivity::platform_default_manager(),707 cul::connectivity::platform_default_manager(),
701 std::make_shared<NullReporter>()708 std::make_shared<NullReporter>()
702 }709 },
710 obfuscator_config,
703 };711 };
704 auto location_service = std::make_shared<cul::service::Implementation>(configuration);712 auto location_service = std::make_shared<cul::service::Implementation>(configuration);
705713
@@ -761,7 +769,11 @@
761 if (t.joinable())769 if (t.joinable())
762 t.join();770 t.join();
763771
764 EXPECT_EQ(reference_position_update, position);772 EXPECT_TRUE(position.when >= reference_position_update.when);
773 /* Clear the accuracy, since it has been altered by the obfuscator. */
774 cul::Position expectedPosition = reference_position_update.value;
775 expectedPosition.accuracy = position.value.accuracy = cul::Position::Accuracy();
776 EXPECT_EQ(expectedPosition, position.value);
765777
766 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;778 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
767 };779 };
768780
=== added file 'tests/obfuscator_test.cpp'
--- tests/obfuscator_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/obfuscator_test.cpp 2016-04-27 10:14:29 +0000
@@ -0,0 +1,101 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alberto Mardegan <alberto.mardegan@canonical.com>
17 */
18
19#include <com/ubuntu/location/service/position_obfuscator.h>
20
21#include <gtest/gtest.h>
22
23namespace cul = com::ubuntu::location;
24namespace culs = com::ubuntu::location::service;
25typedef cul::Optional<cul::Update<cul::Position>> OptionalUpdate;
26
27TEST(Obfuscator, aging_no_update)
28{
29 using namespace ::testing;
30
31 culs::PositionObfuscator::Configuration config;
32 culs::PositionObfuscator obfuscator(config);
33
34 OptionalUpdate empty_update;
35 EXPECT_FALSE(empty_update);
36
37 obfuscator.apply_age(empty_update);
38 EXPECT_FALSE(empty_update);
39}
40
41TEST(Obfuscator, aging_still_valid)
42{
43 using namespace ::testing;
44
45 culs::PositionObfuscator::Configuration config;
46 config.moving_speed = 10.0;
47 config.minimum_accuracy = 10000;
48
49 culs::PositionObfuscator obfuscator(config);
50
51 auto test_time = cul::Clock::now();
52 cul::Update<cul::Position> update
53 {
54 {
55 cul::wgs84::Latitude{9. * cul::units::Degrees},
56 cul::wgs84::Longitude{53. * cul::units::Degrees},
57 cul::wgs84::Altitude{-2. * cul::units::Meters},
58 12 * cul::units::Meters,
59 9 * cul::units::Meters
60 },
61 test_time - std::chrono::seconds(100),
62 };
63
64 OptionalUpdate optional = update;
65 obfuscator.apply_age(optional);
66
67 EXPECT_TRUE(bool(optional));
68 cul::Update<cul::Position> aged_update = optional.get();
69
70 /* Make sure that the time has been updated since the original update */
71 EXPECT_TRUE(aged_update.when >= test_time);
72
73 /* Check that the accuracy is the one we would expect */
74 EXPECT_EQ(1012, int(aged_update.value.accuracy.horizontal.get() / cul::units::Meters));
75 EXPECT_EQ(1009, int(aged_update.value.accuracy.vertical.get() / cul::units::Meters));
76}
77
78TEST(Obfuscator, aging_too_inaccurate)
79{
80 using namespace ::testing;
81
82 culs::PositionObfuscator::Configuration config;
83 config.moving_speed = 1000.1;
84 config.minimum_accuracy = 100000;
85
86 culs::PositionObfuscator obfuscator(config);
87
88 cul::Update<cul::Position> update
89 {
90 {
91 cul::wgs84::Latitude{9. * cul::units::Degrees},
92 cul::wgs84::Longitude{53. * cul::units::Degrees},
93 cul::wgs84::Altitude{-2. * cul::units::Meters}
94 },
95 cul::Clock::now() - std::chrono::seconds(100),
96 };
97
98 OptionalUpdate optional = update;
99 obfuscator.apply_age(optional);
100 EXPECT_FALSE(optional);
101}

Subscribers

People subscribed via source and target branches