From 999fa634829bf90e939f2fc14678a842eb49c75e Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Tue, 4 Nov 2014 17:59:24 +1000 Subject: Support dual sim in QtBearer's networkmanager backend Task-number: QTBUG-42368 Change-Id: I306733b5de7871fdeaa0accb512a3610753c84a5 Reviewed-by: Alex Blasche --- .../bearer/linux_common/qofonoservice_linux.cpp | 9 ++- .../bearer/linux_common/qofonoservice_linux_p.h | 1 + .../networkmanager/qnetworkmanagerengine.cpp | 90 ++++++++++++---------- .../bearer/networkmanager/qnetworkmanagerengine.h | 6 +- 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp index e994ebf2ce..b2e2131a92 100644 --- a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp +++ b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp @@ -112,7 +112,8 @@ QString QOfonoManagerInterface::currentModem() QStringList modems = getModems(); foreach (const QString &modem, modems) { QOfonoModemInterface device(modem); - if (device.isPowered() && device.isOnline()) + if (device.isPowered() && device.isOnline() + && device.interfaces().contains(QStringLiteral("org.ofono.NetworkRegistration"))) return modem; } return QString(); @@ -169,6 +170,12 @@ bool QOfonoModemInterface::isOnline() return qdbus_cast(var); } +QStringList QOfonoModemInterface::interfaces() +{ + const QVariant var = getProperty(QStringLiteral("Interfaces")); + return var.toStringList(); +} + QVariantMap QOfonoModemInterface::getProperties() { if (propertiesMap.isEmpty()) { diff --git a/src/plugins/bearer/linux_common/qofonoservice_linux_p.h b/src/plugins/bearer/linux_common/qofonoservice_linux_p.h index 2b3d43deb5..0ed00d94ff 100644 --- a/src/plugins/bearer/linux_common/qofonoservice_linux_p.h +++ b/src/plugins/bearer/linux_common/qofonoservice_linux_p.h @@ -115,6 +115,7 @@ public: bool isPowered(); bool isOnline(); + QStringList interfaces(); private: QVariantMap getProperties(); QVariantMap propertiesMap; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index f07d7b242b..9adadb8f4f 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -58,9 +58,7 @@ QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) : QBearerEngineImpl(parent), managerInterface(new QNetworkManagerInterface(this)), systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)), - ofonoManager(new QOfonoManagerInterface(this)), - ofonoNetwork(0), - ofonoContextManager(0) + ofonoManager(new QOfonoManagerInterface(this)) { if (!managerInterface->isValid()) @@ -97,16 +95,22 @@ QNetworkManagerEngine::~QNetworkManagerEngine() interfaceDevices.clear(); connectionInterfaces.clear(); + + qDeleteAll(ofonoContextManagers); + ofonoContextManagers.clear(); } void QNetworkManagerEngine::initialize() { QMutexLocker locker(&mutex); - connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem())); - ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); - ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); - + if (ofonoManager->isValid()) { + Q_FOREACH (const QString &modem, ofonoManager->getModems()) { + QOfonoDataConnectionManagerInterface *ofonoContextManager + = new QOfonoDataConnectionManagerInterface(modem,this); + ofonoContextManagers.insert(modem, ofonoContextManager); + } + } // Get current list of access points. foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { locker.unlock(); @@ -746,11 +750,14 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri } } } else if (connectionType == QLatin1String("gsm")) { - cpPriv->bearerType = currentBearerType(); + + const QString contextPath = map.value("connection").value("id").toString(); + cpPriv->name = contextName(contextPath); + cpPriv->bearerType = currentBearerType(contextPath); + if (map.value("connection").contains("timestamp")) { cpPriv->state |= QNetworkConfiguration::Discovered; } - cpPriv->name = contextName(map.value("connection").value("id").toString()); } return cpPriv; @@ -889,34 +896,32 @@ QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration( return QNetworkConfigurationPrivatePointer(); } -void QNetworkManagerEngine::changedModem() +QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType(const QString &id) { - if (ofonoNetwork) - delete ofonoNetwork; - - ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); - - if (ofonoContextManager) - delete ofonoContextManager; - ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); -} + if (ofonoManager->isValid()) { + QString contextPart = id.section('/', -1); -QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType() -{ - if (ofonoContextManager) { - QString bearer = ofonoContextManager->bearer(); - if (bearer == QLatin1String("gsm")) { - return QNetworkConfiguration::Bearer2G; - } else if (bearer == QLatin1String("edge")) { - return QNetworkConfiguration::Bearer2G; - } else if (bearer == QLatin1String("umts")) { - return QNetworkConfiguration::BearerWCDMA; - } else if (bearer == QLatin1String("hspa") - || bearer == QLatin1String("hsdpa") - || bearer == QLatin1String("hsupa")) { - return QNetworkConfiguration::BearerHSPA; - } else if (bearer == QLatin1String("lte")) { - return QNetworkConfiguration::BearerLTE; + QHashIterator i(ofonoContextManagers); + while (i.hasNext()) { + i.next(); + QString contextPath = i.key() +"/"+contextPart; + if (i.value()->contexts().contains(contextPath)) { + + QString bearer = i.value()->bearer(); + if (bearer == QStringLiteral("gsm")) { + return QNetworkConfiguration::Bearer2G; + } else if (bearer == QStringLiteral("edge")) { + return QNetworkConfiguration::Bearer2G; + } else if (bearer == QStringLiteral("umts")) { + return QNetworkConfiguration::BearerWCDMA; + } else if (bearer == QStringLiteral("hspa") + || bearer == QStringLiteral("hsdpa") + || bearer == QStringLiteral("hsupa")) { + return QNetworkConfiguration::BearerHSPA; + } else if (bearer == QStringLiteral("lte")) { + return QNetworkConfiguration::BearerLTE; + } + } } } return QNetworkConfiguration::BearerUnknown; @@ -924,13 +929,16 @@ QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType() QString QNetworkManagerEngine::contextName(const QString &path) { - if (ofonoContextManager) { + if (ofonoManager->isValid()) { QString contextPart = path.section('/', -1); - - Q_FOREACH (const QString &oContext, ofonoContextManager->contexts()) { - if (oContext.contains(contextPart)) { - QOfonoConnectionContextInterface contextInterface(oContext,this); - return contextInterface.name(); + QHashIterator i(ofonoContextManagers); + while (i.hasNext()) { + i.next(); + Q_FOREACH (const QString &oContext, i.value()->contexts()) { + if (oContext.contains(contextPart)) { + QOfonoConnectionContextInterface contextInterface(oContext,this); + return contextInterface.name(); + } } } } diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index d2ef9886a3..84c0b21b6c 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -106,7 +106,6 @@ private Q_SLOTS: void newAccessPoint(const QString &path); void removeAccessPoint(const QString &path); void scanFinished(); - void changedModem(); private: QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath, @@ -125,9 +124,8 @@ private: QHash connectionInterfaces; // ac, interface QOfonoManagerInterface *ofonoManager; - QOfonoNetworkRegistrationInterface *ofonoNetwork; - QOfonoDataConnectionManagerInterface *ofonoContextManager; - QNetworkConfiguration::BearerType currentBearerType(); + QHash ofonoContextManagers; + QNetworkConfiguration::BearerType currentBearerType(const QString &id); QString contextName(const QString &path); }; -- cgit v1.2.3