Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 1 | #/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 16 | """ |
| 17 | Test script to test the pairing scenarios and setting priorities. |
| 18 | """ |
| 19 | |
| 20 | import time |
| 21 | |
tturney | b72742f | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 22 | from acts.test_decorators import test_tracker_info |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 23 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 24 | from acts.base_test import BaseTestClass |
| 25 | from acts.test_utils.bt import bt_test_utils |
| 26 | from acts.test_utils.car import car_bt_utils |
| 27 | from acts.test_utils.bt import BtEnum |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 28 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 29 | # Timed wait between Bonding happens and Android actually gets the list of |
| 30 | # supported services (and subsequently updates the priorities) |
| 31 | BOND_TO_SDP_WAIT = 3 |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 32 | UNBOND_TIMEOUT = 3 |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 33 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 34 | |
| 35 | class BtCarPairingTest(BluetoothBaseTest): |
| 36 | def __init__(self, controllers): |
| 37 | BluetoothBaseTest.__init__(self, controllers) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 38 | self.car = self.android_devices[0] |
| 39 | self.ph = self.android_devices[1] |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 40 | |
Timofey Protopopov | e119223 | 2018-05-02 15:04:42 -0700 | [diff] [blame^] | 41 | def teardown_test(self): |
| 42 | for ad in self.android_devices: |
| 43 | bt_test_utils.clear_bonded_devices(ad) |
| 44 | # Give the stack time to unbond. |
| 45 | time.sleep(UNBOND_TIMEOUT) |
| 46 | |
tturney | b72742f | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 47 | @test_tracker_info(uuid='f56e915-eef7-45cd-b5a6-771f6ef72602') |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 48 | @BluetoothBaseTest.bt_test_wrap |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 49 | def test_simple_pairing(self): |
| 50 | """ |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 51 | Tests if after first pairing the remote device has the default |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 52 | priorities for A2DP and HFP. |
| 53 | |
| 54 | Steps: |
| 55 | 1. Pair the devices (do not connect) |
| 56 | 2. Check the priorities. |
| 57 | |
| 58 | Returns: |
| 59 | Pass if True |
| 60 | Fail if False |
| 61 | |
| 62 | Priority: 0 |
| 63 | """ |
| 64 | # Pair the devices. |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 65 | if not bt_test_utils.pair_pri_to_sec( |
| 66 | self.car, self.ph, attempts=1, auto_confirm=False): |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 67 | self.log.error("cannot pair") |
| 68 | return False |
| 69 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 70 | # Sleep because priorities are not event driven. |
| 71 | time.sleep(BOND_TO_SDP_WAIT) |
| 72 | |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 73 | # Check that the default priority for HFP and A2DP is ON. |
| 74 | ph_hfp_p = self.car.droid.bluetoothHfpClientGetPriority( |
| 75 | self.ph.droid.bluetoothGetLocalAddress()) |
| 76 | if ph_hfp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value: |
| 77 | self.log.error("hfp {} priority {} expected {}".format( |
tturney | 4596252 | 2016-11-16 13:12:44 -0800 | [diff] [blame] | 78 | self.ph.serial, ph_hfp_p, |
| 79 | BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value)) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 80 | return False |
| 81 | |
| 82 | ph_a2dp_p = self.car.droid.bluetoothA2dpSinkGetPriority( |
| 83 | self.ph.droid.bluetoothGetLocalAddress()) |
| 84 | if ph_a2dp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value: |
| 85 | self.log.error("a2dp {} priority {} expected {}".format( |
tturney | 4596252 | 2016-11-16 13:12:44 -0800 | [diff] [blame] | 86 | self.ph.serial, ph_a2dp_p, |
| 87 | BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value)) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 88 | return False |
| 89 | |
| 90 | ph_pbap_p = self.car.droid.bluetoothPbapClientGetPriority( |
| 91 | self.ph.droid.bluetoothGetLocalAddress()) |
| 92 | if ph_pbap_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value: |
| 93 | self.log.error("pbap {} priority {} expected {}".format( |
tturney | 4596252 | 2016-11-16 13:12:44 -0800 | [diff] [blame] | 94 | self.ph.serial, ph_pbap_p, |
| 95 | BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value)) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 96 | return False |
| 97 | return True |
| 98 | |
tturney | b72742f | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 99 | @test_tracker_info(uuid='be4db211-10a0-479a-8958-dff0ccadca1a') |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 100 | @BluetoothBaseTest.bt_test_wrap |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 101 | def test_repairing(self): |
| 102 | """ |
| 103 | Tests that even if we modify the priorities, on unpair and pair |
| 104 | we will reset the priorities. |
| 105 | |
| 106 | Steps: |
| 107 | 1. Pair the devices (do not connect) |
| 108 | 2. Unset the priorities for HFP and A2DP |
| 109 | 3. Pair again |
| 110 | 4. Check the priorities, they should be set to default. |
| 111 | |
| 112 | Returns: |
| 113 | Pass if True |
| 114 | Fail if False |
| 115 | |
| 116 | Priority: 0 |
| 117 | """ |
| 118 | # Pair the devices. |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 119 | self.log.info("Pairing the devices ...") |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 120 | if not bt_test_utils.pair_pri_to_sec( |
| 121 | self.car, self.ph, attempts=1, auto_confirm=False): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 122 | self.log.error("Failed to pair devices.") |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 123 | return False |
| 124 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 125 | # Timed wait for the profile priorities to propagate. |
| 126 | time.sleep(BOND_TO_SDP_WAIT) |
| 127 | |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 128 | # Set the priority to OFF for ALL car profiles. |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 129 | self.car.log.info("Set priorities off ...") |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 130 | car_bt_utils.set_car_profile_priorities_off(self.car, self.ph) |
| 131 | |
| 132 | # Now unpair the devices. |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 133 | self.log.info("Resetting the devices ...") |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 134 | for ad in self.android_devices: |
| 135 | bt_test_utils.clear_bonded_devices(ad) |
| 136 | # Give the stack time to unbond. |
| 137 | time.sleep(UNBOND_TIMEOUT) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 138 | |
| 139 | # Pair them again! |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 140 | self.log.info("Pairing them again ...") |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 141 | if not bt_test_utils.pair_pri_to_sec( |
| 142 | self.car, self.ph, attempts=1, auto_confirm=False): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 143 | self.log.error("Faild to pair devices.") |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 144 | return False |
| 145 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 146 | # Timed wait for the profile priorities to propagate. |
| 147 | time.sleep(BOND_TO_SDP_WAIT) |
| 148 | |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 149 | # Check the default priorities. |
| 150 | ph_hfp_p = self.car.droid.bluetoothHfpClientGetPriority( |
| 151 | self.ph.droid.bluetoothGetLocalAddress()) |
| 152 | if ph_hfp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value: |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 153 | self.hf.log.error("HFP priority found: {}, expected: {}.".format( |
| 154 | ph_hfp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value)) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 155 | return False |
| 156 | |
| 157 | ph_a2dp_p = self.car.droid.bluetoothA2dpSinkGetPriority( |
| 158 | self.ph.droid.bluetoothGetLocalAddress()) |
| 159 | if ph_a2dp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value: |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 160 | self.ph.log.error("A2DP priority found: {}, expected {}.".format( |
| 161 | ph_a2dp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value)) |
Sanket Agarwal | c96b9cc | 2016-08-18 12:01:04 -0700 | [diff] [blame] | 162 | return False |
| 163 | |
| 164 | return True |