Android: Fix android bearer implementation.

1. If the interface used by a configuration changes, remove the whole
configuration and replace it with a new one (instead of updating it).
While this isn't intuitive, this is the exact behavior we used to have
on android when using the generic plugin...

2. Setting the session state to roaming is not correct in this context
as it's a transitional state where we should end up in connected state
(forced roaming). Before this patch we would get stuck in the roaming
state for mobile networks.

4. Use QNetworkInterface::name() instead of
QNetworkInterface::humanReadableName(), as this is the expected
value when querying the interface used.

3. Don't re-iterate through the interface list for each configuration.

Task-number: QTBUG-41832
Change-Id: I315f725434bc6a1a8dca13dffd41f606c87bd06d
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
Christian Strømme 2014-10-10 14:23:00 +02:00 committed by Caroline Chao
parent 0ca0ecdb32
commit 81998b4e8e

View File

@ -166,10 +166,7 @@ QNetworkSession::State QAndroidBearerEngine::sessionStateForId(const QString &id
const QMutexLocker configLocker(&ptr->mutex);
// Don't re-order...
if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
return (m_connectivityManager->isActiveNetworkMetered()
|| m_connectivityManager->getActiveNetworkInfo().isRoaming())
? QNetworkSession::Roaming
: QNetworkSession::Connected;
return QNetworkSession::Connected;
} else if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
return QNetworkSession::Disconnected;
} else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) {
@ -267,6 +264,10 @@ void QAndroidBearerEngine::updateConfigurations()
QMutexLocker locker(&mutex);
QStringList oldKeys = accessPointConfigurations.keys();
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
if (interfaces.isEmpty())
interfaces = QNetworkInterface::allInterfaces();
// Create a configuration for each of the main types (WiFi, Mobile, Bluetooth, WiMax, Ethernet)
foreach (const AndroidNetworkInfo &netInfo, m_connectivityManager->getAllNetworkInfo()) {
@ -279,14 +280,13 @@ void QAndroidBearerEngine::updateConfigurations()
QNetworkConfiguration::BearerType bearerType = getBearerType(netInfo);
QNetworkConfiguration::StateFlag state;
QString interfaceName;
QNetworkConfiguration::StateFlag state = QNetworkConfiguration::Defined;
if (netInfo.isAvailable()) {
if (netInfo.isConnected()) {
state = QNetworkConfiguration::Active;
// Attempt to map an interface to this configuration
const QList<QNetworkInterface> &interfaces = QNetworkInterface::allInterfaces();
foreach (const QNetworkInterface &interface, interfaces) {
while (!interfaces.isEmpty()) {
QNetworkInterface interface = interfaces.takeFirst();
// ignore loopback interface
if (!interface.isValid())
continue;
@ -297,22 +297,17 @@ void QAndroidBearerEngine::updateConfigurations()
// look for an active interface...
if (interface.flags() & QNetworkInterface::IsRunning
&& !interface.addressEntries().isEmpty()) {
interfaceName = interface.humanReadableName();
if (interfaceName.isEmpty())
interfaceName = interface.name();
state = QNetworkConfiguration::Active;
interfaceName = interface.name();
break;
}
}
} else if (netInfo.isConnectedOrConnecting()) {
state = QNetworkConfiguration::Undefined;
} else {
state = QNetworkConfiguration::Discovered;
}
} else {
state = QNetworkConfiguration::Defined;
}
const uint identifier = qHash(QLatin1String("android:") + name);
const QString id = QString::number(identifier);
const QString key = QString(QLatin1String("android:%1:%2")).arg(name).arg(interfaceName);
const QString id = QString::number(qHash(key));
m_configurationInterface[id] = interfaceName;
oldKeys.removeAll(id);
if (accessPointConfigurations.contains(id)) {
@ -347,12 +342,6 @@ void QAndroidBearerEngine::updateConfigurations()
ptr->state = state;
changed = true;
}
QString &oldIfName = m_configurationInterface[id];
if (oldIfName != interfaceName) {
oldIfName = interfaceName;
changed = true;
}
} // Unlock configuration
if (changed) {
@ -369,8 +358,6 @@ void QAndroidBearerEngine::updateConfigurations()
ptr->type = QNetworkConfiguration::InternetAccessPoint;
ptr->bearerType = bearerType;
accessPointConfigurations.insert(id, ptr);
m_configurationInterface.insert(id, interfaceName);
locker.unlock();
Q_EMIT configurationAdded(ptr);
locker.relock();