Skip to content

Commit

Permalink
[connectionagent] Fix contention between manual connections and autoc…
Browse files Browse the repository at this point in the history
…onnections.

When manually connecting to a service connection agent will respond to
the previously connected service going to the 'idle' state by
performing an autoconnect, which can trigger the connection to the
manually service to abort and the connection restored to the previous
service.
  • Loading branch information
Aaron McCarthy committed Nov 27, 2013
1 parent cc064da commit cf2464f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions connd/qconnectionmanager.cpp
Expand Up @@ -69,6 +69,7 @@ QConnectionManager::QConnectionManager(QObject *parent) :
qDebug() << Q_FUNC_INFO;

manualConnnectionTimer.invalidate();
manualDisconnectionTimer.invalidate();

connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));

Expand Down Expand Up @@ -174,7 +175,7 @@ void QConnectionManager::onErrorReported(const QString &servicePath, const QStri
// from useragent
void QConnectionManager::onConnectionRequest()
{
previousConnectedService.clear();
manualDisconnectionTimer.invalidate();
sendConnectReply("Suppress", 15);
bool ok = autoConnect();
qDebug() << serviceInProgress << ok << flightModeSuppression;
Expand Down Expand Up @@ -266,7 +267,8 @@ void QConnectionManager::serviceStateChanged(const QString &state)
if (serviceInProgress == service->path())
serviceInProgress.clear();

previousConnectedService = service->path();
lastManuallyDisconnectedService = service->path();
manualDisconnectionTimer.start();
if (service->type() == "ethernet") { //keep this alive
NetworkTechnology tech;
tech.setPath(netman->technologyPathForService(service->path()));
Expand Down Expand Up @@ -318,6 +320,14 @@ bool QConnectionManager::autoConnect()
if (selectedService.isEmpty()) {
selectedService = findBestConnectableService();
}

// Don't immediately reconnect if the manual disconnection timer has not expired. This prevents
// connectionagent from aborting a manual connection initiated by another process.
if (manualDisconnectionTimer.isValid() && !manualDisconnectionTimer.hasExpired(10000) &&
lastManuallyDisconnectedService == selectedService) {
return false;
}

if (!selectedService.isEmpty()) {
bool ok = connectToNetworkService(selectedService);
if (ok)
Expand Down Expand Up @@ -648,8 +658,6 @@ void QConnectionManager::setup()

if (isStateOnline(netman->state())) {
qDebug() << "default route type:" << netman->defaultRoute()->type();
previousConnectedService = netman->defaultRoute()->path();

if (netman->defaultRoute()->type() == "ethernet")
isEthernet = true;
} else
Expand Down Expand Up @@ -763,7 +771,6 @@ void QConnectionManager::offlineModeChanged(bool b)
{
flightModeSuppression = b;
if (b) {
previousConnectedService.clear();
QTimer::singleShot(5 * 1000 * 60,this,SLOT(flightModeDialogSuppressionTimeout())); //5 minutes
}
}
Expand All @@ -779,7 +786,6 @@ void QConnectionManager::displayStateChanged(const QString &state)
if (state == "on") {
NetworkTechnology *wifiTech = netman->getTechnology("wifi");
if (wifiTech && wifiTech->powered() && !wifiTech->connected()) {
previousConnectedService.clear();
wifiTech->scan();
}
}
Expand Down
4 changes: 3 additions & 1 deletion connd/qconnectionmanager.h
Expand Up @@ -99,7 +99,6 @@ public Q_SLOTS:
bool isEthernet;
bool connmanAvailable;
bool handoverInProgress;
QString previousConnectedService;
QString serviceInProgress;
QString autoConnectService;

Expand All @@ -117,6 +116,9 @@ public Q_SLOTS:
QElapsedTimer manualConnnectionTimer;
QString lastManuallyConnectedService;

QElapsedTimer manualDisconnectionTimer;
QString lastManuallyDisconnectedService;

private slots:
void onScanFinished();
void updateServicesMap();
Expand Down

0 comments on commit cf2464f

Please sign in to comment.