Skip to content

Commit

Permalink
[qtnetwork] Don't identify cellular network connections as being of a…
Browse files Browse the repository at this point in the history
…n unknown type. Contributes to JB#51275

If ofono isn't available to identify the type of a network suppress the
network until that changes. And if ofono is available but doesn't return
something recognizable then return the least capable cellular type.
  • Loading branch information
denexter committed Oct 20, 2020
1 parent 482c782 commit 28ae8bf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
38 changes: 35 additions & 3 deletions src/plugins/bearer/connman/qconnmanengine.cpp
Expand Up @@ -124,6 +124,10 @@ void QConnmanEngine::changedModem()
if (ofonoContextManager)
delete ofonoContextManager;
ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this);

if (connmanManager) {
refreshConfigurations();
}
}

void QConnmanEngine::servicesReady(const QStringList &list)
Expand Down Expand Up @@ -486,9 +490,15 @@ QNetworkConfiguration::BearerType QConnmanEngine::ofonoTechToBearerType(const QS
return QNetworkConfiguration::BearerHSPA;
} else if (currentTechnology == QLatin1String("lte")) {
return QNetworkConfiguration::BearerLTE;
} else {
qCWarning(qLcLibBearer) << "QConnmanEngine: Unable to translate the bearer type of the unknown network technology:" << currentTechnology;
}
} else {
qCWarning(qLcLibBearer) << "QConnmanEngine: Attempted to query the bearer type of a cellular connection but Ofono isn't available";
}
return QNetworkConfiguration::BearerUnknown;

// If the actual type is unknown return something that still identifies it as a cellular connection.
return QNetworkConfiguration::Bearer2G;
}

bool QConnmanEngine::isRoamingAllowed(const QString &context)
Expand Down Expand Up @@ -531,18 +541,28 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath)
}

if (!accessPointConfigurations.contains(servicePath)) {
QConnmanServiceInterface *service = connmanServiceInterfaces.value(servicePath);

const QString connectionType = service->type();

// ofonoNetwork is queried to identify the specific bearer type of a cellular connection,
// and if it's not available at this time that type will be unresolvable so skip the
// connection for now. When ofonoNetwork does become available a new attempt at adding
// the service configuration will be made.
if (!ofonoNetwork && connectionType == QLatin1String("cellular")) {
qCWarning(qLcLibBearer) << "QConnmanEngine: Deferring a cellular service configuration because ofonoNetwork is unavailable";
return;
}

serviceNetworks.append(servicePath);

connect(connmanServiceInterfaces.value(servicePath),SIGNAL(stateChanged(QString)),
this,SLOT(serviceStateChanged(QString)));

QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate();
QConnmanServiceInterface *service = connmanServiceInterfaces.value(servicePath);

QString networkName = service->name();

const QString connectionType = service->type();
if (connectionType == QLatin1String("ethernet")) {
cpPriv->bearerType = QNetworkConfiguration::BearerEthernet;
} else if (connectionType == QLatin1String("wifi")) {
Expand All @@ -553,6 +573,7 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath)
} else if (connectionType == QLatin1String("wimax")) {
cpPriv->bearerType = QNetworkConfiguration::BearerWiMAX;
} else {
qCWarning(qLcLibBearer) << "QConnmanEngine: Unable to translate the bearer type of the unknown connection type:" << connectionType;
cpPriv->bearerType = QNetworkConfiguration::BearerUnknown;
}

Expand Down Expand Up @@ -600,9 +621,15 @@ void QConnmanEngine::setupConfigurations()
connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList)));
connect(connmanManager,SIGNAL(scanFinished(bool)),this,SLOT(finishedScan(bool)));

refreshConfigurations();
}

void QConnmanEngine::refreshConfigurations()
{
foreach (const QString &servPath, connmanManager->getServices()) {
addServiceConfiguration(servPath);
}

Q_EMIT updateCompleted();
}

