mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
WifiManager: set connecting status if NM auto connects (#37247)
* set connecting if nm auto connects * good catch
This commit is contained in:
@@ -10,7 +10,7 @@ from typing import Any
|
||||
|
||||
from jeepney import DBusAddress, new_method_call
|
||||
from jeepney.bus_messages import MatchRule, message_bus
|
||||
from jeepney.io.blocking import open_dbus_connection as open_dbus_connection_blocking
|
||||
from jeepney.io.blocking import DBusConnection, open_dbus_connection as open_dbus_connection_blocking
|
||||
from jeepney.io.threading import DBusRouter, open_dbus_connection as open_dbus_connection_threading
|
||||
from jeepney.low_level import MessageType
|
||||
from jeepney.wrappers import Properties
|
||||
@@ -341,6 +341,17 @@ class WifiManager:
|
||||
if self._connecting_to_ssid == failed_ssid:
|
||||
self._connecting_to_ssid = None
|
||||
|
||||
elif new_state == NMDeviceState.PREPARE and self._connecting_to_ssid is None:
|
||||
# Set connecting status when NetworkManager connects to known networks on its own
|
||||
conn_path, _ = self._get_active_wifi_connection(self._conn_monitor)
|
||||
if conn_path is None:
|
||||
cloudlog.warning("Failed to get active wifi connection during PREPARE state")
|
||||
continue
|
||||
|
||||
ssid = next((s for s, p in self._connections.items() if p == conn_path), None)
|
||||
if ssid:
|
||||
self._set_connecting(ssid)
|
||||
|
||||
elif new_state == NMDeviceState.ACTIVATED:
|
||||
self._update_networks()
|
||||
self._enqueue_callbacks(self._activated)
|
||||
@@ -412,15 +423,21 @@ class WifiManager:
|
||||
def _connection_removed(self, conn_path: str):
|
||||
self._connections = {ssid: path for ssid, path in self._connections.items() if path != conn_path}
|
||||
|
||||
def _get_active_connections(self):
|
||||
def _get_active_connections(self, router: DBusConnection | DBusRouter | None = None):
|
||||
# Returns list of ActiveConnection
|
||||
return self._router_main.send_and_get_reply(Properties(self._nm).get('ActiveConnections')).body[0][1]
|
||||
if router is None:
|
||||
router = self._router_main
|
||||
|
||||
def _get_active_wifi_connection(self) -> tuple[str | None, dict | None]:
|
||||
return router.send_and_get_reply(Properties(self._nm).get('ActiveConnections')).body[0][1]
|
||||
|
||||
def _get_active_wifi_connection(self, router: DBusConnection | DBusRouter | None = None) -> tuple[str | None, dict | None]:
|
||||
# Returns first Connection settings path and ActiveConnection props from ActiveConnections with Type 802-11-wireless
|
||||
for active_conn in self._get_active_connections():
|
||||
if router is None:
|
||||
router = self._router_main
|
||||
|
||||
for active_conn in self._get_active_connections(router):
|
||||
conn_addr = DBusAddress(active_conn, bus_name=NM, interface=NM_ACTIVE_CONNECTION_IFACE)
|
||||
reply = self._router_main.send_and_get_reply(Properties(conn_addr).get_all())
|
||||
reply = router.send_and_get_reply(Properties(conn_addr).get_all())
|
||||
|
||||
if reply.header.message_type == MessageType.error:
|
||||
cloudlog.warning(f"Failed to get active connection properties for {active_conn}: {reply}")
|
||||
|
||||
Reference in New Issue
Block a user