Support dual sim in QtBearer's networkmanager backend

Task-number: QTBUG-42368
Change-Id: I306733b5de7871fdeaa0accb512a3610753c84a5
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
This commit is contained in:
Lorn Potter 2014-11-04 17:59:24 +10:00
parent 13401116cc
commit 999fa63482
4 changed files with 59 additions and 45 deletions

View File

@ -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<bool>(var);
}
QStringList QOfonoModemInterface::interfaces()
{
const QVariant var = getProperty(QStringLiteral("Interfaces"));
return var.toStringList();
}
QVariantMap QOfonoModemInterface::getProperties()
{
if (propertiesMap.isEmpty()) {

View File

@ -115,6 +115,7 @@ public:
bool isPowered();
bool isOnline();
QStringList interfaces();
private:
QVariantMap getProperties();
QVariantMap propertiesMap;

View File

@ -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;
if (ofonoManager->isValid()) {
QString contextPart = id.section('/', -1);
ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this);
QHashIterator<QString, QOfonoDataConnectionManagerInterface*> i(ofonoContextManagers);
while (i.hasNext()) {
i.next();
QString contextPath = i.key() +"/"+contextPart;
if (i.value()->contexts().contains(contextPath)) {
if (ofonoContextManager)
delete ofonoContextManager;
ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this);
}
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;
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<QString, QOfonoDataConnectionManagerInterface*> 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();
}
}
}
}

View File

@ -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<QString,QString> connectionInterfaces; // ac, interface
QOfonoManagerInterface *ofonoManager;
QOfonoNetworkRegistrationInterface *ofonoNetwork;
QOfonoDataConnectionManagerInterface *ofonoContextManager;
QNetworkConfiguration::BearerType currentBearerType();
QHash <QString, QOfonoDataConnectionManagerInterface *> ofonoContextManagers;
QNetworkConfiguration::BearerType currentBearerType(const QString &id);
QString contextName(const QString &path);
};