Initialize Tizen 2.3
[framework/connectivity/bluez.git] / mobile / test / test-telephony
1 #!/usr/bin/python
2
3 from __future__ import absolute_import, print_function, unicode_literals
4
5 import sys
6 import dbus
7 from optparse import OptionParser, make_option
8
9 bus = dbus.SystemBus()
10
11 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
12
13 option_list = [
14                 make_option("-i", "--device", action="store",
15                                 type="string", dest="dev_id"),
16                 ]
17 parser = OptionParser(option_list=option_list)
18
19 (options, args) = parser.parse_args()
20
21 if options.dev_id:
22         adapter_path = manager.FindAdapter(options.dev_id)
23 else:
24         adapter_path = manager.DefaultAdapter()
25
26 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
27                                                         "org.bluez.Adapter")
28
29 test = dbus.Interface(bus.get_object("org.bluez", "/org/bluez/test"),
30                         "org.bluez.TelephonyTest")
31
32 if len(args) < 1:
33         print("""Usage: %s <command>
34
35         connect <bdaddr>
36         disconnect <bdaddr>
37         outgoing <number>
38         incoming <number>
39         cancel
40         signal <level>
41         battery <level>
42         roaming <yes|no>
43         registration <status>
44         subscriber <number>
45         speakergain <bdaddr> [level]
46         microphonegain <bdaddr> [level]
47         play <bdaddr>
48         stop <bdaddr>
49         """ % sys.argv[0])
50         sys.exit(1)
51
52 if args[0] == "connect":
53         if len(args) < 2:
54                 print("Need device address parameter")
55                 sys.exit(1)
56         device = adapter.FindDevice(args[1])
57         headset = dbus.Interface(bus.get_object("org.bluez", device),
58                                         "org.bluez.Headset")
59         headset.Connect()
60         sys.exit(0)
61
62 if args[0] == "disconnect":
63         if len(args) < 2:
64                 print("Need device address parameter")
65                 sys.exit(1)
66         device = adapter.FindDevice(args[1])
67         headset = dbus.Interface(bus.get_object("org.bluez", device),
68                                         "org.bluez.Headset")
69         headset.Disconnect()
70         sys.exit(0)
71
72 if args[0] == "speakergain":
73         if len(args) < 2:
74                 print("Need device address parameter")
75                 sys.exit(1)
76         device = adapter.FindDevice(args[1])
77         headset = dbus.Interface(bus.get_object("org.bluez", device),
78                                         "org.bluez.Headset")
79         if len(args) > 2:
80                 headset.SetProperty('SpeakerGain', dbus.UInt16(args[2]))
81         else:
82                 props = headset.GetProperties()
83                 print(props['SpeakerGain'])
84
85         sys.exit(0)
86
87 if args[0] == "microphonegain":
88         if len(args) < 2:
89                 print("Need device address parameter")
90                 sys.exit(1)
91         device = adapter.FindDevice(args[1])
92         headset = dbus.Interface(bus.get_object("org.bluez", device),
93                                         "org.bluez.Headset")
94         if len(args) > 2:
95                 headset.SetProperty('MicrophoneGain', dbus.UInt16(args[2]))
96         else:
97                 props = headset.GetProperties()
98                 print(props['MicrophoneGain'])
99
100         sys.exit(0)
101
102 if args[0] == "play":
103         if len(args) < 2:
104                 print("Need device address parameter")
105                 sys.exit(1)
106         device = adapter.FindDevice(args[1])
107         headset = dbus.Interface(bus.get_object("org.bluez", device),
108                                         "org.bluez.Headset")
109         headset.Play()
110
111         sys.exit(0)
112
113 if args[0] == "stop":
114         if len(args) < 2:
115                 print("Need device address parameter")
116                 sys.exit(1)
117         device = adapter.FindDevice(args[1])
118         headset = dbus.Interface(bus.get_object("org.bluez", device),
119                                         "org.bluez.Headset")
120         headset.Stop()
121
122         sys.exit(0)
123
124 if args[0] == "outgoing":
125         if len(args) > 1:
126                 test.OutgoingCall(args[1])
127         else:
128                 print("Need number parameter")
129         sys.exit(0)
130
131 if args[0] == "incoming":
132         if len(args) > 1:
133                 test.IncomingCall(args[1])
134         else:
135                 print("Need number parameter")
136         sys.exit(0)
137
138 if args[0] == "cancel":
139         test.CancelCall()
140         sys.exit(0)
141
142 if args[0] == "signal":
143         if len(args) > 1:
144                 test.SignalStrength(args[1])
145         else:
146                 print("Need signal strength parameter")
147         sys.exit(0)
148
149 if args[0] == "battery":
150         if len(args) > 1:
151                 test.BatteryLevel(args[1])
152         else:
153                 print("Need battery level parameter")
154         sys.exit(0)
155
156 if args[0] == "roaming":
157         if len(args) > 1:
158                 test.RoamingStatus(args[1] == "yes" or False)
159         else:
160                 print("Need yes/no parameter")
161         sys.exit(0)
162
163 if args[0] == "registration":
164         if len(args) > 1:
165                 test.RegistrationStatus(args[1] == "yes" or False)
166         else:
167                 print("Need yes/no parameter")
168         sys.exit(0)
169
170 if args[0] == "subscriber":
171         if len(args) > 1:
172                 test.SetSubscriberNumber(args[1])
173         else:
174                 print("Need number parameter")
175         sys.exit(0)
176
177 print("Unknown command")
178 sys.exit(1)