2017-12-15 00:02:45 +01:00
|
|
|
import dbus
|
2020-09-11 01:12:26 +02:00
|
|
|
import time
|
2017-12-15 00:02:45 +01:00
|
|
|
from gi.repository import GLib
|
2020-11-17 21:53:02 +01:00
|
|
|
from config import ctx
|
2017-12-15 00:02:45 +01:00
|
|
|
|
|
|
|
SIM_AUTH_IFACE = 'org.ofono.SimAuthentication'
|
|
|
|
|
|
|
|
class Ofono(dbus.service.Object):
|
2020-11-17 21:53:02 +01:00
|
|
|
def __init__(self, namespace=ctx):
|
|
|
|
self._bus = namespace.get_bus()
|
2017-12-15 00:02:45 +01:00
|
|
|
|
2021-08-13 18:24:37 +02:00
|
|
|
ctx.non_block_wait(self._bus.name_has_owner, 10, 'org.ofono',
|
|
|
|
exception=TimeoutError('Waiting for org.ofono service timed out'))
|
2020-09-11 01:12:26 +02:00
|
|
|
|
2017-12-15 00:02:45 +01:00
|
|
|
def enable_modem(self, path):
|
|
|
|
self._modem_path = path
|
|
|
|
self._modem_iface = dbus.Interface(
|
|
|
|
self._bus.get_object('org.ofono', path),
|
|
|
|
'org.ofono.Modem')
|
|
|
|
self._modem_iface.SetProperty("Powered", dbus.Boolean(1),
|
|
|
|
timeout = 120)
|
|
|
|
|
|
|
|
def _modem_prop_changed(self, property, changed):
|
|
|
|
if property == 'Interfaces':
|
|
|
|
if SIM_AUTH_IFACE in changed:
|
|
|
|
self._sim_auth_up = True
|
|
|
|
|
|
|
|
def wait_for_sim_auth(self, max_wait = 15):
|
|
|
|
self._sim_auth_up = False
|
|
|
|
|
|
|
|
props = self._modem_iface.GetProperties()
|
|
|
|
if SIM_AUTH_IFACE in props['Interfaces']:
|
|
|
|
self._sim_auth_up = True
|
|
|
|
return
|
|
|
|
|
|
|
|
self._modem_iface.connect_to_signal('PropertyChanged',
|
|
|
|
self._modem_prop_changed)
|
|
|
|
|
2021-08-13 18:24:37 +02:00
|
|
|
ctx.non_block_wait(lambda s : s._sim_auth_up, max_wait, self,
|
|
|
|
exception=TimeoutError('waiting for SimAuthetication timed out'))
|