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