Expand Down Expand Up @@ -672,6 +699,11 @@ void QConnmanEngine::ofonoRegistered(const QString &serviceName)

connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem()));
connect(ofonoContextManager,SIGNAL(roamingAllowedChanged(bool)),this,SLOT(reEvaluateCellular()));

QMutexLocker locker(&mutex);
if (connmanManager && !connmanManager->getServices().isEmpty()) {
refreshConfigurations();
}
}

void QConnmanEngine::ofonoUnRegistered(const QString &serviceName)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/bearer/connman/qconnmanengine.h
Expand Up @@ -120,6 +120,7 @@ private Q_SLOTS:
void addServiceConfiguration(const QString &servicePath);

void setupConfigurations();
void refreshConfigurations();

QDateTime activeTime;

Expand Down
14 changes: 8 additions & 6 deletions src/plugins/bearer/connman/qconnmanservice_linux.cpp
Expand Up @@ -49,6 +49,8 @@

QT_BEGIN_NAMESPACE

Q_DECLARE_LOGGING_CATEGORY(qLcLibBearer)

QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &map)
{
argument.beginStructure();
Expand Down Expand Up @@ -123,7 +125,7 @@ void QConnmanManagerInterface::propertiesReply(QDBusPendingCallWatcher *call)
QDBusPendingReply<QVariantMap> props_reply = *call;

if (props_reply.isError()) {
qDebug() << props_reply.error().message();
qCWarning(qLcLibBearer) << "QConnmanManagerInterface::propertiesReply()" << props_reply.error().message();
} else {
propertiesCacheMap = props_reply.value();
}
Expand All @@ -135,7 +137,7 @@ void QConnmanManagerInterface::servicesReply(QDBusPendingCallWatcher *call)
QDBusPendingReply<ConnmanMapList> serv_reply = *call;

if (serv_reply.isError()) {
qDebug() << serv_reply.error().message();
qCWarning(qLcLibBearer) << "QConnmanManagerInterface::servicesReply()" << serv_reply.error().message();
} else {
servicesList.clear(); //connman list changes order
ConnmanMap connmanobj;
Expand All @@ -156,7 +158,7 @@ void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal)
QLatin1String(CONNMAN_MANAGER_INTERFACE),
QLatin1String("PropertyChanged"),
this,SIGNAL(propertyChanged(QString,QDBusVariant)))) {
qWarning() << "PropertyChanged not connected";
qCWarning(qLcLibBearer) << "QConnmanManagerInterface: PropertyChanged not connected";
}
}

Expand All @@ -167,7 +169,7 @@ void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal)
QLatin1String(CONNMAN_MANAGER_INTERFACE),
QLatin1String("ServicesChanged"),
this,SLOT(onServicesChanged(ConnmanMapList, QList<QDBusObjectPath>)))) {
qWarning() << "servicesChanged not connected";
qCWarning(qLcLibBearer) << "QConnmanManagerInterface: servicesChanged not connected";
}
}
}
Expand Down Expand Up @@ -319,7 +321,7 @@ void QConnmanServiceInterface::propertiesReply(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<QVariantMap> props_reply = *call;
if (props_reply.isError()) {
qDebug() << props_reply.error().message();
qCWarning(qLcLibBearer) << "QConnmanServiceInterface::propertiesReply" << props_reply.error().message();
return;
}
propertiesCacheMap = props_reply.value();
Expand Down Expand Up @@ -502,7 +504,7 @@ void QConnmanTechnologyInterface::scanReply(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<void> props_reply = *call;
if (props_reply.isError()) {
qDebug() << props_reply.error().message();
qCWarning(qLcLibBearer) << "QConnmanTechnologyInterface::scanReply()" << props_reply.error().message();
}
Q_EMIT scanFinished(props_reply.isError());
call->deleteLater();
Expand Down

0 comments on commit 28ae8bf

Please sign in to comment.