From dd97dba7dfb153d3cb7b1b1f1f492964a87ba707 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 22 Dec 2022 18:21:38 +0100 Subject: [PATCH] Retake multicast lock on WiFi carrier change --- sbapp/services/sidebandservice.py | 16 ++++++++++------ sbapp/sideband/core.py | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sbapp/services/sidebandservice.py b/sbapp/services/sidebandservice.py index c19ca4b..6bacded 100644 --- a/sbapp/services/sidebandservice.py +++ b/sbapp/services/sidebandservice.py @@ -136,12 +136,12 @@ class SidebandService(): self.update_connectivity_type() if RNS.vendor.platformutils.is_android(): - RNS.log("Discovered USB devices: "+str(self.usb_devices), RNS.LOG_DEBUG) + RNS.log("Discovered USB devices: "+str(self.usb_devices), RNS.LOG_EXTREME) def discover_usb_devices(self): self.usb_devices = [] - RNS.log("Discovering attached USB devices...", RNS.LOG_DEBUG) + RNS.log("Discovering attached USB devices...", RNS.LOG_EXTREME) try: devices = usb.get_usb_device_list() for device in devices: @@ -165,21 +165,25 @@ class SidebandService(): def stop(self): self.should_run = False - def take_locks(self): + def take_locks(self, force_multicast=False): if RNS.vendor.platformutils.get_platform() == "android": - if self.multicast_lock == None: + if self.multicast_lock == None or force_multicast: self.multicast_lock = self.wifi_manager.createMulticastLock("sideband_service") if not self.multicast_lock.isHeld(): - RNS.log("Taking multicast lock") + RNS.log("Taking multicast lock", RNS.LOG_DEBUG) self.multicast_lock.acquire() + else: + RNS.log("Multicast lock already held", RNS.LOG_DEBUG) if self.wake_lock == None: self.wake_lock = self.power_manager.newWakeLock(self.power_manager.PARTIAL_WAKE_LOCK, "sideband_service") if not self.wake_lock.isHeld(): - RNS.log("Taking wake lock") + RNS.log("Taking wake lock", RNS.LOG_DEBUG) self.wake_lock.acquire() + else: + RNS.log("Wake lock already held", RNS.LOG_DEBUG) def release_locks(self): if RNS.vendor.platformutils.get_platform() == "android": diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index f8ccd38..22676d1 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -1282,6 +1282,11 @@ class SidebandCore(): if hasattr(self, "interface_local") and self.interface_local != None: have_peers = len(self.interface_local.peers) > 0 + if self.interface_local.carrier_changed: + RNS.log("AutoInterface carrier change detected, retaking wake locks", RNS.LOG_DEBUG) + self.owner_service.take_locks(force_multicast=True) + self.interface_local.carrier_changed = False + if hasattr(self.interface_local, "had_peers"): if not self.interface_local.had_peers and have_peers: RNS.log("Peers became reachable on the interface "+str(self.interface_local), RNS.LOG_DEBUG)