Narrow Galaxy and Network Owners

This commit is contained in:
firestar5683
2026-11-28 16:05:23 -06:00
parent ee51afb017
commit 4517ab2f34
3 changed files with 59 additions and 40 deletions
+19 -10
View File
@@ -208,6 +208,12 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
simulation_busy = threading.Event()
last_simulation = [float("-inf")]
notification_owner = notifications
def get_notification_owner() -> NotificationOwner:
if notification_owner is None:
raise NotificationUnavailable("Sentry notifications are unavailable")
return notification_owner
snapshots = camera_snapshot if camera_snapshot is not None else CameraSnapshot()
access = owner if owner is not None else default_owner()
from openpilot.starpilot.galaxy.reverse_proxy import ReverseProxySettings
@@ -563,14 +569,17 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
server.vehicle_selection_source = vehicle_gateway
return vehicle_gateway
def model_status():
def model_status_owner():
nonlocal model_source
with models_lock:
if model_source is None:
from openpilot.common.params import Params
model_source = ModelStatusSource(Params())
server.model_source = model_source
return model_source.json()
return model_source
def model_status():
return model_status_owner().json()
def model_owner():
nonlocal model_manager_source
@@ -587,8 +596,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
def model_laboratory():
from openpilot.starpilot.models.laboratory import ModelLaboratory
def runtime_status(config):
model_status()
return model_source.laboratory_json(config)
return model_status_owner().laboratory_json(config)
return ModelLaboratory(model_owner(), runtime_status=runtime_status)
def login(password):
@@ -1476,7 +1484,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
if not self.require_session():
return
try:
result = notification_owner.snapshot()
result = get_notification_owner().snapshot()
except NotificationUnavailable:
if self.require_session():
self.json(503, {'error': 'Sentry notifications are unavailable'})
@@ -1491,7 +1499,8 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
self.json(400, {'error': 'Choose an event image'})
return
try:
body = notification_owner.test_image(parts[0]) if parts[1] == 'test' else motion_events.image(parts[0], parts[1])
body = (get_notification_owner().test_image(parts[0]) if parts[1] == 'test'
else motion_events.image(parts[0], parts[1]))
if body is None:
raise SentryEventsUnavailable
except SentryEventsUnavailable:
@@ -2010,7 +2019,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
try:
photo = snapshots.capture(payload['camera'], permitted=permitted, parked=True)
notification_owner.photo_test(payload['id'], payload['camera'], photo, permitted=permitted)
get_notification_owner().photo_test(payload['id'], payload['camera'], photo, permitted=permitted)
except (SnapshotDenied, PermissionError):
if self.require_session():
self.json(409, {'error': 'Park the car before sending a photo test'})
@@ -2053,7 +2062,7 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
def capture_simulation():
try:
record_motion_event(notification_owner.store, snapshots, 'warning', time.monotonic_ns(),
record_motion_event(get_notification_owner().store, snapshots, 'warning', time.monotonic_ns(),
permitted, simulated=True)
except SnapshotDenied:
pass
@@ -2069,9 +2078,9 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
simulation_busy.clear()
raise NotificationUnavailable("Could not start Sentry simulation") from error
last_simulation[0] = clock()
result = notification_owner.snapshot()
result = get_notification_owner().snapshot()
else:
result = notification_owner.action(payload, permitted=lambda: self.settings_session() == identity)
result = get_notification_owner().action(payload, permitted=lambda: self.settings_session() == identity)
except LookupError:
self.json(404, {'error': 'Phone subscription not found'})
except ValueError as error:
+39 -29
View File
@@ -212,6 +212,12 @@ class WifiManager:
self._initialize()
atexit.register(self.stop)
def _system_router(self) -> DBusRouter:
router = self._router_main
if router is None:
raise ConnectionError("NetworkManager D-Bus is unavailable")
return router
def _initialize(self):
def worker():
self._wait_for_wifi_device()
@@ -248,7 +254,7 @@ class WifiManager:
epoch = self._user_epoch
dev_addr = DBusAddress(self._wifi_device, bus_name=NM, interface=NM_DEVICE_IFACE)
dev_state = self._router_main.send_and_get_reply(Properties(dev_addr).get('State')).body[0][1]
dev_state = self._system_router().send_and_get_reply(Properties(dev_addr).get('State')).body[0][1]
ssid: str | None = None
status = ConnectStatus.DISCONNECTED
@@ -343,6 +349,9 @@ class WifiManager:
self._update_networks(block=False)
def _monitor_state(self):
connection = self._conn_monitor
if connection is None:
return
# Filter for signals
rules = (
MatchRule(
@@ -372,15 +381,15 @@ class WifiManager:
)
for rule in rules:
self._conn_monitor.send_and_get_reply(message_bus.AddMatch(rule))
connection.send_and_get_reply(message_bus.AddMatch(rule))
with (self._conn_monitor.filter(rules[0], bufsize=SIGNAL_QUEUE_SIZE) as state_q,
self._conn_monitor.filter(rules[1], bufsize=SIGNAL_QUEUE_SIZE) as new_conn_q,
self._conn_monitor.filter(rules[2], bufsize=SIGNAL_QUEUE_SIZE) as removed_conn_q,
self._conn_monitor.filter(rules[3], bufsize=SIGNAL_QUEUE_SIZE) as props_q):
with (connection.filter(rules[0], bufsize=SIGNAL_QUEUE_SIZE) as state_q,
connection.filter(rules[1], bufsize=SIGNAL_QUEUE_SIZE) as new_conn_q,
connection.filter(rules[2], bufsize=SIGNAL_QUEUE_SIZE) as removed_conn_q,
connection.filter(rules[3], bufsize=SIGNAL_QUEUE_SIZE) as props_q):
while not self._exit:
try:
self._conn_monitor.recv_messages(timeout=1)
connection.recv_messages(timeout=1)
except TimeoutError:
continue
@@ -496,9 +505,10 @@ class WifiManager:
self._update_active_connection_info()
# Persist volatile connections (created by AddAndActivateConnection2) to disk
if conn_path is not None:
connection = self._conn_monitor
if conn_path is not None and connection is not None:
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE)
save_reply = self._conn_monitor.send_and_get_reply(new_method_call(conn_addr, 'Save'))
save_reply = connection.send_and_get_reply(new_method_call(conn_addr, 'Save'))
if save_reply.header.message_type == MessageType.error:
cloudlog.warning(f"Failed to persist connection to disk: {save_reply}")
@@ -529,13 +539,13 @@ class WifiManager:
def _get_adapter(self, adapter_type: int) -> str | None:
# Return the first NetworkManager device path matching adapter_type
try:
reply = self._router_main.send_and_get_reply(new_method_call(self._nm, 'GetDevices'))
reply = self._system_router().send_and_get_reply(new_method_call(self._nm, 'GetDevices'))
if reply.header.message_type == MessageType.error:
# NetworkManager is not available, body holds an error string instead of device paths
return None
for device_path in reply.body[0]:
dev_addr = DBusAddress(device_path, bus_name=NM, interface=NM_DEVICE_IFACE)
dev_type = self._router_main.send_and_get_reply(Properties(dev_addr).get('DeviceType')).body[0][1]
dev_type = self._system_router().send_and_get_reply(Properties(dev_addr).get('DeviceType')).body[0][1]
if dev_type == adapter_type:
return str(device_path)
except Exception as e:
@@ -544,7 +554,7 @@ class WifiManager:
def _init_connections(self) -> None:
settings_addr = DBusAddress(NM_SETTINGS_PATH, bus_name=NM, interface=NM_SETTINGS_IFACE)
known_connections = self._router_main.send_and_get_reply(new_method_call(settings_addr, 'ListConnections')).body[0]
known_connections = self._system_router().send_and_get_reply(new_method_call(settings_addr, 'ListConnections')).body[0]
conns: dict[str, str] = {}
for conn_path in known_connections:
@@ -574,14 +584,14 @@ class WifiManager:
def _get_active_connections(self, router: DBusConnection | DBusRouter | None = None):
# Returns list of ActiveConnection
if router is None:
router = self._router_main
router = self._system_router()
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
if router is None:
router = self._router_main
router = self._system_router()
for active_conn in self._get_active_connections(router):
conn_addr = DBusAddress(active_conn, bus_name=NM, interface=NM_ACTIVE_CONNECTION_IFACE)
@@ -601,7 +611,7 @@ class WifiManager:
def _get_connection_settings(self, conn_path: str) -> dict:
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE)
reply = self._router_main.send_and_get_reply(new_method_call(conn_addr, 'GetSettings'))
reply = self._system_router().send_and_get_reply(new_method_call(conn_addr, 'GetSettings'))
if reply.header.message_type == MessageType.error:
cloudlog.warning(f'Failed to get connection settings: {reply}')
return {}
@@ -642,7 +652,7 @@ class WifiManager:
}
settings_addr = DBusAddress(NM_SETTINGS_PATH, bus_name=NM, interface=NM_SETTINGS_IFACE)
self._router_main.send_and_get_reply(new_method_call(settings_addr, 'AddConnection', 'a{sa{sv}}', (connection,)))
self._system_router().send_and_get_reply(new_method_call(settings_addr, 'AddConnection', 'a{sa{sv}}', (connection,)))
def connect_to_network(self, ssid: str, password: str, hidden: bool = False):
self._set_connecting(ssid)
@@ -685,7 +695,7 @@ class WifiManager:
self._init_wifi_state()
return
reply = self._router_main.send_and_get_reply(new_method_call(self._nm, 'AddAndActivateConnection2', 'a{sa{sv}}ooa{sv}',
reply = self._system_router().send_and_get_reply(new_method_call(self._nm, 'AddAndActivateConnection2', 'a{sa{sv}}ooa{sv}',
(connection, self._wifi_device, "/", {'persist': ('s', 'volatile')})))
if reply.header.message_type == MessageType.error:
@@ -702,7 +712,7 @@ class WifiManager:
cloudlog.warning(f"Trying to forget unknown connection: {ssid}")
else:
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE)
self._router_main.send_and_get_reply(new_method_call(conn_addr, 'Delete'))
self._system_router().send_and_get_reply(new_method_call(conn_addr, 'Delete'))
self._enqueue_callbacks(self._forgotten, ssid)
@@ -722,7 +732,7 @@ class WifiManager:
self._init_wifi_state()
return
reply = self._router_main.send_and_get_reply(new_method_call(self._nm, 'ActivateConnection', 'ooo',
reply = self._system_router().send_and_get_reply(new_method_call(self._nm, 'ActivateConnection', 'ooo',
(conn_path, self._wifi_device, "/")))
if reply.header.message_type == MessageType.error:
@@ -738,7 +748,7 @@ class WifiManager:
def _deactivate_connection(self, ssid: str):
for active_conn in self._get_active_connections():
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('SpecificObject'))
reply = self._system_router().send_and_get_reply(Properties(conn_addr).get('SpecificObject'))
if reply.header.message_type == MessageType.error:
continue # object gone (e.g. rapid connect/disconnect)
@@ -746,14 +756,14 @@ class WifiManager:
if specific_obj_path != "/":
ap_addr = DBusAddress(specific_obj_path, bus_name=NM, interface=NM_ACCESS_POINT_IFACE)
ap_reply = self._router_main.send_and_get_reply(Properties(ap_addr).get('Ssid'))
ap_reply = self._system_router().send_and_get_reply(Properties(ap_addr).get('Ssid'))
if ap_reply.header.message_type == MessageType.error:
continue # AP gone (e.g. mode switch)
ap_ssid = bytes(ap_reply.body[0][1]).decode("utf-8", "replace")
if ap_ssid == ssid:
self._router_main.send_and_get_reply(new_method_call(self._nm, 'DeactivateConnection', 'o', (active_conn,)))
self._system_router().send_and_get_reply(new_method_call(self._nm, 'DeactivateConnection', 'o', (active_conn,)))
return
def is_tethering_active(self) -> bool:
@@ -778,7 +788,7 @@ class WifiManager:
settings['802-11-wireless-security']['psk'] = ('s', password)
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE)
reply = self._router_main.send_and_get_reply(new_method_call(conn_addr, 'Update', 'a{sa{sv}}', (settings,)))
reply = self._system_router().send_and_get_reply(new_method_call(conn_addr, 'Update', 'a{sa{sv}}', (settings,)))
if reply.header.message_type == MessageType.error:
cloudlog.warning(f'Failed to update tethering settings: {reply}')
return
@@ -795,7 +805,7 @@ class WifiManager:
cloudlog.warning('No tethering connection found')
return ''
reply = self._router_main.send_and_get_reply(new_method_call(
reply = self._system_router().send_and_get_reply(new_method_call(
DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE),
'GetSecrets', 's', ('802-11-wireless-security',)
))
@@ -847,7 +857,7 @@ class WifiManager:
settings['connection']['metered'] = ('i', int(metered))
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_CONNECTION_IFACE)
reply = self._router_main.send_and_get_reply(new_method_call(conn_addr, 'Update', 'a{sa{sv}}', (settings,)))
reply = self._system_router().send_and_get_reply(new_method_call(conn_addr, 'Update', 'a{sa{sv}}', (settings,)))
if reply.header.message_type == MessageType.error:
cloudlog.warning(f'Failed to update metered settings: {reply}')
@@ -859,7 +869,7 @@ class WifiManager:
return
wifi_addr = DBusAddress(self._wifi_device, bus_name=NM, interface=NM_WIRELESS_IFACE)
reply = self._router_main.send_and_get_reply(new_method_call(wifi_addr, 'RequestScan', 'a{sv}', ({},)))
reply = self._system_router().send_and_get_reply(new_method_call(wifi_addr, 'RequestScan', 'a{sv}', ({},)))
if reply.header.message_type == MessageType.error:
cloudlog.warning(f"Failed to request scan: {reply}")
@@ -876,7 +886,7 @@ class WifiManager:
# NOTE: AccessPoints property may exclude hidden APs (use GetAllAccessPoints method if needed)
wifi_addr = DBusAddress(self._wifi_device, NM, interface=NM_WIRELESS_IFACE)
wifi_props_reply = self._router_main.send_and_get_reply(Properties(wifi_addr).get_all())
wifi_props_reply = self._system_router().send_and_get_reply(Properties(wifi_addr).get_all())
if wifi_props_reply.header.message_type == MessageType.error:
cloudlog.warning(f"Failed to get WiFi properties: {wifi_props_reply}")
return
@@ -887,7 +897,7 @@ class WifiManager:
for ap_path in ap_paths:
ap_addr = DBusAddress(ap_path, NM, interface=NM_ACCESS_POINT_IFACE)
ap_props = self._router_main.send_and_get_reply(Properties(ap_addr).get_all())
ap_props = self._system_router().send_and_get_reply(Properties(ap_addr).get_all())
# some APs have been seen dropping off during iteration
if ap_props.header.message_type == MessageType.error:
@@ -928,7 +938,7 @@ class WifiManager:
if ip4config_path != "/":
ip4config_addr = DBusAddress(ip4config_path, bus_name=NM, interface=NM_IP4_CONFIG_IFACE)
address_data = self._router_main.send_and_get_reply(Properties(ip4config_addr).get('AddressData')).body[0][1]
address_data = self._system_router().send_and_get_reply(Properties(ip4config_addr).get('AddressData')).body[0][1]
for entry in address_data:
if 'address' in entry:
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "0d0c116cf77395694c44e3ba8a20d22e0f8c2e5eb45f28401300221e95407def", "schema_version": 1}
{"protected_inventory_sha256": "7342d6f682a67c15418812523b2b8a7ea5cd23c45a077338b073dc7b671b23e2", "schema_version": 1}