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