2022-09-17 16:00:55 +02:00
|
|
|
import time
|
2022-09-20 17:28:39 +02:00
|
|
|
import RNS
|
|
|
|
from sideband.core import SidebandCore
|
|
|
|
from os import environ
|
|
|
|
from jnius import autoclass, cast
|
|
|
|
|
|
|
|
Context = autoclass('android.content.Context')
|
2022-09-17 16:00:55 +02:00
|
|
|
|
|
|
|
class sidebandservice():
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-09-20 17:28:39 +02:00
|
|
|
self.argument = environ.get('PYTHON_SERVICE_ARGUMENT', '')
|
|
|
|
self.multicast_lock = None
|
|
|
|
self.wake_lock = None
|
|
|
|
|
|
|
|
self.service = autoclass('org.kivy.android.PythonService').mService
|
|
|
|
self.app_context = self.service.getApplication().getApplicationContext()
|
|
|
|
self.wifi_manager = self.app_context.getSystemService(Context.WIFI_SERVICE)
|
|
|
|
# The returned instance is an android.net.wifi.WifiManager
|
|
|
|
|
2022-09-17 16:00:55 +02:00
|
|
|
print("Sideband Service created")
|
2022-09-20 17:28:39 +02:00
|
|
|
self.take_locks()
|
2022-09-17 16:00:55 +02:00
|
|
|
self.run()
|
|
|
|
|
2022-09-20 17:28:39 +02:00
|
|
|
def take_locks(self):
|
|
|
|
if self.multicast_lock == None:
|
|
|
|
self.multicast_lock = self.wifi_manager.createMulticastLock("sideband_service")
|
|
|
|
|
|
|
|
if not self.multicast_lock.isHeld():
|
|
|
|
RNS.log("Taking multicast lock")
|
|
|
|
self.multicast_lock.acquire()
|
|
|
|
RNS.log("Took lock")
|
|
|
|
|
|
|
|
|
|
|
|
def release_locks():
|
|
|
|
if not self.multicast_lock == None and self.multicast_lock.isHeld():
|
|
|
|
self.multicast_lock.release()
|
|
|
|
|
2022-09-17 16:00:55 +02:00
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
print("Service ping")
|
2022-09-20 17:28:39 +02:00
|
|
|
time.sleep(5)
|
2022-09-17 16:00:55 +02:00
|
|
|
|
|
|
|
sbs = sidebandservice()
|