@@ -0,0 +1,96 @@
3+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
5+# Unity Indicators Autopilot Test Suite
6+# Copyright (C) 2014 Canonical
8+# This program is free software: you can redistribute it and/or modify
9+# it under the terms of the GNU General Public License as published by
10+# the Free Software Foundation, either version 3 of the License, or
11+# (at your option) any later version.
13+# This program is distributed in the hope that it will be useful,
14+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+# GNU General Public License for more details.
18+# You should have received a copy of the GNU General Public License
19+# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+from __future__ import absolute_import
26+from time import sleep
29+class PhonesimManager(object):
31+ def __init__(self, sims, exe=None):
33+ self.phonesim_exe = '/usr/bin/ofono-phonesim'
35+ self.phonesim_exe = exe
37+ self.sim_processes = {}
38+ self.system_bus = dbus.SystemBus()
39+ self.ofono = self.system_bus.get_object('org.ofono', '/')
40+ self.phonesim_manager = dbus.Interface(
42+ 'org.ofono.phonesim.Manager'
45+ def start_phonesim_processes(self):
46+ for simname, simport, conffile in self.sims:
47+ cmd = ['/usr/bin/xvfb-run', '-a', self.phonesim_exe, '-p', str(simport), conffile]
48+ p = subprocess.Popen(cmd)
49+ self.sim_processes[simname] = p
50+ # give the processes some time to start
54+ for p in self.sim_processes.values():
56+ self.sim_processes = {}
58+ def reset_ofono(self):
59+ self.phonesim_manager.Reset()
61+ def remove_all_ofono(self):
62+ self.phonesim_manager.RemoveAll()
64+ def add_ofono(self, name):
65+ for simname, simport, _ in self.sims:
67+ self.phonesim_manager.Add(simname, '127.0.0.1', str(simport))
69+ raise RuntimeError('Tried to add unknown modem %s.' % name)
71+ def power_on(self, sim_name):
72+ sim = self.system_bus.get_object('org.ofono', '/'+sim_name)
73+ modem = dbus.Interface(sim, dbus_interface='org.ofono.Modem')
74+ modem.SetProperty('Powered', True)
77+ def power_off(self, sim_name):
78+ sim = self.system_bus.get_object('org.ofono', '/'+sim_name)
79+ modem = dbus.Interface(sim, dbus_interface='org.ofono.Modem')
80+ modem.SetProperty('Powered', False)
83+ def get_required_pin(self, sim_name):
84+ sim = self.system_bus.get_object('org.ofono', '/'+sim_name)
85+ interface = dbus.Interface(sim, dbus_interface='org.ofono.SimManager')
86+ return str(interface.GetProperties()['PinRequired'])
89+if __name__ == '__main__':
90+ sims = [('sim1', 12345, '/usr/share/phonesim/default.xml'),
91+ ('sim2', 12346, '/usr/share/phonesim/default.xml')]
92+ m = PhonesimManager(sims)
93+ m.start_phonesim_processes()