Skip to content
Snippets Groups Projects
Commit 4480d9de authored by Guido Gunther's avatar Guido Gunther :zzz:
Browse files

Fix modem enablement

This got broken when switching to the ModemManager1 API. Instead
of checking the error, check state upfront.
parent 4501f4ce
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,6 @@ MM_DBUS_TIMEOUT = 5000
MM_DBUS_FLAGS = (Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS)
class ModemError(Exception):
def __init__(self, msg):
self.msg = msg
......@@ -41,6 +40,8 @@ class Modem(GObject.GObject):
MM_DBUS_INTERFACE_MODEM = 'org.freedesktop.ModemManager1.Modem'
MM_DBUS_INTERFACE_MODEM_GSM_USSD = "{}.Modem3gpp.Ussd".format(MM_DBUS_INTERFACE_MODEM)
MM_STATE_ENABLED = 6
def on_new_proxy_done(self, proxy, res, iface_name):
try:
_proxy = proxy.new_for_bus_finish(res)
......@@ -55,7 +56,7 @@ class Modem(GObject.GObject):
self._modem_proxy = None
Gio.DBusProxy.new_for_bus(Gio.BusType.SYSTEM,
MM_DBUS_FLAGS,
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
None,
MM_DBUS_SERVICE,
self.path,
......@@ -87,6 +88,11 @@ class Modem(GObject.GObject):
def ussd_proxy(self):
return self._ussd_proxy
@property
def enabled(self):
variant = self.modem_proxy.get_cached_property("State")
return variant.get_int32() >= self.MM_STATE_ENABLED
class ModemManagerProxy(GObject.GObject):
"""Interface to ModemManager DBus API
......
......@@ -88,6 +88,9 @@ class PPMController(Gtk.Application):
def fetch_balance(self):
"""Fetch the current account balance from the network"""
if not self.mm.modem.enabled:
self.view.show_modem_enable()
if not self.provider.fetch_balance(self.mm,
reply_func=self.on_balance_info_fetched,
error_func=self.on_modem_error):
......@@ -170,6 +173,11 @@ class PPMController(Gtk.Application):
"""Fetch the imsi and deduce account and provider information"""
logging.debug("Fetching account information")
if not self.mm.modem.enabled:
self.view.show_modem_enable()
return False
try:
self.imsi = self.mm.get_imsi()
except ModemError as me:
......@@ -177,12 +185,8 @@ class PPMController(Gtk.Application):
if me.is_forbidden():
self.view.show_provider_assistant()
return False
if not me.is_disabled():
self.view.show_modem_error(me.msg)
return False
logging.info("modem not enabled.")
self.view.show_modem_enable()
self.view.show_modem_error(me.msg)
return False
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment