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
17import time
18
19from acts.test_utils.bt import BtEnum
20from acts.test_utils.bt.bt_test_utils import clear_bonded_devices
21from acts.test_utils.coex.CoexBaseTest import CoexBaseTest
22from acts.test_utils.coex.coex_test_utils import connect_dev_to_headset
23from acts.test_utils.coex.coex_test_utils import connect_ble
24from acts.test_utils.coex.coex_test_utils import disconnect_headset_from_dev
25from acts.test_utils.coex.coex_test_utils import multithread_func
26from acts.test_utils.coex.coex_test_utils import music_play_and_check
27from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset
28from acts.test_utils.coex.coex_test_utils import perform_classic_discovery
29from acts.test_utils.coex.coex_test_utils import toggle_screen_state
30from acts.test_utils.coex.coex_test_utils import start_fping
31
32BLUETOOTH_WAIT_TIME = 2
33
34
35class WlanWithA2dpFunctionalityTest(CoexBaseTest):
36
37    def __init__(self, controllers):
38        CoexBaseTest.__init__(self, controllers)
39
40    def setup_class(self):
41        CoexBaseTest.setup_class(self)
42        req_params = ["iterations"]
43        self.unpack_userparams(req_params)
44
45    def setup_test(self):
46        CoexBaseTest.setup_test(self)
47        self.audio_receiver.power_on()
48        self.audio_receiver.pairing_mode()
49        if not pair_and_connect_headset(
50                self.pri_ad, self.audio_receiver.mac_address,
51                set([BtEnum.BluetoothProfile.A2DP.value])):
52            self.log.error("Failed to pair and connect to headset")
53            return False
54
55    def teardown_test(self):
56        clear_bonded_devices(self.pri_ad)
57        CoexBaseTest.teardown_test(self)
58        self.audio_receiver.clean_up()
59
60    def connect_disconnect_a2dp_headset(self):
61        """Connects and disconnect a2dp profile on headset for multiple
62        iterations.
63
64        Steps:
65        1.Connect a2dp profile on headset.
66        2.Disconnect a2dp profile on headset.
67        3.Repeat step 1 and 2 for N iterations.
68
69        Returns:
70            True if successful, False otherwise.
71        """
72        for i in range(0, self.iterations):
73            self.log.info("A2DP connect/disconnect Iteration {}".format(i))
74            if not connect_dev_to_headset(
75                    self.pri_ad, self.audio_receiver.mac_address,
76                    set([BtEnum.BluetoothProfile.A2DP.value])):
77                self.log.error("Failed to connect headset.")
78                return False
79
80            if not disconnect_headset_from_dev(
81                    self.pri_ad, self.audio_receiver.mac_address,
82                    [BtEnum.BluetoothProfile.A2DP.value]):
83                self.log.error("Failed to disconnect headset.")
84                return False
85        return True
86
87    def connect_disconnect_headset(self):
88        """Initiates connection to paired headset and disconnects headset.
89
90        Returns:
91            True if successful False otherwise.
92        """
93        for i in range(0, self.iterations):
94            self.pri_ad.droid.bluetoothConnectBonded(
95                self.audio_receiver.mac_address)
96            time.sleep(BLUETOOTH_WAIT_TIME)
97            if not self.pri_ad.droid.bluetoothIsDeviceConnected(
98                    self.audio_receiver.mac_address):
99                return False
100            self.pri_ad.droid.bluetoothDisconnectConnected(
101                self.audio_receiver.mac_address)
102        return True
103
104    def perform_classic_discovery_with_iperf(self):
105        """Wrapper function to start iperf traffic and classic discovery"""
106        self.run_iperf_and_get_result()
107        if not perform_classic_discovery(self.pri_ad):
108            return False
109        return self.teardown_result()
110
111    def connect_disconnect_a2dp_headset_with_iperf(self):
112        """Wrapper function to start iperf traffic and connect/disconnect
113        to headset for N iterations.
114        """
115        self.run_iperf_and_get_result()
116        if not self.connect_disconnect_a2dp_headset():
117            return False
118        return self.teardown_result()
119
120    def music_streaming_bluetooth_discovery_with_iperf(self):
121        """Wrapper function to start iperf traffic, music streaming and
122        classic discovery.
123        """
124        self.run_iperf_and_get_result()
125        tasks = [(music_play_and_check,
126                  (self.pri_ad, self.audio_receiver.mac_address,
127                   self.music_file_to_play, self.iperf["duration"])),
128                 (perform_classic_discovery, (self.pri_ad,))]
129        if not multithread_func(self.log, tasks):
130            return False
131        return self.teardown_result()
132
133    def music_streaming_with_iperf(self):
134        """Wrapper function to start iperf traffic and music streaming."""
135        self.run_iperf_and_get_result()
136        if not music_play_and_check(
137                self.pri_ad, self.audio_receiver.mac_address,
138                self.music_file_to_play, self.iperf["duration"]):
139            return False
140        return self.teardown_result()
141
142    def music_streaming_avrcp_controls_with_iperf(self):
143        """Wrapper function to start iperf traffic, music streaming and avrcp
144        controls.
145        """
146        self.run_iperf_and_get_result()
147        tasks = [(music_play_and_check,
148                  (self.pri_ad, self.audio_receiver.mac_address,
149                   self.music_file_to_play, self.iperf["duration"])),
150                 (self.avrcp_actions, ())]
151        if not multithread_func(self.log, tasks):
152            return False
153        return self.teardown_result()
154
155    def music_streaming_discovery_avrcp_controls_with_iperf(self):
156        """Wrapper function to start iperf traffic, music streaming, bluetooth
157        discovery and avrcp controls.
158        """
159        self.run_iperf_and_get_result()
160        tasks = [(music_play_and_check,
161                  (self.pri_ad, self.audio_receiver.mac_address,
162                   self.music_file_to_play, self.iperf["duration"])),
163                 (perform_classic_discovery, (self.pri_ad,)),
164                 (self.avrcp_actions, ())]
165        if not multithread_func(self.log, tasks):
166            return False
167        return self.teardown_result()
168
169    def music_streaming_ble_connection_with_iperf(self):
170        """Wrapper function to start iperf traffic, music streaming and ble
171        connection.
172        """
173        self.run_iperf_and_get_result()
174        tasks = [(music_play_and_check,
175                  (self.pri_ad, self.audio_receiver.mac_address,
176                   self.music_file_to_play, self.iperf["duration"])),
177                 (connect_ble, (self.pri_ad, self.sec_ad))]
178        if not multithread_func(self.log, tasks):
179            return False
180        return self.teardown_result()
181
182    def test_inquiry_after_headset_connection_with_tcp_ul(self):
183        """Starts TCP-uplink traffic, start inquiry after bluetooth connection.
184
185        This test is to start TCP-uplink traffic between host machine and
186        android device and test functional behaviour of bluetooth discovery
187        after connecting to headset.
188
189        Steps:
190        1. Run TCP-uplink traffic.
191        2. Start bluetooth discovery when headset is connected.
192
193        Returns:
194            True if successful, False otherwise.
195
196        Test Id: Bt_CoEx_009
197        """
198        if not self.perform_classic_discovery_with_iperf():
199            return False
200        return True
201
202    def test_inquiry_after_headset_connection_with_tcp_dl(self):
203        """Starts TCP-downlink traffic, start inquiry after bluetooth connection.
204
205        This test is to start TCP-downlink traffic between host machine and
206        android device and test functional behaviour of bluetooth discovery
207        after connecting to headset.
208
209        Steps:
210        1. Run TCP-downlink traffic.
211        2. Start bluetooth discovery when headset is connected.
212
213        Returns:
214            True if successful, False otherwise.
215
216        Test Id: Bt_CoEx_010
217        """
218        if not self.perform_classic_discovery_with_iperf():
219            return False
220        return True
221
222    def test_inquiry_after_headset_connection_with_udp_ul(self):
223        """Starts UDP-uplink traffic, start inquiry after bluetooth connection.
224
225        This test is to start UDP-uplink traffic between host machine and
226        android device and test functional behaviour of bluetooth discovery
227        after connecting to headset.
228
229        Steps:
230        1. Run UDP-uplink traffic.
231        2. Start bluetooth discovery when headset is connected.
232
233        Returns:
234            True if successful, False otherwise.
235
236        Test Id: Bt_CoEx_011
237        """
238        if not self.perform_classic_discovery_with_iperf():
239            return False
240        return True
241
242    def test_inquiry_after_headset_connection_with_udp_dl(self):
243        """Starts UDP-downlink traffic, start inquiry after bluetooth connection.
244
245        This test is to start UDP-downlink traffic between host machine and
246        android device and test functional behaviour of bluetooth discovery
247        after connecting to headset.
248
249        Steps:
250        1. Run UDP-downlink traffic.
251        2. Start bluetooth discovery when headset is connected.
252
253        Returns:
254            True if successful, False otherwise.
255
256        Test Id: Bt_CoEx_012
257        """
258        if not self.perform_classic_discovery_with_iperf():
259            return False
260        return True
261
262    def test_connect_disconnect_a2dp_headset_with_tcp_ul(self):
263        """Starts TCP-uplink traffic and connect/disconnect a2dp headset.
264
265        This test is to start TCP-uplink traffic between host machine and
266        android device and test functional behaviour of connection and
267        disconnection to a2dp headset.
268
269        Steps:
270        1. Run TCP-uplink traffic.
271        2. Connect and disconnect A2DP headset.
272        3. Repeat step 2 for N iterations.
273
274        Returns:
275            True if successful, False otherwise.
276
277        Test Id: Bt_CoEx_013
278        """
279        if not self.connect_disconnect_a2dp_headset_with_iperf():
280            return False
281        return True
282
283    def test_connect_disconnect_a2dp_headset_with_tcp_dl(self):
284        """Starts TCP-downlink traffic and connect/disconnect a2dp headset.
285
286        This test is to start TCP-downlink traffic between host machine and
287        android device and test functional behaviour of connection and
288        disconnection to a2dp headset.
289
290        Steps:
291        1. Run TCP-downlink traffic.
292        2. Connect and disconnect A2DP headset.
293        3. Repeat step 2 for N iterations.
294
295        Returns:
296            True if successful, False otherwise.
297
298        Test Id: Bt_CoEx_014
299        """
300        if not self.connect_disconnect_a2dp_headset_with_iperf():
301            return False
302        return True
303
304    def test_connect_disconnect_a2dp_headset_with_udp_ul(self):
305        """Starts UDP-uplink traffic and connect/disconnect a2dp headset.
306
307        This test is to start UDP-uplink traffic between host machine and
308        android device and test functional behaviour of connection and
309        disconnection to a2dp headset.
310
311        Steps:
312        1. Run UDP-uplink traffic.
313        2. Connect and disconnect A2DP headset.
314        3. Repeat step 2 for N iterations.
315
316        Returns:
317            True if successful, False otherwise.
318
319        Test Id: Bt_CoEx_015
320        """
321        if not self.connect_disconnect_a2dp_headset_with_iperf():
322            return False
323        return True
324
325    def test_connect_disconnect_a2dp_headset_with_udp_dl(self):
326        """Starts UDP-downlink traffic and connect/disconnect a2dp headset.
327
328        This test is to start UDP-downlink traffic between host machine and
329        android device and test functional behaviour of connection and
330        disconnection to a2dp headset.
331
332        Steps:
333        1. Run UDP-downlink traffic.
334        2. Connect and disconnect A2DP headset.
335        3. Repeat step 2 for N iterations.
336
337        Returns:
338            True if successful, False otherwise.
339
340        Test Id: Bt_CoEx_016
341        """
342        if not self.connect_disconnect_a2dp_headset_with_iperf():
343            return False
344        return True
345
346    def test_a2dp_streaming_bluetooth_discovery_with_tcp_ul(self):
347        """Starts TCP-uplink traffic, with music streaming to a2dp headset and
348        bluetooth discovery.
349
350        This test is to start TCP-uplink traffic between host machine and
351        android device and test functional behaviour of a2dp music streaming
352        and bluetooth discovery.
353
354        Steps:
355        1. Run TCP-uplink traffic.
356        2. Start media streaming to a2dp headset.
357        3. Start bluetooth discovery on android device.
358
359        Returns:
360            True if successful, False otherwise.
361
362        Test Id: Bt_CoEx_017
363        """
364        if not self.music_streaming_bluetooth_discovery_with_iperf():
365            return False
366        return True
367
368    def test_a2dp_streaming_bluetooth_discovery_with_tcp_dl(self):
369        """Starts TCP-downlink traffic, with music streaming to a2dp headset
370        and bluetooth discovery.
371
372        This test is to start TCP-downlink traffic between host machine and
373        android device and test functional behaviour of a2dp music streaming
374        and bluetooth discovery.
375
376        Steps:
377        1. Run TCP-downlink traffic.
378        2. Start media streaming to a2dp headset.
379        3. Start bluetooth discovery on android device.
380
381        Returns:
382            True if successful, False otherwise.
383
384        Test Id: Bt_CoEx_018
385        """
386        if not self.music_streaming_bluetooth_discovery_with_iperf():
387            return False
388        return True
389
390    def test_a2dp_streaming_bluetooth_discovery_with_udp_ul(self):
391        """Starts UDP-uplink traffic, with music streaming to a2dp headset and
392        bluetooth discovery.
393
394        This test is to start UDP-uplink traffic between host machine and
395        android device and test functional behaviour of a2dp music streaming
396        and bluetooth discovery.
397
398        Steps:
399        1. Run UDP-uplink traffic.
400        2. Start media streaming to a2dp headset.
401        3. Start bluetooth discovery on android device.
402
403        Returns:
404            True if successful, False otherwise.
405
406        Test Id: Bt_CoEx_019
407        """
408        if not self.music_streaming_bluetooth_discovery_with_iperf():
409            return False
410        return True
411
412    def test_a2dp_streaming_bluetooth_discovery_with_udp_dl(self):
413        """Starts UDP-downlink traffic, with music streaming to a2dp headset
414        and bluetooth discovery.
415
416        This test is to start UDP-downlink traffic between host machine and
417        android device and test functional behaviour of a2dp music streaming
418        and bluetooth discovery.
419
420        Steps:
421        1. Run UDP-downlink traffic.
422        2. Start media streaming to a2dp headset.
423        3. Start bluetooth discovery on android device.
424
425        Returns:
426            True if successful, False otherwise.
427
428        Test Id: Bt_CoEx_020
429        """
430        if not self.music_streaming_bluetooth_discovery_with_iperf():
431            return False
432        return True
433
434    def test_a2dp_streaming_with_tcp_ul(self):
435        """Starts TCP-uplink traffic with music streaming to a2dp headset.
436
437        This test is to start TCP-uplink traffic between host machine and
438        android device and test the functional behaviour of a2dp music
439        streaming.
440
441        Steps:
442        1. Run TCP-uplink traffic.
443        2. Start media streaming to a2dp headset.
444
445        Returns:
446            True if successful, False otherwise.
447
448        Test Id: Bt_CoEx_021
449        """
450        if not self.music_streaming_with_iperf():
451            return False
452        return True
453
454    def test_a2dp_streaming_with_tcp_dl(self):
455        """Starts TCP-downlink traffic with music streaming to a2dp headset.
456
457        This test is to start TCP-downlink traffic between host machine and
458        android device and test the functional behaviour of a2dp music
459        streaming.
460
461        Steps:
462        1. Run TCP-downlink traffic.
463        2. Start media streaming to a2dp headset.
464
465        Returns:
466            True if successful, False otherwise.
467
468        Test Id: Bt_CoEx_022
469        """
470        if not self.music_streaming_with_iperf():
471            return False
472        return True
473
474    def test_a2dp_streaming_with_udp_ul(self):
475        """Starts UDP-uplink traffic with music streaming to a2dp headset.
476
477        This test is to start UDP-uplink traffic between host machine and
478        android device and test the functional behaviour of a2dp music
479        streaming.
480
481        Steps:
482        1. Run UDP-uplink traffic.
483        2. Start media streaming to a2dp headset.
484
485        Returns:
486            True if successful, False otherwise.
487
488        Test Id: Bt_CoEx_023
489        """
490        if not self.music_streaming_with_iperf():
491            return False
492        return True
493
494    def test_a2dp_streaming_with_udp_dl(self):
495        """Starts UDP-downlink traffic with music streaming to a2dp headset.
496
497        This test is to start UDP-downlink traffic between host machine and
498        android device and test the functional behaviour of a2dp music
499        streaming.
500
501        Steps:
502        1. Run UDP-downlink traffic.
503        2. Start media streaming to a2dp headset.
504
505        Returns:
506            True if successful, False otherwise.
507
508        Test Id: Bt_CoEx_024
509        """
510        if not self.music_streaming_with_iperf():
511            return False
512        return True
513
514    def test_a2dp_streaming_avrcp_controls_with_tcp_ul(self):
515        """Starts TCP-uplink traffic with music streaming and avrcp controls.
516
517        This test is to start TCP-uplink traffic between host machine and
518        android device and test the functional behaviour of a2dp music
519        streaming and avrcp controls.
520
521        1. Run TCP-uplink traffic.
522        2. Start media streaming to a2dp headset.
523        3. Check all avrcp related controls.
524
525        Returns:
526            True if successful, False otherwise.
527
528        Test Id: Bt_CoEx_025
529        """
530        if not self.music_streaming_avrcp_controls_with_iperf():
531            return False
532        return True
533
534    def test_a2dp_streaming_avrcp_controls_with_tcp_dl(self):
535        """Starts TCP-downlink traffic with music streaming and avrcp controls.
536
537        This test is to start TCP-downlink traffic between host machine and
538        android device and test the functional behaviour of a2dp music
539        streaming and avrcp controls.
540
541        1. Run TCP-downlink traffic.
542        2. Start media streaming to a2dp headset.
543        3. Check all avrcp related controls.
544
545        Returns:
546            True if successful, False otherwise.
547
548        Test Id: Bt_CoEx_026
549        """
550        if not self.music_streaming_avrcp_controls_with_iperf():
551            return False
552        return True
553
554    def test_a2dp_streaming_avrcp_controls_with_udp_ul(self):
555        """Starts UDP-uplink traffic with music streaming and avrcp controls.
556
557        This test is to start UDP-uplink traffic between host machine and
558        android device and test the functional behaviour of a2dp music
559        streaming and avrcp controls.
560
561        1. Run UDP-uplink traffic.
562        2. Start media streaming to a2dp headset.
563        3. Check all avrcp related controls.
564
565        Returns:
566            True if successful, False otherwise.
567
568        Test Id: Bt_CoEx_027
569        """
570        if not self.music_streaming_avrcp_controls_with_iperf():
571            return False
572        return True
573
574    def test_a2dp_streaming_avrcp_controls_with_udp_dl(self):
575        """Starts UDP-downlink traffic with music streaming and avrcp controls.
576
577        This test is to start UDP-downlink traffic between host machine and
578        android device and test the functional behaviour of a2dp music
579        streaming and avrcp controls.
580
581        1. Run UDP-downlink traffic.
582        2. Start media streaming to a2dp headset.
583        3. Check all avrcp related controls.
584
585        Returns:
586            True if successful, False otherwise.
587
588        Test Id: Bt_CoEx_028
589        """
590        if not self.music_streaming_avrcp_controls_with_iperf():
591            return False
592        return True
593
594    def test_a2dp_streaming_avrcp_controls_bluetooth_discovery_tcp_ul(self):
595        """Starts TCP-uplink traffic with music streaming, avrcp controls and
596        bluetooth discovery.
597
598        This test is to start TCP-uplink traffic between host machine and
599        android device and test the functional behaviour of a2dp music
600        streaming, avrcp controls and bluetooth discovery.
601
602        1. Run TCP-uplink traffic.
603        2. Start media streaming to a2dp headset.
604        3. Check all avrcp related controls.
605        4. Start bluetooth discovery.
606
607        Returns:
608            True if successful, False otherwise.
609
610        Test Id: Bt_CoEx_029
611        """
612        if not self.music_streaming_discovery_avrcp_controls_with_iperf():
613            return False
614        return True
615
616    def test_a2dp_streaming_avrcp_controls_bluetooth_discovery_tcp_dl(self):
617        """Starts TCP-downlink traffic with music streaming, avrcp controls and
618        bluetooth discovery.
619
620        This test is to start TCP-downlink traffic between host machine and
621        android device and test the functional behaviour of a2dp music
622        streaming, avrcp controls and bluetooth discovery.
623
624        1. Run TCP-downlink traffic.
625        2. Start media streaming to a2dp headset.
626        3. Check all avrcp related controls.
627        4. Start bluetooth discovery.
628
629        Returns:
630            True if successful, False otherwise.
631
632        Test Id: Bt_CoEx_030
633        """
634        if not self.music_streaming_discovery_avrcp_controls_with_iperf():
635            return False
636        return True
637
638    def test_a2dp_streaming_avrcp_controls_bluetooth_discovery_udp_ul(self):
639        """Starts UDP-uplink traffic with music streaming, avrcp controls and
640        bluetooth discovery.
641
642        This test is to start UDP-uplink traffic between host machine and
643        android device and test the functional behaviour of a2dp music
644        streaming, avrcp controls and bluetooth discovery.
645
646        1. Run UDP-uplink traffic.
647        2. Start media streaming to a2dp headset.
648        3. Check all avrcp related controls.
649        4. Start bluetooth discovery.
650
651        Returns:
652            True if successful, False otherwise.
653
654        Test Id: Bt_CoEx_031
655        """
656        if not self.music_streaming_discovery_avrcp_controls_with_iperf():
657            return False
658        return True
659
660    def test_a2dp_streaming_avrcp_controls_bluetooth_discovery_udp_dl(self):
661        """Starts UDP-downlink traffic with music streaming, avrcp controls and
662        bluetooth discovery.
663
664        This test is to start UDP-downlink traffic between host machine and
665        android device and test the functional behaviour of a2dp music
666        streaming, avrcp controls and bluetooth discovery.
667
668        1. Run UDP-downlink traffic.
669        2. Start media streaming to a2dp headset.
670        3. Check all avrcp related controls.
671        4. Start bluetooth discovery.
672
673        Returns:
674            True if successful, False otherwise.
675
676        Test Id: Bt_CoEx_032
677        """
678        if not self.music_streaming_discovery_avrcp_controls_with_iperf():
679            return False
680        return True
681
682    def test_connect_disconnect_headset_with_fping(self):
683        """Starts fping, along with connection and disconnection of headset.
684
685        This test is to start fping between host machine and android device
686        with connection and disconnection of paired headset.
687
688        Steps:
689        1. Start fping.
690        2. Enable bluetooth
691        3. Connect bluetooth headset.
692        4. Disconnect bluetooth headset.
693
694        Returns:
695            True if successful, False otherwise.
696
697        Test Id: Bt_CoEx_076
698        """
699        args = [lambda: start_fping(self.pri_ad, self.iperf["duration"])]
700        self.run_thread(args)
701        if not self.connect_disconnect_headset():
702            return False
703        return self.teardown_thread()
704
705    def test_a2dp_streaming_with_fping(self):
706        """Starts fping along with a2dp streaming.
707
708        This test is to start fping between host machine and android device
709        and test the functional behaviour of music streaming to a2dp headset.
710
711        Steps:
712        1. Start fping.
713        1. Start media play on android device and check for music streaming.
714
715        Returns:
716            True if successful, False otherwise.
717
718        Test Id: Bt_CoEx_077
719        """
720        args = [lambda: start_fping(self.pri_ad, self.iperf["duration"])]
721        self.run_thread(args)
722        if not music_play_and_check(
723                self.pri_ad, self.audio_receiver.mac_address,
724                self.music_file_to_play, self.iperf["duration"]):
725            return False
726        return self.teardown_thread()
727
728    def test_connect_disconnect_headset_toggle_screen_state_with_fping(self):
729        """Starts fping along with connection and disconnection of the headset.
730
731        This test is to start fping between host machine and android device
732        and test the functional behaviour of connection and disconnection of
733        the paired headset when screen is off and on.
734
735        Steps:
736        1. Start fping.
737        2. Connect bluetooth headset.
738        4. Disconnect bluetooth headset.
739        5. Screen on/off.
740
741        Returns:
742            True if successful, False otherwise.
743
744        Test Id: Bt_CoEx_079
745        """
746        tasks = [(start_fping, (self.pri_ad, self.iperf["duration"])),
747                 (self.connect_disconnect_headset, ()),
748                 (toggle_screen_state, (self.pri_ad, self.iterations))]
749        if not multithread_func(self.log, tasks):
750            return False
751        return self.teardown_thread()
752
753    def test_a2dp_streaming_toggle_screen_state_with_fping(self):
754        """Starts fping along with a2dp streaming.
755
756        This test is to start fping with traffic between host machine and
757        android device and test the functional behaviour of a2dp streaming when
758        screen turned on or off.
759
760        Steps:
761        1. Start fping.
762        2. Start media play on android device and check for music streaming.
763        3. Start screen on/off of android device multiple times.
764
765        Returns:
766            True if successful, False otherwise.
767
768        Test Id: Bt_CoEx_080
769        """
770        tasks = [(start_fping, (self.pri_ad, self.iperf["duration"])),
771                 (music_play_and_check,
772                  (self.pri_ad, self.audio_receiver.mac_address,
773                   self.music_file_to_play, self.iperf["duration"])),
774                 (toggle_screen_state, (self.pri_ad, self.iterations))]
775        if not multithread_func(self.log, tasks):
776            return False
777        return self.teardown_thread()
778
779    def test_a2dp_streaming_ble_connection_with_tcp_ul(self):
780        """Starts TCP-uplink traffic with a2dp streaming and ble connection.
781
782        This test is to start TCP-uplink traffic between host machine and
783        android device and test the functional behaviour of  ble connection
784        and a2dp streaming.
785
786        Steps:
787        1. Start TCP-uplink traffic.
788        2. Start media play on android device and check for music streaming.
789        3. Initiate ble connection to android device.
790
791        Returns:
792            True if successful, False otherwise.
793
794        Test Id: Bt_CoEx_084
795        """
796        if not self.music_streaming_ble_connection_with_iperf():
797            return False
798        return True
799
800    def test_a2dp_streaming_ble_connection_with_tcp_dl(self):
801        """Starts TCP-downlink traffic with a2dp streaming and ble connection.
802
803        This test is to start TCP-downlink traffic between host machine and
804        android device and test the functional behaviour of  ble connection
805        and a2dp streaming.
806
807        Steps:
808        1. Start TCP-downlink traffic.
809        2. Start media play on android device and check for music streaming.
810        3. Initiate ble connection to android device.
811
812        Returns:
813            True if successful, False otherwise.
814
815        Test Id: Bt_CoEx_085
816        """
817        if not self.music_streaming_ble_connection_with_iperf():
818            return False
819        return True
820