From 4114aca02f2dafaefdf3a52a96067e1492f8d372 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 17 Apr 2013 05:46:42 +1000 Subject: [PATCH] [connectionagent] add roaming, autoconenct features. fix other bugs --- connd/com.jollamobile.Connectiond.xml | 44 +++-- connd/connadaptor.cpp | 14 +- connd/connadaptor.h | 31 ++-- connd/connd.pro | 2 +- connd/qconnectionmanager.cpp | 173 +++++++++++++----- connd/qconnectionmanager.h | 25 ++- .../connectionagentplugin.cpp | 13 +- connectionagentplugin/connectionagentplugin.h | 4 + .../connectionagentplugin.pro | 2 +- .../connectionamanagerinterface.cpp | 8 +- .../connectionamanagerinterface.h | 20 +- rpm/connectionagent.changes | 3 + 12 files changed, 248 insertions(+), 91 deletions(-) diff --git a/connd/com.jollamobile.Connectiond.xml b/connd/com.jollamobile.Connectiond.xml index 3b76516..ff026d1 100644 --- a/connd/com.jollamobile.Connectiond.xml +++ b/connd/com.jollamobile.Connectiond.xml @@ -1,34 +1,42 @@ - - + + + + + + + - + - + + + - - - - + + + - - - + + + + + + + + - - + + - - - - - + + diff --git a/connd/connadaptor.cpp b/connd/connadaptor.cpp index e67634d..7f0bc4a 100644 --- a/connd/connadaptor.cpp +++ b/connd/connadaptor.cpp @@ -1,6 +1,6 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -v -c ConnAdaptor -a connadaptor.h:connadaptor.cpp conn.xml + * Command line was: qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jollamobile.Connectiond.xml * * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). * @@ -33,6 +33,18 @@ ConnAdaptor::~ConnAdaptor() // destructor } +bool ConnAdaptor::askRoaming() const +{ + // get the value of property askRoaming + return qvariant_cast< bool >(parent()->property("askRoaming")); +} + +void ConnAdaptor::setAskRoaming(bool value) +{ + // set the value of property askRoaming + parent()->setProperty("askRoaming", QVariant::fromValue(value)); +} + void ConnAdaptor::connectToType(const QString &in0) { // handle method call com.jolla.Connectiond.connectToType diff --git a/connd/connadaptor.h b/connd/connadaptor.h index 3995b1c..04b32b7 100644 --- a/connd/connadaptor.h +++ b/connd/connadaptor.h @@ -1,6 +1,6 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -v -c ConnAdaptor -a connadaptor.h:connadaptor.cpp conn.xml + * Command line was: qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jollamobile.Connectiond.xml * * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). * @@ -9,8 +9,8 @@ * before re-generating it. */ -#ifndef CONNADAPTOR_H_1363752885 -#define CONNADAPTOR_H_1363752885 +#ifndef CONNADAPTOR_H_1366057292 +#define CONNADAPTOR_H_1366057292 #include #include @@ -30,9 +30,11 @@ class ConnAdaptor: public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Interface", "com.jolla.Connectiond") Q_CLASSINFO("D-Bus Introspection", "" " \n" +" \n" " \n" -" \n" -" \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" @@ -46,10 +48,15 @@ class ConnAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" -" \n" -" \n" +" \n" " \n" " \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" @@ -58,9 +65,6 @@ class ConnAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" -" \n" -" \n" -" \n" " \n" "") public: @@ -68,18 +72,23 @@ class ConnAdaptor: public QDBusAbstractAdaptor virtual ~ConnAdaptor(); public: // PROPERTIES + Q_PROPERTY(bool askRoaming READ askRoaming WRITE setAskRoaming) + bool askRoaming() const; + void setAskRoaming(bool value); + public Q_SLOTS: // METHODS void connectToType(const QString &in0); void sendConnectReply(const QString &in0, int in1); void sendUserReply(const QVariantMap &input); Q_SIGNALS: // SIGNALS + void configurationNeeded(const QString &type); void connectionRequest(); void connectionState(const QString &state, const QString &type); void errorReported(const QString &error); void requestBrowser(const QString &url); + void roamingAskChanged(bool askRoaming); void userInputCanceled(); void userInputRequested(const QString &service, const QVariantMap &fields); - void configurationNeeded( const QString &type); }; #endif diff --git a/connd/connd.pro b/connd/connd.pro index 6fd2411..6450bd7 100644 --- a/connd/connd.pro +++ b/connd/connd.pro @@ -18,7 +18,7 @@ INCLUDEPATH += lipstick OTHER_FILES += com.jolla.Connectiond.xml # create adaptor -#system(qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jolla.Connectiond.xml) +#system(qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jollamobile.Connectiond.xml) SOURCES += main.cpp \ qconnectionmanager.cpp \ diff --git a/connd/qconnectionmanager.cpp b/connd/qconnectionmanager.cpp index 511bb0c..275f8d2 100644 --- a/connd/qconnectionmanager.cpp +++ b/connd/qconnectionmanager.cpp @@ -27,7 +27,10 @@ #include #include #include + #include +#include + QConnectionManager* QConnectionManager::self = NULL; @@ -43,7 +46,8 @@ QConnectionManager::QConnectionManager(QObject *parent) : currentNetworkState(QString()), currentType(QString()), serviceConnect(0), - currentNotification(0) + currentNotification(0), + askForRoaming(0) { connectionAdaptor = new ConnAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -56,6 +60,8 @@ QConnectionManager::QConnectionManager(QObject *parent) : qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX"; } + askForRoaming = askRoaming(); + ua = new UserAgent(this); connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)), @@ -72,14 +78,31 @@ QConnectionManager::QConnectionManager(QObject *parent) : connect(netman,SIGNAL(serviceAdded(QString)),this,SLOT(onServiceAdded(QString))); connect(netman,SIGNAL(serviceRemoved(QString)),this,SLOT(onServiceRemoved(QString))); - connect(netman,SIGNAL(defaultRouteChanged(NetworkService*)), - this,SLOT(defaultRouteChanged(NetworkService*))); + connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString))); + + + QFile connmanConf("/etc/connman/main.conf"); + if (connmanConf.open(QIODevice::ReadOnly | QIODevice::Text)) { + while (!connmanConf.atEnd()) { + QString line = connmanConf.readLine(); + if (line.startsWith("DefaultAutoConnectTechnologies")) { + QString token = line.section(" = ",1,1).simplified(); + techPreferenceList = token.split(","); + break; + } + } + connmanConf.close(); + } else { + techPreferenceList << "wifi" << "bluetooth" << "cellular"; + } updateServicesMap(); currentNetworkState = netman->state(); // let me control autoconnect netman->setSessionMode(true); + + } QConnectionManager::~QConnectionManager() @@ -136,8 +159,6 @@ void QConnectionManager::sendUserReply(const QVariantMap &input) void QConnectionManager::onServiceAdded(const QString &servicePath) { - //TODO connection migration? - if (!servicesMap.contains(servicePath)) { updateServicesMap(); } @@ -145,7 +166,8 @@ void QConnectionManager::onServiceAdded(const QString &servicePath) if (okToConnect && !currentType.isEmpty()) { if (servicesMap.contains(servicePath) && servicesMap.value(servicePath)->type() == currentType - && servicesMap.value(servicePath)->favorite()) { + && servicesMap.value(servicePath)->favorite() + && !servicesMap.value(servicePath)->roaming()) { connectToNetworkService(servicePath); } else { Q_EMIT configurationNeeded(servicesMap.value(servicePath)->type()); @@ -153,25 +175,11 @@ void QConnectionManager::onServiceAdded(const QString &servicePath) } } //automigrate -// for (int i = 0; i < servicesMap.keys().count(); i++) { -// QString path = servicesMap.keys().at(i); - -// if (!connectedServices.isEmpty() -// && !connectedServices.contains(path) -// && (servicesMap.value(path)->strength() > servicesMap.value(connectedServices.at(0))->strength()) -// && (servicesMap.value(path)->state() != "online") -// && servicesMap.value(path)->favorite() -// && servicesMap.value(path)->autoConnect()) { - -// qDebug() << " a better service becomes available"; - -// connectionHandover(connectedServices.at(0),path); -// } -// qDebug() << Q_FUNC_INFO -// << servicesMap.value(path)->name() -// << servicesMap.value(path)->state() -// << servicesMap.value(path)->favorite(); -// } + if (servicesMap.value(servicePath)->autoConnect()) { + connectionHandover(connectedServices.isEmpty() ? QString() : connectedServices.at(0) + ,findBestConnectableService()); + + } } void QConnectionManager::onServiceRemoved(const QString &servicePath) @@ -184,7 +192,7 @@ void QConnectionManager::serviceErrorChanged(const QString &error) Q_EMIT errorReported(error); } -void QConnectionManager::stateChanged(const QString &state) +void QConnectionManager::serviceStateChanged(const QString &state) { NetworkService *service = qobject_cast(sender()); @@ -195,9 +203,21 @@ void QConnectionManager::stateChanged(const QString &state) service->requestDisconnect(); service->remove(); //reset this service } + + //auto migrate + if (state == "online" || state == "ready") { + if(!connectedServices.contains(service->path())) + connectedServices.prepend(service->path()); + } + //auto migrate + if (state == "idle") { + connectedServices.removeOne(service->path()); + } + if (!(currentNetworkState == "online" && state == "association")) Q_EMIT connectionState(state, service->type()); + currentNetworkState = state; } @@ -209,13 +229,18 @@ bool QConnectionManager::autoConnect() Q_FOREACH (const QString &servicePath, servicesMap.keys()) { + bool isCellRoaming = false; + if (servicesMap.value(servicePath)->type() == "cellular" + && servicesMap.value(servicePath)->roaming()) { + isCellRoaming = askForRoaming; + } if(servicesMap.value(servicePath)->autoConnect() - && servicesMap.value(servicePath)->favorite()) { + && servicesMap.value(servicePath)->favorite() + && !isCellRoaming) { if (!selectedService.isEmpty() && (!currentType.isEmpty() && servicesMap.value(servicePath)->type() != currentType)) { - qDebug() << "break here"; break; } if ((servicesMap.value(servicePath)->strength() > strength)) { @@ -229,7 +254,7 @@ bool QConnectionManager::autoConnect() if (!selectedService.isEmpty()) { serviceConnect = true; - connectToNetworkService(selectedService); + connectToNetworkService(selectedService); return true; } @@ -273,7 +298,6 @@ void QConnectionManager::connectToType(const QString &type) } if (needConfig) { - qDebug() << Q_FUNC_INFO << "no favorite service found. Configuration needed"; Q_EMIT configurationNeeded(type); serviceConnect = false; okToConnect = false; @@ -287,44 +311,105 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath) NetworkTechnology *tech = netman->getTechnology(servicesMap.value(servicePath)->type()); tech->setIdleTimeout(120); - servicesMap.value(servicePath)->requestConnect(); + if (servicesMap.contains(servicePath)) + servicesMap.value(servicePath)->requestConnect(); + okToConnect = false; } - void QConnectionManager::onScanFinished() { } -void QConnectionManager::defaultRouteChanged(NetworkService* defaultRoute) -{ - //not really default route, more of default/first service in list - Q_UNUSED(defaultRoute) -} - void QConnectionManager::updateServicesMap() { - QStringList techPreferenceList; - techPreferenceList << "wifi" << "cellular" << "bluetooth"; - //TODO settings servicesMap.clear(); + connectedServices.clear(); Q_FOREACH (const QString &tech,techPreferenceList) { + QVector services = netman->getServices(tech); Q_FOREACH (NetworkService *serv, services) { servicesMap.insert(serv->path(), serv); + orderedServicesList << serv->path(); +//auto migrate + if (serv->state() == "online") { + if(!connectedServices.contains(serv->path())) + connectedServices.prepend(serv->path()); + } + QObject::connect(serv, SIGNAL(stateChanged(QString)), - this,SLOT(stateChanged(QString)), Qt::UniqueConnection); + this,SLOT(serviceStateChanged(QString)), Qt::UniqueConnection); QObject::connect(serv, SIGNAL(connectRequestFailed(QString)), this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection); + QObject::connect(serv, SIGNAL(strengthChanged(uint)), + this,SLOT(onServiceStrengthChanged(uint)), Qt::UniqueConnection); + } + } + +} + +QString QConnectionManager::findBestConnectableService() +{ + + for (int i = 0; i < orderedServicesList.count(); i++) { + QString path = orderedServicesList.at(i); + + if (!connectedServices.contains(path) + && servicesMap.contains(path) + // && (servicesMap.value(path)->strength() > servicesMap.value(connectedServices.at(0))->strength()) + && (servicesMap.value(path)->state() != "online") + && servicesMap.value(path)->autoConnect()) { + return path; } } + return QString(); } void QConnectionManager::connectionHandover(const QString &oldService, const QString &newService) { - servicesMap.value(oldService)->requestDisconnect(); - connectToNetworkService(newService); + if (newService.isEmpty()) + return; + if (servicesMap.contains(oldService)) + servicesMap.value(oldService)->requestDisconnect(); + + if (servicesMap.contains(newService) && servicesMap.value(newService)->autoConnect()) + connectToNetworkService(newService); +} + + +void QConnectionManager::networkStateChanged(const QString &state) +{ + if (state == "idle") { + //automigrate + QString bestService = findBestConnectableService(); + + connectionHandover(connectedServices.isEmpty() ? QString() : connectedServices.at(0), + bestService); + } +} + +void QConnectionManager::onServiceStrengthChanged(uint level) +{ + NetworkService *service = qobject_cast(sender()); + qDebug() << Q_FUNC_INFO << service->name() << level; +} + +bool QConnectionManager::askRoaming() const +{ + bool roaming; + QSettings confFile; + confFile.beginGroup("Connectionagent"); + roaming = confFile.value("askForRoaming").toBool(); + return roaming; +} + +void QConnectionManager::setAskRoaming(bool value) +{ + QSettings confFile; + confFile.beginGroup("Connectionagent"); + confFile.setValue("askForRoaming",value); + askForRoaming = value; } diff --git a/connd/qconnectionmanager.h b/connd/qconnectionmanager.h index 0aed146..62e9bbf 100644 --- a/connd/qconnectionmanager.h +++ b/connd/qconnectionmanager.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include class UserAgent; class SessionAgent; @@ -34,11 +36,14 @@ class NetworkService; class QConnectionManager : public QObject { Q_OBJECT + Q_PROPERTY(bool askRoaming READ askRoaming WRITE setAskRoaming) public: ~QConnectionManager(); static QConnectionManager &instance(); + bool askRoaming() const; + void setAskRoaming(bool value); Q_SIGNALS: void connectionChanged(const QString &, bool); // ? @@ -62,13 +67,7 @@ public Q_SLOTS: void sendConnectReply(const QString &in0, int in1); void sendUserReply(const QVariantMap &input); - void onServiceAdded(const QString &servicePath); - void onServiceRemoved(const QString &servicePath); - void serviceErrorChanged(const QString &error); - void stateChanged(const QString &state); - void connectToType(const QString &type); - void defaultRouteChanged(NetworkService* defaultRoute); private: explicit QConnectionManager(QObject *parent = 0); @@ -87,14 +86,26 @@ public Q_SLOTS: void connectToNetworkService(const QString &service); uint currentNotification; - QHash servicesMap; + QMap servicesMap; + QStringList orderedServicesList; + + QString findBestConnectableService(); void connectionHandover(const QString &oldService, const QString &newService); QList connectedServices; + QStringList techPreferenceList; + bool askForRoaming; private slots: void onScanFinished(); void updateServicesMap(); + void onServiceAdded(const QString &servicePath); + void onServiceRemoved(const QString &servicePath); + void serviceErrorChanged(const QString &error); + void serviceStateChanged(const QString &state); + void networkStateChanged(const QString &state); + void onServiceStrengthChanged(uint); + }; #endif // QCONNECTIONMANAGER_H diff --git a/connectionagentplugin/connectionagentplugin.cpp b/connectionagentplugin/connectionagentplugin.cpp index a443080..b9ce84d 100644 --- a/connectionagentplugin/connectionagentplugin.cpp +++ b/connectionagentplugin/connectionagentplugin.cpp @@ -103,7 +103,6 @@ void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int ti void ConnectionAgentPlugin::connectToType(const QString &type) { - qDebug() << Q_FUNC_INFO << type;; connManagerInterface->connectToType(type); } @@ -130,7 +129,6 @@ void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const Q QVariantMap vmap = qdbus_cast(arg); map.insert(i.key(), vmap); } -// qDebug() << Q_FUNC_INFO << map; Q_EMIT userInputRequested(service, map); } @@ -149,6 +147,15 @@ void ConnectionAgentPlugin::connectiondUnregistered(QString) void ConnectionAgentPlugin::onConnectionState(const QString &state, const QString &type) { - qDebug() << Q_FUNC_INFO << state << type; Q_EMIT connectionState(state, type); } + +bool ConnectionAgentPlugin::askRoaming() const +{ + return connManagerInterface->askRoaming(); +} + +void ConnectionAgentPlugin::setAskRoaming(bool value) +{ + connManagerInterface->setAskRoaming(value); +} diff --git a/connectionagentplugin/connectionagentplugin.h b/connectionagentplugin/connectionagentplugin.h index e6b9bbc..9f819eb 100644 --- a/connectionagentplugin/connectionagentplugin.h +++ b/connectionagentplugin/connectionagentplugin.h @@ -25,11 +25,15 @@ class NetworkManager; class ConnectionAgentPlugin : public QObject { Q_OBJECT + Q_PROPERTY(bool askRoaming READ askRoaming WRITE setAskRoaming) + Q_DISABLE_COPY(ConnectionAgentPlugin) public: explicit ConnectionAgentPlugin(QObject *parent = 0); ~ConnectionAgentPlugin(); + bool askRoaming() const; + void setAskRoaming(bool value); public slots: void sendUserReply(const QVariantMap &input); diff --git a/connectionagentplugin/connectionagentplugin.pro b/connectionagentplugin/connectionagentplugin.pro index 173794d..b69a5ff 100644 --- a/connectionagentplugin/connectionagentplugin.pro +++ b/connectionagentplugin/connectionagentplugin.pro @@ -6,7 +6,7 @@ CONFIG += qt plugin uri = com.jolla.connection #create client -#system(qdbusxml2cpp ../connd/com.jolla.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface) +#system(qdbusxml2cpp ../connd/com.jollamobile.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface) SOURCES += \ connectionagentplugin_plugin.cpp \ diff --git a/connectionagentplugin/connectionamanagerinterface.cpp b/connectionagentplugin/connectionamanagerinterface.cpp index 79c4d25..51d59cf 100644 --- a/connectionagentplugin/connectionamanagerinterface.cpp +++ b/connectionagentplugin/connectionamanagerinterface.cpp @@ -1,6 +1,12 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp ../connd/conn.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * Command line was: qdbusxml2cpp ../connd/com.jollamobile.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * + * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. */ #include "connectionamanagerinterface.h" diff --git a/connectionagentplugin/connectionamanagerinterface.h b/connectionagentplugin/connectionamanagerinterface.h index 2250425..87061a2 100644 --- a/connectionagentplugin/connectionamanagerinterface.h +++ b/connectionagentplugin/connectionamanagerinterface.h @@ -1,10 +1,15 @@ /* * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp ../connd/conn.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * Command line was: qdbusxml2cpp ../connd/com.jollamobile.Connectiond.xml -c ConnectionManagerInterface -p connectionamanagerinterface + * + * qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. */ -#ifndef CONNECTIONAMANAGERINTERFACE_H_1363759925 -#define CONNECTIONAMANAGERINTERFACE_H_1363759925 +#ifndef CONNECTIONAMANAGERINTERFACE_H_1366057321 +#define CONNECTIONAMANAGERINTERFACE_H_1366057321 #include #include @@ -30,6 +35,12 @@ class ConnectionManagerInterface: public QDBusAbstractInterface ~ConnectionManagerInterface(); + Q_PROPERTY(bool askRoaming READ askRoaming WRITE setAskRoaming) + inline bool askRoaming() const + { return qvariant_cast< bool >(property("askRoaming")); } + inline void setAskRoaming(bool value) + { setProperty("askRoaming", QVariant::fromValue(value)); } + public Q_SLOTS: // METHODS inline QDBusPendingReply<> connectToType(const QString &in0) { @@ -53,13 +64,14 @@ public Q_SLOTS: // METHODS } Q_SIGNALS: // SIGNALS + void configurationNeeded(const QString &type); void connectionRequest(); void connectionState(const QString &state, const QString &type); void errorReported(const QString &error); void requestBrowser(const QString &url); + void roamingAskChanged(bool askRoaming); void userInputCanceled(); void userInputRequested(const QString &service, const QVariantMap &fields); - void configurationNeeded(const QString &type); }; namespace com { diff --git a/rpm/connectionagent.changes b/rpm/connectionagent.changes index 209452a..5863904 100644 --- a/rpm/connectionagent.changes +++ b/rpm/connectionagent.changes @@ -1,3 +1,6 @@ +Wed Apr 17 2013 Lorn Potter - 0.5.7 +* add roaming, autoconenct features. fix other bugs + * Sat Apr 13 2013 Lorn Potter - 0.5.6 - make one daemon running only. remove defaultRoute handling for now.