smsutil: Fix warning
[platform/upstream/ofono.git] / test / test-stk-menu
1 #!/usr/bin/python
2
3 import gobject
4
5 import sys
6 import dbus
7 import dbus.service
8 import dbus.mainloop.glib
9 import signal
10
11 def handler(signum, frame):
12         raise Exception("\nSingle tone is finished!")
13
14 class GoBack(dbus.DBusException):
15         _dbus_error_name = "org.ofono.Error.GoBack"
16
17 class EndSession(dbus.DBusException):
18         _dbus_error_name = "org.ofono.Error.EndSession"
19
20 class Busy(dbus.DBusException):
21         _dbus_error_name = "org.ofono.Error.Busy"
22
23 class StkAgent(dbus.service.Object):
24         exit_on_release = True
25
26         def set_exit_on_release(self, exit_on_release):
27                 self.exit_on_release = exit_on_release
28
29         @dbus.service.method("org.ofono.SimToolkitAgent",
30                                         in_signature="", out_signature="")
31         def Release(self):
32                 print "Release"
33                 if self.exit_on_release:
34                         mainloop.quit()
35
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)
41                 index = 0;
42                 for item in items:
43                         print "%d. %s (icon: %d)" % (index, item[0], item[1])
44                         index += 1
45
46                 print "\nDefault: %d" % (default)
47                 select = raw_input("Enter Selection (t, b):")
48
49                 if select == 'b':
50                         raise GoBack("User wishes to go back")
51                 elif select == 't':
52                         raise EndSession("User wishes to terminate session")
53                 else:
54                         return int(select);
55
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):")
64
65                 if key == 'b':
66                         raise GoBack("User wishes to go back")
67                 elif key == 't':
68                         raise EndSession("User wishes to terminate session")
69                 elif key == 'n':
70                         raise Busy("User wishes to simulate busy screen")
71
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,
75                                 hide_typing):
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,
81                                                                 max_chars)
82                 userin = raw_input("");
83
84                 return userin
85
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,
89                                 hide_typing):
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,
95                                                                 max_chars)
96                 userin = raw_input("'t' terminates, 'b' goes back:");
97
98                 if userin == 'b':
99                         raise GoBack("User wishes to go back")
100                 elif userin == 't':
101                         raise EndSession("User wishes to terminate session")
102                 else:
103                         return userin
104
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):")
111
112                 if key == 'b':
113                         raise GoBack("User wishes to go back");
114                 elif key == 't':
115                         raise EndSession("User wishes to terminate session");
116                 else:
117                         return key
118
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):")
125
126                 if key == 'b':
127                         raise GoBack("User wishes to go back");
128                 elif key == 't':
129                         raise EndSession("User wishes to terminate session");
130                 else:
131                         return key
132
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):")
139
140                 if key == 'b':
141                         raise GoBack("User wishes to go back");
142                 elif key == 't':
143                         raise EndSession("User wishes to terminate session");
144                 else:
145                         return key
146
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):")
153
154                 if key == 'b':
155                         raise GoBack("User wishes to go back");
156                 elif key == 't':
157                         raise EndSession("User wishes to terminate session");
158                 elif key == 'y':
159                         return True
160                 else:
161                         return False
162
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):")
169
170                 if key == 't':
171                         raise EndSession("User wishes to terminate session");
172                 elif key == 'y':
173                         return True
174                 else:
175                         return False
176
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):")
184
185                 if key == 'y':
186                         return True
187                 else:
188                         return False
189
190         @dbus.service.method("org.ofono.SimToolkitAgent",
191                                         in_signature="", out_signature="")
192         def Cancel(self):
193                 print "Cancel"
194
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)
201
202                 signal.signal(signal.SIGALRM, handler)
203                 signal.alarm(5)
204
205                 try:
206                         key = raw_input("Press return to end before end of"
207                                                          " single tone (t):")
208                         signal.alarm(0)
209
210                         if key == 't':
211                                 raise EndSession("User wishes to terminate"
212                                                                  " session");
213                 except Exception, exc:
214                         print exc
215
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):")
223
224                 if key == 't':
225                         raise EndSession("User wishes to terminate session");
226
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)
232
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 ")
239
240                 if key == 't':
241                         raise EndSession("User wishes to terminate session")
242
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):")
249
250                 if key == 't':
251                         raise EndSession("User wishes to terminate session");
252                 elif key == 'y':
253                         return True
254                 else:
255                         return False
256
257 def property_changed(name, value):
258         print "SimToolKit property: %s changed to '%s'" % (name, value)
259
260 if __name__ == '__main__':
261         if len(sys.argv) == 2:
262                 mode = sys.argv[1]
263         else:
264                 mode = 'menu'
265
266         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
267
268         bus = dbus.SystemBus()
269         manager = dbus.Interface(bus.get_object("org.ofono", "/"),
270                                                         "org.ofono.Manager")
271
272         modems = manager.GetModems()
273
274         for path, properties in modems:
275                 if "org.ofono.SimToolkit" not in properties["Interfaces"]:
276                         continue
277
278                 stk = dbus.Interface(bus.get_object('org.ofono', path),
279                                         'org.ofono.SimToolkit')
280
281         stk.connect_to_signal("PropertyChanged", property_changed)
282
283         properties = stk.GetProperties()
284
285         if mode == 'menu':
286                 if "MainMenuTitle" in properties:
287                         print "Main Menu:"
288                         print "%s" % (properties["MainMenuTitle"])
289                         print "\n"
290
291                 if "MainMenu" in properties:
292                         print "Items:"
293                         index = 0
294                         for item in properties["MainMenu"]:
295                                 print "%d. %s" % (index, item[0])
296                                 index += 1
297
298                 path = "/test/agent"
299                 agent = StkAgent(bus, path)
300
301                 select = int(raw_input("Enter Selection: "))
302                 stk.SelectItem(select, path)
303         elif mode == 'agent':
304                 path = "/test/agent"
305                 agent = StkAgent(bus, path)
306
307                 stk.RegisterAgent(path)
308
309                 print "Default Agent registered - Waiting for STK command..."
310         else:
311                 print "%s [menu|agent]" % (sys.argv[0])
312                 exit(0)
313
314         mainloop = gobject.MainLoop()
315         mainloop.run()