Navigation Menu

Skip to content

Commit

Permalink
[connectionagent] Prevent auto connect after a manual connection.
Browse files Browse the repository at this point in the history
If a manual connection to a service network is detected disable auto
connect for 5 minutes. This is a bit of a work around until
SingleConnectedTechnology can be turned off.
  • Loading branch information
Aaron McCarthy committed Nov 14, 2013
1 parent 2b052a7 commit c47979c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
32 changes: 29 additions & 3 deletions connd/qconnectionmanager.cpp
Expand Up @@ -67,6 +67,9 @@ QConnectionManager::QConnectionManager(QObject *parent) :
flightModeSuppression(false)
{
qDebug() << Q_FUNC_INFO;

manualConnnectionTimer.invalidate();

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

connectionAdaptor = new ConnAdaptor(this);
Expand Down Expand Up @@ -240,6 +243,14 @@ void QConnectionManager::serviceStateChanged(const QString &state)
&& netman->state() != "online") {
goodConnectTimer->start();
}

//manual connection
if ((state == "ready" || state == "online") && service->path() != serviceInProgress) {
qDebug() << "manual connection of" << service->path() << "detected, enabling auto connect timeout";
lastManuallyConnectedService = service->path();
manualConnnectionTimer.start();
}

//auto migrate
if (service->path() == serviceInProgress
&& state == "online") {
Expand All @@ -248,6 +259,10 @@ void QConnectionManager::serviceStateChanged(const QString &state)

//auto migrate
if (state == "idle") {
if (lastManuallyConnectedService == service->path()) {
lastManuallyConnectedService.clear();
manualConnnectionTimer.invalidate();
}

if (serviceInProgress == service->path())
serviceInProgress.clear();
Expand All @@ -262,8 +277,10 @@ void QConnectionManager::serviceStateChanged(const QString &state)
} else {
updateServicesMap();
qDebug() <<"serviceInProgress"<< serviceInProgress;
if (!serviceInProgress.isEmpty())
autoConnect();
// If a manual connection has recently been detected autoConnect() will do nothing.
// Always call autoConnect() here as this state change could be that manual connection
// disconnecting.
autoConnect();
}
}

Expand All @@ -289,6 +306,16 @@ bool QConnectionManager::autoConnect()
if (tetheringEnabled || !serviceInProgress.isEmpty())
return false;

if (manualConnnectionTimer.isValid() && !manualConnnectionTimer.hasExpired(5 * 60 * 1000)) {
qDebug() << "skipping auto connect," << (manualConnnectionTimer.elapsed() / 1000)
<< "seconds since manual connection.";
return false;
} else {
qDebug() << "clearing manual connected service data";
lastManuallyConnectedService.clear();
manualConnnectionTimer.invalidate();
}

if (selectedService.isEmpty()) {
selectedService = findBestConnectableService();
}
Expand Down Expand Up @@ -726,7 +753,6 @@ void QConnectionManager::requestConnect(const QString &servicePath)
QDBusInterface service("net.connman", servicePath.toLocal8Bit(),
"net.connman.Service", QDBusConnection::systemBus());
QDBusMessage reply = service.call(QDBus::NoBlock, QStringLiteral("Connect"));
manualConnected = false;
autoConnectService = servicePath;
}
}
Expand Down
5 changes: 4 additions & 1 deletion connd/qconnectionmanager.h
Expand Up @@ -25,6 +25,7 @@
#include <QDBusObjectPath>
#include <QQueue>
#include <QPair>
#include <QElapsedTimer>
#include <connman-qt5/clockmodel.h>

class UserAgent;
Expand Down Expand Up @@ -100,7 +101,6 @@ public Q_SLOTS:
bool connmanAvailable;
bool handoverInProgress;
QString previousConnectedService;
bool manualConnected;
QString serviceInProgress;
QString autoConnectService;

Expand All @@ -116,6 +116,9 @@ public Q_SLOTS:
QTimer *goodConnectTimer;
ClockModel clockModel;

QElapsedTimer manualConnnectionTimer;
QString lastManuallyConnectedService;

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

0 comments on commit c47979c

Please sign in to comment.