From 5ca3153eff61edf7b612612c1f03036571117671 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 5 Nov 2023 12:20:30 +0100 Subject: [PATCH] Added periodic multicast lock check --- sbapp/services/sidebandservice.py | 2 ++ sbapp/sideband/core.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sbapp/services/sidebandservice.py b/sbapp/services/sidebandservice.py index f7d84c3..479e40a 100644 --- a/sbapp/services/sidebandservice.py +++ b/sbapp/services/sidebandservice.py @@ -194,6 +194,7 @@ class SidebandService(): def take_locks(self, force_multicast=False): if RNS.vendor.platformutils.get_platform() == "android": if self.multicast_lock == None or force_multicast: + RNS.log("Creating multicast lock", RNS.LOG_DEBUG) self.multicast_lock = self.wifi_manager.createMulticastLock("sideband_service") if not self.multicast_lock.isHeld(): @@ -203,6 +204,7 @@ class SidebandService(): RNS.log("Multicast lock already held", RNS.LOG_DEBUG) if self.wake_lock == None: + RNS.log("Creating wake lock", RNS.LOG_DEBUG) self.wake_lock = self.power_manager.newWakeLock(self.power_manager.PARTIAL_WAKE_LOCK, "sideband_service") if not self.wake_lock.isHeld(): diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 6de2e06..8c496e4 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -2377,10 +2377,22 @@ class SidebandCore(): def _service_jobs(self): if self.is_service: last_usb_discovery = time.time() + last_multicast_lock_check = time.time() while True: time.sleep(SidebandCore.SERVICE_JOB_INTERVAL) now = time.time() + 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 + last_multicast_lock_check = now + + if (now - last_multicast_lock_check > 120): + RNS.log("Checking multicast and wake locks", RNS.LOG_DEBUG) + self.owner_service.take_locks() + last_multicast_lock_check = now + announce_wanted = self.getstate("wants.announce") announce_attached_interface = None announce_delay = 0 @@ -2392,10 +2404,6 @@ 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: