mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T295, based on bug report of RP (no WIFI detected) creating a network report
* network report when starting swift * also ignore inactive configs when checking for "the bearer bug" references: https://stackoverflow.com/questions/51824242/disable-qt-bearer-management-at-runtime https://swift-project.slack.com/archives/G7GD2UP9C/p1534181224000115 https://swift-project.slack.com/archives/G96QTUBEG/p1534162173000320
This commit is contained in:
@@ -1093,22 +1093,9 @@ namespace BlackCore
|
||||
|
||||
void CApplication::onNetworkConfigurationsUpdateCompleted()
|
||||
{
|
||||
Q_ASSERT_X(m_networkConfigManager, Q_FUNC_INFO, "Need network config manager");
|
||||
const QNetworkConfiguration config = m_networkConfigManager->defaultConfiguration();
|
||||
const QList<QNetworkConfiguration> allConfigurations = m_networkConfigManager->allConfigurations();
|
||||
|
||||
/** testing only
|
||||
for (const QNetworkConfiguration &config : allConfigurations)
|
||||
{
|
||||
const QString cs = CNetworkUtils::networkConfigurationToString(config);
|
||||
CLogMessage(this).info("Network config: '%1'") << cs;
|
||||
}
|
||||
if (m_accessManager)
|
||||
{
|
||||
const QString cs = CNetworkUtils::networkConfigurationToString(m_accessManager->configuration());
|
||||
CLogMessage(this).info("Network access manager config: '%1'") << cs;
|
||||
}
|
||||
**/
|
||||
|
||||
if (allConfigurations.isEmpty())
|
||||
{
|
||||
// this is an odd situation we cannot handle, network check will be disabled
|
||||
@@ -1121,14 +1108,25 @@ namespace BlackCore
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool isOnline = m_networkConfigManager->isOnline();
|
||||
int active = 0;
|
||||
int valid = 0;
|
||||
for (const QNetworkConfiguration &config : allConfigurations)
|
||||
{
|
||||
if (config.state() == QNetworkConfiguration::Active) { active++; }
|
||||
if (config.isValid()) { valid++; }
|
||||
}
|
||||
Q_UNUSED(valid);
|
||||
|
||||
// const bool isOnline = m_networkConfigManager->isOnline();
|
||||
const bool canStartIAP = (m_networkConfigManager->capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
|
||||
m_networkWatchDog->disableNetworkAccessibilityCheck(!isOnline);
|
||||
const bool disable = active < 1; // only inactive
|
||||
if (disable) { CLogMessage(this).warning("Disabling network accessibility check in watchdog"); }
|
||||
m_networkWatchDog->disableNetworkAccessibilityCheck(disable);
|
||||
|
||||
// Is there default access point, use it
|
||||
if (!config.isValid() || (!canStartIAP && config.state() != QNetworkConfiguration::Active))
|
||||
{
|
||||
CLogMessage(this).error("No network access point found");
|
||||
CLogMessage(this).warning("No network access point found for swift");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1171,6 +1169,15 @@ namespace BlackCore
|
||||
// enable by setting accessible
|
||||
// http://doc.qt.io/qt-5/qnetworkaccessmanager.html#setNetworkAccessible
|
||||
m_accessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
|
||||
|
||||
// create a network report in the log
|
||||
QTimer::singleShot(4000, this, [ = ]
|
||||
{
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
const QString r = CNetworkUtils::createNetworkConfigurationReport(m_networkConfigManager, m_accessManager);
|
||||
CLogMessage(this).info("Network report:\n%1") << r;
|
||||
});
|
||||
}
|
||||
|
||||
CStatusMessageList CApplication::asyncWebAndContextStart()
|
||||
|
||||
@@ -426,6 +426,10 @@ namespace BlackCore
|
||||
//! \remark supposed to be used only in special cases
|
||||
const QNetworkAccessManager *getNetworkAccessManager() const { return m_accessManager; }
|
||||
|
||||
//! Access to configuration manager
|
||||
//! \remark supposed to be used only in special cases
|
||||
const QNetworkConfigurationManager *getNetworkConfigurationManager() const { return m_networkConfigManager; }
|
||||
|
||||
//! Web data services available?
|
||||
//! \threadsafe
|
||||
bool hasWebDataServices() const;
|
||||
|
||||
@@ -94,11 +94,11 @@ namespace BlackCore
|
||||
|
||||
QString CNetworkWatchdog::getCheckInfo() const
|
||||
{
|
||||
static const QString info("Internet accessible: %1 (good: %2 / bad: %3), swift DB accessible: %4 (good: %5 / bad: %6) DB last ping URL: '%7' canConnect: %8ms");
|
||||
static const QString info("Network accessibility check: %1 | Internet accessible: %2 (good: %3 / bad: %4), swift DB accessible: %5 (good: %6 / bad: %7) DB last ping URL: '%8' canConnect: %9ms");
|
||||
const QString pUrl(this->getLastPingDbUrl());
|
||||
static const QString cct = QString::number(CanConnectTimeMs);
|
||||
return info.
|
||||
arg(boolToYesNo(this->isInternetAccessible())).arg(m_totalGoodCountInternet).arg(m_totalBadCountInternet).
|
||||
arg(boolToEnabledDisabled(!this->isNetworkAccessibilityCheckDisabled()), boolToYesNo(this->isInternetAccessible())).arg(m_totalGoodCountInternet).arg(m_totalBadCountInternet).
|
||||
arg(boolToYesNo(this->isSwiftDbAccessible())).arg(m_totalGoodCountDb).arg(m_totalBadCountDb).
|
||||
arg(pUrl, cct); // cct has to be string, otherwise the % in the URL will be replaced
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/setupreader.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackcore/setupreader.h"
|
||||
#include "blackgui/components/applicationclosedialog.h"
|
||||
#include "blackgui/components/updateinfodialog.h"
|
||||
#include "blackgui/components/aboutdialog.h"
|
||||
@@ -542,7 +543,21 @@ namespace BlackGui
|
||||
|
||||
a = menu.addAction(CIcons::swift24(), "Check for updates");
|
||||
c = connect(a, &QAction::triggered, this, &CGuiApplication::checkNewVersionMenu);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
|
||||
a = menu.addAction(CIcons::monitorError16(), "Network config. (console)");
|
||||
c = connect(a, &QAction::triggered, this, [ = ]()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
const QString r = CNetworkUtils::createNetworkConfigurationReport(this->getNetworkConfigurationManager(), this->getNetworkAccessManager());
|
||||
this->displayTextInConsole(r);
|
||||
|
||||
if (this->getNetworkWatchdog())
|
||||
{
|
||||
const QString w = this->getNetworkWatchdog()->getCheckInfo();
|
||||
this->displayTextInConsole(w);
|
||||
}
|
||||
});
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <QTextStream>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QStringBuilder>
|
||||
#include <QEventLoop>
|
||||
#include <QVariant>
|
||||
#include <QtDebug>
|
||||
@@ -386,7 +387,7 @@ namespace BlackMisc
|
||||
return CNetworkUtils::createNetworkReport(CUrl(), am);
|
||||
}
|
||||
|
||||
CStatusMessageList CNetworkUtils::createNetworkReport(const CUrl &url, const QNetworkAccessManager *am)
|
||||
CStatusMessageList CNetworkUtils::createNetworkReport(const CUrl &url, const QNetworkAccessManager *qam)
|
||||
{
|
||||
static const CLogCategoryList cats({CLogCategory::network()});
|
||||
CStatusMessageList msgs;
|
||||
@@ -410,25 +411,74 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
if (am)
|
||||
if (qam)
|
||||
{
|
||||
const bool accessible = am->networkAccessible() == QNetworkAccessManager::Accessible;
|
||||
const QNetworkConfiguration c = am->configuration();
|
||||
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
|
||||
|
||||
const QString msg = QString("Accessible: %1 (%2) config: %3").arg(
|
||||
boolToYesNo(accessible),
|
||||
enumAccessible.valueToKey(am->networkAccessible()),
|
||||
networkConfigurationToString(c));
|
||||
const QString msg = CNetworkUtils::createNetworkAccessManagerReport(qam);
|
||||
const bool accessible = qam->networkAccessible() == QNetworkAccessManager::Accessible;
|
||||
msgs.push_back(CStatusMessage(cats, accessible ? CStatusMessage::SeverityInfo : CStatusMessage::SeverityError, msg));
|
||||
}
|
||||
|
||||
return msgs;
|
||||
}
|
||||
|
||||
QString CNetworkUtils::createNetworkConfigurationReport(const QNetworkConfigurationManager *qcm, const QNetworkAccessManager *qam, const QString &separator)
|
||||
{
|
||||
if (!qcm) { return QStringLiteral("No configuration manager"); }
|
||||
|
||||
static const QString empty;
|
||||
QString report;
|
||||
int c = 0;
|
||||
|
||||
int active = 0;
|
||||
int inActive = 0;
|
||||
int valid = 0;
|
||||
for (const QNetworkConfiguration &config : qcm->allConfigurations())
|
||||
{
|
||||
if (config.state() == QNetworkConfiguration::Active) { active++; }
|
||||
else { inActive++; }
|
||||
if (config.isValid()) { valid++; }
|
||||
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
QString::number(++c) % QStringLiteral(": ") %
|
||||
CNetworkUtils::networkConfigurationToString(config);
|
||||
}
|
||||
|
||||
if (c < 1)
|
||||
{
|
||||
report = QStringLiteral("No network configurations!");
|
||||
}
|
||||
else
|
||||
{
|
||||
static const QString count("Network configurations: active %1 / inactive %2 / valid %3");
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
count.arg(active).arg(inActive).arg(valid);
|
||||
}
|
||||
|
||||
if (qam)
|
||||
{
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
QStringLiteral("QAM: ") %
|
||||
CNetworkUtils::createNetworkAccessManagerReport(qam);
|
||||
}
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
QString CNetworkUtils::createNetworkAccessManagerReport(const QNetworkAccessManager *qam)
|
||||
{
|
||||
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
|
||||
static const QString info("Accessible: '%1' (%2) config: '%3'");
|
||||
|
||||
const bool accessible = qam->networkAccessible() == QNetworkAccessManager::Accessible;
|
||||
return info.arg(boolToYesNo(accessible), enumAccessible.valueToKey(qam->networkAccessible()), CNetworkUtils::networkConfigurationToString(qam->configuration()));
|
||||
}
|
||||
|
||||
QString CNetworkUtils::networkConfigurationToString(const QNetworkConfiguration &configuration)
|
||||
{
|
||||
static const QString s("%1 %2 valid: %3 %4 %5");
|
||||
static const QString s("'%1' '%2' valid: '%3' '%4' '%5'");
|
||||
const QString stateFlagsStr = networkStatesToString(configuration.state());
|
||||
return s.arg(configuration.name(), configuration.identifier(), boolToYesNo(configuration.isValid()), stateFlagsStr, networkTypeToString(configuration.type()));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QNetworkConfiguration>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -158,7 +159,13 @@ namespace BlackMisc
|
||||
|
||||
//! Status about network, can be used when an URL fails to resolve issues
|
||||
//! \remark that can take a moment to complete, as it checks network
|
||||
static BlackMisc::CStatusMessageList createNetworkReport(const CUrl &url, const QNetworkAccessManager *am = nullptr);
|
||||
static BlackMisc::CStatusMessageList createNetworkReport(const CUrl &url, const QNetworkAccessManager *qam = nullptr);
|
||||
|
||||
//! Info about network configurations
|
||||
static QString createNetworkConfigurationReport(const QNetworkConfigurationManager *qcm, const QNetworkAccessManager *qam, const QString &separator = "\n");
|
||||
|
||||
//! Report for QAM
|
||||
static QString createNetworkAccessManagerReport(const QNetworkAccessManager *qam);
|
||||
|
||||
//! Configuration as string
|
||||
static QString networkConfigurationToString(const QNetworkConfiguration &configuration);
|
||||
|
||||
Reference in New Issue
Block a user