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