Skip to content

Commit

Permalink
[connectionagent] don't try to connect to context if there is no mobile
Browse files Browse the repository at this point in the history
network registered.
  • Loading branch information
Lorn Potter committed Oct 10, 2013
1 parent b26a7cd commit 0dfdf07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions connd/qconnectionmanager.cpp
Expand Up @@ -25,6 +25,7 @@
#include <connman-qt5/sessionagent.h>
#include <qofono-qt5/qofonoconnectioncontext.h>
#include <qofono-qt5/qofonoconnectionmanager.h>
#include <qofono-qt5/qofononetworkregistration.h>
#include <qofono-qt5/qofonomanager.h>

#else
Expand Down Expand Up @@ -295,9 +296,9 @@ bool QConnectionManager::autoConnect()
selectedService = findBestConnectableService();
}
if (!selectedService.isEmpty()) {
connectToNetworkService(selectedService);
bool ok = connectToNetworkService(selectedService);
currentType = servicesMap.value(selectedService)->type();
return true;
return ok;
}
return false;
}
Expand Down Expand Up @@ -353,35 +354,43 @@ void QConnectionManager::connectToType(const QString &type)
}
}

void QConnectionManager::connectToNetworkService(const QString &servicePath)
bool QConnectionManager::connectToNetworkService(const QString &servicePath)
{
qDebug() << servicePath
<< handoverInProgress
<< netman->state();

if (!servicesMap.contains(servicePath) || !serviceInProgress.isEmpty())
return;
return false;

NetworkTechnology technology;
QString type = servicesMap.value(servicePath)->type();
if (type.isEmpty())
return;
return false;
technology.setPath(netman->technologyPathForType(type));

if (manuallyDisconnectedService.isEmpty() && servicesMap.value(servicePath)->state() != "online")
requestDisconnect(netman->defaultRoute()->path());

if (manuallyConnectedService.isEmpty() && technology.powered() && !handoverInProgress) {
if (servicePath.contains("cellular")) {

QOfonoManager oManager;
if (!oManager.available()) {
qDebug() << "ofono not available.";
return;
return false;
}

QOfonoConnectionManager oConnManager;
oConnManager.setModemPath(oManager.modems().at(0));

QOfonoNetworkRegistration ofonoReg;
ofonoReg.setModemPath(oManager.modems().at(0));
if (ofonoReg.status() != "registered"
|| ofonoReg.status() == "roaming") { //not on any cell network so bail
qDebug() << "ofono is not registered yet";
return false;
}
//isCellRoaming
bool ok = true;
if (servicesMap.value(servicePath)->roaming()) {
Expand All @@ -392,7 +401,7 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)
} else {
//roaming and user doesnt want connection while roaming
qDebug() << "roaming not allowed";
return;
return false;
}
}

Expand All @@ -402,6 +411,7 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)
requestConnect(servicePath);
}
}
return true;
}

void QConnectionManager::onScanFinished()
Expand Down Expand Up @@ -514,7 +524,7 @@ QString QConnectionManager::findBestConnectableService()
bool isCellRoaming = false;
if (service->type() == "cellular"
&& service->roaming()) {
isCellRoaming = askForRoaming;
isCellRoaming = askForRoaming;
}

if (isBestService(service->path())
Expand Down Expand Up @@ -736,11 +746,8 @@ void QConnectionManager::connectToContext(const QString &servicePath)
{
// requestConnect(servicePath);
// ofono active seems to work better in our case

QOfonoManager oManager;
if (!oManager.available()) {
qDebug() << "ofono not available.";
return;
}

QOfonoConnectionManager oConnManager;
oConnManager.setModemPath(oManager.modems().at(0));
Expand Down
2 changes: 1 addition & 1 deletion connd/qconnectionmanager.h
Expand Up @@ -122,7 +122,7 @@ private slots:
void serviceStateChanged(const QString &state);
void networkStateChanged(const QString &state);
void onServiceStrengthChanged(uint);
void connectToNetworkService(const QString &service);
bool connectToNetworkService(const QString &service);

void connmanAvailabilityChanged(bool b);
void setup();
Expand Down

0 comments on commit 0dfdf07

Please sign in to comment.