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 def set_exit_on_release(self, exit_on_release):
27 self.exit_on_release = exit_on_release
29 @dbus.service.method("org.ofono.SimToolkitAgent",
30 in_signature="", out_signature="")
33 if self.exit_on_release:
36 @dbus.service.method("org.ofono.SimToolkitAgent",
37 in_signature="sya(sy)n", out_signature="y")
38 def RequestSelection(self, title, icon, items, default):
39 print "Title: (%s)" % (title)
40 print "Icon: (%d)" % (icon)
43 print "%d. %s (icon: %d)" % (index, item[0], item[1])
46 print "\nDefault: %d" % (default)
47 select = raw_input("Enter Selection (t, b):")
50 raise GoBack("User wishes to go back")
52 raise EndSession("User wishes to terminate session")
56 @dbus.service.method("org.ofono.SimToolkitAgent",
57 in_signature="syb", out_signature="")
58 def DisplayText(self, title, icon, urgent):
59 print "DisplayText (%s)" % (title)
60 print "Icon: (%d)" % (icon)
61 print "Urgent: (%d)" % (urgent)
62 key = raw_input("Press return to clear ('t' terminates, "
63 "'b' goes back, 'n' busy):")
66 raise GoBack("User wishes to go back")
68 raise EndSession("User wishes to terminate session")
70 raise Busy("User wishes to simulate busy screen")
72 @dbus.service.method("org.ofono.SimToolkitAgent",
73 in_signature="sysyyb", out_signature="s")
74 def RequestInput(self, title, icon, default, min_chars, max_chars,
76 print "Title: (%s)" % (title)
77 print "Icon: (%d)" % (icon)
78 print "Default: (%s)" % (default)
79 print "Hide typing: (%s)" % (hide_typing)
80 print "Enter characters, min: %d, max: %d:" % (min_chars,
82 userin = raw_input("");
86 @dbus.service.method("org.ofono.SimToolkitAgent",
87 in_signature="sysyyb", out_signature="s")
88 def RequestDigits(self, title, icon, default, min_chars, max_chars,
90 print "Title: (%s)" % (title)
91 print "Icon: (%d)" % (icon)
92 print "Default: (%s)" % (default)
93 print "Hide typing: (%s)" % (hide_typing)
94 print "Enter digits, min: %d, max: %d:" % (min_chars,
96 userin = raw_input("'t' terminates, 'b' goes back:");
99 raise GoBack("User wishes to go back")
101 raise EndSession("User wishes to terminate session")
105 @dbus.service.method("org.ofono.SimToolkitAgent",
106 in_signature="sy", out_signature="s")
107 def RequestKey(self, title, icon):
108 print "Title: (%s)" % (title)
109 print "Icon: (%d)" % (icon)
110 key = raw_input("Enter Key (t, b):")
113 raise GoBack("User wishes to go back");
115 raise EndSession("User wishes to terminate session");
119 @dbus.service.method("org.ofono.SimToolkitAgent",
120 in_signature="sy", out_signature="s")
121 def RequestDigit(self, title, icon):
122 print "Title: (%s)" % (title)
123 print "Icon: (%d)" % (icon)
124 key = raw_input("Enter Digit (t, b):")
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 RequestQuickDigit(self, title, icon):
136 print "Title: (%s)" % (title)
137 print "Icon: (%d)" % (icon)
138 key = raw_input("Quick digit (0-9, *, #, 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="b")
149 def RequestConfirmation(self, title, icon):
150 print "Title: (%s)" % (title)
151 print "Icon: (%d)" % (icon)
152 key = raw_input("Enter Confirmation (t, b, y, n):")
155 raise GoBack("User wishes to go back");
157 raise EndSession("User wishes to terminate session");
163 @dbus.service.method("org.ofono.SimToolkitAgent",
164 in_signature="sy", out_signature="b")
165 def ConfirmCallSetup(self, info, icon):
166 print "Information: (%s)" % (info)
167 print "Icon: (%d)" % (icon)
168 key = raw_input("Enter Confirmation (t, y, n):")
171 raise EndSession("User wishes to terminate session");
177 @dbus.service.method("org.ofono.SimToolkitAgent",
178 in_signature="sys", out_signature="b")
179 def ConfirmLaunchBrowser(self, info, icon, url):
180 print "Information: (%s)" % (info)
181 print "Icon: (%d)" % (icon)
182 print "URL (%s)" % (url)
183 key = raw_input("Enter Confirmation (y, n):")
190 @dbus.service.method("org.ofono.SimToolkitAgent",
191 in_signature="", out_signature="")
195 @dbus.service.method("org.ofono.SimToolkitAgent",
196 in_signature="ssy", out_signature="")
197 def PlayTone(self, tone, text, icon):
198 print "PlayTone: %s" % (tone)
199 print "Text: %s" % (text)
200 print "Icon: %d" % (icon)
202 signal.signal(signal.SIGALRM, handler)
206 key = raw_input("Press return to end before end of"
211 raise EndSession("User wishes to terminate"
213 except Exception, exc:
216 @dbus.service.method("org.ofono.SimToolkitAgent",
217 in_signature="ssy", out_signature="")
218 def LoopTone(self, tone, text, icon):
219 print "LoopTone: %s" % (tone)
220 print "Text: %s" % (text)
221 print "Icon: %d" % (icon)
222 key = raw_input("Press return to end before timeout (t):")
225 raise EndSession("User wishes to terminate session");
227 @dbus.service.method("org.ofono.SimToolkitAgent",
228 in_signature="sy", out_signature="")
229 def DisplayActionInformation(self, text, icon):
230 print "Text: %s" % (text)
231 print "Icon: %d" % (icon)
233 @dbus.service.method("org.ofono.SimToolkitAgent",
234 in_signature="sy", out_signature="")
235 def DisplayAction(self, text, icon):
236 print "Text: (%s)" % (text)
237 print "Icon: (%d)" % (icon)
238 key = raw_input("Press 't' to terminate the session ")
241 raise EndSession("User wishes to terminate session")
243 @dbus.service.method("org.ofono.SimToolkitAgent",
244 in_signature="sy", out_signature="b")
245 def ConfirmOpenChannel(self, info, icon):
246 print "Open channel confirmation: (%s)" % (info)
247 print "Icon: (%d)" % (icon)
248 key = raw_input("Enter Confirmation (t, y, n):")
251 raise EndSession("User wishes to terminate session");
257 def property_changed(name, value):
258 print "SimToolKit property: %s changed to '%s'" % (name, value)
260 if __name__ == '__main__':
261 if len(sys.argv) == 2:
266 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
268 bus = dbus.SystemBus()
269 manager = dbus.Interface(bus.get_object("org.ofono", "/"),
272 modems = manager.GetModems()
274 for path, properties in modems:
275 if "org.ofono.SimToolkit" not in properties["Interfaces"]:
278 stk = dbus.Interface(bus.get_object('org.ofono', path),
279 'org.ofono.SimToolkit')
281 stk.connect_to_signal("PropertyChanged", property_changed)
283 properties = stk.GetProperties()
286 if "MainMenuTitle" in properties:
288 print "%s" % (properties["MainMenuTitle"])
291 if "MainMenu" in properties:
294 for item in properties["MainMenu"]:
295 print "%d. %s" % (index, item[0])
299 agent = StkAgent(bus, path)
301 select = int(raw_input("Enter Selection: "))
302 stk.SelectItem(select, path)
303 elif mode == 'agent':
305 agent = StkAgent(bus, path)
307 stk.RegisterAgent(path)
309 print "Default Agent registered - Waiting for STK command..."
311 print "%s [menu|agent]" % (sys.argv[0])
314 mainloop = gobject.MainLoop()