Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -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. |
| 16 | """ |
| 17 | Automated tests for the testing Connectivity of Avrcp/A2dp profile. |
| 18 | """ |
| 19 | |
| 20 | import time |
| 21 | |
tturney | 0323397 | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 22 | from acts.test_decorators import test_tracker_info |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 23 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
| 24 | from acts.test_utils.bt import bt_test_utils |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 25 | from acts.test_utils.car import car_bt_utils |
Ram Periathiruvadi | cb34f7c | 2016-10-06 16:00:29 -0700 | [diff] [blame] | 26 | from acts.test_utils.car import car_media_utils |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 27 | from acts.test_utils.bt import BtEnum |
| 28 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 29 | |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 30 | class BtCarMediaConnectionTest(BluetoothBaseTest): |
| 31 | def setup_class(self): |
| 32 | # AVRCP roles |
| 33 | self.CT = self.android_devices[0] |
| 34 | self.TG = self.android_devices[1] |
| 35 | # A2DP roles for the same devices |
| 36 | self.SNK = self.CT |
| 37 | self.SRC = self.TG |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 38 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 39 | # Setup devices |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 40 | bt_test_utils.setup_multiple_devices_for_bt_test([self.CT, self.TG]) |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 41 | |
| 42 | self.btAddrCT = self.CT.droid.bluetoothGetLocalAddress() |
| 43 | self.btAddrTG = self.TG.droid.bluetoothGetLocalAddress() |
| 44 | |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 45 | # Additional time from the stack reset in setup. |
| 46 | time.sleep(4) |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 47 | # Pair the devices. |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 48 | if not bt_test_utils.pair_pri_to_sec( |
| 49 | self.CT, self.TG, attempts=4, auto_confirm=False): |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 50 | self.log.error("Failed to pair") |
| 51 | return False |
| 52 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 53 | # Disable all |
| 54 | car_bt_utils.set_car_profile_priorities_off(self.SNK, self.SRC) |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 55 | |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 56 | # Enable A2DP |
| 57 | bt_test_utils.set_profile_priority( |
| 58 | self.SNK, self.SRC, [BtEnum.BluetoothProfile.A2DP_SINK], |
| 59 | BtEnum.BluetoothPriorityLevel.PRIORITY_ON) |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 60 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 61 | def is_a2dp_connected(self, device1, device2): |
| 62 | """ |
| 63 | Convenience Function to see if the 2 devices are connected on |
| 64 | A2dp. |
| 65 | ToDo: Move to bt_test_utils if used in more places. |
| 66 | Args: |
| 67 | device1: Device 1 |
| 68 | device2: Device 2 |
| 69 | Returns: |
| 70 | True if Connected |
| 71 | False if Not connected |
| 72 | """ |
| 73 | devices = device1.droid.bluetoothA2dpSinkGetConnectedDevices() |
| 74 | for device in devices: |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 75 | self.device1.log.info("A2dp Connected device {}".format(device[ |
| 76 | "name"])) |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 77 | if (device["address"] == device2.droid.bluetoothGetLocalAddress()): |
| 78 | return True |
| 79 | return False |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 80 | |
tturney | 0323397 | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 81 | @test_tracker_info(uuid='1934c0d5-3fa3-43e5-a91f-2c8a4424f5cd') |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 82 | @BluetoothBaseTest.bt_test_wrap |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 83 | def test_a2dp_connect_disconnect_from_src(self): |
| 84 | """ |
| 85 | Test Connect/Disconnect on A2DP profile. |
| 86 | |
| 87 | Pre-Condition: |
| 88 | 1. Devices previously bonded and NOT connected on A2dp |
| 89 | |
| 90 | Steps: |
| 91 | 1. Initiate a connection on A2DP profile from SRC |
| 92 | 2. Check if they connected. |
| 93 | 3. Initiate a disconnect on A2DP profile from SRC |
| 94 | 4. Ensure they disconnected on A2dp alone |
| 95 | |
| 96 | Returns: |
| 97 | True if we connected/disconnected successfully |
| 98 | False if we did not connect/disconnect successfully |
| 99 | |
| 100 | Priority: 0 |
| 101 | """ |
Ram Periathiruvadi | cb34f7c | 2016-10-06 16:00:29 -0700 | [diff] [blame] | 102 | if (car_media_utils.is_a2dp_connected(self.log, self.SNK, self.SRC)): |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 103 | self.log.info("Already Connected") |
| 104 | else: |
tturney | 0323397 | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 105 | if (not bt_test_utils.connect_pri_to_sec( |
| 106 | self.SRC, self.SNK, |
| 107 | set([BtEnum.BluetoothProfile.A2DP.value]))): |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 108 | return False |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 109 | |
| 110 | result = bt_test_utils.disconnect_pri_from_sec( |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 111 | self.SRC, self.SNK, [BtEnum.BluetoothProfile.A2DP.value]) |
| 112 | # Grace timeout to allow a2dp time to disconnect |
| 113 | time.sleep(3) |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 114 | if not result: |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 115 | # Additional profile connection check for b/ |
| 116 | if bt_test_utils.is_a2dp_src_device_connected( |
| 117 | self.SRC, self.SNK.droid.bluetoothGetLocalAddress()): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 118 | self.SRC.log.error("Failed to disconnect on A2dp") |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 119 | return False |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 120 | # Logging if we connected right back, since that happens sometimes |
| 121 | # Not failing the test if it did though |
Ram Periathiruvadi | cb34f7c | 2016-10-06 16:00:29 -0700 | [diff] [blame] | 122 | if (car_media_utils.is_a2dp_connected(self.log, self.SNK, self.SRC)): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 123 | self.SNK.log.error("Still connected after a disconnect") |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 124 | |
| 125 | return True |
| 126 | |
tturney | 0323397 | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 127 | @test_tracker_info(uuid='70d30007-540a-4e86-bd75-ab218774350e') |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 128 | @BluetoothBaseTest.bt_test_wrap |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 129 | def test_a2dp_connect_disconnect_from_snk(self): |
| 130 | """ |
| 131 | Test Connect/Disconnect on A2DP Sink profile. |
| 132 | |
| 133 | Pre-Condition: |
| 134 | 1. Devices previously bonded and NOT connected on A2dp |
| 135 | |
| 136 | Steps: |
| 137 | 1. Initiate a connection on A2DP Sink profile from SNK |
| 138 | 2. Check if they connected. |
| 139 | 3. Initiate a disconnect on A2DP Sink profile from SNK |
| 140 | 4. Ensure they disconnected on A2dp alone |
| 141 | |
| 142 | Returns: |
| 143 | True if we connected/disconnected successfully |
| 144 | False if we did not connect/disconnect successfully |
| 145 | |
| 146 | Priority: 0 |
| 147 | """ |
| 148 | # Connect |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 149 | if car_media_utils.is_a2dp_connected(self.log, self.SNK, self.SRC): |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 150 | self.log.info("Already Connected") |
| 151 | else: |
tturney | 0323397 | 2017-08-29 17:46:50 -0700 | [diff] [blame] | 152 | if (not bt_test_utils.connect_pri_to_sec( |
| 153 | self.SNK, self.SRC, |
| 154 | set([BtEnum.BluetoothProfile.A2DP_SINK.value]))): |
tturney | 4606078 | 2016-11-14 16:44:38 -0800 | [diff] [blame] | 155 | return False |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 156 | # Disconnect |
| 157 | result = bt_test_utils.disconnect_pri_from_sec( |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 158 | self.SNK, self.SRC, [BtEnum.BluetoothProfile.A2DP_SINK.value]) |
| 159 | # Grace timeout to allow a2dp time to disconnect |
| 160 | time.sleep(3) |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 161 | if not result: |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 162 | # Additional profile connection check for b/ |
| 163 | if bt_test_utils.is_a2dp_snk_device_connected( |
| 164 | self.SNK, self.SRC.droid.bluetoothGetLocalAddress()): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 165 | self.SNK.log.error("Failed to disconnect on A2dp Sink") |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 166 | return False |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 167 | # Logging if we connected right back, since that happens sometimes |
| 168 | # Not failing the test if it did though |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame] | 169 | if car_media_utils.is_a2dp_connected(self.log, self.SNK, self.SRC): |
tturney | 34ee54d | 2016-11-16 15:29:02 -0800 | [diff] [blame] | 170 | self.SNK.log.error("Still connected after a disconnect") |
Ram Periathiruvadi | e3f9a70 | 2016-07-26 17:41:59 -0700 | [diff] [blame] | 171 | return True |