Add better mobile connections to QtBearer NetworkManager backend.

Task-number: QTBUG-41807

Change-Id: Ifb5904d4887111416b4bb1a32d6d056029186f5c
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Lorn Potter 2014-10-07 17:18:09 +10:00 committed by Lorn Potter
parent 151061ad4a
commit 520b10be4c
3 changed files with 142 additions and 9 deletions

View File

@ -67,10 +67,6 @@ QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent)
this, SLOT(deviceAdded(QDBusObjectPath)));
connect(interface, SIGNAL(deviceRemoved(QDBusObjectPath)),
this, SLOT(deviceRemoved(QDBusObjectPath)));
#if 0
connect(interface, SIGNAL(stateChanged(QString,quint32)),
this, SIGNAL(configurationsChanged()));
#endif
connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
this, SLOT(activationFinished(QDBusPendingCallWatcher*)));
connect(interface, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),
@ -586,7 +582,7 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec
ptr->isValid = true;
ptr->id = objectPath.path();
ptr->type = QNetworkConfiguration::InternetAccessPoint;
if(accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) {
if (accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) {
ptr->purpose = QNetworkConfiguration::PrivatePurpose;
} else {
ptr->purpose = QNetworkConfiguration::PublicPurpose;
@ -724,7 +720,7 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri
const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString();
const QString connectionSecurity = map.value("802-11-wireless").value("security").toString();
if(!connectionSecurity.isEmpty()) {
if (!connectionSecurity.isEmpty()) {
cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
} else {
cpPriv->purpose = QNetworkConfiguration::PublicPurpose;
@ -749,9 +745,34 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri
break;
}
}
} else if (connectionType == "gsm") {
cpPriv->bearerType = QNetworkConfiguration::Bearer2G;
} else if (connectionType == "cdma") {
} else if (connectionType == QLatin1String("gsm")) {
foreach (const QDBusObjectPath &devicePath, interface->getDevices()) {
QNetworkManagerInterfaceDevice device(devicePath.path());
if (device.deviceType() == DEVICE_TYPE_GSM) {
QNetworkManagerInterfaceDeviceModem deviceModem(device.connectionInterface()->path(),this);
switch (deviceModem.currentCapabilities()) {
case 2:
cpPriv->bearerType = QNetworkConfiguration::Bearer2G;
break;
case 4:
cpPriv->bearerType = QNetworkConfiguration::Bearer3G;
break;
case 8:
cpPriv->bearerType = QNetworkConfiguration::Bearer4G;
break;
default:
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
break;
};
}
}
cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
cpPriv->state |= QNetworkConfiguration::Discovered;
} else if (connectionType == QLatin1String("cdma")) {
cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;
cpPriv->bearerType = QNetworkConfiguration::BearerCDMA2000;
}

View File

@ -568,6 +568,81 @@ quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const
return d->connectionInterface->property("WirelelessCapabilities").toUInt();
}
class QNetworkManagerInterfaceDeviceModemPrivate
{
public:
QDBusInterface *connectionInterface;
QString path;
bool valid;
};
QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent)
: QObject(parent), nmDBusHelper(0)
{
d = new QNetworkManagerInterfaceDeviceModemPrivate();
d->path = ifaceDevicePath;
d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM),
QDBusConnection::systemBus(), parent);
if (!d->connectionInterface->isValid()) {
d->valid = false;
return;
}
d->valid = true;
}
QNetworkManagerInterfaceDeviceModem::~QNetworkManagerInterfaceDeviceModem()
{
delete d->connectionInterface;
delete d;
}
bool QNetworkManagerInterfaceDeviceModem::isValid()
{
return d->valid;
}
bool QNetworkManagerInterfaceDeviceModem::setConnections()
{
if (!isValid() )
return false;
bool allOk = false;
delete nmDBusHelper;
nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));
if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM),
QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotDevicePropertiesChanged(QMap<QString,QVariant>))) ) {
allOk = true;
}
return allOk;
}
QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const
{
return d->connectionInterface;
}
quint32 QNetworkManagerInterfaceDeviceModem::modemCapabilities() const
{
return d->connectionInterface->property("ModemCapabilities").toUInt();
}
quint32 QNetworkManagerInterfaceDeviceModem::currentCapabilities() const
{
return d->connectionInterface->property("CurrentCapabilities").toUInt();
}
class QNetworkManagerSettingsPrivate
{
public:

View File

@ -98,6 +98,7 @@ typedef enum
#define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device"
#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired"
#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless"
#define NM_DBUS_INTERFACE_DEVICE_MODEM NM_DBUS_INTERFACE_DEVICE ".Modem"
#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint"
#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint"
@ -329,6 +330,42 @@ private:
QNmDBusHelper *nmDBusHelper;
};
class QNetworkManagerInterfaceDeviceModemPrivate;
class QNetworkManagerInterfaceDeviceModem : public QObject
{
Q_OBJECT
public:
enum ModemCapability {
None = 0x0,
Pots = 0x1,
Cmda_Edvo = 0x2,
Gsm_Umts = 0x4,
Lte = 0x08
};
explicit QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath,
QObject *parent = 0);
~QNetworkManagerInterfaceDeviceModem();
QDBusObjectPath path() const;
QDBusInterface *connectionInterface() const;
bool setConnections();
bool isValid();
quint32 modemCapabilities() const;
quint32 currentCapabilities() const;
Q_SIGNALS:
void propertiesChanged( const QString &, QMap<QString,QVariant>);
private:
QNetworkManagerInterfaceDeviceModemPrivate *d;
QNmDBusHelper *nmDBusHelper;
};
class QNetworkManagerSettingsPrivate;
class QNetworkManagerSettings : public QObject
{