Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit 72b56f0

Browse files
author
Chris Adams
committed
[systemsettings] Expose enabledDataSources in LocationSettings. Contributes to JB#33753
1 parent 82e3bd2 commit 72b56f0

File tree

3 files changed

+177
-29
lines changed

3 files changed

+177
-29
lines changed

src/locationsettings.cpp

Lines changed: 142 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,88 @@
4646
#include <networkmanager.h>
4747
#include <networktechnology.h>
4848

49+
#include <limits>
50+
4951
namespace {
52+
// TODO: replace all of this with DBus calls to a central settings service...
5053
QString boolToString(bool value) { return value ? QStringLiteral("true") : QStringLiteral("false"); }
5154
const QString LocationSettingsDir = QStringLiteral("/etc/location/");
5255
const QString LocationSettingsFile = QStringLiteral("/etc/location/location.conf");
5356
const QString LocationSettingsKeys = QStringLiteral(
54-
"enabled" ";"
55-
"custom_mode" ";"
56-
"agps_providers" ";"
57-
"gps\\enabled" ";"
58-
"mls\\enabled" ";"
59-
"mls\\agreement_accepted" ";"
60-
"mls\\online_enabled" ";"
61-
"here\\enabled" ";"
62-
"here\\agreement_accepted" ";"
63-
"here\\online_enabled" ";"
64-
/* and the deprecated keys: */
65-
"cell_id_positioning_enabled" ";"
66-
"here_agreement_accepted" ";"
67-
"agreement_accepted");
57+
"enabled" ";"
58+
"allowed_data_sources\\online" ";"
59+
"allowed_data_sources\\device_sensors" ";"
60+
"allowed_data_sources\\bt_data" ";"
61+
"allowed_data_sources\\wlan_data" ";"
62+
"allowed_data_sources\\cell_data" ";"
63+
"allowed_data_sources\\gps" ";"
64+
"allowed_data_sources\\glonass" ";"
65+
"allowed_data_sources\\beidou" ";"
66+
"allowed_data_sources\\galileo" ";"
67+
"allowed_data_sources\\qzss" ";"
68+
"allowed_data_sources\\sbas" ";"
69+
"custom_mode" ";"
70+
"agps_providers" ";"
71+
"gps\\enabled" ";"
72+
"mls\\enabled" ";"
73+
"mls\\agreement_accepted" ";"
74+
"mls\\online_enabled" ";"
75+
"here\\enabled" ";"
76+
"here\\agreement_accepted" ";"
77+
"here\\online_enabled" ";"
78+
/* and the deprecated keys: */
79+
"cell_id_positioning_enabled" ";"
80+
"here_agreement_accepted" ";"
81+
"agreement_accepted");
82+
const int LocationSettingsValueIndex_Enabled = 0;
83+
const int LocationSettingsValueIndex_AllowedDataSources_Online = 1;
84+
const int LocationSettingsValueIndex_AllowedDataSources_DeviceSensors = 2;
85+
const int LocationSettingsValueIndex_AllowedDataSources_Bluetooth = 3;
86+
const int LocationSettingsValueIndex_AllowedDataSources_WlanData = 4;
87+
const int LocationSettingsValueIndex_AllowedDataSources_CellData = 5;
88+
const int LocationSettingsValueIndex_AllowedDataSources_Gps = 6;
89+
const int LocationSettingsValueIndex_AllowedDataSources_Glonass = 7;
90+
const int LocationSettingsValueIndex_AllowedDataSources_Beidou = 8;
91+
const int LocationSettingsValueIndex_AllowedDataSources_Galileo = 9;
92+
const int LocationSettingsValueIndex_AllowedDataSources_Qzss = 10;
93+
const int LocationSettingsValueIndex_AllowedDataSources_Sbas = 11;
94+
const int LocationSettingsValueIndex_CustomMode = 12;
95+
const int LocationSettingsValueIndex_AgpsProviders = 13;
96+
const int LocationSettingsValueIndex_Gps_Enabled = 14;
97+
const int LocationSettingsValueIndex_Mls_Enabled = 15;
98+
const int LocationSettingsValueIndex_Mls_AgreementAccepted = 16;
99+
const int LocationSettingsValueIndex_Mls_OnlineEnabled = 17;
100+
const int LocationSettingsValueIndex_Here_Enabled = 18;
101+
const int LocationSettingsValueIndex_Here_AgreementAccepted = 19;
102+
const int LocationSettingsValueIndex_Here_OnlineEnabled = 26;
103+
const int LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled = 20;
104+
const int LocationSettingsValueIndex_DEPRECATED_HereEnabled = 21;
105+
const int LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted = 22;
106+
QMap<int, LocationSettings::DataSource> LocationSettingsValueIndexToDataSourceMap
107+
{
108+
{ LocationSettingsValueIndex_AllowedDataSources_Online,
109+
LocationSettings::OnlineDataSources },
110+
{ LocationSettingsValueIndex_AllowedDataSources_DeviceSensors,
111+
LocationSettings::DeviceSensorsData },
112+
{ LocationSettingsValueIndex_AllowedDataSources_Bluetooth,
113+
LocationSettings::BluetoothData },
114+
{ LocationSettingsValueIndex_AllowedDataSources_WlanData,
115+
LocationSettings::WlanData },
116+
{ LocationSettingsValueIndex_AllowedDataSources_CellData,
117+
LocationSettings::CellTowerData },
118+
{ LocationSettingsValueIndex_AllowedDataSources_Gps,
119+
LocationSettings::GpsData },
120+
{ LocationSettingsValueIndex_AllowedDataSources_Glonass,
121+
LocationSettings::GlonassData },
122+
{ LocationSettingsValueIndex_AllowedDataSources_Beidou,
123+
LocationSettings::BeidouData },
124+
{ LocationSettingsValueIndex_AllowedDataSources_Galileo,
125+
LocationSettings::GalileoData },
126+
{ LocationSettingsValueIndex_AllowedDataSources_Qzss,
127+
LocationSettings::QzssData },
128+
{ LocationSettingsValueIndex_AllowedDataSources_Sbas,
129+
LocationSettings::SbasData },
130+
};
68131
const QString PoweredPropertyName = QStringLiteral("Powered");
69132
}
70133

