1# /usr/bin/env python3.4 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 17from acts.test_utils.bt import BtEnum 18from acts.test_utils.bt.bt_test_utils import clear_bonded_devices 19from acts.test_utils.coex.CoexBaseTest import CoexBaseTest 20from acts.test_utils.coex.coex_test_utils import connect_dev_to_headset 21from acts.test_utils.coex.coex_test_utils import initiate_disconnect_from_hf 22from acts.test_utils.coex.coex_test_utils import initiate_disconnect_call_dut 23from acts.test_utils.coex.coex_test_utils import multithread_func 24from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset 25from acts.test_utils.coex.coex_test_utils import perform_classic_discovery 26from acts.test_utils.coex.coex_test_utils import connect_wlan_profile 27from acts.test_utils.coex.coex_test_utils import toggle_screen_state 28from acts.test_utils.coex.coex_test_utils import setup_tel_config 29from acts.test_utils.coex.coex_test_utils import start_fping 30from acts.test_utils.tel.tel_test_utils import hangup_call 31from acts.test_utils.tel.tel_test_utils import initiate_call 32 33BLUETOOTH_WAIT_TIME = 2 34 35 36class WlanWithHfpFunctionalityTest(CoexBaseTest): 37 38 def __init__(self, controllers): 39 CoexBaseTest.__init__(self, controllers) 40 41 def setup_class(self): 42 CoexBaseTest.setup_class(self) 43 req_params = ["sim_conf_file"] 44 self.unpack_userparams(req_params) 45 self.ag_phone_number, self.re_phone_number = setup_tel_config( 46 self.pri_ad, self.sec_ad, self.sim_conf_file) 47 48 def setup_test(self): 49 CoexBaseTest.setup_test(self) 50 self.audio_receiver.pairing_mode() 51 if not pair_and_connect_headset( 52 self.pri_ad, self.audio_receiver.mac_address, 53 set([BtEnum.BluetoothProfile.HEADSET.value])): 54 self.log.error("Failed to pair and connect to headset.") 55 return False 56 57 def teardown_test(self): 58 clear_bonded_devices(self.pri_ad) 59 CoexBaseTest.teardown_test(self) 60 self.audio_receiver.clean_up() 61 62 def call_from_sec_ad_to_pri_ad(self): 63 """Initiates the call from secondary device and accepts the call 64 from HF. 65 66 Steps: 67 1. Initiate call from secondary device to primary device. 68 2. Accept the call from HF. 69 3. Hangup the call from primary device. 70 71 Returns: 72 True if successful, False otherwise. 73 """ 74 if not initiate_call(self.log, self.sec_ad, self.ag_phone_number): 75 self.log.error("Failed to initiate call") 76 return False 77 if not self.audio_receiver.accept_call(): 78 self.log.error("Failed to answer call from HF.") 79 return False 80 if not hangup_call(self.log, self.pri_ad): 81 self.log.error("Failed to hangup call.") 82 return False 83 return False 84 85 def connect_to_headset_when_turned_off_with_iperf(self): 86 """Wrapper function to start iperf and test connection to headset 87 when it is turned off. 88 89 Returns: 90 True if successful, False otherwise. 91 """ 92 self.run_iperf_and_get_result() 93 self.audio_receiver.clean_up() 94 if not connect_dev_to_headset( 95 self.pri_ad, self.audio_receiver.mac_address, 96 set([BtEnum.BluetoothProfile.HEADSET.value])): 97 self.log.error("Failed to connect to headset.") 98 return True 99 return False 100 101 def check_headset_reconnection_with_iperf(self): 102 """Wrapper function to start iperf and check behaviour of hfp 103 reconnection.""" 104 self.run_iperf_and_get_result() 105 self.audio_receiver.clean_up() 106 self.audio_receiver.power_on() 107 if not self.pri_ad.droid.bluetoothIsDeviceConnected( 108 self.audio_receiver.mac_address): 109 self.log.error("Device not found in connected list") 110 return False 111 return self.teardown_result() 112 113 def initiate_call_from_hf_with_iperf(self): 114 """Wrapper function to start iperf and initiate call""" 115 self.run_iperf_and_get_result() 116 if not initiate_disconnect_from_hf( 117 self.audio_receiver, self.pri_ad, self.sec_ad, 118 self.iperf["duration"]): 119 return False 120 return self.teardown_result() 121 122 def initiate_call_from_hf_bt_discovery_with_iperf(self): 123 """Wrapper function to start iperf, initiate call and perform classic 124 discovery. 125 """ 126 self.run_iperf_and_get_result() 127 tasks = [(initiate_disconnect_from_hf, ( 128 self.audio_receiver, self.pri_ad, self.sec_ad, 129 self.iperf["duration"])), 130 (perform_classic_discovery, (self.pri_ad,))] 131 if not multithread_func(self.log, tasks): 132 return False 133 return self.teardown_result() 134 135 def initiate_call_associate_ap_with_iperf(self): 136 """Wrapper function to initiate call from primary device and associate 137 with access point and start iperf traffic.""" 138 args = [ 139 lambda: initiate_disconnect_call_dut( 140 self.pri_ad, self.sec_ad, self.iperf["duration"], 141 self.re_phone_number) 142 ] 143 self.run_thread(args) 144 if not connect_wlan_profile(self.pri_ad, self.network): 145 return False 146 self.run_iperf_and_get_result() 147 return self.teardown_result() 148 149 def test_hfp_call_with_tcp_ul(self): 150 """Starts TCP-uplink traffic with hfp connection. 151 152 This test is to start TCP-uplink traffic between host machine and 153 android device and test the functional behaviour of hfp connection 154 and call. 155 156 Steps:. 157 1. Start TCP-uplink traffic. 158 2. Initiate call from HF and disconnect call from primary device. 159 160 Returns: 161 True if successful, False otherwise. 162 163 Test Id: Bt_CoEx_042 164 """ 165 if not self.initiate_call_from_hf_with_iperf(): 166 return False 167 return True 168 169 def test_hfp_call_with_tcp_dl(self): 170 """Starts TCP-downlink traffic with hfp connection. 171 172 This test is to start TCP-downlink traffic between host machine and 173 android device and test the functional behaviour of hfp connection 174 and call. 175 176 Steps:. 177 1. Start TCP-downlink traffic. 178 2. Initiate call from HF and disconnect call from primary device. 179 180 Returns: 181 True if successful, False otherwise. 182 183 Test Id: Bt_CoEx_043 184 """ 185 if not self.initiate_call_from_hf_with_iperf(): 186 return False 187 return True 188 189 def test_hfp_call_with_udp_ul(self): 190 """Starts UDP-uplink traffic with hfp connection. 191 192 This test is to start UDP-uplink traffic between host machine and 193 android device and test the functional behaviour of hfp connection 194 and call. 195 196 Steps:. 197 1. Start UDP-uplink traffic. 198 2. Initiate call from HF and disconnect call from primary device. 199 200 Returns: 201 True if successful, False otherwise. 202 203 Test Id: Bt_CoEx_044 204 """ 205 if not self.initiate_call_from_hf_with_iperf(): 206 return False 207 return True 208 209 def test_hfp_call_with_udp_dl(self): 210 """Starts UDP-downlink traffic with hfp connection. 211 212 This test is to start UDP-downlink traffic between host machine and 213 android device and test the functional behaviour of hfp connection 214 and call. 215 216 Steps:. 217 1. Start UDP-downlink traffic. 218 2. Initiate call from HF and disconnect call from primary device. 219 220 Returns: 221 True if successful, False otherwise. 222 223 Test Id: Bt_CoEx_045 224 """ 225 if not self.initiate_call_from_hf_with_iperf(): 226 return False 227 return True 228 229 def test_hfp_call_bluetooth_discovery_with_tcp_ul(self): 230 """Starts TCP-uplink traffic with hfp connection and bluetooth 231 discovery. 232 233 This test is to start TCP-uplink traffic between host machine and 234 android device and test the functional behaviour of hfp connection 235 and call and bluetooth discovery. 236 237 Steps:. 238 1. Start TCP-uplink traffic. 239 2. Initiate call from HF and disconnect call from primary device. 240 3. Start bluetooth discovery. 241 242 Returns: 243 True if successful, False otherwise. 244 245 Test Id: Bt_CoEx_046 246 """ 247 if not self.initiate_call_from_hf_bt_discovery_with_iperf(): 248 return False 249 return True 250 251 def test_hfp_call_bluetooth_discovery_with_tcp_dl(self): 252 """Starts TCP-downlink traffic with hfp connection and bluetooth 253 discovery. 254 255 This test is to start TCP-downlink traffic between host machine and 256 android device and test the functional behaviour of hfp connection 257 and call and bluetooth discovery. 258 259 Steps:. 260 1. Start TCP-downlink traffic. 261 2. Initiate call from HF and disconnect call from primary device. 262 3. Start bluetooth discovery. 263 264 Returns: 265 True if successful, False otherwise. 266 267 Test Id: Bt_CoEx_047 268 """ 269 if not self.initiate_call_from_hf_bt_discovery_with_iperf(): 270 return False 271 return True 272 273 def test_hfp_call_bluetooth_discovery_with_udp_ul(self): 274 """Starts UDP-uplink traffic with hfp connection and bluetooth 275 discovery. 276 277 This test is to start UDP-uplink traffic between host machine and 278 android device and test the functional behaviour of hfp connection 279 and call and bluetooth discovery. 280 281 Steps:. 282 1. Start UDP-uplink traffic. 283 2. Initiate call from HF and disconnect call from primary device. 284 3. Start bluetooth discovery. 285 286 Returns: 287 True if successful, False otherwise. 288 289 Test Id: Bt_CoEx_048 290 """ 291 if not self.initiate_call_from_hf_bt_discovery_with_iperf(): 292 return False 293 return True 294 295 def test_hfp_call_bluetooth_discovery_with_udp_dl(self): 296 """Starts UDP-downlink traffic with hfp connection and bluetooth 297 discovery. 298 299 This test is to start UDP-downlink traffic between host machine and 300 android device and test the functional behaviour of hfp connection 301 and call and bluetooth discovery. 302 303 Steps:. 304 1. Start UDP-downlink traffic. 305 2. Initiate call from HF and disconnect call from primary device. 306 3. Start bluetooth discovery. 307 308 Returns: 309 True if successful, False otherwise. 310 311 Test Id: Bt_CoEx_049 312 """ 313 if not self.initiate_call_from_hf_bt_discovery_with_iperf(): 314 return False 315 return True 316 317 def test_hfp_call_and_associate_ap_with_tcp_ul(self): 318 """Starts TCP-uplink traffic with hfp call. 319 320 This test is to start TCP-uplink traffic between host machine and 321 android device and test functional behaviour of hfp call connection 322 while associating with AP. 323 324 Steps: 325 1. Initiate call from HF and disconnect call from primary device. 326 2. Associate with AP. 327 3. Start TCP-uplink traffic. 328 329 Returns: 330 True if successful, False otherwise. 331 332 Test Id: Bt_CoEx_050 333 """ 334 if not self.initiate_call_associate_ap_with_iperf(): 335 return False 336 return True 337 338 def test_hfp_call_and_associate_ap_with_tcp_dl(self): 339 """Starts TCP-downlink traffic with hfp call. 340 341 This test is to start TCP-downlink traffic between host machine and 342 android device and test functional behaviour of hfp call connection 343 while associating with AP. 344 345 Steps: 346 1. Initiate call from HF and disconnect call from primary device. 347 2. Associate with AP. 348 3. Start TCP-downlink traffic. 349 350 Returns: 351 True if successful, False otherwise. 352 353 Test Id: Bt_CoEx_051 354 """ 355 if not self.initiate_call_associate_ap_with_iperf(): 356 return False 357 return True 358 359 def test_hfp_call_and_associate_ap_with_udp_ul(self): 360 """Starts UDP-uplink traffic with hfp call. 361 362 This test is to start UDP-uplink traffic between host machine and 363 android device and test functional behaviour of hfp call connection 364 while associating with AP. 365 366 Steps: 367 1. Initiate call from HF and disconnect call from primary device. 368 2. Associate with AP. 369 3. Start UDP-uplink traffic. 370 371 Returns: 372 True if successful, False otherwise. 373 374 Test Id: Bt_CoEx_052 375 """ 376 if not self.initiate_call_associate_ap_with_iperf(): 377 return False 378 return True 379 380 def test_hfp_call_and_associate_ap_with_udp_dl(self): 381 """Starts UDP-downlink traffic with hfp call. 382 383 This test is to start UDP-downlink traffic between host machine and 384 android device and test functional behaviour of hfp call connection 385 while associating with AP. 386 387 Steps: 388 1. Initiate call from HF and disconnect call from primary device. 389 2. Associate with AP. 390 3. Start UDP-downlink traffic. 391 392 Returns: 393 True if successful, False otherwise. 394 395 Test Id: Bt_CoEx_053 396 """ 397 if not self.initiate_call_associate_ap_with_iperf(): 398 return False 399 return True 400 401 def test_hfp_redial_with_tcp_ul(self): 402 """Starts TCP-uplink traffic with hfp connection. 403 404 This test is to start TCP-uplink traffic between host machine and 405 android device with hfp connection. 406 407 Steps: 408 1. Start TCP-uplink traffic. 409 2. Initiate call from HF(last dialed number) and disconnect call 410 from primary device. 411 412 Returns: 413 True if successful, False otherwise. 414 415 Test Id: Bt_CoEx_054 416 """ 417 if not self.initiate_call_from_hf_with_iperf(): 418 return False 419 return True 420 421 def test_hfp_redial_with_tcp_dl(self): 422 """Starts TCP-downlink traffic with hfp connection. 423 424 This test is to start TCP-downlink traffic between host machine and 425 android device with hfp connection. 426 427 Steps: 428 1. Start TCP-downlink traffic. 429 2. Initiate call from HF(last dialed number) and disconnect call 430 from primary device. 431 432 Returns: 433 True if successful, False otherwise. 434 435 Test Id: Bt_CoEx_055 436 """ 437 if not self.initiate_call_from_hf_with_iperf(): 438 return False 439 return True 440 441 def test_hfp_redial_with_udp_ul(self): 442 """Starts UDP-uplink traffic with hfp connection. 443 444 This test is to start UDP-uplink traffic between host machine and 445 android device with hfp connection. 446 447 Steps: 448 1. Start UDP-uplink traffic. 449 2. Initiate call from HF(last dialed number) and disconnect call 450 from primary device. 451 452 Returns: 453 True if successful, False otherwise. 454 455 Test Id: Bt_CoEx_056 456 """ 457 if not self.initiate_call_from_hf_with_iperf(): 458 return False 459 return True 460 461 def test_hfp_redial_with_udp_dl(self): 462 """Starts UDP-downlink traffic with hfp connection. 463 464 This test is to start TCP-downlink traffic between host machine and 465 android device with hfp connection. 466 467 Steps: 468 1. Start UDP-downlink traffic. 469 2. Initiate call from HF(last dialed number) and disconnect call 470 from primary device. 471 472 Returns: 473 True if successful, False otherwise. 474 475 Test Id: Bt_CoEx_057 476 """ 477 if not self.initiate_call_from_hf_with_iperf(): 478 return False 479 return True 480 481 def test_hfp_reconnection_with_tcp_ul(self): 482 """Starts TCP-uplink traffic with hfp reconnection. 483 484 This test is to start TCP-uplink traffic between host machine and 485 android device and test the functional behaviour of hfp reconnection. 486 487 Steps:. 488 1. Start TCP-uplink traffic. 489 2. Connect HF to DUT. 490 3. Disconnect HF from DUT. 491 4. Switch off the headset and turn ON HF to reconnect. 492 493 Returns: 494 True if successful, False otherwise. 495 496 Test Id: Bt_CoEx_062 497 """ 498 if not self.check_headset_reconnection_with_iperf(): 499 return False 500 return True 501 502 def test_hfp_reconnection_with_tcp_dl(self): 503 """Starts TCP-downlink traffic with hfp reconnection. 504 505 This test is to start TCP-downlink traffic between host machine and 506 android device and test the functional behaviour of hfp reconnection. 507 508 Steps:. 509 1. Start TCP-downlink traffic. 510 2. Connect HF to DUT. 511 3. Disconnect HF from DUT. 512 4. Switch off the headset and turn ON HF to reconnect. 513 514 Returns: 515 True if successful, False otherwise. 516 517 Test Id: Bt_CoEx_063 518 """ 519 if not self.check_headset_reconnection_with_iperf(): 520 return False 521 return True 522 523 def test_hfp_reconnection_with_udp_ul(self): 524 """Starts UDP-uplink traffic with hfp reconnection. 525 526 This test is to start UDP-uplink traffic between host machine and 527 android device and test the functional behaviour of hfp reconnection. 528 529 Steps:. 530 1. Start UDP-uplink traffic. 531 2. Connect HF to DUT. 532 3. Disconnect HF from DUT. 533 4. Switch off the headset and turn ON HF to reconnect. 534 535 Returns: 536 True if successful, False otherwise. 537 538 Test Id: Bt_CoEx_064 539 """ 540 if not self.check_headset_reconnection_with_iperf(): 541 return False 542 return True 543 544 def test_hfp_reconnection_with_udp_dl(self): 545 """Starts UDP-downlink traffic with hfp reconnection. 546 547 This test is to start UDP-downlink traffic between host machine and 548 android device and test the functional behaviour of hfp reconnection. 549 550 Steps:. 551 1. Start UDP-downlink traffic. 552 2. Connect HF to DUT. 553 3. Disconnect HF from DUT. 554 4. Switch off the headset and turn ON HF to reconnect. 555 556 Returns: 557 True if successful, False otherwise. 558 559 Test Id: Bt_CoEx_065 560 """ 561 if not self.check_headset_reconnection_with_iperf(): 562 return False 563 return True 564 565 def test_hfp_connection_when_hf_turned_off_with_tcp_ul(self): 566 """Starts TCP-uplink traffic with hfp connection. 567 568 This test is to start TCP-Uplink traffic between host machine and 569 android device and test the functional behaviour of hfp connection 570 when device is off. 571 572 Steps: 573 1. Start TCP-uplink traffic. 574 2. Make sure headset is turned off. 575 3. Initiate hfp connection to headset from DUT. 576 577 Returns: 578 True if successful, False otherwise. 579 580 Test Id: Bt_CoEx_072 581 """ 582 if not self.connect_to_headset_when_turned_off_with_iperf(): 583 return False 584 return self.teardown_result() 585 586 def test_hfp_connection_when_hf_turned_off_with_tcp_dl(self): 587 """Starts TCP-downlink traffic with hfp connection. 588 589 This test is to start TCP-downlink traffic between host machine and 590 android device and test the functional behaviour of hfp connection 591 when device is off. 592 593 Steps: 594 1. Start TCP-downlink traffic. 595 2. Make sure headset is turned off. 596 3. Initiate hfp connection to headset from DUT. 597 598 Returns: 599 True if successful, False otherwise. 600 601 Test Id: Bt_CoEx_073 602 """ 603 if not self.connect_to_headset_when_turned_off_with_iperf(): 604 return False 605 return self.teardown_result() 606 607 def test_hfp_connection_when_hf_turned_off_with_udp_ul(self): 608 """Starts UDP-uplink traffic with hfp connection. 609 610 This test is to start UDP-Uplink traffic between host machine and 611 android device and test the functional behaviour of hfp connection 612 when device is off. 613 614 Steps: 615 1. Start UDP-uplink traffic. 616 2. Make sure headset is turned off. 617 3. Initiate hfp connection to headset from DUT. 618 619 Returns: 620 True if successful, False otherwise. 621 622 Test Id: Bt_CoEx_074 623 """ 624 if not self.connect_to_headset_when_turned_off_with_iperf(): 625 return False 626 return self.teardown_result() 627 628 def test_hfp_connection_when_hf_turned_off_with_udp_dl(self): 629 """Starts UDP-downlink traffic with hfp connection. 630 631 This test is to start UDP-downlink traffic between host machine and 632 android device and test the functional behaviour of hfp connection 633 when device is off. 634 635 Steps: 636 1. Start UDP-downlink traffic. 637 2. Make sure headset is turned off. 638 3. Initiate hfp connection to headset from DUT. 639 640 Returns: 641 True if successful, False otherwise. 642 643 Test Id: Bt_CoEx_075 644 """ 645 if not self.connect_to_headset_when_turned_off_with_iperf(): 646 return False 647 return self.teardown_result() 648 649 def test_hfp_call_with_fping(self): 650 """Starts fping with hfp call connection. 651 652 This test is to start fping between host machine and android device 653 and test the functional behaviour of hfp call. 654 655 Steps: 656 1. Start fping from AP backend to android device. 657 1. Initiate call from headset to secondary device. 658 659 Returns: 660 True if successful, False otherwise. 661 662 Test Id: Bt_CoEx_078 663 """ 664 args = [lambda: start_fping(self.pri_ad, self.iperf["duration"])] 665 self.run_thread(args) 666 if not initiate_disconnect_from_hf( 667 self.audio_receiver,self.pri_ad, self.sec_ad, 668 self.iperf["duration"]): 669 return False 670 return self.teardown_thread() 671 672 def test_hfp_call_toggle_screen_state_with_fping(self): 673 """Starts fping with hfp call connection. 674 675 This test is to start fping between host machine and android device 676 and test the functional behaviour of hfp call when toggling the 677 screen state. 678 679 Steps: 680 1. Start fping from AP backend. 681 1. Initiate call from primary device headset to secondary device. 682 683 Returns: 684 True if successful, False otherwise. 685 686 Test Id: Bt_CoEx_081 687 """ 688 tasks = [(start_fping, (self.pri_ad, self.iperf["duration"])), 689 (initiate_disconnect_from_hf, ( 690 self.audio_receiver, self.pri_ad, self.sec_ad, 691 self.iperf["duration"])), 692 (toggle_screen_state, (self.pri_ad, self.iterations))] 693 if not multithread_func(self.log, tasks): 694 return False 695 return True 696