1#!/usr/bin/env python3
2#
3#   Copyright 2016 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of 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,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17Sanity tests for voice tests in telephony
18"""
19import time
20
21from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
22from acts.controllers.anritsu_lib.md8475a import CsfbType
23from acts.controllers.anritsu_lib.md8475a import MD8475A
24from acts.controllers.anritsu_lib.md8475a import VirtualPhoneAutoAnswer
25from acts_contrib.test_utils.tel.anritsu_utils import WAIT_TIME_ANRITSU_REG_AND_CALL
26from acts_contrib.test_utils.tel.anritsu_utils import call_mo_setup_teardown
27from acts_contrib.test_utils.tel.anritsu_utils import ims_call_cs_teardown
28from acts_contrib.test_utils.tel.anritsu_utils import call_mt_setup_teardown
29from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_1x
30from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_1x_evdo
31from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_gsm
32from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte
33from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte_1x
34from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte_wcdma
35from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte_gsm
36from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_wcdma
37from acts_contrib.test_utils.tel.anritsu_utils import set_usim_parameters
38from acts_contrib.test_utils.tel.anritsu_utils import set_post_sim_params
39from acts_contrib.test_utils.tel.tel_defines import CALL_TEARDOWN_PHONE
40from acts_contrib.test_utils.tel.tel_defines import DEFAULT_EMERGENCY_CALL_NUMBER
41from acts_contrib.test_utils.tel.tel_defines import EMERGENCY_CALL_NUMBERS
42from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
43from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_GSM
44from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_LTE
45from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
46from acts_contrib.test_utils.tel.tel_defines import RAT_1XRTT
47from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
48from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
49from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
50from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_CDMA_EVDO
51from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
52from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
53from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
54from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL_FOR_IMS
55from acts_contrib.test_utils.tel.tel_ims_utils import toggle_volte
56from acts_contrib.test_utils.tel.tel_logging_utils import start_qxdm_loggers
57from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_rat
58from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phone_default_state
59from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_idle_volte
60from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
61from acts_contrib.test_utils.tel.tel_test_utils import check_apm_mode_on_by_serial
62from acts_contrib.test_utils.tel.tel_test_utils import set_apm_mode_on_by_serial
63from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_apn_by_adb
64from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
65from acts.test_decorators import test_tracker_info
66from acts.utils import exe_cmd
67
68
69class TelLabEmergencyCallTest(TelephonyBaseTest):
70    def setup_class(self):
71        super().setup_class()
72        try:
73            self.stress_test_number = int(
74                self.user_params["stress_test_number"])
75            self.log.info("Executing {} calls per test in stress test mode".
76                          format(self.stress_test_number))
77        except KeyError:
78            self.stress_test_number = 0
79            self.log.info(
80                "No 'stress_test_number' defined: running single iteration tests"
81            )
82
83        self.ad = self.android_devices[0]
84        self.ad.sim_card = getattr(self.ad, "sim_card", None)
85        self.md8475a_ip_address = self.user_params[
86            "anritsu_md8475a_ip_address"]
87        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
88        self.md8475_version = self.user_params.get("md8475", "A")
89
90        setattr(self, 'emergency_call_number', DEFAULT_EMERGENCY_CALL_NUMBER)
91        if 'emergency_call_number' in self.user_params:
92            self.emergency_call_number = self.user_params[
93                'emergency_call_number']
94            self.log.info("Using provided emergency call number: {}".format(
95                self.emergency_call_number))
96        if not self.emergency_call_number in EMERGENCY_CALL_NUMBERS:
97            self.log.warning("Unknown Emergency Number {}".format(
98                self.emergency_call_number))
99
100        # Check for all adb devices on the linux machine, and set APM ON
101        cmd = "|".join(("adb devices", "grep -i device$", "cut -f1"))
102        output = exe_cmd(cmd)
103        list_of_devices = output.decode("utf-8").split("\n")
104        if len(list_of_devices) > 1:
105            for i in range(len(list_of_devices) - 1):
106                self.log.info("Serial %s", list_of_devices[i])
107                if check_apm_mode_on_by_serial(self.ad, list_of_devices[i]):
108                    self.log.info("Device is already in APM ON")
109                else:
110                    self.log.info("Device is not in APM, turning it ON")
111                    set_apm_mode_on_by_serial(self.ad, list_of_devices[i])
112                    if check_apm_mode_on_by_serial(self.ad,
113                                                   list_of_devices[i]):
114                        self.log.info("Device is now in APM ON")
115
116        if self.ad.sim_card == "VzW12349":
117            set_preferred_apn_by_adb(self.ad, "VZWINTERNET")
118
119        try:
120            self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option,
121                                   self.md8475_version)
122        except AnritsuError:
123            self.log.error("Error in connecting to Anritsu Simulator")
124            return False
125        return True
126
127    def setup_test(self):
128        if getattr(self, "qxdm_log", True):
129            start_qxdm_loggers(self.log, self.android_devices)
130        ensure_phone_default_state(self.log, self.ad, check_subscription=False)
131        toggle_airplane_mode_by_adb(self.log, self.ad, True)
132        try:
133            if self.ad.sim_card == "VzW12349":
134                self.ad.droid.imsSetVolteProvisioning(True)
135        except Exception as e:
136            self.ad.log.error(e)
137        # get a handle to virtual phone
138        self.virtualPhoneHandle = self.anritsu.get_VirtualPhone()
139        return True
140
141    def teardown_test(self):
142        self.log.info("Stopping Simulation")
143        self.anritsu.stop_simulation()
144        toggle_airplane_mode_by_adb(self.log, self.ad, True)
145        return True
146
147    def teardown_class(self):
148        self.anritsu.disconnect()
149        return True
150
151    def _setup_emergency_call(self,
152                              set_simulation_func,
153                              phone_setup_func,
154                              phone_idle_func_after_registration=None,
155                              is_ims_call=False,
156                              is_wait_for_registration=True,
157                              csfb_type=None,
158                              srlte_csfb=None,
159                              srvcc=None,
160                              emergency_number=DEFAULT_EMERGENCY_CALL_NUMBER,
161                              teardown_side=CALL_TEARDOWN_PHONE,
162                              wait_time_in_call=WAIT_TIME_IN_CALL):
163        try:
164            set_simulation_func(self.anritsu, self.user_params,
165                                self.ad.sim_card)
166            set_usim_parameters(self.anritsu, self.ad.sim_card)
167            if is_ims_call or srvcc or csfb_type:
168                set_post_sim_params(self.anritsu, self.user_params,
169                                    self.ad.sim_card)
170            self.virtualPhoneHandle.auto_answer = (VirtualPhoneAutoAnswer.ON,
171                                                   2)
172            if csfb_type:
173                self.anritsu.csfb_type = csfb_type
174            if srlte_csfb == "lte_call_failure":
175                self.anritsu.send_command("IMSPSAPAUTOANSWER 1,DISABLE")
176                self.anritsu.start_simulation()
177                self.anritsu.send_command("IMSSTARTVN 1")
178                check_ims_reg = True
179                check_ims_calling = True
180            elif srlte_csfb == "ims_unregistered":
181                self.anritsu.start_simulation()
182                self.anritsu.send_command("IMSSTARTVN 1")
183                self.anritsu.send_command(
184                    "IMSCSCFBEHAVIOR 1,SENDERRORRESPONSE603")
185                check_ims_reg = False
186                check_ims_calling = False
187            elif srlte_csfb == "ps911_unsupported":
188                self.anritsu.send_command("EMCBS NOTSUPPORT,BTS1")
189                self.anritsu.start_simulation()
190                self.anritsu.send_command("IMSSTARTVN 1")
191                check_ims_reg = True
192                check_ims_calling = False
193            elif srlte_csfb == "emc_barred":
194                self.anritsu.send_command("ACBARRED USERSPECIFIC,BTS1")
195                self.anritsu.send_command("LTEEMERGENCYACBARRED BARRED,BTS1")
196                self.anritsu.start_simulation()
197                self.anritsu.send_command("IMSSTARTVN 1")
198                check_ims_reg = True
199                check_ims_calling = False
200            elif srvcc == "InCall":
201                self.anritsu.start_simulation()
202                self.anritsu.send_command("IMSSTARTVN 1")
203                self.anritsu.send_command("IMSSTARTVN 2")
204                self.anritsu.send_command("IMSSTARTVN 3")
205                check_ims_reg = True
206                check_ims_calling = True
207            else:
208                self.anritsu.start_simulation()
209            if is_ims_call or csfb_type:
210                self.anritsu.send_command("IMSSTARTVN 1")
211                self.anritsu.send_command("IMSSTARTVN 2")
212                self.anritsu.send_command("IMSSTARTVN 3")
213
214            iterations = 1
215            if self.stress_test_number > 0:
216                iterations = self.stress_test_number
217            successes = 0
218            for i in range(1, iterations + 1):
219                if self.stress_test_number:
220                    self.log.info(
221                        "Running iteration {} of {}".format(i, iterations))
222                # FIXME: There's no good reason why this must be true;
223                # I can only assume this was done to work around a problem
224                self.ad.droid.telephonyToggleDataConnection(False)
225
226                # turn off all other BTS to ensure UE registers on BTS1
227                sim_model = (self.anritsu.get_simulation_model()).split(",")
228                no_of_bts = len(sim_model)
229                for i in range(2, no_of_bts + 1):
230                    self.anritsu.send_command(
231                        "OUTOFSERVICE OUT,BTS{}".format(i))
232
233                if phone_setup_func is not None:
234                    if not phone_setup_func(self.ad):
235                        self.log.warning(
236                            "phone_setup_func failed. Rebooting UE")
237                        self.ad.reboot()
238                        time.sleep(30)
239                        if self.ad.sim_card == "VzW12349":
240                            set_preferred_apn_by_adb(self.ad, "VZWINTERNET")
241                        if not phone_setup_func(self.ad):
242                            self.log.error("phone_setup_func failed.")
243                            continue
244
245                if is_wait_for_registration:
246                    self.anritsu.wait_for_registration_state()
247
248                if phone_idle_func_after_registration:
249                    if not phone_idle_func_after_registration(self.log,
250                                                              self.ad):
251                        continue
252
253                for i in range(2, no_of_bts + 1):
254                    self.anritsu.send_command(
255                        "OUTOFSERVICE IN,BTS{}".format(i))
256
257                time.sleep(WAIT_TIME_ANRITSU_REG_AND_CALL)
258                if srlte_csfb or srvcc:
259                    if not ims_call_cs_teardown(
260                            self.log, self.ad, self.anritsu, emergency_number,
261                            CALL_TEARDOWN_PHONE, True, check_ims_reg,
262                            check_ims_calling, srvcc,
263                            WAIT_TIME_IN_CALL_FOR_IMS, WAIT_TIME_IN_CALL):
264                        self.log.error(
265                            "Phone {} Failed to make emergency call to {}"
266                            .format(self.ad.serial, emergency_number))
267                        continue
268                else:
269                    if not call_mo_setup_teardown(
270                            self.log, self.ad, self.anritsu, emergency_number,
271                            CALL_TEARDOWN_PHONE, True, WAIT_TIME_IN_CALL,
272                            is_ims_call):
273                        self.log.error(
274                            "Phone {} Failed to make emergency call to {}"
275                            .format(self.ad.serial, emergency_number))
276                        continue
277                successes += 1
278                if self.stress_test_number:
279                    self.log.info("Passed iteration {}".format(i))
280            if self.stress_test_number:
281                self.log.info("Total of {} successes out of {} attempts".
282                              format(successes, iterations))
283            return True if successes == iterations else False
284
285        except AnritsuError as e:
286            self.log.error("Error in connection with Anritsu Simulator: " +
287                           str(e))
288            return False
289        except Exception as e:
290            self.log.error("Exception during emergency call procedure: " + str(
291                e))
292            return False
293        return True
294
295    def _phone_setup_lte_wcdma(self, ad):
296        toggle_volte(self.log, ad, False)
297        return ensure_network_rat(
298            self.log,
299            ad,
300            NETWORK_MODE_LTE_GSM_WCDMA,
301            RAT_FAMILY_LTE,
302            toggle_apm_after_setting=True)
303
304    def _phone_setup_lte_1x(self, ad):
305        return ensure_network_rat(
306            self.log,
307            ad,
308            NETWORK_MODE_LTE_CDMA_EVDO,
309            RAT_FAMILY_LTE,
310            toggle_apm_after_setting=True)
311
312    def _phone_setup_wcdma(self, ad):
313        return ensure_network_rat(
314            self.log,
315            ad,
316            NETWORK_MODE_GSM_UMTS,
317            RAT_FAMILY_UMTS,
318            toggle_apm_after_setting=True)
319
320    def _phone_setup_gsm(self, ad):
321        return ensure_network_rat(
322            self.log,
323            ad,
324            NETWORK_MODE_GSM_ONLY,
325            RAT_FAMILY_GSM,
326            toggle_apm_after_setting=True)
327
328    def _phone_setup_1x(self, ad):
329        return ensure_network_rat(
330            self.log,
331            ad,
332            NETWORK_MODE_CDMA,
333            RAT_FAMILY_CDMA2000,
334            toggle_apm_after_setting=True)
335
336    def _phone_setup_airplane_mode(self, ad):
337        return toggle_airplane_mode_by_adb(self.log, ad, True)
338
339    def _phone_disable_airplane_mode(self, ad):
340        return toggle_airplane_mode_by_adb(self.log, ad, False)
341
342    def _phone_setup_volte_airplane_mode(self, ad):
343        toggle_volte(self.log, ad, True)
344        return toggle_airplane_mode_by_adb(self.log, ad, True)
345
346    def _phone_setup_volte(self, ad):
347        ad.droid.telephonyToggleDataConnection(True)
348        toggle_volte(self.log, ad, True)
349        return ensure_network_rat(
350            self.log,
351            ad,
352            NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA,
353            RAT_FAMILY_LTE,
354            toggle_apm_after_setting=True)
355
356    """ Tests Begin """
357
358    @test_tracker_info(uuid="f5c93228-3b43-48a3-b509-796d41625171")
359    @TelephonyBaseTest.tel_test_wrap
360    def test_emergency_call_lte_wcdma_csfb_redirection(self):
361        """ Test Emergency call functionality on LTE.
362            CSFB type is REDIRECTION
363
364        Steps:
365        1. Setup CallBox on LTE and WCDMA network, make sure DUT register on LTE network.
366        2. Make an emergency call to 911. Make sure DUT does not CSFB to WCDMA.
367        3. Make sure Anritsu receives the call and accept.
368        4. Tear down the call.
369
370        Expected Results:
371        2. Emergency call succeed. DUT does not CSFB to WCDMA.
372        3. Anritsu can accept the call.
373        4. Tear down call succeed.
374
375        Returns:
376            True if pass; False if fail
377        """
378        return self._setup_emergency_call(
379            set_system_model_lte_wcdma,
380            self._phone_setup_lte_wcdma,
381            emergency_number=self.emergency_call_number,
382            csfb_type=CsfbType.CSFB_TYPE_REDIRECTION,
383            is_ims_call=True)
384
385    @test_tracker_info(uuid="8deb6b21-2cb0-4241-bcad-6cd62a340b07")
386    @TelephonyBaseTest.tel_test_wrap
387    def test_emergency_call_lte_wcdma_csfb_handover(self):
388        """ Test Emergency call functionality on LTE.
389            CSFB type is HANDOVER
390
391        Steps:
392        1. Setup CallBox on LTE and WCDMA network, make sure DUT register on LTE network.
393        2. Make an emergency call to 911. Make sure DUT does not CSFB to WCDMA.
394        3. Make sure Anritsu receives the call and accept.
395        4. Tear down the call.
396
397        Expected Results:
398        2. Emergency call succeed. DUT does not CSFB to WCDMA.
399        3. Anritsu can accept the call.
400        4. Tear down call succeed.
401
402        Returns:
403            True if pass; False if fail
404        """
405        return self._setup_emergency_call(
406            set_system_model_lte_wcdma,
407            self._phone_setup_lte_wcdma,
408            emergency_number=self.emergency_call_number,
409            csfb_type=CsfbType.CSFB_TYPE_HANDOVER,
410            is_ims_call=True)
411
412    @test_tracker_info(uuid="52b6b783-de77-497d-87e0-63c930e6c9bb")
413    @TelephonyBaseTest.tel_test_wrap
414    def test_emergency_call_lte_1x_csfb(self):
415        """ Test Emergency call functionality on LTE (CSFB to 1x).
416
417        Steps:
418        1. Setup CallBox on LTE and CDMA 1X network, make sure DUT register on LTE network.
419        2. Make an emergency call to 911. Make sure DUT CSFB to 1x.
420        3. Make sure Anritsu receives the call and accept.
421        4. Tear down the call.
422
423        Expected Results:
424        2. Emergency call succeed. DUT CSFB to 1x.
425        3. Anritsu can accept the call.
426        4. Tear down call succeed.
427
428        Returns:
429            True if pass; False if fail
430        """
431        return self._setup_emergency_call(
432            set_system_model_lte_1x,
433            self._phone_setup_lte_1x,
434            emergency_number=self.emergency_call_number)
435
436    @test_tracker_info(uuid="fcdd5a4f-fdf2-44dc-b1b2-44ab175791ce")
437    @TelephonyBaseTest.tel_test_wrap
438    def test_emergency_call_wcdma(self):
439        """ Test Emergency call functionality on WCDMA
440
441        Steps:
442        1. Setup CallBox on WCDMA network, make sure DUT register on WCDMA network.
443        2. Make an emergency call to 911.
444        3. Make sure Anritsu receives the call and accept.
445        4. Tear down the call.
446
447        Expected Results:
448        2. Emergency call succeed.
449        3. Anritsu can accept the call.
450        4. Tear down call succeed.
451
452        Returns:
453            True if pass; False if fail
454        """
455        return self._setup_emergency_call(
456            set_system_model_wcdma,
457            self._phone_setup_wcdma,
458            emergency_number=self.emergency_call_number)
459
460    @test_tracker_info(uuid="295c3188-24e2-4c53-80c6-3d3001e2ff16")
461    @TelephonyBaseTest.tel_test_wrap
462    def test_emergency_call_gsm(self):
463        """ Test Emergency call functionality on GSM
464
465        Steps:
466        1. Setup CallBox on GSM network, make sure DUT register on GSM network.
467        2. Make an emergency call to 911.
468        3. Make sure Anritsu receives the call and accept.
469        4. Tear down the call.
470
471        Expected Results:
472        2. Emergency call succeed.
473        3. Anritsu can accept the call.
474        4. Tear down call succeed.
475
476        Returns:
477            True if pass; False if fail
478        """
479        return self._setup_emergency_call(
480            set_system_model_gsm,
481            self._phone_setup_gsm,
482            emergency_number=self.emergency_call_number)
483
484    @test_tracker_info(uuid="4f21bfc0-a0a9-43b8-9285-dcfb131a3a04")
485    @TelephonyBaseTest.tel_test_wrap
486    def test_emergency_call_1x(self):
487        """ Test Emergency call functionality on CDMA 1X
488
489        Steps:
490        1. Setup CallBox on 1x network, make sure DUT register on 1x network.
491        2. Make an emergency call to 911.
492        3. Make sure Anritsu receives the call and accept.
493        4. Tear down the call.
494
495        Expected Results:
496        2. Emergency call succeed.
497        3. Anritsu can accept the call.
498        4. Tear down call succeed.
499
500        Returns:
501            True if pass; False if fail
502        """
503        return self._setup_emergency_call(
504            set_system_model_1x,
505            self._phone_setup_1x,
506            emergency_number=self.emergency_call_number)
507
508    @test_tracker_info(uuid="6dfd3e1d-7faa-426f-811a-ebd5e54f9c9a")
509    @TelephonyBaseTest.tel_test_wrap
510    def test_emergency_call_1x_evdo(self):
511        """ Test Emergency call functionality on CDMA 1X with EVDO
512
513        Steps:
514        1. Setup CallBox on 1x and EVDO network, make sure DUT register on 1x network.
515        2. Make an emergency call to 911.
516        3. Make sure Anritsu receives the call and accept.
517        4. Tear down the call.
518
519        Expected Results:
520        2. Emergency call succeed.
521        3. Anritsu can accept the call.
522        4. Tear down call succeed.
523
524        Returns:
525            True if pass; False if fail
526        """
527        return self._setup_emergency_call(
528            set_system_model_1x_evdo,
529            self._phone_setup_1x,
530            emergency_number=self.emergency_call_number)
531
532    @test_tracker_info(uuid="40f9897e-4924-4896-9f2c-0b4f45331251")
533    @TelephonyBaseTest.tel_test_wrap
534    def test_emergency_call_1x_apm(self):
535        """ Test Emergency call functionality on Airplane mode
536
537        Steps:
538        1. Setup CallBox on 1x network.
539        2. Turn on Airplane mode on DUT. Make an emergency call to 911.
540        3. Make sure Anritsu receives the call and accept.
541        4. Tear down the call.
542
543        Expected Results:
544        2. Emergency call succeed.
545        3. Anritsu can accept the call.
546        4. Tear down call succeed.
547
548        Returns:
549            True if pass; False if fail
550        """
551        return self._setup_emergency_call(
552            set_system_model_1x,
553            self._phone_setup_airplane_mode,
554            is_wait_for_registration=False,
555            emergency_number=self.emergency_call_number)
556
557    @test_tracker_info(uuid="5997c004-449b-4a5e-816e-2ff0c0eb928d")
558    @TelephonyBaseTest.tel_test_wrap
559    def test_emergency_call_wcdma_apm(self):
560        """ Test Emergency call functionality on Airplane mode
561
562        Steps:
563        1. Setup CallBox on WCDMA network.
564        2. Make an emergency call to 911.
565        3. Make sure Anritsu receives the call and accept.
566        4. Tear down the call.
567
568        Expected Results:
569        2. Emergency call succeed.
570        3. Anritsu can accept the call.
571        4. Tear down call succeed.
572
573        Returns:
574            True if pass; False if fail
575        """
576        return self._setup_emergency_call(
577            set_system_model_wcdma,
578            self._phone_setup_airplane_mode,
579            is_wait_for_registration=False,
580            emergency_number=self.emergency_call_number)
581
582    @test_tracker_info(uuid="9afde8d3-bdf0-41d9-af8c-2a8f36aae169")
583    @TelephonyBaseTest.tel_test_wrap
584    def test_emergency_call_volte_wcdma_srvcc(self):
585        """ Test Emergency call functionality,
586        VoLTE to WCDMA SRVCC
587        Steps:
588        1. Setup CallBox on VoLTE network with WCDMA.
589        2. Turn on DUT and enable VoLTE. Make an emergency call to 911.
590        3. Check if VoLTE emergency call connected successfully.
591        4. Handover the call to WCDMA and check if the call is still up.
592        5. Tear down the call.
593
594        Expected Results:
595        1. VoLTE Emergency call is made successfully.
596        2. After SRVCC, the 911 call is not dropped.
597        3. Tear down call succeed.
598
599        Returns:
600            True if pass; False if fail
601        """
602        return self._setup_emergency_call(
603            set_system_model_lte_wcdma,
604            self._phone_setup_volte,
605            phone_idle_volte,
606            srvcc="InCall",
607            emergency_number=self.emergency_call_number,
608            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
609
610    @test_tracker_info(uuid="2e454f11-e77d-452a-bcac-7271378953ed")
611    @TelephonyBaseTest.tel_test_wrap
612    def test_emergency_call_volte_gsm_srvcc(self):
613        """ Test Emergency call functionality,
614        VoLTE to GSM SRVCC
615        Steps:
616        1. Setup CallBox on VoLTE network with GSM.
617        2. Turn on DUT and enable VoLTE. Make an emergency call to 911.
618        3. Check if VoLTE emergency call connected successfully.
619        4. Handover the call to GSM and check if the call is still up.
620        5. Tear down the call.
621
622        Expected Results:
623        1. VoLTE Emergency call is made successfully.
624        2. After SRVCC, the 911 call is not dropped.
625        3. Tear down call succeed.
626
627        Returns:
628            True if pass; False if fail
629        """
630        return self._setup_emergency_call(
631            set_system_model_lte_gsm,
632            self._phone_setup_volte,
633            phone_idle_volte,
634            srvcc="InCall",
635            emergency_number=self.emergency_call_number,
636            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
637
638    @test_tracker_info(uuid="4dae7e62-b73e-4ba1-92ee-ecc121b898b3")
639    @TelephonyBaseTest.tel_test_wrap
640    def test_emergency_call_csfb_1x_lte_call_failure(self):
641        """ Test Emergency call functionality,
642        CSFB to CDMA1x after VoLTE call failure
643        Ref: VzW LTE E911 test plan, 2.23, VZ_TC_LTEE911_7481
644        Steps:
645        1. Setup CallBox on VoLTE network with CDMA1x.
646        2. Turn on DUT and enable VoLTE. Make an emergency call to 911.
647        3. Make sure Anritsu IMS server does not answer the call
648        4. The DUT requests CSFB to 1XCDMA and Anritsu accepts the call.
649        5. Tear down the call.
650
651        Expected Results:
652        1. VoLTE Emergency call is made.
653        2. Anritsu receive the call but does not answer.
654        3. The 911 call CSFB to CDMA1x and answered successfully.
655        4. Tear down call succeed.
656
657        Returns:
658            True if pass; False if fail
659        """
660        return self._setup_emergency_call(
661            set_system_model_lte_1x,
662            self._phone_setup_volte,
663            phone_idle_volte,
664            srlte_csfb="lte_call_failure",
665            emergency_number=self.emergency_call_number,
666            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
667
668    @test_tracker_info(uuid="e98c9101-1ab6-497e-9d67-a4ff62d28fea")
669    @TelephonyBaseTest.tel_test_wrap
670    def test_emergency_call_csfb_1x_ims_unregistered(self):
671        """ Test Emergency call functionality,
672        CSFB to CDMA1x because ims registration delcined
673        Ref: VzW LTE E911 test plan, 2.25, VZ_TC_LTEE911_7483
674        Steps:
675        1. Setup CallBox on VoLTE network with CDMA1x.
676        2. Setup Anritsu IMS server to decline IMS registration
677        3. Turn on DUT and enable VoLTE. Make an emergency call to 911.
678        4. The DUT requests CSFB to 1XCDMA and Anritsu accepts the call.
679        5. Tear down the call.
680
681        Expected Results:
682        1. Phone registers on LTE network with VoLTE enabled.
683        2. When Emergency call is made, phone request CSFB to CDMA1x.
684        3. The 911 call on CDMA1x is answered successfully.
685        4. Tear down call succeed.
686
687        Returns:
688            True if pass; False if fail
689        """
690        return self._setup_emergency_call(
691            set_system_model_lte_1x,
692            self._phone_setup_volte,
693            None,
694            srlte_csfb="ims_unregistered",
695            emergency_number=self.emergency_call_number,
696            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
697
698    @test_tracker_info(uuid="d96e1b9b-2f6d-49f3-a203-f4277056869e")
699    @TelephonyBaseTest.tel_test_wrap
700    def test_emergency_call_csfb_1x_ps911_unsupported(self):
701        """ Test Emergency call functionality,
702        CSFB to CDMA1x because MME does not support PS911, by setting
703        Emergency Bearer Service not supported in EPS network feature
704        Ref: VzW LTE E911 test plan, 2.26, VZ_TC_LTEE911_8357
705        Steps:
706        1. Setup CallBox on VoLTE network with CDMA1x.
707        2. Setup Emergency Bearer Service not supported in EPS network feature
708        3. Turn on DUT and enable VoLTE. Make an emergency call to 911.
709        4. The DUT requests CSFB to 1XCDMA and Anritsu accepts the call.
710        5. Tear down the call.
711
712        Expected Results:
713        1. Phone registers on LTE network with VoLTE enabled.
714        2. When Emergency call is made, phone request CSFB to CDMA1x.
715        3. The 911 call on CDMA1x is answered successfully.
716        4. Tear down call succeed.
717
718        Returns:
719            True if pass; False if fail
720        """
721        return self._setup_emergency_call(
722            set_system_model_lte_1x,
723            self._phone_setup_volte,
724            phone_idle_volte,
725            srlte_csfb="ps911_unsupported",
726            emergency_number=self.emergency_call_number,
727            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
728
729    @test_tracker_info(uuid="f7d48841-b8ef-4031-99de-28534aaf4c44")
730    @TelephonyBaseTest.tel_test_wrap
731    def test_emergency_call_csfb_1x_emc_barred(self):
732        """ Test Emergency call functionality,
733        CSFB to CDMA1x because SIB2 Emergency Barred,
734        by setting Access Class Barred for Emergency
735        Ref: VzW LTE E911 test plan, 2.27, VZ_TC_LTEE911_8358
736        Steps:
737        1. Setup CallBox on VoLTE network with CDMA1x.
738        2. Set Access Class Barred for Emergency in SIB2
739        3. Turn on DUT and enable VoLTE. Make an emergency call to 911.
740        4. The DUT requests CSFB to 1XCDMA and Anritsu accepts the call.
741        5. Tear down the call.
742
743        Expected Results:
744        1. Phone registers on LTE network with VoLTE enabled.
745        2. When Emergency call is made, phone request CSFB to CDMA1x.
746        3. The 911 call on CDMA1x is answered successfully.
747        4. Tear down call succeed.
748
749        Returns:
750            True if pass; False if fail
751        """
752        return self._setup_emergency_call(
753            set_system_model_lte_1x,
754            self._phone_setup_volte,
755            phone_idle_volte,
756            srlte_csfb="emc_barred",
757            emergency_number=self.emergency_call_number,
758            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
759
760    @test_tracker_info(uuid="5bbbecec-0fef-430b-acbd-01ef7c7055c0")
761    @TelephonyBaseTest.tel_test_wrap
762    def test_emergency_call_volte_1x(self):
763        """ Test Emergency call functionality on VoLTE with CDMA1x
764        Ref: VzW LTE E911 test plan, 2.24, VZ_TC_LTEE911_7482
765        Steps:
766        1. Setup CallBox on VoLTE network with CDMA1x.
767        2. Turn on DUT and enable VoLTE. Make an emergency call to 911.
768        3. Make sure Anritsu receives the call and accept.
769        4. Tear down the call.
770
771        Expected Results:
772        2. Emergency call succeed.
773        3. Anritsu can accept the call.
774        4. Tear down call succeed.
775
776        Returns:
777            True if pass; False if fail
778        """
779        return self._setup_emergency_call(
780            set_system_model_lte_1x,
781            self._phone_setup_volte,
782            phone_idle_volte,
783            is_ims_call=True,
784            emergency_number=self.emergency_call_number,
785            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
786
787    @test_tracker_info(uuid="e32862e0-ec11-4de8-8b9a-851bab9feb29")
788    @TelephonyBaseTest.tel_test_wrap
789    def test_emergency_call_volte(self):
790        """ Test Emergency call functionality on VoLTE
791
792        Steps:
793        1. Setup CallBox on VoLTE network.
794        2. Turn on DUT and enable VoLTE. Make an emergency call to 911.
795        3. Make sure Anritsu receives the call and accept.
796        4. Tear down the call.
797
798        Expected Results:
799        2. Emergency call succeed.
800        3. Anritsu can accept the call.
801        4. Tear down call succeed.
802
803        Returns:
804            True if pass; False if fail
805        """
806        return self._setup_emergency_call(
807            set_system_model_lte,
808            self._phone_setup_volte,
809            phone_idle_volte,
810            is_ims_call=True,
811            emergency_number=self.emergency_call_number,
812            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
813
814    @test_tracker_info(uuid="fa5b4e52-c249-42ec-a9d3-9523336f88f7")
815    @TelephonyBaseTest.tel_test_wrap
816    def test_emergency_call_volte_apm(self):
817        """ Test Emergency call functionality on VoLTE
818
819        Steps:
820        1. Setup CallBox on VoLTE network.
821        2. Turn on Airplane mode on DUT. Make an emergency call to 911.
822        3. Make sure Anritsu receives the call and accept.
823        4. Tear down the call.
824
825        Expected Results:
826        2. Emergency call succeed.
827        3. Anritsu can accept the call.
828        4. Tear down call succeed.
829
830        Returns:
831            True if pass; False if fail
832        """
833        return self._setup_emergency_call(
834            set_system_model_lte,
835            self._phone_setup_volte_airplane_mode,
836            is_ims_call=True,
837            is_wait_for_registration=False,
838            emergency_number=self.emergency_call_number,
839            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
840
841    @test_tracker_info(uuid="260e4892-fdae-4d49-bfc6-04fe72a5a715")
842    @TelephonyBaseTest.tel_test_wrap
843    def test_emergency_call_no_sim_wcdma(self):
844        """ Test Emergency call functionality with no SIM.
845
846        Steps:
847        1. Setup CallBox on WCDMA network.
848        2. Make an emergency call to 911.
849        3. Make sure Anritsu receives the call and accept.
850        4. Tear down the call.
851
852        Expected Results:
853        2. Emergency call succeed.
854        3. Anritsu can accept the call.
855        4. Tear down call succeed.
856
857        Returns:
858            True if pass; False if fail
859        """
860        return self._setup_emergency_call(
861            set_system_model_wcdma,
862            self._phone_disable_airplane_mode,
863            emergency_number=self.emergency_call_number,
864            is_wait_for_registration=False)
865
866    @test_tracker_info(uuid="2dbbbde5-c298-4a2d-ae65-b739d1dd1445")
867    @TelephonyBaseTest.tel_test_wrap
868    def test_emergency_call_no_sim_1x(self):
869        """ Test Emergency call functionality with no SIM.
870
871        Steps:
872        1. Setup CallBox on 1x network.
873        2. Make an emergency call to 911.
874        3. Make sure Anritsu receives the call and accept.
875        4. Tear down the call.
876
877        Expected Results:
878        2. Emergency call succeed.
879        3. Anritsu can accept the call.
880        4. Tear down call succeed.
881
882        Returns:
883            True if pass; False if fail
884        """
885        return self._setup_emergency_call(
886            set_system_model_1x,
887            self._phone_disable_airplane_mode,
888            emergency_number=self.emergency_call_number,
889            is_wait_for_registration=False)
890
891    @test_tracker_info(uuid="fa77dee2-3235-42e0-b24d-c8fdb3fbef2f")
892    @TelephonyBaseTest.tel_test_wrap
893    def test_emergency_call_no_sim_gsm(self):
894        """ Test Emergency call functionality with no SIM.
895
896        Steps:
897        1. Setup CallBox on GSM network.
898        2. Make an emergency call to 911.
899        3. Make sure Anritsu receives the call and accept.
900        4. Tear down the call.
901
902        Expected Results:
903        2. Emergency call succeed.
904        3. Anritsu can accept the call.
905        4. Tear down call succeed.
906
907        Returns:
908            True if pass; False if fail
909        """
910        return self._setup_emergency_call(
911            set_system_model_gsm,
912            self._phone_disable_airplane_mode,
913            emergency_number=self.emergency_call_number,
914            is_wait_for_registration=False)
915
916    @test_tracker_info(uuid="9ead5c6a-b4cb-40d5-80b0-54d3c7ad31ff")
917    @TelephonyBaseTest.tel_test_wrap
918    def test_emergency_call_no_sim_volte(self):
919        """ Test Emergency call functionality with no SIM.
920
921        Steps:
922        1. Setup CallBox on VoLTE network.
923        2. Make an emergency call to 911.
924        3. Make sure Anritsu receives the call and accept.
925        4. Tear down the call.
926
927        Expected Results:
928        2. Emergency call succeed.
929        3. Anritsu can accept the call.
930        4. Tear down call succeed.
931
932        Returns:
933            True if pass; False if fail
934        """
935        return self._setup_emergency_call(
936            set_system_model_lte,
937            self._phone_disable_airplane_mode,
938            is_wait_for_registration=False,
939            is_ims_call=True,
940            emergency_number=self.emergency_call_number,
941            wait_time_in_call=WAIT_TIME_IN_CALL_FOR_IMS)
942
943    @test_tracker_info(uuid="d6bdc1d7-0a08-4e6e-9de8-4084abb48bad")
944    @TelephonyBaseTest.tel_test_wrap
945    def test_emergency_call_no_sim_1x_ecbm(self):
946        """ Test Emergency call functionality with no SIM.
947
948        Steps:
949        1. Setup CallBox on 1x network.
950        2. Make an emergency call to 911.
951        3. Make sure Anritsu receives the call and accept.
952        4. Tear down the call.
953        5. Make a call from Callbox to DUT.
954        6. Verify DUT receive the incoming call.
955        7. Answer on DUT, verify DUT can answer the call correctly.
956        8. Hangup the call on DUT.
957
958        Expected Results:
959        2. Emergency call succeed.
960        3. Anritsu can accept the call.
961        4. Tear down call succeed.
962        6. DUT receive incoming call.
963        7. DUT answer the call correctly.
964        8. Tear down call succeed.
965
966        Returns:
967            True if pass; False if fail
968        """
969        if not self._setup_emergency_call(
970                set_system_model_1x,
971                self._phone_disable_airplane_mode,
972                emergency_number=self.emergency_call_number,
973                is_wait_for_registration=False):
974            self.log.error("Failed to make 911 call.")
975            return False
976        return call_mt_setup_teardown(self.log, self.ad,
977                                      self.anritsu.get_VirtualPhone(), None,
978                                      CALL_TEARDOWN_PHONE, RAT_1XRTT)
979
980    """ Tests End """
981