3b755e754e250ebd08091bea0e3381f05610f172
[fso-scripts.git] / fso-auth.py
1 #!/usr/bin/env python
2
3 import sys
4 import dbus
5 import gobject
6
7 from dbus.mainloop.glib import DBusGMainLoop
8 DBusGMainLoop(set_as_default=True)
9
10 pin = ''
11 gsm_device_iface = None
12 loop = gobject.MainLoop()
13
14 def onDeviceStatus(status):
15     print "DeviceStatus:", status
16     if status == "alive-sim-locked":
17         gsm_device_iface.SetFunctionality("full", True, pin)
18     elif status == "alive-sim-ready":
19         loop.quit()
20         
21 def fso_auth():
22     global gsm_device_iface
23     global gsm_sim_iface
24
25     bus = dbus.SystemBus()
26
27     usage_obj = bus.get_object("org.freesmartphone.ousaged", "/org/freesmartphone/Usage")
28     usage_iface = dbus.Interface(usage_obj, "org.freesmartphone.Usage")
29
30     gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
31     gsm_device_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.Device")
32
33     gsm_device_iface.connect_to_signal('DeviceStatus', onDeviceStatus)
34
35     usage_iface.RequestResource("GSM")
36
37     print "starting the main loop"
38     try:
39         loop.run()
40     except KeyboardInterrupt:
41         print "Interrupted"
42         loop.quit()
43
44     gsm_device_iface.SetFunctionality("minimal", True, "")
45     usage_iface.ReleaseResource("GSM")
46
47 if __name__ == "__main__":
48
49     if len(sys.argv) != 2:
50         sys.stderr.write("usage: %s <pin>\n")
51         sys.exit(1)
52
53     pin = sys.argv[1]
54     fso_auth()