1#!/usr/bin/env python3 2# 3# Copyright (C) 2018 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""" 17Test suite to check Multi Profile Functionality with Wlan. 18 19Test Setup: 20 21Two Android device. 22One A2DP and HFP Headset connected to Relay. 23""" 24from acts.test_utils.bt import BtEnum 25from acts.test_utils.bt.bt_test_utils import clear_bonded_devices 26from acts.test_utils.coex.CoexBaseTest import CoexBaseTest 27from acts.test_utils.coex.coex_test_utils import connect_ble 28from acts.test_utils.coex.coex_test_utils import initiate_disconnect_from_hf 29from acts.test_utils.coex.coex_test_utils import multithread_func 30from acts.test_utils.coex.coex_test_utils import music_play_and_check_via_app 31from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset 32from acts.test_utils.coex.coex_test_utils import setup_tel_config 33 34 35class CoexBtMultiProfileFunctionalityTest(CoexBaseTest): 36 37 def __init__(self, controllers): 38 super().__init__(controllers) 39 40 def setup_class(self): 41 super().setup_class() 42 req_params = ["sim_conf_file", "music_play_time", "music_file"] 43 self.unpack_userparams(req_params) 44 self.ag_phone_number, self.re_phone_number = setup_tel_config( 45 self.pri_ad, self.sec_ad, self.sim_conf_file) 46 if hasattr(self, "music_file"): 47 self.push_music_to_android_device(self.pri_ad) 48 49 def setup_test(self): 50 super().setup_test() 51 self.audio_receiver.enter_pairing_mode() 52 if not pair_and_connect_headset( 53 self.pri_ad, self.audio_receiver.mac_address, 54 set([BtEnum.BluetoothProfile.HEADSET.value]) and 55 set([BtEnum.BluetoothProfile.A2DP.value])): 56 self.log.error("Failed to pair and connect to headset") 57 return False 58 59 def teardown_test(self): 60 clear_bonded_devices(self.pri_ad) 61 super().teardown_test() 62 self.audio_receiver.clean_up() 63 64 def start_media_streaming_initiate_hfp_call_with_iperf(self): 65 """Start media streaming and initiate call from hf to check 66 SCO connection along with iperf. 67 68 Returns: 69 True if successful, False otherwise. 70 """ 71 self.run_iperf_and_get_result() 72 if not music_play_and_check_via_app( 73 self.pri_ad, self.audio_receiver.mac_address): 74 self.log.error("Failed to stream music file") 75 return False 76 if not initiate_disconnect_from_hf( 77 self.audio_receiver, self.pri_ad, self.sec_ad, 78 self.iperf["duration"]): 79 self.log.error("Failed to initiate/hang up call") 80 return False 81 return self.teardown_result() 82 83 def ble_with_multiprofile_connection(self): 84 """Wrapper function to check ble connection along with a2dp streaming 85 and hfp call connection with iperf. 86 """ 87 if not connect_ble(self.pri_ad, self.sec_ad): 88 self.log.error("Failed to connect BLE device") 89 return False 90 if not music_play_and_check_via_app( 91 self.pri_ad, self.audio_receiver.mac_address): 92 self.log.error("Failed to stream music file") 93 return False 94 tasks = [(self.run_iperf_and_get_result,()), 95 (initiate_disconnect_from_hf, 96 (self.audio_receiver, self.pri_ad, self.sec_ad, 97 self.iperf["duration"]))] 98 if not multithread_func(self.log, tasks): 99 return False 100 return self.teardown_result() 101 102 def test_a2dp_streaming_hfp_call_with_tcp_ul(self): 103 """Starts TCP-uplink traffic with media streaming and HFP call. 104 105 This test is to start TCP-uplink traffic between host machine and 106 android device and test the functional behaviour of media streaming 107 via A2DP and initiating a call when media streaming is ongoing to 108 check HFP. 109 110 Steps: 111 1. Start TCP-uplink traffic. 112 1. Enable bluetooth. 113 2. Start media streaming to A2DP headset. 114 4. Initiate a call from headset. 115 116 Returns: 117 True if successful, False otherwise. 118 119 Test Id: Bt_CoEx_066 120 """ 121 if not self.start_media_streaming_initiate_hfp_call_with_iperf(): 122 return False 123 return True 124 125 def test_a2dp_streaming_hfp_call_with_tcp_dl(self): 126 """Starts TCP-downlink traffic with media streaming and HFP call. 127 128 This test is to start TCP-downlink traffic between host machine and 129 android device and test the functional behaviour of media streaming 130 via A2DP and initiating a call when media streaming is ongoing to 131 check HFP. 132 133 Steps: 134 1. Start TCP-downlink traffic. 135 1. Enable bluetooth. 136 2. Start media streaming to A2DP headset. 137 4. Initiate a call from headset. 138 139 Returns: 140 True if successful, False otherwise. 141 142 Test Id: Bt_CoEx_067 143 """ 144 if not self.start_media_streaming_initiate_hfp_call_with_iperf(): 145 return False 146 return True 147 148 def test_a2dp_streaming_hfp_call_with_udp_ul(self): 149 """Starts UDP-uplink traffic with media streaming and HFP call. 150 151 This test is to start UDP-uplink traffic between host machine and 152 android device and test the functional behaviour of media streaming 153 via A2DP and initiating a call when media streaming is ongoing to 154 check HFP. 155 156 Steps: 157 1. Start UDP-uplink traffic. 158 1. Enable bluetooth. 159 2. Start media streaming to A2DP headset. 160 4. Initiate a call from headset. 161 162 Returns: 163 True if successful, False otherwise. 164 165 Test Id: Bt_CoEx_068 166 """ 167 if not self.start_media_streaming_initiate_hfp_call_with_iperf(): 168 return False 169 return True 170 171 def test_a2dp_streaming_hfp_call_with_udp_dl(self): 172 """Starts UDP-downlink traffic with media streaming and HFP call. 173 174 This test is to start UDP-uplink traffic between host machine and 175 android device and test the functional behaviour of media streaming 176 via A2DP and initiating a call when media streaming is ongoing to 177 check HFP. 178 179 Steps: 180 1. Start UDP-downlink traffic. 181 1. Enable bluetooth. 182 2. Start media streaming to A2DP headset. 183 4. Initiate a call from headset. 184 185 Returns: 186 True if successful, False otherwise. 187 188 Test Id: Bt_CoEx_069 189 """ 190 if not self.start_media_streaming_initiate_hfp_call_with_iperf(): 191 return False 192 return True 193 194 def test_ble_connection_a2dp_streaming_hfp_call_with_tcp_ul(self): 195 """Starts TCP-uplink traffic while connecting to BLE device, 196 A2DP streaming and HFP call. 197 198 This test is to start TCP-uplink traffic between host machine and 199 android device and test the functional behaviour of BLE connection, 200 media streaming via A2DP and HFP call connection. 201 202 Steps: 203 1. Enable Bluetooth. 204 2. Connect to BLE device. 205 3. Start media streaming to A2DP headset. 206 4. Start TCP-uplink traffic. 207 5. Initiate HFP call. 208 209 Returns: 210 True if successful, False otherwise. 211 212 Test Id: Bt_CoEx_082 213 """ 214 if not self.ble_with_multiprofile_connection(): 215 return False 216 return True 217 218 def test_ble_connection_a2dp_streaming_hfp_call_with_tcp_dl(self): 219 """Starts TCP-downlink traffic while connecting to BLE device, 220 A2DP streaming and HFP call. 221 222 This test is to start TCP-downlink traffic between host machine and 223 android device and test the functional behaviour of BLE connection, 224 media streaming via A2DP and HFP call connection. 225 226 Steps: 227 1. Enable Bluetooth. 228 2. Connect to BLE device. 229 3. Start media streaming to A2DP headset. 230 4. Start TCP-uplink traffic. 231 5. Initiate HFP call. 232 233 Returns: 234 True if successful, False otherwise. 235 236 Test Id: Bt_CoEx_083. 237 """ 238 if not self.ble_with_multiprofile_connection(): 239 return False 240 return True 241