1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
#!/usr/bin/python
import gobject
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
class GoBack(dbus.DBusException):
_dbus_error_name = "org.ofono.Error.GoBack"
class EndSession(dbus.DBusException):
_dbus_error_name = "org.ofono.Error.EndSession"
class Busy(dbus.DBusException):
_dbus_error_name = "org.ofono.Error.Busy"
class StkAgent(dbus.service.Object):
exit_on_release = True
def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="", out_signature="")
def Release(self):
print "Release"
if self.exit_on_release:
mainloop.quit()
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sya(sy)n", out_signature="y")
def RequestSelection(self, title, icon, items, default):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
index = 0;
for item in items:
print "%d. %s (icon: %d)" % (index, item[0], item[1])
index += 1
print "\nDefault: %d" % (default)
select = raw_input("Enter Selection (t, b):")
if select == 'b':
raise GoBack("User wishes to go back")
elif select == 't':
raise EndSession("User wishes to terminate session")
else:
return int(select);
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="syb", out_signature="")
def DisplayText(self, title, icon, urgent):
print "DisplayText (%s)" % (title)
print "Icon: (%d)" % (icon)
print "Urgent: (%d)" % (urgent)
key = raw_input("Press return to clear ('t' terminates, "
"'b' goes back, 'n' busy):")
if key == 'b':
raise GoBack("User wishes to go back")
elif key == 't':
raise EndSession("User wishes to terminate session")
elif key == 'n':
raise Busy("User wishes to simulate busy screen")
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sysyyb", out_signature="s")
def RequestInput(self, title, icon, default, min_chars, max_chars,
hide_typing):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
print "Default: (%s)" % (default)
print "Hide typing: (%s)" % (hide_typing)
print "Enter characters, min: %d, max: %d:" % (min_chars,
max_chars)
userin = raw_input("");
return userin
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sysyyb", out_signature="s")
def RequestDigits(self, title, icon, default, min_chars, max_chars,
hide_typing):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
print "Default: (%s)" % (default)
print "Hide typing: (%s)" % (hide_typing)
print "Enter digits, min: %d, max: %d:" % (min_chars,
max_chars)
userin = raw_input("'t' terminates, 'b' goes back:");
if userin == 'b':
raise GoBack("User wishes to go back")
elif userin == 't':
raise EndSession("User wishes to terminate session")
else:
return userin
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="s")
def RequestKey(self, title, icon):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
key = raw_input("Enter Key (t, b):")
if key == 'b':
raise GoBack("User wishes to go back");
elif key == 't':
raise EndSession("User wishes to terminate session");
else:
return key
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="s")
def RequestDigit(self, title, icon):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
key = raw_input("Enter Digit (t, b):")
if key == 'b':
raise GoBack("User wishes to go back");
elif key == 't':
raise EndSession("User wishes to terminate session");
else:
return key
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="b")
def RequestConfirmation(self, title, icon):
print "Title: (%s)" % (title)
print "Icon: (%d)" % (icon)
key = raw_input("Enter Confirmation (t, b, y, n):")
if key == 'b':
raise GoBack("User wishes to go back");
elif key == 't':
raise EndSession("User wishes to terminate session");
elif key == 'y':
return True
else:
return False
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="b")
def ConfirmCallSetup(self, info, icon):
print "Information: (%s)" % (info)
print "Icon: (%d)" % (icon)
key = raw_input("Enter Confirmation (t, y, n):")
if key == 't':
raise EndSession("User wishes to terminate session");
elif key == 'y':
return True
else:
return False
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sys", out_signature="b")
def ConfirmLaunchBrowser(self, info, icon, url):
print "Information: (%s)" % (info)
print "Icon: (%d)" % (icon)
print "URL (%s)" % (url)
key = raw_input("Enter Confirmation (y, n):")
if key == 'y':
return True
else:
return False
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="", out_signature="")
def Cancel(self):
print "Cancel"
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="ssy", out_signature="")
def PlayTone(self, tone, text, icon):
print "PlayTone: %s" % (tone)
print "Text: %s" % (text)
print "Icon: %d" % (icon)
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="ssy", out_signature="")
def LoopTone(self, tone, text, icon):
print "LoopTone: %s" % (tone)
print "Text: %s" % (text)
print "Icon: %d" % (icon)
key = raw_input("Press return to end before timeout (t):")
if key == 't':
raise EndSession("User wishes to terminate session");
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="")
def DisplayActionInformation(self, text, icon):
print "Text: %s" % (text)
print "Icon: %d" % (icon)
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="")
def DisplayAction(self, text, icon):
print "Text: (%s)" % (text)
print "Icon: (%d)" % (icon)
key = raw_input("Press 't' to terminate the session ")
if key == 't':
raise EndSession("User wishes to terminate session")
@dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="sy", out_signature="b")
def ConfirmOpenChannel(self, info, icon):
print "Open channel confirmation: (%s)" % (info)
print "Icon: (%d)" % (icon)
key = raw_input("Enter Confirmation (t, y, n):")
if key == 't':
raise EndSession("User wishes to terminate session");
elif key == 'y':
return True
else:
return False
def property_changed(name, value):
print "SimToolKit property: %s changed to '%s'" % (name, value)
if __name__ == '__main__':
if len(sys.argv) == 2:
mode = sys.argv[1]
else:
mode = 'menu'
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.ofono", "/"),
"org.ofono.Manager")
modems = manager.GetModems()
for path, properties in modems:
if "org.ofono.SimToolkit" not in properties["Interfaces"]:
continue
stk = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.SimToolkit')
stk.connect_to_signal("PropertyChanged", property_changed)
properties = stk.GetProperties()
if mode == 'menu':
if "MainMenuTitle" in properties:
print "Main Menu:"
print "%s" % (properties["MainMenuTitle"])
print "\n"
if "MainMenu" in properties:
print "Items:"
index = 0
for item in properties["MainMenu"]:
print "%d. %s" % (index, item[0])
index += 1
path = "/test/agent"
agent = StkAgent(bus, path)
select = int(raw_input("Enter Selection: "))
stk.SelectItem(select, path)
elif mode == 'agent':
path = "/test/agent"
agent = StkAgent(bus, path)
stk.RegisterAgent(path)
print "Default Agent registered - Waiting for STK command..."
else:
print "%s [menu|agent]" % (sys.argv[0])
exit(0)
mainloop = gobject.MainLoop()
mainloop.run()
|