From ef44a431978d1d0425a76663e51721d2294d313d Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Mon, 16 Apr 2018 09:50:06 -0400 Subject: [PATCH 1/2] Skip host lookup on Android --- src/QtLocationPlugin/QGCTileCacheWorker.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.cpp b/src/QtLocationPlugin/QGCTileCacheWorker.cpp index 074bcf0..7ccc034 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.cpp +++ b/src/QtLocationPlugin/QGCTileCacheWorker.cpp @@ -1094,15 +1094,40 @@ QGCCacheWorker::_createDB(QSqlDatabase* db, bool createDefault) void 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) { _hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo))); } +#endif } //----------------------------------------------------------------------------- void QGCCacheWorker::_lookupReady(QHostInfo info) { +#if defined(__android__) + Q_UNUSED(info); +#else _hostLookupID = 0; if(info.error() == QHostInfo::NoError && info.addresses().size()) { QTcpSocket socket; @@ -1118,4 +1143,5 @@ QGCCacheWorker::_lookupReady(QHostInfo info) } qWarning() << "No Internet Access"; emit internetStatus(false); +#endif } From 585e71d9702ae02fd1c0da711ae8667c6927a5e4 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Mon, 16 Apr 2018 20:17:42 -0400 Subject: [PATCH 2/2] Don't bother testing the reason for exiting the wait condition. If there is nothing to do, it will exit any way. --- src/QtLocationPlugin/QGCTileCacheWorker.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.cpp b/src/QtLocationPlugin/QGCTileCacheWorker.cpp index 7ccc034..0f84731 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.cpp +++ b/src/QtLocationPlugin/QGCTileCacheWorker.cpp @@ -188,18 +188,15 @@ QGCCacheWorker::run() //-- Wait a bit before shutting things down _waitmutex.lock(); int timeout = 5000; - if(!_waitc.wait(&_waitmutex, timeout)) - { - _waitmutex.unlock(); - _mutex.lock(); - //-- If nothing to do, close db and leave thread - if(!_taskQueue.count()) { - _mutex.unlock(); - break; - } + _waitc.wait(&_waitmutex, timeout); + _waitmutex.unlock(); + _mutex.lock(); + //-- If nothing to do, close db and leave thread + if(!_taskQueue.count()) { _mutex.unlock(); + break; } - _waitmutex.unlock(); + _mutex.unlock(); } } if(_db) {