@@ -79,6 +142,7 @@ LocationSettingsPrivate::LocationSettingsPrivate(LocationSettings::Mode mode, Lo
79142
, m_locationMode(LocationSettings::CustomMode)
80143
, m_settingLocationMode(true)
81144
, m_settingMultipleSettings(false)
145+
, m_allowedDataSources(static_cast<LocationSettings::DataSources>(std::numeric_limits<quint32>::max()))
82146
, m_connMan(Q_NULLPTR)
83147
, m_gpsTech(Q_NULLPTR)
84148
, m_gpsTechInterface(mode == LocationSettings::AsynchronousMode
@@ -431,6 +495,23 @@ void LocationSettings::setLocationMode(LocationMode locationMode)
431495
d->m_settingLocationMode = false;
432496
}
433497

498+
LocationSettings::DataSources LocationSettings::allowedDataSources() const
499+
{
500+
Q_D(const LocationSettings);
501+
return d->m_allowedDataSources;
502+
}
503+
504+
void LocationSettings::setAllowedDataSources(LocationSettings::DataSources dataSources)
505+
{
506+
Q_D(LocationSettings);
507+
if (dataSources == d->m_allowedDataSources)
508+
return;
509+
510+
d->m_allowedDataSources = dataSources;
511+
d->writeSettings();
512+
emit allowedDataSourcesChanged();
513+
}
514+
434515
void LocationSettingsPrivate::readSettings()
435516
{
436517
if (!m_processMutex) {
@@ -451,22 +532,44 @@ void LocationSettingsPrivate::readSettings()
451532
}
452533

453534
// read the deprecated keys first, for compatibility purposes:
454-
bool oldMlsEnabled = locationSettingsValues[10] != NULL && strcmp(locationSettingsValues[10], "true") == 0;
455-
bool oldHereEnabled = locationSettingsValues[11] != NULL && strcmp(locationSettingsValues[11], "true") == 0;
456-
bool oldHereAgreementAccepted = locationSettingsValues[12] != NULL && strcmp(locationSettingsValues[12], "true") == 0;
535+
bool oldMlsEnabled = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled] != NULL
536+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled], "true") == 0;
537+
bool oldHereEnabled = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereEnabled] != NULL
538+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereEnabled], "true") == 0;
539+
bool oldHereAgreementAccepted = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted] != NULL
540+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted], "true") == 0;
541+
457542
// then read the new key values (overriding with deprecated values if needed):
458-
bool locationEnabled = locationSettingsValues[0] != NULL && strcmp(locationSettingsValues[0], "true") == 0;
459-
bool customMode = locationSettingsValues[1] != NULL && strcmp(locationSettingsValues[1], "true") == 0;
460-
// skip over the agps_providers value at [2]
461-
bool gpsEnabled = locationSettingsValues[3] != NULL && strcmp(locationSettingsValues[3], "true") == 0;
462-
bool mlsEnabled = oldMlsEnabled || (locationSettingsValues[4] != NULL && strcmp(locationSettingsValues[4], "true") == 0);
463-
bool mlsAgreementAccepted = locationSettingsValues[5] != NULL && strcmp(locationSettingsValues[5], "true") == 0;
464-
bool mlsOnlineEnabled = locationSettingsValues[6] != NULL && strcmp(locationSettingsValues[6], "true") == 0;
465-
bool hereEnabled = oldHereEnabled || (locationSettingsValues[7] != NULL && strcmp(locationSettingsValues[7], "true") == 0);
466-
bool hereAgreementAccepted = oldHereAgreementAccepted || (locationSettingsValues[8] != NULL && strcmp(locationSettingsValues[8], "true") == 0);
467-
// skip over here\online_enabled value at [9]
468-
469-
const int expectedCount = 13; // should equal: LocationSettingsKeys.split(';').count();
543+
bool locationEnabled = locationSettingsValues[LocationSettingsValueIndex_Enabled] != NULL
544+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Enabled], "true") == 0;
545+
bool customMode = locationSettingsValues[LocationSettingsValueIndex_CustomMode] != NULL
546+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_CustomMode], "true") == 0;
547+
LocationSettings::DataSources allowedDataSources = static_cast<LocationSettings::DataSources>(std::numeric_limits<quint32>::max());
548+
for (QMap<int, LocationSettings::DataSource>::const_iterator it = LocationSettingsValueIndexToDataSourceMap.constBegin();
549+
it != LocationSettingsValueIndexToDataSourceMap.constEnd(); it++) {
550+
if (locationSettingsValues[it.key()] != NULL && strcmp(locationSettingsValues[it.key()], "true") != 0) {
551+
allowedDataSources &= ~it.value(); // mark the data source as disabled
552+
}
553+
}
554+
// skip over the agps_providers value.
555+
bool gpsEnabled = locationSettingsValues[LocationSettingsValueIndex_Gps_Enabled] != NULL
556+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Gps_Enabled], "true") == 0;
557+
bool mlsEnabled = oldMlsEnabled
558+
|| (locationSettingsValues[LocationSettingsValueIndex_Mls_Enabled] != NULL
559+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Mls_Enabled], "true") == 0);
560+
bool mlsAgreementAccepted = locationSettingsValues[LocationSettingsValueIndex_Mls_AgreementAccepted] != NULL
561+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Mls_AgreementAccepted], "true") == 0;
562+
bool mlsOnlineEnabled = locationSettingsValues[LocationSettingsValueIndex_Mls_OnlineEnabled] != NULL
563+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Mls_OnlineEnabled], "true") == 0;
564+
bool hereEnabled = oldHereEnabled
565+
|| (locationSettingsValues[LocationSettingsValueIndex_Here_Enabled] != NULL
566+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Here_Enabled], "true") == 0);
567+
bool hereAgreementAccepted = oldHereAgreementAccepted
568+
|| (locationSettingsValues[LocationSettingsValueIndex_Here_AgreementAccepted] != NULL
569+
&& strcmp(locationSettingsValues[LocationSettingsValueIndex_Here_AgreementAccepted], "true") == 0);
570+
// skip over here\online_enabled value.
571+
572+
const int expectedCount = 23; // should equal: LocationSettingsKeys.split(';').count();
470573
for (int i = 0; i < expectedCount; ++i) {
471574
if (locationSettingsValues[i] != NULL) {
472575
free(locationSettingsValues[i]);
@@ -479,6 +582,11 @@ void LocationSettingsPrivate::readSettings()
479582
emit q->locationEnabledChanged();
480583
}
481584

585+
if (m_allowedDataSources != allowedDataSources) {
586+
m_allowedDataSources = allowedDataSources;
587+
emit q->allowedDataSourcesChanged();
588+
}
589+
482590
if (m_gpsEnabled != gpsEnabled) {
483591
m_gpsEnabled = gpsEnabled;
484592
emit q->gpsEnabledChanged();
@@ -541,6 +649,11 @@ void LocationSettingsPrivate::writeSettings()
541649
QString locationSettingsValues;
542650
locationSettingsValues.append(boolToString(m_locationEnabled));
543651
locationSettingsValues.append(";");
652+
for (QMap<int, LocationSettings::DataSource>::const_iterator it = LocationSettingsValueIndexToDataSourceMap.constBegin();
653+
it != LocationSettingsValueIndexToDataSourceMap.constEnd(); it++) {
654+
locationSettingsValues.append(boolToString(m_allowedDataSources & it.value()));
655+
locationSettingsValues.append(";");
656+
}
544657
locationSettingsValues.append(boolToString(m_locationMode == LocationSettings::CustomMode));
545658
locationSettingsValues.append(";");
546659
locationSettingsValues.append(agps_providers);

src/locationsettings.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <QObject>
3939
#include <QString>
4040

41+
#define LOCATION_SETTINGS_LAST_DATA_SOURCE_BIT 31
42+
4143
class LocationSettingsPrivate;
4244
class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
4345
{
@@ -58,6 +60,8 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
5860

5961
Q_PROPERTY(LocationMode locationMode READ locationMode WRITE setLocationMode NOTIFY locationModeChanged)
6062

63+
Q_PROPERTY(DataSources allowedDataSources READ allowedDataSources WRITE setAllowedDataSources NOTIFY allowedDataSourcesChanged)
64+
6165
Q_ENUMS(OnlineAGpsState)
6266
Q_ENUMS(LocationMode)
6367

@@ -106,6 +110,33 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
106110
LocationMode locationMode() const;
107111
void setLocationMode(LocationMode locationMode);
108112

113+
// Data sources are grouped roughly by type,
114+
// with gaps left for future expansion.
115+
enum DataSource {
116+
NoDataSources = 0UL,
117+
118+
OnlineDataSources = 1UL << 0,
119+
120+
DeviceSensorsData = 1UL << 5,
121+
BluetoothData = 1UL << 10,
122+
WlanData = 1UL << 15,
123+
CellTowerData = 1UL << 20,
124+
125+
GpsData = 1UL << 25,
126+
GlonassData = 1UL << 26,
127+
BeidouData = 1UL << 27,
128+
GalileoData = 1UL << 28,
129+
QzssData = 1UL << 29,
130+
SbasData = 1UL << 30,
131+
132+
LastDataSource = 1UL << LOCATION_SETTINGS_LAST_DATA_SOURCE_BIT
133+
};
134+
Q_DECLARE_FLAGS(DataSources, DataSource)
135+
Q_FLAG(DataSources)
136+
137+
DataSources allowedDataSources() const;
138+
void setAllowedDataSources(DataSources dataSources);
139+
109140
signals:
110141
void hereStateChanged();
111142
void locationEnabledChanged();
@@ -114,11 +145,14 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
114145
void mlsEnabledChanged();
115146
void mlsOnlineStateChanged();
116147
void locationModeChanged();
148+
void allowedDataSourcesChanged();
117149

118150
private:
119151
LocationSettingsPrivate *d_ptr;
120152
Q_DISABLE_COPY(LocationSettings)
121153
Q_DECLARE_PRIVATE(LocationSettings)
122154
};
123155

156+
Q_DECLARE_OPERATORS_FOR_FLAGS(LocationSettings::DataSources)
157+
124158
#endif // LOCATIONSETTINGS_H

src/locationsettings_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class LocationSettingsPrivate : public QObject
7171
LocationSettings::LocationMode m_locationMode;
7272
bool m_settingLocationMode;
7373
bool m_settingMultipleSettings;
74+
LocationSettings::DataSources m_allowedDataSources;
7475
NetworkManager *m_connMan;
7576
NetworkTechnology *m_gpsTech;
7677
QDBusInterface *m_gpsTechInterface;

0 commit comments

Comments
 (0)