1from acts.base_test import BaseTestClass
2from acts.controllers import native_android_device
3from acts.test_utils.bt.native_bt_test_utils import setup_native_bluetooth
4from acts.test_utils.bt.bt_test_utils import generate_id_by_size
5
6
7class BtNativeTest(BaseTestClass):
8    tests = None
9
10    def __init__(self, controllers):
11        BaseTestClass.__init__(self, controllers)
12        self.tests = (
13            "test_binder_get_name",
14            "test_binder_get_name_invalid_parameter",
15            "test_binder_set_name_get_name",
16            "test_binder_get_address", )
17
18    def setup_class(self):
19        setup_native_bluetooth(self.native_android_devices)
20        self.droid = self.native_android_devices[0].droid
21        if len(self.native_android_devices) > 1:
22            self.droid1 = self.native_android_devices[1].droid
23            self.tests = self.tests + ("test_two_devices_set_get_name", )
24
25    def test_binder_get_name(self):
26        result = self.droid.BtBinderGetName()
27        self.log.info("Bluetooth device name: {}".format(result))
28        return True
29
30    def test_binder_get_name_invalid_parameter(self):
31        try:
32            self.droid.BtBinderGetName("unexpected_parameter")
33            return False
34        except Exception:
35            return True
36
37    def test_binder_set_name_get_name(self):
38        test_name = generate_id_by_size(4)
39        result = self.droid.BtBinderSetName(test_name)
40        if not result:
41            return False
42        name = self.droid.BtBinderGetName()
43        if test_name != name:
44            return False
45        return True
46
47    def test_binder_get_address(self):
48        result = self.droid.BtBinderGetAddress()
49        self.log.info("Found BT address: {}".format(result))
50        if not result:
51            return False
52        return True
53
54    def test_two_devices_set_get_name(self):
55        test_name = generate_id_by_size(4)
56        for n in self.native_android_devices:
57            d = n.droid
58            d.BtBinderSetName(test_name)
59            name = d.BtBinderGetName()
60            if name != test_name:
61                return False
62        return True
63
64