diff --git a/libs/handler.h b/libs/handler.h --- a/libs/handler.h +++ b/libs/handler.h @@ -141,6 +141,7 @@ void enableBluetooth(bool enable); void scanRequestFailed(const QString &interface); + bool checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice); }; diff --git a/libs/handler.cpp b/libs/handler.cpp --- a/libs/handler.cpp +++ b/libs/handler.cpp @@ -496,6 +496,10 @@ continue; } + if (!checkRequestScanRateLimit(wifiDevice)) { + return; + } + qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName(); QDBusPendingReply<> reply = wifiDevice->requestScan(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); @@ -507,6 +511,27 @@ } } +bool Handler::checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice) +{ + QDateTime now = QDateTime::currentDateTime(); + QDateTime lastScan = wifiDevice->lastScan(); + QDateTime lastRequestScan = wifiDevice->lastRequestScan(); + + // if the last scan finished within the last 10 seconds + bool ret = lastScan.isValid() && lastScan.msecsTo(now) < 10 * 1000; + // or a scan request has been sent but hasn't finished yet + ret |= lastRequestScan.isValid() && lastScan.isValid() && lastScan < lastRequestScan; + // or if the last Request was sent within the last 10 seconds + ret |= lastRequestScan.isValid() && lastRequestScan.msecsTo(now) < 10 * 1000; + // skip the request scan + if (ret) { + qCDebug(PLASMA_NM) << "Last scan finished " << lastScan.msecsTo(now) << "ms ago and last request scan was sent " + << lastRequestScan.msecsTo(now) << "ms ago, Skipping scanning interface:" << wifiDevice->interfaceName(); + return false; + } + return true; +} + void Handler::scanRequestFailed(const QString &interface) { if (m_wirelessScanRetryTimer.isActive()) {