@@ -60,7 +60,17 @@
const quint32 PreferredInitialFixTime = 0;
const double KnotsToMps = 0.514444;
+const QString LocationSettingsDir = QStringLiteral("/etc/location/");
const QString LocationSettingsFile = QStringLiteral("/etc/location/location.conf");
+const QString LocationSettingsEnabledKey = QStringLiteral("location/enabled");
+const QString LocationSettingsGpsEnabledKey = QStringLiteral("location/gps/enabled");
+const QString LocationSettingsAgpsEnabledKey = QStringLiteral("location/%1/enabled");
+const QString LocationSettingsAgpsOnlineEnabledKey = QStringLiteral("location/%1/online_enabled");
+const QString LocationSettingsAgpsAgreementAcceptedKey = QStringLiteral("location/%1/agreement_accepted");
+const QString LocationSettingsAgpsProvidersKey = QStringLiteral("location/agps_providers");
+// deprecated keys
+const QString LocationSettingsOldAgpsEnabledKey = QStringLiteral("location/agreement_accepted");
+const QString LocationSettingsOldAgpsAgreementAcceptedKey = QStringLiteral("location/here_agreement_accepted");
void locationCallback(GpsLocation *location)
{
@@ -424,7 +434,7 @@
m_networkManager(new NetworkManager(this)), m_cellularTechnology(0),
m_ofonoExtModemManager(new QOfonoExtModemManager(this)),
m_connectionManager(new QOfonoConnectionManager(this)), m_connectionContext(0), m_ntpSocket(0),
- m_agpsEnabled(false)
+ m_agpsEnabled(false), m_agpsOnlineEnabled(false)
{
if (staticProvider)
qFatal("Only a single instance of HybrisProvider is supported.");
@@ -440,6 +450,9 @@
m_locationSettings = new QFileSystemWatcher(this);
connect(m_locationSettings, SIGNAL(fileChanged(QString)),
this, SLOT(locationEnabledChanged()));
+ connect(m_locationSettings, SIGNAL(directoryChanged(QString)),
+ this, SLOT(locationEnabledChanged()));
+ m_locationSettings->addPath(LocationSettingsDir);
m_locationSettings->addPath(LocationSettingsFile);
new GeoclueAdaptor(this);
@@ -475,7 +488,9 @@
m_connectionSelector = new ComJollaLipstickConnectionSelectorIfInterface(
QStringLiteral("com.jolla.lipstick.ConnectionSelector"), QStringLiteral("/"), connection);
- m_idleTimer.start(QuitIdleTime, this);
+ if (m_watchedServices.isEmpty()) {
+ m_idleTimer.start(QuitIdleTime, this);
+ }
const hw_module_t *hwModule;
@@ -571,9 +586,14 @@
if (!calledFromDBus())
qFatal("AddReference must only be called from DBus");
+ bool wasInactive = m_watchedServices.isEmpty();
const QString service = message().service();
m_watcher->addWatchedService(service);
m_watchedServices[service].referenceCount += 1;
+ if (wasInactive) {
+ qCDebug(lcGeoclueHybris) << "new watched service, stopping idle timer.";
+ m_idleTimer.stop();
+ }
startPositioningIfNeeded();
}
@@ -593,8 +613,10 @@
m_watchedServices.remove(service);
}
- if (m_watchedServices.isEmpty())
+ if (m_watchedServices.isEmpty()) {
+ qCDebug(lcGeoclueHybris) << "no watched services, starting idle timer.";
m_idleTimer.start(QuitIdleTime, this);
+ }
stopPositioningIfNeeded();
}
@@ -701,6 +723,7 @@
{
if (event->timerId() == m_idleTimer.timerId()) {
m_idleTimer.stop();
+ qCDebug(lcGeoclueHybris) << "have been idle for too long, quitting";
qApp->quit();
} else if (event->timerId() == m_fixLostTimer.timerId()) {
m_fixLostTimer.stop();
@@ -753,8 +776,10 @@
m_watchedServices.remove(service);
m_watcher->removeWatchedService(service);
- if (m_watchedServices.isEmpty())
+ if (m_watchedServices.isEmpty()) {
+ qCDebug(lcGeoclueHybris) << "no watched services, starting idle timer.";
m_idleTimer.start(QuitIdleTime, this);
+ }
stopPositioningIfNeeded();
}
@@ -922,6 +947,9 @@
void HybrisProvider::xtraDownloadRequest()
{
+ if (!m_agpsOnlineEnabled)
+ return;
+
if (m_xtraDownloadReply)
return;
@@ -1040,7 +1068,12 @@
void HybrisProvider::dataServiceConnected()
{
qCDebug(lcGeoclueHybris);
- foreach (NetworkService *service, m_networkManager->getServices(QStringLiteral("cellular"))) {
+
+ if (!m_agpsOnlineEnabled)
+ return;
+
+ QVector<NetworkService*> services = m_networkManager->getServices(QStringLiteral("cellular"));
+ Q_FOREACH (NetworkService *service, services) {
if (!service->connected())
continue;
@@ -1154,7 +1187,7 @@
{
qCDebug(lcGeoclueHybris);
- if (!m_agpsInterface.isEmpty())
+ if (m_agpsOnlineEnabled && !m_agpsInterface.isEmpty())
processConnectionContexts();
}
@@ -1162,6 +1195,9 @@
{
qCDebug(lcGeoclueHybris);
+ if (!m_agpsOnlineEnabled)
+ return;
+
if (m_connectionContext->isValid() &&
m_connectionContext->settings().value(QStringLiteral("Interface")) == m_agpsInterface) {
const QByteArray apn = m_connectionContext->accessPointName().toLocal8Bit();
@@ -1331,23 +1367,31 @@
bool HybrisProvider::positioningEnabled()
{
QSettings settings(LocationSettingsFile, QSettings::IniFormat);
- settings.beginGroup(QStringLiteral("location"));
-
- bool enabled = settings.value(QStringLiteral("enabled"), false).toBool();
-
- // Setting names are a bit confusing, agreement_accepted is what the WLAN/CellId positioning
- // daemons check and is used to toggle use of those services. here_agreement_accepted is the
- // actual acceptance state of the agreement from the user's perspective. Both need to be true
- // for AGPS (SUPL assistance) to be used.
- bool agpsEnabled = settings.value(QStringLiteral("agreement_accepted"), false).toBool();
- bool agpsAgreementAccepted = agpsEnabled;
- if (settings.contains(QStringLiteral("here_agreement_accepted")))
- agpsAgreementAccepted = settings.value(QStringLiteral("here_agreement_accepted"), false).toBool();
- m_agpsEnabled = agpsAgreementAccepted && agpsEnabled;
+ // check the keys related to agps enablement. We can have multiple agps providers.
+ bool agpsAgreementAccepted = false;
+ bool agpsEnabled = false;
+ bool agpsOnlineEnabled = false;
+ QString agpsProviders = settings.value(LocationSettingsAgpsProvidersKey, QStringLiteral("here")).toString();
+ Q_FOREACH (const QString &agpsProvider, agpsProviders.split(',', QString::SkipEmptyParts)) {
+ agpsAgreementAccepted = settings.value(LocationSettingsAgpsAgreementAcceptedKey.arg(agpsProvider), false).toBool();
+ agpsEnabled = settings.value(LocationSettingsAgpsEnabledKey.arg(agpsProvider), false).toBool();
+ agpsOnlineEnabled = settings.value(LocationSettingsAgpsOnlineEnabledKey.arg(agpsProvider), false).toBool();
+ if (agpsAgreementAccepted && agpsEnabled && agpsOnlineEnabled) {
+ break;
+ }
+ }
+ // check the deprecated keys, also:
+ bool oldAgpsAgreementAccepted = settings.value(LocationSettingsOldAgpsAgreementAcceptedKey, false).toBool();
+ bool oldAgpsEnabled = settings.value(LocationSettingsOldAgpsEnabledKey, false).toBool();
+ m_agpsEnabled = (agpsAgreementAccepted || oldAgpsAgreementAccepted) && (agpsEnabled || oldAgpsEnabled);
+ m_agpsOnlineEnabled = agpsOnlineEnabled || (oldAgpsAgreementAccepted && oldAgpsEnabled);
+
+ // check the keys related to the location and gps enablement, plus gps power state
+ bool locationEnabled = settings.value(LocationSettingsEnabledKey, false).toBool();
+ bool gpsEnabled = settings.value(LocationSettingsGpsEnabledKey, true).toBool(); // defaults to true if no key exists but location is enabled.
bool powered = m_deviceControl->powered();
-
- return enabled && powered;
+ return locationEnabled && gpsEnabled && powered;
}
quint32 HybrisProvider::minimumRequestedUpdateInterval() const
@@ -1378,6 +1422,16 @@
{
qCDebug(lcGeoclueHybris);
+ if (!m_agpsOnlineEnabled) {
+ qCDebug(lcGeoclueHybris) << "Online aGPS not enabled, not starting data connection.";
+#if GEOCLUE_ANDROID_GPS_INTERFACE == 2 || GEOCLUE_ANDROID_GPS_INTERFACE == 1
+ m_agps->data_conn_failed();
+#else
+ m_agps->data_conn_failed(AGPS_TYPE_SUPL);
+#endif
+ return;
+ }
+
// Check if existing cellular network service is connected
|
[-]
[+]
|
Changed |
_service:tar_git:geoclue-provider-hybris-0.2.11.tar.gz/main.cpp
^
|
@@ -28,6 +28,14 @@
uid_t effectiveUid;
uid_t savedUid;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
+ QCoreApplication::setSetuidAllowed(true);
+#endif
+ QLoggingCategory::setFilterRules(QStringLiteral("geoclue.provider.hybris.debug=false\n"
+ "geoclue.provider.hybris.nmea.debug=false\n"
+ "geoclue.provider.hybris.position.debug=false"));
+ QCoreApplication a(argc, argv);
+
int result = getresuid(&realUid, &effectiveUid, &savedUid);
if (result == -1)
qFatal("Failed to get process uids, %s", strerror(errno));
@@ -62,6 +70,9 @@
// Register service on DBus system bus prior to dropping privileges.
QDBusConnection system = QDBusConnection::systemBus();
+ DeviceControl control;
+ if (!system.registerObject(QStringLiteral("/com/jollamobile/gps/Device"), &control))
+ qFatal("Failed to register object /com/jollamobile/gps/Device");
if (!system.registerService(QStringLiteral("com.jollamobile.gps")))
qFatal("Failed to register service com.jollamobile.gps");
@@ -72,29 +83,12 @@
qFatal("Failed to set process uid to %d, %s", realUid, strerror(errno));
#endif
- QLoggingCategory::setFilterRules(QStringLiteral("geoclue.provider.hybris.debug=false\n"
- "geoclue.provider.hybris.nmea.debug=false\n"
- "geoclue.provider.hybris.position.debug=false"));
-
- QCoreApplication a(argc, argv);
-
-
- DeviceControl control;
-
- if (!system.registerObject(QStringLiteral("/com/jollamobile/gps/Device"), &control))
- qFatal("Failed to register object /com/jollamobile/gps/Device");
-
-
- QDBusConnection connection = QDBusConnection::sessionBus();
-
- if (!connection.registerService(QStringLiteral("org.freedesktop.Geoclue.Providers.Hybris")))
- qFatal("Failed to register service org.freedesktop.Geoclue.Providers.Hybris");
-
+ QDBusConnection session = QDBusConnection::sessionBus();
HybrisProvider provider;
-
- if (!connection.registerObject(QStringLiteral("/org/freedesktop/Geoclue/Providers/Hybris"), &provider))
+ if (!session.registerObject(QStringLiteral("/org/freedesktop/Geoclue/Providers/Hybris"), &provider))
qFatal("Failed to register object /org/freedesktop/Geoclue/Providers/Hybris");
-
+ if (!session.registerService(QStringLiteral("org.freedesktop.Geoclue.Providers.Hybris")))
+ qFatal("Failed to register service org.freedesktop.Geoclue.Providers.Hybris");
provider.setDeviceController(&control);
return a.exec();
|