blob: 38d8a9bac2a93cf226cc3d1f2aa1eab5f6c7db54 [file] [log] [blame]
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07005
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07006from autotest_lib.client.cros import constants
7from autotest_lib.server import autotest
8
9
10class BluetoothClient(object):
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070011 """BluetoothClient is a thin layer of logic over a remote DUT.
12
13 The Autotest host object representing the remote DUT, passed to this
14 class on initialization, can be accessed from its host property.
15
16 """
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070017
18 XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60
19
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070020 def __init__(self, client_host):
21 """Construct a BluetoothClient.
22
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070023 @param client_host: host object representing a remote host.
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070024
25 """
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070026 self.host = client_host
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070027 # Make sure the client library is on the device so that the proxy code
28 # is there when we try to call it.
29 client_at = autotest.Autotest(self.host)
30 client_at.install()
31 # Start up the XML-RPC proxy on the client.
32 self._proxy = self.host.xmlrpc_connect(
33 constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_COMMAND,
34 constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_PORT,
35 command_name=
36 constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_CLEANUP_PATTERN,
37 ready_test_name=
38 constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_READY_METHOD,
39 timeout_seconds=self.XMLRPC_BRINGUP_TIMEOUT_SECONDS)
40
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070041
Scott James Remnanta6442f52013-07-24 15:04:55 -070042 def reset_on(self):
43 """Reset the adapter and settings and power up the adapter.
44
45 @return True on success, False otherwise.
46
47 """
48 return self._proxy.reset_on()
49
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070050
Scott James Remnanta6442f52013-07-24 15:04:55 -070051 def reset_off(self):
52 """Reset the adapter and settings, leave the adapter powered off.
53
54 @return True on success, False otherwise.
55
56 """
57 return self._proxy.reset_off()
58
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070059
Scott James Remnanta6442f52013-07-24 15:04:55 -070060 def set_powered(self, powered):
61 """Set the adapter power state.
62
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070063 @param powered: adapter power state to set (True or False).
Scott James Remnanta6442f52013-07-24 15:04:55 -070064
65 @return True on success, False otherwise.
66
67 """
68 return self._proxy.set_powered(powered)
69
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070070
Scott James Remnanta6442f52013-07-24 15:04:55 -070071 def set_discoverable(self, discoverable):
72 """Set the adapter discoverable state.
73
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070074 @param discoverable: adapter discoverable state to set (True or False).
Scott James Remnanta6442f52013-07-24 15:04:55 -070075
76 @return True on success, False otherwise.
77
78 """
79 return self._proxy.set_discoverable(discoverable)
80
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070081
Scott James Remnanta6442f52013-07-24 15:04:55 -070082 def set_pairable(self, pairable):
83 """Set the adapter pairable state.
84
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070085 @param pairable: adapter pairable state to set (True or False).
Scott James Remnanta6442f52013-07-24 15:04:55 -070086
87 @return True on success, False otherwise.
88
89 """
90 return self._proxy.set_pairable(pairable)
91
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070092
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070093 def close(self):
94 """Tear down state associated with the client."""
Scott James Remnanta6442f52013-07-24 15:04:55 -070095 # Leave the adapter powered off, but don't do a full reset.
96 self._proxy.set_powered(False)
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070097 # This kills the RPC server.
Scott James Remnant1c72d7a2013-07-29 15:00:04 -070098 self.host.close()