Browse Source

Merge pull request #6359 from mavlink/androidSkipLookup

Skip host lookup on Android
QGC4.4
Gus Grubba 7 years ago committed by GitHub
parent
commit
c29c83a9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      src/QtLocationPlugin/QGCTileCacheWorker.cpp

43
src/QtLocationPlugin/QGCTileCacheWorker.cpp

@ -188,18 +188,15 @@ QGCCacheWorker::run()
//-- Wait a bit before shutting things down //-- Wait a bit before shutting things down
_waitmutex.lock(); _waitmutex.lock();
int timeout = 5000; int timeout = 5000;
if(!_waitc.wait(&_waitmutex, timeout)) _waitc.wait(&_waitmutex, timeout);
{ _waitmutex.unlock();
_waitmutex.unlock(); _mutex.lock();
_mutex.lock(); //-- If nothing to do, close db and leave thread
//-- If nothing to do, close db and leave thread if(!_taskQueue.count()) {
if(!_taskQueue.count()) {
_mutex.unlock();
break;
}
_mutex.unlock(); _mutex.unlock();
break;
} }
_waitmutex.unlock(); _mutex.unlock();
} }
} }
if(_db) { if(_db) {
@ -1094,15 +1091,40 @@ QGCCacheWorker::_createDB(QSqlDatabase* db, bool createDefault)
void void
QGCCacheWorker::_testInternet() QGCCacheWorker::_testInternet()
{ {
/*
To test if you have Internet connection, the code tests a connection to
8.8.8.8:53 (google DNS). It appears that some routers are now blocking TCP
connections to port 53. So instead, we use a TCP connection to "github.com"
(80). On exit, if the look up for github.com is under way, a call to abort
the lookup is made. This abort call on Android has no effect, and the code
blocks for a full minute. So to work around the issue, we continue a direct
TCP connection to 8.8.8.8:53 on Android and do the lookup/connect on the
other platforms.
*/
#if defined(__android__)
QTcpSocket socket;
socket.connectToHost("8.8.8.8", 53);
if (socket.waitForConnected(2000)) {
qCDebug(QGCTileCacheLog) << "Yes Internet Access";
emit internetStatus(true);
return;
}
qWarning() << "No Internet Access";
emit internetStatus(false);
#else
if(!_hostLookupID) { if(!_hostLookupID) {
_hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo))); _hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo)));
} }
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCCacheWorker::_lookupReady(QHostInfo info) QGCCacheWorker::_lookupReady(QHostInfo info)
{ {
#if defined(__android__)
Q_UNUSED(info);
#else
_hostLookupID = 0; _hostLookupID = 0;
if(info.error() == QHostInfo::NoError && info.addresses().size()) { if(info.error() == QHostInfo::NoError && info.addresses().size()) {
QTcpSocket socket; QTcpSocket socket;
@ -1118,4 +1140,5 @@ QGCCacheWorker::_lookupReady(QHostInfo info)
} }
qWarning() << "No Internet Access"; qWarning() << "No Internet Access";
emit internetStatus(false); emit internetStatus(false);
#endif
} }

Loading…
Cancel
Save