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)" % (int(icon)))
56 print("%d. %s (icon: %d)" %
57 (index, item[0], int(item[1])))
60 print("\nDefault: %d" % (default))
61 select = input("Enter Selection (t, b):")
64 raise GoBack("User wishes to go back")
66 raise EndSession("User wishes to terminate session")
70 @dbus.service.method("org.ofono.SimToolkitAgent",
71 in_signature="syb", out_signature="",
72 async_callbacks=("reply_func",
74 def DisplayText(self, title, icon, urgent, reply_func, error_func):
75 print("DisplayText (%s)" % (title))
76 print("Icon: (%d)" % (int(icon)))
77 print("Urgent: (%d)" % (urgent))
78 key = input("Press return to clear ('t' terminates, "
79 "'b' goes back, 'n' busy, "
80 "'w' return and wait):")
88 raise GoBack("User wishes to go back")
90 raise EndSession("User wishes to terminate session")
92 raise Busy("User wishes to simulate busy screen")
95 print("Waiting for %d seconds" % (seconds))
97 self.timeout_reply_handler = reply_func
98 self.timeout_id = GLib.timeout_add_seconds(seconds,
99 self.timeout_callback)
101 @dbus.service.method("org.ofono.SimToolkitAgent",
102 in_signature="sysyyb", out_signature="s")
103 def RequestInput(self, title, icon, default, min_chars, max_chars,
105 print("Title: (%s)" % (title))
106 print("Icon: (%d)" % (int(icon)))
107 print("Default: (%s)" % (default))
108 print("Hide typing: (%s)" % (hide_typing))
109 print("Enter characters, min: %d, max: %d:" % (min_chars,
115 @dbus.service.method("org.ofono.SimToolkitAgent",
116 in_signature="sysyyb", out_signature="s")
117 def RequestDigits(self, title, icon, default, min_chars, max_chars,
119 print("Title: (%s)" % (title))
120 print("Icon: (%d)" % (int(icon)))
121 print("Default: (%s)" % (default))
122 print("Hide typing: (%s)" % (hide_typing))
123 print("Enter digits, min: %d, max: %d:" % (min_chars,
125 userin = input("'t' terminates, 'b' goes back:")
128 raise GoBack("User wishes to go back")
130 raise EndSession("User wishes to terminate session")
134 @dbus.service.method("org.ofono.SimToolkitAgent",
135 in_signature="sy", out_signature="s")
136 def RequestKey(self, title, icon):
137 print("Title: (%s)" % (title))
138 print("Icon: (%d)" % (int(icon)))
139 key = input("Enter Key (t, b):")
142 raise GoBack("User wishes to go back")
144 raise EndSession("User wishes to terminate session")
148 @dbus.service.method("org.ofono.SimToolkitAgent",
149 in_signature="sy", out_signature="s")
150 def RequestDigit(self, title, icon):
151 print("Title: (%s)" % (title))
152 print("Icon: (%d)" % (int(icon)))
153 key = input("Enter Digit (t, b):")
156 raise GoBack("User wishes to go back")
158 raise EndSession("User wishes to terminate session")
162 @dbus.service.method("org.ofono.SimToolkitAgent",
163 in_signature="sy", out_signature="s")
164 def RequestQuickDigit(self, title, icon):
165 print("Title: (%s)" % (title))
166 print("Icon: (%d)" % (int(icon)))
167 key = input("Quick digit (0-9, *, #, t, b):")
170 raise GoBack("User wishes to go back")
172 raise EndSession("User wishes to terminate session")
176 @dbus.service.method("org.ofono.SimToolkitAgent",
177 in_signature="sy", out_signature="b")
178 def RequestConfirmation(self, title, icon):
179 print("Title: (%s)" % (title))
180 print("Icon: (%d)" % (int(icon)))
181 key = input("Enter Confirmation (t, b, y, n):")
184 raise GoBack("User wishes to go back")
186 raise EndSession("User wishes to terminate session")
192 @dbus.service.method("org.ofono.SimToolkitAgent",
193 in_signature="sy", out_signature="b")
194 def ConfirmCallSetup(self, info, icon):
195 print("Information: (%s)" % (info))
196 print("Icon: (%d)" % (int(icon)))
197 key = input("Enter Confirmation (t, y, n):")
200 raise EndSession("User wishes to terminate session")
206 @dbus.service.method("org.ofono.SimToolkitAgent",
207 in_signature="sys", out_signature="b")
208 def ConfirmLaunchBrowser(self, info, icon, url):
209 print("Information: (%s)" % (info))
210 print("Icon: (%d)" % (int(icon)))
211 print("URL (%s)" % (url))
212 key = input("Enter Confirmation (y, n):")
219 @dbus.service.method("org.ofono.SimToolkitAgent",
220 in_signature="", out_signature="")
224 @dbus.service.method("org.ofono.SimToolkitAgent",
225 in_signature="ssy", out_signature="")
226 def PlayTone(self, tone, text, icon):
227 print("PlayTone: %s" % (tone))
228 print("Text: %s" % (text))
229 print("Icon: %d" % (int(icon)))
231 signal.signal(signal.SIGALRM, handler)
235 key = input("Press return to end before end of"
240 raise EndSession("User wishes to terminate"
242 except Exception as exc:
245 @dbus.service.method("org.ofono.SimToolkitAgent",
246 in_signature="ssy", out_signature="",
247 async_callbacks=("reply_func",
249 def LoopTone(self, tone, text, icon, reply_func, error_func):
250 print("LoopTone: %s" % (tone))
251 print("Text: %s" % (text))
252 print("Icon: %d" % (int(icon)))
253 key = input("Press return to end before timeout "
254 "('t' terminates, 'w' return and wait):")
262 raise EndSession("User wishes to terminate session")
265 print("Waiting for %d seconds" % (seconds))
267 self.timeout_reply_handler = reply_func
268 self.timeout_id = GLib.timeout_add_seconds(seconds,
269 self.timeout_callback)
271 @dbus.service.method("org.ofono.SimToolkitAgent",
272 in_signature="sy", out_signature="")
273 def DisplayActionInformation(self, text, icon):
274 print("Text: %s" % (text))
275 print("Icon: %d" % (int(icon)))
277 @dbus.service.method("org.ofono.SimToolkitAgent",
278 in_signature="sy", out_signature="")
279 def DisplayAction(self, text, icon):
280 print("Text: (%s)" % (text))
281 print("Icon: (%d)" % (int(icon)))
282 key = input("Press 't' to terminate the session ")
285 raise EndSession("User wishes to terminate session")
287 @dbus.service.method("org.ofono.SimToolkitAgent",
288 in_signature="sy", out_signature="b")
289 def ConfirmOpenChannel(self, info, icon):
290 print("Open channel confirmation: (%s)" % (info))
291 print("Icon: (%d)" % (int(icon)))
292 key = input("Enter Confirmation (t, y, n):")
295 raise EndSession("User wishes to terminate session")
311 dbus.ByteArray : str,
312 dbus.ObjectPath : str
318 return _dbus2py[t](d)
319 if t is dbus.Dictionary:
320 return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
321 if t is dbus.Array and d.signature == "y":
322 return "".join([chr(b) for b in d])
323 if t is dbus.Array or t is list:
324 return [dbus2py(v) for v in d]
325 if t is dbus.Struct or t is tuple:
326 return tuple([dbus2py(v) for v in d])
333 if t in (dict, tuple, list) and len(d) > 0:
335 d = ", ".join(["%s = %s" % (k, pretty(v))
336 for k, v in d.items()])
339 d = " ".join([pretty(e) for e in d])
349 def property_changed(name, value):
350 print("SimToolKit property: %s changed to '%s'" % (name, pretty(value)))
352 if __name__ == '__main__':
353 if len(sys.argv) == 2:
358 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
360 bus = dbus.SystemBus()
361 manager = dbus.Interface(bus.get_object("org.ofono", "/"),
364 modems = manager.GetModems()
366 for path, properties in modems:
367 if "org.ofono.SimToolkit" in properties["Interfaces"]:
368 stk = dbus.Interface(bus.get_object('org.ofono', path),
369 'org.ofono.SimToolkit')
370 if "org.ofono.VoiceCallManager" in properties["Interfaces"]:
371 vcm = dbus.Interface(bus.get_object('org.ofono', path),
372 'org.ofono.VoiceCallManager')
374 stk.connect_to_signal("PropertyChanged", property_changed)
376 properties = stk.GetProperties()
379 if "MainMenuTitle" in properties:
381 print("%s" % (properties["MainMenuTitle"]))
384 if "MainMenu" in properties:
387 for item in properties["MainMenu"]:
388 print("%d. %s" % (index, item[0]))
392 agent = StkAgent(bus, path)
395 vcm.connect_to_signal("CallAdded", agent.call_added)
399 select = int(input("Enter Selection: "))
400 stk.SelectItem(select, path)
401 elif mode == 'agent':
403 agent = StkAgent(bus, path)
406 vcm.connect_to_signal("CallAdded", agent.call_added)
410 stk.RegisterAgent(path)
412 print("Default Agent registered - Waiting for STK command...")
414 print("%s [menu|agent]" % (sys.argv[0]))
417 mainloop = GLib.MainLoop()