Skip to content

Commit

Permalink
Merge branch 'jb50745-accept-connections' into 'master'
Browse files Browse the repository at this point in the history
[buteo-syncfw] Accept unrecognised connection types if applicable. JB#50745

See merge request mer-core/buteo-syncfw!54
  • Loading branch information
blam committed Sep 17, 2020
2 parents 19ca0e2 + cc01ba8 commit 1d36739
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
30 changes: 26 additions & 4 deletions libbuteosyncfw/common/NetworkManager.cpp
Expand Up @@ -28,6 +28,27 @@
#include "NetworkManager.h"
#include "LogMacros.h"

namespace {
Sync::InternetConnectionType convertNetworkConnectionType(QNetworkConfiguration::BearerType connectionType)
{
switch (connectionType) {
case QNetworkConfiguration::BearerEthernet: return Sync::INTERNET_CONNECTION_ETHERNET;
case QNetworkConfiguration::BearerWLAN: return Sync::INTERNET_CONNECTION_WLAN;
case QNetworkConfiguration::Bearer2G: return Sync::INTERNET_CONNECTION_2G;
case QNetworkConfiguration::BearerCDMA2000: return Sync::INTERNET_CONNECTION_CDMA2000;
case QNetworkConfiguration::BearerWCDMA: return Sync::INTERNET_CONNECTION_WCDMA;
case QNetworkConfiguration::BearerHSPA: return Sync::INTERNET_CONNECTION_HSPA;
case QNetworkConfiguration::BearerBluetooth: return Sync::INTERNET_CONNECTION_BLUETOOTH;
case QNetworkConfiguration::BearerWiMAX: return Sync::INTERNET_CONNECTION_WIMAX;
case QNetworkConfiguration::BearerEVDO: return Sync::INTERNET_CONNECTION_EVDO;
case QNetworkConfiguration::BearerLTE: return Sync::INTERNET_CONNECTION_LTE;
case QNetworkConfiguration::Bearer3G: return Sync::INTERNET_CONNECTION_3G;
case QNetworkConfiguration::Bearer4G: return Sync::INTERNET_CONNECTION_4G;
default: return Sync::INTERNET_CONNECTION_UNKNOWN;
}
}
}

using namespace Buteo;

int NetworkManager::m_refCount = 0;
Expand Down Expand Up @@ -185,12 +206,13 @@ void NetworkManager::idleRefresh()
}
}
}
LOG_INFO("New network state:" << isOnline << " New type: " << bearerTypeName << "(" << connectionType << ")");
if ((isOnline != m_isOnline) ||
((Sync::InternetConnectionType)connectionType != m_connectionType))

const Sync::InternetConnectionType convertedConnectionType = convertNetworkConnectionType(connectionType);
LOG_INFO("New network state:" << isOnline << " New type: " << bearerTypeName << "(" << convertedConnectionType << ")");
if (isOnline != m_isOnline || convertedConnectionType != m_connectionType)
{
m_isOnline = isOnline;
m_connectionType = (Sync::InternetConnectionType) connectionType;
m_connectionType = convertedConnectionType;
emit statusChanged(m_isOnline, m_connectionType);
}
}
Expand Down
19 changes: 12 additions & 7 deletions msyncd/synchronizer.cpp
Expand Up @@ -340,7 +340,7 @@ bool Synchronizer::startScheduledSync(QString aProfileName)
}
else
{
LOG_DEBUG("Scheduled sync of" << aProfileName << "accepted with current connectivity status.");
LOG_DEBUG("Scheduled sync of" << aProfileName << "accepted with current connection type" << iNetworkManager->connectionType());
startSync(aProfileName, true);
}
}
Expand All @@ -350,7 +350,7 @@ bool Synchronizer::startScheduledSync(QString aProfileName)
if (iNetworkManager->isOnline())
{
// see acceptScheduledSync() for the determination of whether the connection type is allowed for sync operations.
LOG_INFO("Connection is of disallowed type (e.g. mobile data). The sync will be postponed until an allowed connection is available.");
LOG_INFO("Connection" << iNetworkManager->connectionType() << "is of disallowed type. The sync will be postponed until an allowed connection is available.");
}
else
{
Expand Down Expand Up @@ -2210,7 +2210,13 @@ void Synchronizer::removeExternalSyncStatus(const SyncProfile *aProfile)

bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType, SyncProfile *aSyncProfile) const
{
if (!aSyncProfile || !aConnected) {
if (!aConnected) {
LOG_WARNING("Scheduled sync refused, not connected");
return false;
}

if (!aSyncProfile) {
LOG_WARNING("Scheduled sync refused, invalid sync profile");
return false;
}

Expand All @@ -2224,13 +2230,12 @@ bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnection
|| aType == Sync::INTERNET_CONNECTION_ETHERNET) {
return true;
}
if (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular")
&& aType != Sync::INTERNET_CONNECTION_UNKNOWN
&& aType != Sync::INTERNET_CONNECTION_BLUETOOTH) {
// Assume type is cellular if it is not unknown/bluetooth.
if (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular")) {
LOG_INFO("Allowing sync for cellular/other connection type:" << aType);
return true;
}

LOG_WARNING("Scheduled sync refused, profile disallows current connection type:" << aType);
return false;
}

Expand Down

0 comments on commit 1d36739

Please sign in to comment.