@@ -38,6 +38,8 @@
#include <qofonoextmodemmanager.h>
+#include <android-config.h>
+
#include <strings.h>
#include <sys/time.h>
@@ -71,6 +73,9 @@
const QString LocationSettingsOldAgpsEnabledKey = QStringLiteral("location/agreement_accepted");
const QString LocationSettingsOldAgpsAgreementAcceptedKey = QStringLiteral("location/here_agreement_accepted");
+const int MaxXtraServers = 3;
+const QString XtraConfigFile = QStringLiteral("/etc/gps_xtra.ini");
+
void locationCallback(GpsLocation *location)
{
Location loc;
@@ -164,6 +169,28 @@
}
#endif
+#ifdef USE_GPS_VENDOR_EXTENSION
+void gnssSvStatusCallback_custom(GnssSvStatus *svStatus)
+{
+ QList<SatelliteInfo> satellites;
+ QList<int> usedPrns;
+
+ for (int i = 0; i < svStatus->num_svs; ++i) {
+ SatelliteInfo satInfo;
+ GnssSvInfo &svInfo = svStatus->sv_list[i];
+ satInfo.setPrn(svInfo.prn);
+ satInfo.setSnr(svInfo.snr);
+ satInfo.setElevation(svInfo.elevation);
+ satInfo.setAzimuth(svInfo.azimuth);
+ satellites.append(satInfo);
+ }
+
+ QMetaObject::invokeMethod(staticProvider, "setSatellite", Qt::QueuedConnection,
+ Q_ARG(QList<SatelliteInfo>, satellites),
+ Q_ARG(QList<int>, usedPrns));
+}
+#endif
+
bool nmeaChecksumValid(const QByteArray &nmea)
{
unsigned char checksum = 0;
@@ -348,6 +375,9 @@
locationCallback,
statusCallback,
svStatusCallback,
+#ifdef USE_GPS_VENDOR_EXTENSION
+ gnssSvStatusCallback_custom,
+#endif
nmeaCallback,
setCapabilitiesCallback,
acquireWakelockCallback,
@@ -465,12 +495,12 @@
HybrisProvider::HybrisProvider(QObject *parent)
: QObject(parent), m_gps(0), m_agps(0), m_agpsril(0), m_gpsni(0), m_xtra(0),
- m_status(StatusUnavailable), m_positionInjectionConnected(false), m_xtraDownloadReply(0),
+ m_status(StatusUnavailable), m_positionInjectionConnected(false), m_xtraDownloadReply(0), m_xtraServerIndex(0),
m_requestedConnect(false), m_gpsStarted(false), m_locationSettings(0),
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_agpsOnlineEnabled(false)
+ m_agpsEnabled(false), m_agpsOnlineEnabled(false), m_useForcedXtraInject(false), m_xtraUserAgent("")
{
if (staticProvider)
qFatal("Only a single instance of HybrisProvider is supported.");
@@ -491,6 +521,7 @@
m_manager = new QNetworkAccessManager(this);
connect(m_networkManager, SIGNAL(technologiesChanged()), this, SLOT(technologiesChanged()));
+ connect(m_networkManager, SIGNAL(stateChanged(QString)), this, SLOT(stateChanged(QString)));
technologiesChanged();
@@ -520,6 +551,48 @@
m_idleTimer.start(QuitIdleTime, this);
}
+ QString xtraUserAgentFileName;
+ QSettings settings(XtraConfigFile, QSettings::IniFormat);
+ QString xtraServer;
+
+ for (int i = 0; i < MaxXtraServers; i++) {
+ QString key = QString("xtra/XTRA_SERVER_%1").arg(i);
+ xtraServer = settings.value(key, "").toString();
+ if (xtraServer != "") {
+ m_xtraServers.enqueue(xtraServer);
+ }
+ }
+
+ m_useForcedXtraInject = settings.value("xtra/XTRA_FORCE_INJECT", "").toBool();
+
+ xtraUserAgentFileName = settings.value("xtra/XTRA_USERAGENT_FILE", "").toString();
+ if (xtraUserAgentFileName != "") {
+ QFile xtraUserAgentFile(xtraUserAgentFileName);
+ if (xtraUserAgentFile.open(QIODevice::ReadOnly)) {
+ m_xtraUserAgent = xtraUserAgentFile.readLine();
+ }
+ }
+
+ if (m_xtraServers.isEmpty()) {
+ QFile gpsConf(QStringLiteral("/system/etc/gps.conf"));
+ if (!gpsConf.open(QIODevice::ReadOnly))
+ return;
+
+ while (!gpsConf.atEnd()) {
+ const QByteArray line = gpsConf.readLine().trimmed();
+ if (line.startsWith('#'))
+ continue;
+
+ const QList<QByteArray> split = line.split('=');
+ if (split.length() != 2)
+ continue;
+
+ const QByteArray key = split.at(0).trimmed();
+ if (key == "XTRA_SERVER_1" || key == "XTRA_SERVER_2" || key == "XTRA_SERVER_3")
+ m_xtraServers.enqueue(QUrl::fromEncoded(split.at(1).trimmed()));
+ }
+ }
+
const hw_module_t *hwModule;
int error = hw_get_module(GPS_HARDWARE_MODULE_ID, &hwModule);
@@ -986,36 +1059,26 @@
qCDebug(lcGeoclueHybris) << "xtra download requested";
- QFile gpsConf(QStringLiteral("/system/etc/gps.conf"));
- if (!gpsConf.open(QIODevice::ReadOnly))
- return;
-
- while (!gpsConf.atEnd()) {
- const QByteArray line = gpsConf.readLine().trimmed();
- if (line.startsWith('#'))
- continue;
-
- const QList<QByteArray> split = line.split('=');
- if (split.length() != 2)
- continue;
-
- const QByteArray key = split.at(0).trimmed();
- if (key == "XTRA_SERVER_1" || key == "XTRA_SERVER_2" || key == "XTRA_SERVER_3")
- m_xtraServers.enqueue(QUrl::fromEncoded(split.at(1).trimmed()));
- }
+ m_xtraServerIndex = 0;
xtraDownloadRequestSendNext();
}
void HybrisProvider::xtraDownloadRequestSendNext()
{
- if (m_xtraServers.isEmpty())
+ if (m_xtraServerIndex >= m_xtraServers.count())
return;
qCDebug(lcGeoclueHybris) << m_xtraServers;
- m_xtraDownloadReply = m_manager->get(QNetworkRequest(m_xtraServers.dequeue()));
+ QNetworkRequest network_request(m_xtraServers[m_xtraServerIndex]);
+ if (m_xtraUserAgent != "") {
+ network_request.setRawHeader("User-Agent", m_xtraUserAgent.toUtf8());
+ }
+ m_xtraDownloadReply = m_manager->get(network_request);
connect(m_xtraDownloadReply, SIGNAL(finished()), this, SLOT(xtraDownloadFinished()));
+
+ m_xtraServerIndex++;
}
void HybrisProvider::xtraDownloadFinished()
@@ -1039,9 +1102,9 @@
QByteArray xtraData = m_xtraDownloadReply->readAll();
m_xtra->inject_xtra_data(xtraData.data(), xtraData.length());
- m_xtraDownloadReply = 0;
+ qCDebug(lcGeoclueHybris) << "injected " << xtraData.length() << " bytes of xtra data";
- m_xtraServers.clear();
+ m_xtraDownloadReply = 0;
}
}
@@ -1207,6 +1270,15 @@
}
}
+void HybrisProvider::stateChanged(const QString &state)
+{
+ if (state == "online") {
+ if (m_gpsStarted && m_useForcedXtraInject) {
+ gpsXtraDownloadRequest();
+ }
+ }
+}
|