summaryrefslogtreecommitdiffstats
path: root/test/test-call-barring
blob: d32da7f9f7cf6334246fdfb682867f54c3fa45d8 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python

import gobject
import sys
import dbus
import dbus.mainloop.glib


def property_changed(name, value):
	print "CallBarring property: '%s' changed to '%s'" % (name, str(value))
	if canexit:
		mainloop.quit()

def print_useage(s):
	print "Usage: %s <property> <newvalue> <password>" % (s)
	print "Usage: %s disableall <password>" % (s)
	sys.exit(1);

if __name__ == "__main__":
	if len(sys.argv) != 3 and len(sys.argv) != 4:
		print_useage(sys.argv[0])

	if (sys.argv[1] == 'disableall'):
		pin = sys.argv[2]
	else:
		if (len(sys.argv) != 4):
			print_useage(sys.argv[0])
		property = sys.argv[1]
		newvalue = sys.argv[2]
		pin = sys.argv[3]

	canexit = False

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

	bus = dbus.SystemBus()

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

	modems = manager.GetProperties()['Modems']

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

	cb.connect_to_signal("PropertyChanged", property_changed)

	properties = cb.GetProperties()

	print "Barring settings for Incoming Voice calls: %s" %\
		(properties['VoiceIncoming'])
	print "Barring settings for Outgoing Calls: %s" %\
		(properties['VoiceOutgoing'])

	if (sys.argv[1] == 'disableall'):
		print "Disabling all barrings"
		try:
			cb.DisableAll(pin)
		except dbus.DBusException, e:
			print "Unable to Disable All barrings: ", e
			sys.exit(1)
	else:
		try:
			cb.SetProperty(property, newvalue, pin)
		except dbus.DBusException, e:
			print "Unable to set property: ", e
			sys.exit(1)

	canexit = True

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