Skip to content

Commit

Permalink
[connectionagent] report cell errors.
Browse files Browse the repository at this point in the history
Do not autoconnect if roaming,
and make basis for ask roaming (TODO)
  • Loading branch information
Lorn Potter committed Oct 4, 2013
1 parent c7cea6c commit a38439f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
72 changes: 57 additions & 15 deletions connd/qconnectionmanager.cpp
Expand Up @@ -60,7 +60,8 @@ QConnectionManager::QConnectionManager(QObject *parent) :
askForRoaming(0),
isEthernet(0),
connmanAvailable(0),
handoverInProgress(0)
handoverInProgress(0),
oContext(0)
{
qDebug() << Q_FUNC_INFO;
connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));
Expand Down Expand Up @@ -367,25 +368,52 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)

if (manuallyConnectedService.isEmpty() && technology.powered() && !handoverInProgress) {
if (servicePath.contains("cellular")) {
// ofono active seems to work better in our case
// requestConnect(servicePath);
// ofono active seems to work better in our case
QOfonoManager oManager;
if (!oManager.available()) {
qDebug() << Q_FUNC_INFO << "ofono not available.";
return;
}

QOfonoConnectionManager oConnManager;
oConnManager.setModemPath(oManager.modems().at(0));
Q_FOREACH (const QString &contextPath, oConnManager.contexts()) {

if (contextPath.contains(servicePath.section("_",2,2))) {
qDebug() << Q_FUNC_INFO << "requesting cell connection";
serviceInProgress = servicePath;
autoConnectService = servicePath;
manualConnected = false;
handoverInProgress = true;
QOfonoConnectionContext oContext;
oContext.setContextPath(contextPath);
oContext.setActive(true);

//isCellRoaming
bool ok = true;
if (servicesMap.value(servicePath)->roaming()) {
if (oConnManager.roamingAllowed()) {
if (askRoaming()) {
// ask user
}
} else {
//roaming and user doesnt want connection while roaming
qDebug() << Q_FUNC_INFO << "roaming not allowed";
return;
}
}

if (ok)
Q_FOREACH (const QString &contextPath, oConnManager.contexts()) {

if (contextPath.contains(servicePath.section("_",2,2))) {
serviceInProgress = servicePath;
autoConnectService = servicePath;
manualConnected = false;
handoverInProgress = true;
if (!oContext) {
oContext = new QOfonoConnectionContext(this);
}
oContext->setContextPath(contextPath);
if (oContext->type() != "internet")
continue;
qDebug() << Q_FUNC_INFO << "requesting cell connection";
connect(oContext,SIGNAL(reportError(QString)),
this,SLOT(ofonoServicesError(QString)),Qt::UniqueConnection);
oContext->setActive(true);
return;
}
}
} else {
requestConnect(servicePath);
}
Expand All @@ -399,7 +427,6 @@ void QConnectionManager::onScanFinished()
void QConnectionManager::updateServicesMap()
{
qDebug() << Q_FUNC_INFO;
int numbServices = servicesMap.count();
QStringList oldServices = orderedServicesList;
orderedServicesList.clear();

Expand Down Expand Up @@ -456,6 +483,20 @@ void QConnectionManager::servicesError(const QString &errorMessage)
handoverInProgress = false;
}

void QConnectionManager::ofonoServicesError(const QString &errorMessage)
{
QOfonoConnectionContext *context = qobject_cast<QOfonoConnectionContext *>(sender());
QVector<NetworkService*> services = netman->getServices("cellular");
Q_FOREACH (NetworkService *serv, services) {
if (context->contextPath().contains(serv->path().section("_",2,2))) {
Q_EMIT onErrorReported(serv->path(), errorMessage);
handoverInProgress = false;
qDebug() << Q_FUNC_INFO << serv->name() << errorMessage;
return;
}
}
}

QString QConnectionManager::findBestConnectableService()
{
qDebug() << Q_FUNC_INFO <<orderedServicesList.count();
Expand Down Expand Up @@ -605,7 +646,7 @@ void QConnectionManager::setup()

QSettings confFile;
confFile.beginGroup("Connectionagent");

qDebug() << Q_FUNC_INFO << "config file says" << confFile.value("connected", "online").toString();
if (netman->state() != "online"
&& (!isEthernet && confFile.value("connected", "online").toString() == "online")) {
autoConnect();
Expand Down Expand Up @@ -654,6 +695,7 @@ bool QConnectionManager::isBestService(const QString &servicePath)
<< manuallyDisconnectedService;
if (!manuallyDisconnectedService.isEmpty() && manuallyDisconnectedService == servicePath) return false;
if (netman->defaultRoute()->path().contains(servicePath)) return false;
if (!serviceInProgress.isEmpty() && serviceInProgress != servicePath) return false;
if (netman->defaultRoute()->state() != "online") return true;
int dfIndex = orderedServicesList.indexOf(netman->defaultRoute()->path());
if (dfIndex == -1) return true;
Expand Down
4 changes: 3 additions & 1 deletion connd/qconnectionmanager.h
Expand Up @@ -32,7 +32,7 @@ class SessionAgent;
class ConnAdaptor;
class NetworkManager;
class NetworkService;

class QOfonoConnectionContext;

class QConnectionManager : public QObject
{
Expand Down Expand Up @@ -108,6 +108,7 @@ public Q_SLOTS:
bool isStateOnline(const QString &state);
void requestDisconnect(const QString &service);
void requestConnect(const QString &service);
QOfonoConnectionContext *oContext;

private slots:
void onScanFinished();
Expand All @@ -124,6 +125,7 @@ private slots:
void setup();
void emitConnectionState();
void servicesError(const QString &);
void ofonoServicesError(const QString &);
void technologyPowerChanged(bool);
void browserRequest(const QString &servicePath, const QString &url);
void onServiceConnectionStarted();
Expand Down

0 comments on commit a38439f

Please sign in to comment.