2022-09-17 08:00:55 -06:00
|
|
|
import time
|
2022-09-20 09:28:39 -06: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 08:00:55 -06:00
|
|
|
|
2022-09-28 05:12:14 -06:00
|
|
|
class RnsService():
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def restart(self):
|
|
|
|
self.stop()
|
|
|
|
self.start()
|
|
|
|
|
2022-09-17 08:00:55 -06:00
|
|
|
class sidebandservice():
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-09-20 09:28:39 -06: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 08:00:55 -06:00
|
|
|
print("Sideband Service created")
|
2022-09-20 09:28:39 -06:00
|
|
|
self.take_locks()
|
2022-09-17 08:00:55 -06:00
|
|
|
self.run()
|
|
|
|
|
2022-09-20 09:28:39 -06: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 08:00:55 -06:00
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
print("Service ping")
|
2022-09-20 09:28:39 -06:00
|
|
|
time.sleep(5)
|
2022-09-17 08:00:55 -06:00
|
|
|
|
|
|
|
sbs = sidebandservice()
|