3 from gi.repository import GLib
8 import dbus.mainloop.glib
11 def handler(signum, frame):
12 raise Exception("\nSingle tone is finished!")
14 class GoBack(dbus.DBusException):
15 _dbus_error_name = "org.ofono.Error.GoBack"
17 class EndSession(dbus.DBusException):
18 _dbus_error_name = "org.ofono.Error.EndSession"
20 class Busy(dbus.DBusException):
21 _dbus_error_name = "org.ofono.Error.Busy"
23 class StkAgent(dbus.service.Object):
24 exit_on_release = True
26 timeout_reply_handler = None
28 def set_exit_on_release(self, exit_on_release):
29 self.exit_on_release = exit_on_release
31 def timeout_callback(self):
33 self.timeout_reply_handler()
36 def call_added(self, path, properties):
37 print("call added %s" % (path))
38 if (self.timeout_id > 0):
39 GLib.source_remove(self.timeout_id)
40 self.timeout_callback()
42 @dbus.service.method("org.ofono.SimToolkitAgent",
43 in_signature="", out_signature="")
46 if self.exit_on_release:
49 @dbus.service.method("org.ofono.SimToolkitAgent",
50 in_signature="sya(sy)n", out_signature="y")
51 def RequestSelection(self, title, icon, items, default):
52 print("Title: (%s)" % (title))
53 print("Icon: (%d)" % (icon))
56 print("%d. %s (icon: %d)" % (index, item[0], item[1]))
59 print("\nDefault: %d" % (default))
60 select = input("Enter Selection (t, b):")
63 raise GoBack("User wishes to go back")
65 raise EndSession("User wishes to terminate session")
69 @dbus.service.method("org.ofono.SimToolkitAgent",
70 in_signature="syb", out_signature="",
71 async_callbacks=("reply_func",
73 def DisplayText(self, title, icon, urgent, reply_func, error_func):
74 print("DisplayText (%s)" % (title))
75 print("Icon: (%d)" % (icon))
76 print("Urgent: (%d)" % (urgent))
77 key = input("Press return to clear ('t' terminates, "
78 "'b' goes back, 'n' busy, "
79 "'w' return and wait):")
87 raise GoBack("User wishes to go back")
89 raise EndSession("User wishes to terminate session")
91 raise Busy("User wishes to simulate busy screen")
94 print("Waiting for %d seconds" % (seconds))
96 self.timeout_reply_handler = reply_func
97 self.timeout_id = GLib.timeout_add_seconds(seconds,
98 self.timeout_callback)
100 @dbus.service.method("org.ofono.SimToolkitAgent",
101 in_signature="sysyyb", out_signature="s")
102 def RequestInput(self, title, icon, default, min_chars, max_chars,
104 print("Title: (%s)" % (title))
105 print("Icon: (%d)" % (icon))
106 print("Default: (%s)" % (default))
107 print("Hide typing: (%s)" % (hide_typing))
108 print("Enter characters, min: %d, max: %d:" % (min_chars,
114 @dbus.service.method("org.ofono.SimToolkitAgent",
115 in_signature="sysyyb", out_signature="s")
116 def RequestDigits(self, title, icon, default, min_chars, max_chars,
118 print("Title: (%s)" % (title))
119 print("Icon: (%d)" % (icon))
120 print("Default: (%s)" % (default))
121 print("Hide typing: (%s)" % (hide_typing))
122 print("Enter digits, min: %d, max: %d:" % (min_chars,
124 userin = input("'t' terminates, 'b' goes back:")
127 raise GoBack("User wishes to go back")
129 raise EndSession("User wishes to terminate session")
133 @dbus.service.method("org.ofono.SimToolkitAgent",
134 in_signature="sy", out_signature="s")
135 def RequestKey(self, title, icon):
136 print("Title: (%s)" % (title))
137 print("Icon: (%d)" % (icon))
138 key = input("Enter Key (t, b):")
141 raise GoBack("User wishes to go back")
143 raise EndSession("User wishes to terminate session")
147 @dbus.service.method("org.ofono.SimToolkitAgent",
148 in_signature="sy", out_signature="s")
149 def RequestDigit(self, title, icon):
150 print("Title: (%s)" % (title))
151 print("Icon: (%d)" % (icon))
152 key = input("Enter Digit (t, b):")
155 raise GoBack("User wishes to go back")
157 raise EndSession("User wishes to terminate session")
161 @dbus.service.method("org.ofono.SimToolkitAgent",
162 in_signature="sy", out_signature="s")
163 def RequestQuickDigit(self, title, icon):
164 print("Title: (%s)" % (title))
165 print("Icon: (%d)" % (icon))
166 key = input("Quick digit (0-9, *, #, t, b):")
169 raise GoBack("User wishes to go back")
171 raise EndSession("User wishes to terminate session")
175 @dbus.service.method("org.ofono.SimToolkitAgent",
176 in_signature="sy", out_signature="b")
177 def RequestConfirmation(self, title, icon):
178 print("Title: (%s)" % (title))
179 print("Icon: (%d)" % (icon))
180 key = input("Enter Confirmation (t, b, y, n):")
183 raise GoBack("User wishes to go back")
185 raise EndSession("User wishes to terminate session")
191 @dbus.service.method("org.ofono.SimToolkitAgent",
192 in_signature="sy", out_signature="b")
193 def ConfirmCallSetup(self, info, icon):
194 print("Information: (%s)" % (info))
195 print("Icon: (%d)" % (icon))
196 key = input("Enter Confirmation (t, y, n):")
199 raise EndSession("User wishes to terminate session")
205 @dbus.service.method("org.ofono.SimToolkitAgent",
206 in_signature="sys", out_signature="b")
207 def ConfirmLaunchBrowser(self, info, icon, url):
208 print("Information: (%s)" % (info))
209 print("Icon: (%d)" % (icon))
210 print("URL (%s)" % (url))
211 key = input("Enter Confirmation (y, n):")
218 @dbus.service.method("org.ofono.SimToolkitAgent",
219 in_signature="", out_signature="")
223 @dbus.service.method("org.ofono.SimToolkitAgent",
224 in_signature="ssy", out_signature="")
225 def PlayTone(self, tone, text, icon):
226 print("PlayTone: %s" % (tone))
227 print("Text: %s" % (text))
228 print("Icon: %d" % (icon))
230 signal.signal(signal.SIGALRM, handler)
234 key = input("Press return to end before end of"
239 raise EndSession("User wishes to terminate"
241 except Exception as exc:
244 @dbus.service.method("org.ofono.SimToolkitAgent",
245 in_signature="ssy", out_signature="",
246 async_callbacks=("reply_func",
248 def LoopTone(self, tone, text, icon, reply_func, error_func):
249 print("LoopTone: %s" % (tone))
250 print("Text: %s" % (text))
251 print("Icon: %d" % (icon))
252 key = input("Press return to end before timeout "
253 "('t' terminates, 'w' return and wait):")
261 raise EndSession("User wishes to terminate session")
264 print("Waiting for %d seconds" % (seconds))
266 self.timeout_reply_handler = reply_func
267 self.timeout_id = GLib.timeout_add_seconds(seconds,
268 self.timeout_callback)
270 @dbus.service.method("org.ofono.SimToolkitAgent",
271 in_signature="sy", out_signature="")
272 def DisplayActionInformation(self, text, icon):
273 print("Text: %s" % (text))
274 print("Icon: %d" % (icon))
276 @dbus.service.method("org.ofono.SimToolkitAgent",
277 in_signature="sy", out_signature="")
278 def DisplayAction(self, text, icon):
279 print("Text: (%s)" % (text))
280 print("Icon: (%d)" % (icon))
281 key = input("Press 't' to terminate the session ")
284 raise EndSession("User wishes to terminate session")
286 @dbus.service.method("org.ofono.SimToolkitAgent",
287 in_signature="sy", out_signature="b")
288 def ConfirmOpenChannel(self, info, icon):
289 print("Open channel confirmation: (%s)" % (info))
290 print("Icon: (%d)" % (icon))
291 key = input("Enter Confirmation (t, y, n):")
294 raise EndSession("User wishes to terminate session")
310 dbus.ByteArray : str,
311 dbus.ObjectPath : str
317 return _dbus2py[t](d)
318 if t is dbus.Dictionary:
319 return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
320 if t is dbus.Array and d.signature == "y":
321 return "".join([chr(b) for b in d])
322 if t is dbus.Array or t is list:
323 return [dbus2py(v) for v in d]
324 if t is dbus.Struct or t is tuple:
325 return tuple([dbus2py(v) for v in d])
332 if t in (dict, tuple, list) and len(d) > 0:
334 d = ", ".join(["%s = %s" % (k, pretty(v))
335 for k, v in d.items()])
338 d = " ".join([pretty(e) for e in d])
348 def property_changed(name, value):
349 print("SimToolKit property: %s changed to '%s'" % (name, pretty(value)))
351 if __name__ == '__main__':
352 if len(sys.argv) == 2:
357 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
359 bus = dbus.SystemBus()
360 manager = dbus.Interface(bus.get_object("org.ofono", "/"),
363 modems = manager.GetModems()
365 for path, properties in modems:
366 if "org.ofono.SimToolkit" in properties["Interfaces"]:
367 stk = dbus.Interface(bus.get_object('org.ofono', path),
368 'org.ofono.SimToolkit')
369 if "org.ofono.VoiceCallManager" in properties["Interfaces"]:
370 vcm = dbus.Interface(bus.get_object('org.ofono', path),
371 'org.ofono.VoiceCallManager')
373 stk.connect_to_signal("PropertyChanged", property_changed)
375 properties = stk.GetProperties()
378 if "MainMenuTitle" in properties:
380 print("%s" % (properties["MainMenuTitle"]))
383 if "MainMenu" in properties:
386 for item in properties["MainMenu"]:
387 print("%d. %s" % (index, item[0]))
391 agent = StkAgent(bus, path)
394 vcm.connect_to_signal("CallAdded", agent.call_added)
398 select = int(input("Enter Selection: "))
399 stk.SelectItem(select, path)
400 elif mode == 'agent':
402 agent = StkAgent(bus, path)
405 vcm.connect_to_signal("CallAdded", agent.call_added)
409 stk.RegisterAgent(path)
411 print("Default Agent registered - Waiting for STK command...")
413 print("%s [menu|agent]" % (sys.argv[0]))
416 mainloop = GLib.MainLoop()