11#include " wireless.hpp"
22
3- #include < qcontainerfwd.h>
43#include < qdbusconnection.h>
54#include < qlogging.h>
65#include < qloggingcategory.h>
76#include < qobject.h>
87#include < qstring.h>
9- #include < qtypes.h>
108
119#include " dbus_types.hpp"
1210#include " nm/enums.hpp"
@@ -90,11 +88,18 @@ void NMWirelessNetwork::updateSignalStrength() {
9088 NMAccessPoint* selectedAp = nullptr ;
9189
9290 for (auto * ap: this ->mAccessPoints .values ()) {
91+ // Always prefer the active AP if found.
92+ if (ap->path () == this ->mActiveApPath .path ()) {
93+ selectedStrength = ap->signalStrength ();
94+ selectedAp = ap;
95+ break ;
96+ }
97+
98+ // Otherwise, track the strongest signal.
9399 if (selectedStrength <= ap->signalStrength ()) {
94100 selectedStrength = ap->signalStrength ();
95101 selectedAp = ap;
96102 }
97- if (ap->path () == this ->mActiveApPath .path ()) break ;
98103 }
99104
100105 if (selectedStrength != this ->mSignalStrength ) {
@@ -124,9 +129,7 @@ void NMWirelessNetwork::addAccessPoint(NMAccessPoint* ap) {
124129
125130void NMWirelessNetwork::removeAccessPoint (NMAccessPoint* ap) {
126131 auto * found = this ->mAccessPoints .take (ap->path ());
127- if (!found) {
128- qCWarning (logNetworkManager) << " Backend network" << this ->ssid () << " is not in sync!" ;
129- } else {
132+ if (found) {
130133 if (this ->mAccessPoints .isEmpty ()) {
131134 emit this ->disappeared ();
132135 } else {
@@ -149,9 +152,7 @@ void NMWirelessNetwork::addConnectionSettings(NMConnectionSettings* conn) {
149152
150153void NMWirelessNetwork::removeConnectionSettings (NMConnectionSettings* conn) {
151154 auto * found = this ->mConnections .take (conn->path ());
152- if (!found) {
153- qCWarning (logNetworkManager) << " Backend network" << this ->ssid () << " is not in sync!" ;
154- } else {
155+ if (found) {
155156 QObject::disconnect (conn, nullptr , this , nullptr );
156157 this ->updateReferenceConnection ();
157158 if (mConnections .isEmpty ()) {
@@ -162,7 +163,6 @@ void NMWirelessNetwork::removeConnectionSettings(NMConnectionSettings* conn) {
162163
163164void NMWirelessNetwork::addActiveConnection (NMActiveConnection* active) {
164165 if (this ->mActiveConnection ) {
165- qCWarning (logNetworkManager) << " Backend network" << this ->ssid () << " is not in sync!" ;
166166 return ;
167167 }
168168 this ->setState (active->state ());
@@ -181,8 +181,6 @@ void NMWirelessNetwork::removeActiveConnection(NMActiveConnection* active) {
181181 this ->setState (NMConnectionState::Deactivated);
182182 this ->setReason (NMConnectionStateReason::None);
183183 this ->mActiveConnection = nullptr ;
184- } else {
185- qCWarning (logNetworkManager) << " Backend network" << this ->ssid () << " is not in sync!" ;
186184 }
187185};
188186
@@ -228,13 +226,11 @@ void NMWirelessDevice::onAccessPointPathAdded(const QDBusObjectPath& path) {
228226
229227void NMWirelessDevice::onAccessPointPathRemoved (const QDBusObjectPath& path) {
230228 auto * ap = mAccessPoints .take (path.path ());
231-
232229 if (!ap) {
233- qCDebug (logNetworkManager) << " NetworkManager sent removal signal for" << path.path ()
230+ qCDebug (logNetworkManager) << " Sent removal signal for" << path.path ()
234231 << " which is not registered." ;
235232 return ;
236233 }
237-
238234 emit ap->disappeared ();
239235 delete ap;
240236}
@@ -286,14 +282,12 @@ void NMWirelessDevice::registerAccessPoint(const QString& path) {
286282}
287283
288284NMWirelessNetwork* NMWirelessDevice::registerNetwork (const QString& ssid) {
289- auto * backend = new NMWirelessNetwork (ssid, this );
290285 // clang-format off
286+ auto * backend = new NMWirelessNetwork (ssid, this );
291287 backend->setActiveApPath (this ->activeApPath ());
292288 QObject::connect (this , &NMWirelessDevice::activeAccessPointChanged, backend, &NMWirelessNetwork::setActiveApPath);
293- // clang-format on
294289
295290 auto * frontend = new WifiNetwork (ssid, this );
296- // clang-format off
297291 frontend->setSignalStrength (backend->signalStrength ());
298292 frontend->setState (static_cast <NetworkConnectionState::Enum>(backend->state ()));
299293 frontend->setKnown (backend->known ());
@@ -347,7 +341,8 @@ void NMWirelessDevice::onAccessPointLoaded(NMAccessPoint* ap) {
347341
348342void NMWirelessDevice::onConnectionLoaded (NMConnectionSettings* conn) {
349343 const ConnectionSettingsMap& settings = conn->settings ();
350- // Early return for invalid connections
344+ // Skip connections that have empty settings,
345+ // or who are this devices own hotspots.
351346 if (settings[" connection" ][" id" ].toString ().isEmpty ()
352347 || settings[" connection" ][" uuid" ].toString ().isEmpty ()
353348 || !settings.contains (" 802-11-wireless" )
@@ -369,10 +364,10 @@ void NMWirelessDevice::onConnectionLoaded(NMConnectionSettings* conn) {
369364}
370365
371366void NMWirelessDevice::onActiveConnectionLoaded (NMActiveConnection* active) {
372- QString connPath = active->connection ().path ();
367+ QString activeConnPath = active->connection ().path ();
373368 for (auto * net: this ->mBackendNetworks .values ()) {
374369 for (auto * conn: net->connections ()) {
375- if (connPath == conn->path ()) {
370+ if (activeConnPath == conn->path ()) {
376371 net->addActiveConnection (active);
377372 return ;
378373 }
0 commit comments