summaryrefslogtreecommitdiffstats
path: root/test/test-ussd
blob: 79dd59643d60b0d68b3d3b42155f90450eb7577a (plain)
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
#!/usr/bin/python

import sys
import gobject

import dbus
import dbus.mainloop.glib

def ussd_notification_received(content):
	print("Network sent a Notification: " + content)

def ussd_request_received(content):
	print("Network sent a Request: " + content)
	ss.Cancel()

def ussd_property_changed(name, value):
	if name != "State":
		return
	print("USSD session state is " + value)

if __name__ == "__main__":
	if (len(sys.argv) < 2):
		print "Useage: %s <ussd-string>" % (sys.argv[0])
		sys.exit(1)

	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

	bus = dbus.SystemBus()

	manager = dbus.Interface(bus.get_object('org.ofono', '/'),
							'org.ofono.Manager')

	try:
		modems = manager.GetProperties()['Modems']
	except dbus.DBusException, e:
		print "Unable to get the Modems property %s" % e

	ss = dbus.Interface(bus.get_object('org.ofono', modems[0]),
							'org.ofono.SupplementaryServices')

	props = ss.GetProperties()
	for p in props:
		ussd_property_changed(p, props[p])

	ss.connect_to_signal("NotificationReceived", ussd_notification_received)
	ss.connect_to_signal("RequestReceived", ussd_request_received)
	ss.connect_to_signal("PropertyChanged", ussd_property_changed)

	print ss.Initiate(sys.argv[1], timeout=100)

	mainloop = gobject.MainLoop()
	mainloop.run()