Home | History | Annotate | Download | only in live
      1 #!/usr/bin/env python3.4
      2 #
      3 #   Copyright 2016 - Google
      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 """
     17     Test Script for Telephony Settings
     18 """
     19 
     20 import time
     21 from acts.utils import load_config
     22 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     23 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WIFI_CONNECTION
     24 from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
     25 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_IMS_REGISTRATION
     26 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VOLTE_ENABLED
     27 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WFC_ENABLED
     28 from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN
     29 from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
     30 from acts.test_utils.tel.tel_defines import WFC_MODE_DISABLED
     31 from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
     32 from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
     33 from acts.test_utils.tel.tel_test_utils import is_droid_in_rat_family
     34 from acts.test_utils.tel.tel_test_utils import is_wfc_enabled
     35 from acts.test_utils.tel.tel_test_utils import set_wfc_mode
     36 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
     37 from acts.test_utils.tel.tel_test_utils import toggle_volte
     38 from acts.test_utils.tel.tel_test_utils import verify_http_connection
     39 from acts.test_utils.tel.tel_test_utils import wait_for_ims_registered
     40 from acts.test_utils.tel.tel_test_utils import wait_for_network_rat
     41 from acts.test_utils.tel.tel_test_utils import wait_for_not_network_rat
     42 from acts.test_utils.tel.tel_test_utils import wait_for_volte_enabled
     43 from acts.test_utils.tel.tel_test_utils import wait_for_wfc_disabled
     44 from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
     45 from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
     46 from acts.test_utils.tel.tel_test_utils import WifiUtils
     47 from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
     48 from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
     49 from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
     50 from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
     51 from acts.test_utils.tel.tel_voice_utils import phone_idle_iwlan
     52 
     53 class TelLiveSettingsTest(TelephonyBaseTest):
     54 
     55     _TEAR_DOWN_OPERATION_DISCONNECT_WIFI = "disconnect_wifi"
     56     _TEAR_DOWN_OPERATION_RESET_WIFI = "reset_wifi"
     57     _TEAR_DOWN_OPERATION_DISABLE_WFC = "disable_wfc"
     58     _DEFAULT_STRESS_NUMBER = 5
     59 
     60     def __init__(self, controllers):
     61         TelephonyBaseTest.__init__(self, controllers)
     62         self.tests = (
     63             "test_lte_volte_wifi_connected_toggle_wfc",
     64             "test_lte_wifi_connected_toggle_wfc",
     65             "test_3g_wifi_connected_toggle_wfc",
     66             "test_apm_wifi_connected_toggle_wfc",
     67 
     68             "test_lte_volte_wfc_enabled_toggle_wifi",
     69             "test_lte_wfc_enabled_toggle_wifi",
     70             "test_3g_wfc_enabled_toggle_wifi",
     71             "test_apm_wfc_enabled_toggle_wifi",
     72 
     73             "test_lte_wfc_enabled_wifi_connected_toggle_volte",
     74 
     75             "test_lte_volte_wfc_wifi_preferred_to_cellular_preferred",
     76             "test_lte_wfc_wifi_preferred_to_cellular_preferred",
     77             "test_3g_wfc_wifi_preferred_to_cellular_preferred",
     78             "test_apm_wfc_wifi_preferred_to_cellular_preferred",
     79             "test_lte_volte_wfc_cellular_preferred_to_wifi_preferred",
     80             "test_lte_wfc_cellular_preferred_to_wifi_preferred",
     81             "test_3g_wfc_cellular_preferred_to_wifi_preferred",
     82             "test_apm_wfc_cellular_preferred_to_wifi_preferred",
     83 
     84             "test_apm_wfc_wifi_preferred_turn_off_apm",
     85             "test_apm_wfc_cellular_preferred_turn_off_apm",
     86 
     87             "test_wfc_setup_timing",
     88             "test_lte_volte_wfc_enabled_toggle_wifi_stress",
     89             "test_lte_volte_wfc_enabled_reset_wifi_stress",
     90             "test_lte_volte_wfc_wifi_preferred_to_cellular_preferred_stress"
     91 
     92         )
     93         self.ad = self.android_devices[0]
     94         self.simconf = load_config(self.user_params["sim_conf_file"])
     95         self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
     96         try:
     97             self.wifi_network_pass = self.user_params["wifi_network_pass"]
     98         except KeyError:
     99             self.wifi_network_pass = None
    100         try:
    101             self.stress_test_number = int(self.user_params["stress_test_number"])
    102         except KeyError:
    103             self.stress_test_number = self._DEFAULT_STRESS_NUMBER
    104 
    105     def _wifi_connected_enable_wfc_teardown_wfc(self,
    106         tear_down_operation, initial_setup_wifi=True,
    107         initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED,
    108         check_volte_after_wfc_disabled=False):
    109         if initial_setup_wifi and not ensure_wifi_connected(
    110             self.log, self.ad, self.wifi_network_ssid, self.wifi_network_pass):
    111             self.log.error("Failed to connect WiFi")
    112             return False
    113         if initial_setup_wfc_mode and not set_wfc_mode(
    114             self.log, self.ad, initial_setup_wfc_mode):
    115             self.log.error("Failed to set WFC mode.")
    116             return False
    117         if not phone_idle_iwlan(self.log, self.ad):
    118             self.log.error("WFC is not available.")
    119             return False
    120 
    121         # Tear Down WFC based on tear_down_operation
    122         if tear_down_operation == self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI:
    123             if not WifiUtils.wifi_toggle_state(self.log, self.ad, False):
    124                 self.log.error("Failed to turn off WiFi.")
    125                 return False
    126         elif tear_down_operation == self._TEAR_DOWN_OPERATION_RESET_WIFI:
    127             if not WifiUtils.wifi_reset(self.log, self.ad, False):
    128                 self.log.error("Failed to reset WiFi")
    129                 return False
    130         elif tear_down_operation == self._TEAR_DOWN_OPERATION_DISABLE_WFC:
    131             if not set_wfc_mode(self.log, self.ad, WFC_MODE_DISABLED):
    132                 self.log.error("Failed to turn off WFC.")
    133                 return False
    134         else:
    135             self.log.error("No tear down operation")
    136             return False
    137 
    138         if not wait_for_not_network_rat(self.log, self.ad, RAT_FAMILY_WLAN,
    139             voice_or_data=NETWORK_SERVICE_DATA):
    140             self.log.error("Data Rat is still iwlan.")
    141             return False
    142         if not wait_for_wfc_disabled(self.log, self.ad):
    143             self.log.error("WFC is still available after turn off WFC.")
    144             return False
    145 
    146         # If VoLTE was previous available, after tear down WFC, DUT should have
    147         # VoLTE service.
    148         if check_volte_after_wfc_disabled and not wait_for_volte_enabled(
    149             self.log, self.ad, MAX_WAIT_TIME_VOLTE_ENABLED):
    150             self.log.error("Device failed to acquire VoLTE service")
    151             return False
    152         return True
    153 
    154     def _wifi_connected_set_wfc_mode_change_wfc_mode(self,
    155         initial_wfc_mode,
    156         new_wfc_mode,
    157         is_wfc_available_in_initial_wfc_mode,
    158         is_wfc_available_in_new_wfc_mode,
    159         initial_setup_wifi=True,
    160         check_volte_after_wfc_disabled=False):
    161         if initial_setup_wifi and not ensure_wifi_connected(
    162             self.log, self.ad, self.wifi_network_ssid, self.wifi_network_pass):
    163             self.log.error("Failed to connect WiFi")
    164             return False
    165         # Set to initial_wfc_mode first, then change to new_wfc_mode
    166         for (wfc_mode, is_wfc_available) in \
    167             [(initial_wfc_mode, is_wfc_available_in_initial_wfc_mode),
    168              (new_wfc_mode, is_wfc_available_in_new_wfc_mode)]:
    169             current_wfc_status = is_wfc_enabled(self.log, self.ad)
    170             self.log.info("Current WFC: {}, Set WFC to {}".
    171                 format(current_wfc_status, wfc_mode))
    172             if not set_wfc_mode(self.log, self.ad, wfc_mode):
    173                 self.log.error("Failed to set WFC mode.")
    174                 return False
    175             if is_wfc_available:
    176                 if current_wfc_status:
    177                     # Previous is True, after set it still need to be true
    178                     # wait and check if DUT WFC got disabled.
    179                     if wait_for_wfc_disabled(self.log, self.ad):
    180                         self.log.error("WFC is not available.")
    181                         return False
    182                 else:
    183                     # Previous is False, after set it will be true,
    184                     # wait and check if DUT WFC got enabled.
    185                     if not wait_for_wfc_enabled(self.log, self.ad):
    186                         self.log.error("WFC is not available.")
    187                         return False
    188             else:
    189                 if current_wfc_status:
    190                     # Previous is True, after set it will be false,
    191                     # wait and check if DUT WFC got disabled.
    192                     if not wait_for_wfc_disabled(self.log, self.ad):
    193                         self.log.error("WFC is available.")
    194                         return False
    195                 else:
    196                     # Previous is False, after set it still need to be false
    197                     # Wait and check if DUT WFC got enabled.
    198                     if wait_for_wfc_enabled(self.log, self.ad):
    199                         self.log.error("WFC is available.")
    200                         return False
    201                 if check_volte_after_wfc_disabled and not wait_for_volte_enabled(
    202                     self.log, self.ad, MAX_WAIT_TIME_VOLTE_ENABLED):
    203                     self.log.error("Device failed to acquire VoLTE service")
    204                     return False
    205         return True
    206 
    207     def _wifi_connected_set_wfc_mode_turn_off_apm(self, wfc_mode,
    208         is_wfc_available_after_turn_off_apm):
    209         if not ensure_wifi_connected(self.log, self.ad, self.wifi_network_ssid,
    210                                      self.wifi_network_pass):
    211             self.log.error("Failed to connect WiFi")
    212             return False
    213         if not set_wfc_mode(self.log, self.ad, wfc_mode):
    214             self.log.error("Failed to set WFC mode.")
    215             return False
    216         if not phone_idle_iwlan(self.log, self.ad):
    217             self.log.error("WFC is not available.")
    218             return False
    219         if not toggle_airplane_mode(self.log, self.ad, False):
    220             self.log.error("Failed to turn off airplane mode")
    221             return False
    222         is_wfc_not_available = wait_for_wfc_disabled(self.log, self.ad)
    223         if is_wfc_available_after_turn_off_apm and is_wfc_not_available:
    224                 self.log.error("WFC is not available.")
    225                 return False
    226         elif (not is_wfc_available_after_turn_off_apm and
    227               not is_wfc_not_available):
    228                 self.log.error("WFC is available.")
    229                 return False
    230         return True
    231 
    232     @TelephonyBaseTest.tel_test_wrap
    233     def test_lte_volte_wifi_connected_toggle_wfc(self):
    234         """Test for WiFi Calling settings:
    235         LTE + VoLTE Enabled + WiFi Connected, Toggling WFC
    236 
    237         Steps:
    238         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    239         2. Make sure DUT WiFi connected, WFC disabled.
    240         3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
    241             report iwlan rat.
    242         4. Set DUT WFC disabled, verify DUT WFC unavailable,
    243             not report iwlan rat.
    244 
    245         Expected Results:
    246         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    247         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    248         """
    249 
    250         if not phone_setup_volte(self.log, self.ad):
    251             self.log.error("Failed to setup VoLTE")
    252             return False
    253         return self._wifi_connected_enable_wfc_teardown_wfc(
    254             tear_down_operation=self._TEAR_DOWN_OPERATION_DISABLE_WFC,
    255             initial_setup_wifi=True,
    256             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED,
    257             check_volte_after_wfc_disabled=True)
    258 
    259     @TelephonyBaseTest.tel_test_wrap
    260     def test_lte_wifi_connected_toggle_wfc(self):
    261         """Test for WiFi Calling settings:
    262         LTE + VoLTE Disabled + WiFi Connected, Toggling WFC
    263 
    264         Steps:
    265         1. Setup DUT Idle, LTE network type, VoLTE disabled.
    266         2. Make sure DUT WiFi connected, WFC disabled.
    267         3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
    268             report iwlan rat.
    269         4. Set DUT WFC disabled, verify DUT WFC unavailable,
    270             not report iwlan rat.
    271 
    272         Expected Results:
    273         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    274         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    275         """
    276 
    277         if not phone_setup_csfb(self.log, self.ad):
    278             self.log.error("Failed to setup LTE")
    279             return False
    280         return self._wifi_connected_enable_wfc_teardown_wfc(
    281             tear_down_operation=self._TEAR_DOWN_OPERATION_DISABLE_WFC,
    282             initial_setup_wifi=True,
    283             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    284 
    285     @TelephonyBaseTest.tel_test_wrap
    286     def test_3g_wifi_connected_toggle_wfc(self):
    287         """Test for WiFi Calling settings:
    288         3G + WiFi Connected, Toggling WFC
    289 
    290         Steps:
    291         1. Setup DUT Idle, 3G network type.
    292         2. Make sure DUT WiFi connected, WFC disabled.
    293         3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
    294             report iwlan rat.
    295         4. Set DUT WFC disabled, verify DUT WFC unavailable,
    296             not report iwlan rat.
    297 
    298         Expected Results:
    299         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    300         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    301         """
    302 
    303         if not phone_setup_voice_3g(self.log, self.ad):
    304             self.log.error("Failed to setup 3G")
    305             return False
    306         return self._wifi_connected_enable_wfc_teardown_wfc(
    307             tear_down_operation=self._TEAR_DOWN_OPERATION_DISABLE_WFC,
    308             initial_setup_wifi=True,
    309             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    310 
    311     @TelephonyBaseTest.tel_test_wrap
    312     def test_apm_wifi_connected_toggle_wfc(self):
    313         """Test for WiFi Calling settings:
    314         APM + WiFi Connected, Toggling WFC
    315 
    316         Steps:
    317         1. Setup DUT Idle, Airplane mode.
    318         2. Make sure DUT WiFi connected, WFC disabled.
    319         3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
    320             report iwlan rat.
    321         4. Set DUT WFC disabled, verify DUT WFC unavailable,
    322             not report iwlan rat.
    323 
    324         Expected Results:
    325         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    326         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    327         """
    328 
    329         if not toggle_airplane_mode(self.log, self.ad, True):
    330             self.log.error("Failed to turn on airplane mode")
    331             return False
    332         return self._wifi_connected_enable_wfc_teardown_wfc(
    333             tear_down_operation=self._TEAR_DOWN_OPERATION_DISABLE_WFC,
    334             initial_setup_wifi=True,
    335             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    336 
    337     @TelephonyBaseTest.tel_test_wrap
    338     def test_lte_volte_wfc_enabled_toggle_wifi(self):
    339         """Test for WiFi Calling settings:
    340         LTE + VoLTE Enabled + WFC enabled, Toggling WiFi
    341 
    342         Steps:
    343         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    344         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    345         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    346         4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
    347 
    348         Expected Results:
    349         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    350         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    351         """
    352 
    353         if not phone_setup_volte(self.log, self.ad):
    354             self.log.error("Failed to setup VoLTE")
    355             return False
    356         return self._wifi_connected_enable_wfc_teardown_wfc(
    357             tear_down_operation=self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI,
    358             initial_setup_wifi=True,
    359             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED,
    360             check_volte_after_wfc_disabled=True)
    361 
    362     @TelephonyBaseTest.tel_test_wrap
    363     def test_lte_wfc_enabled_toggle_wifi(self):
    364         """Test for WiFi Calling settings:
    365         LTE + VoLTE Disabled + WFC enabled, Toggling WiFi
    366 
    367         Steps:
    368         1. Setup DUT Idle, LTE network type, VoLTE disabled.
    369         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    370         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    371         4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
    372 
    373         Expected Results:
    374         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    375         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    376         """
    377 
    378         if not phone_setup_csfb(self.log, self.ad):
    379             self.log.error("Failed to setup LTE")
    380             return False
    381         return self._wifi_connected_enable_wfc_teardown_wfc(
    382             tear_down_operation=self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI,
    383             initial_setup_wifi=True,
    384             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    385 
    386     @TelephonyBaseTest.tel_test_wrap
    387     def test_3g_wfc_enabled_toggle_wifi(self):
    388         """Test for WiFi Calling settings:
    389         3G + WFC enabled, Toggling WiFi
    390 
    391         Steps:
    392         1. Setup DUT Idle, 3G network type.
    393         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    394         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    395         4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
    396 
    397         Expected Results:
    398         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    399         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    400         """
    401 
    402         if not phone_setup_voice_3g(self.log, self.ad):
    403             self.log.error("Failed to setup 3G")
    404             return False
    405         return self._wifi_connected_enable_wfc_teardown_wfc(
    406             tear_down_operation=self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI,
    407             initial_setup_wifi=True,
    408             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    409 
    410     @TelephonyBaseTest.tel_test_wrap
    411     def test_apm_wfc_enabled_toggle_wifi(self):
    412         """Test for WiFi Calling settings:
    413         APM + WFC enabled, Toggling WiFi
    414 
    415         Steps:
    416         1. Setup DUT Idle, Airplane mode.
    417         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    418         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    419         4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
    420 
    421         Expected Results:
    422         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    423         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    424         """
    425 
    426         if not toggle_airplane_mode(self.log, self.ad, True):
    427             self.log.error("Failed to turn on airplane mode")
    428             return False
    429         return self._wifi_connected_enable_wfc_teardown_wfc(
    430             tear_down_operation=self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI,
    431             initial_setup_wifi=True,
    432             initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED)
    433 
    434     @TelephonyBaseTest.tel_test_wrap
    435     def test_lte_wfc_enabled_wifi_connected_toggle_volte(self):
    436         """Test for WiFi Calling settings:
    437         LTE + VoLTE Enabled + WiFi Connected + WFC enabled, toggle VoLTE setting
    438 
    439         Steps:
    440         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    441         2. Make sure DUT WiFi connected, WFC enabled (WiFi Preferred).
    442             Verify DUT WFC available, report iwlan rat.
    443         3. Disable VoLTE on DUT, verify in 2 minutes period,
    444             DUT does not lost WiFi Calling, DUT still report WFC available,
    445             rat iwlan.
    446         4. Enable VoLTE on DUT, verify in 2 minutes period,
    447             DUT does not lost WiFi Calling, DUT still report WFC available,
    448             rat iwlan.
    449 
    450         Expected Results:
    451         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    452         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    453         4. DUT WiFi Calling feature bit return True, network rat is iwlan.
    454         """
    455         if not phone_setup_volte(self.log, self.ad):
    456             self.log.error("Failed to setup VoLTE.")
    457             return False
    458         if not phone_setup_iwlan(self.log, self.ad, False,
    459                                  WFC_MODE_WIFI_PREFERRED,
    460                                  self.wifi_network_ssid,
    461                                  self.wifi_network_pass):
    462             self.log.error("Failed to setup WFC.")
    463             return False
    464         # Turn Off VoLTE, then Turn On VoLTE
    465         for i in range(2):
    466             if not toggle_volte(self.log, self.ad):
    467                 self.log.error("Failed to toggle VoLTE.")
    468                 return False
    469             if wait_for_wfc_disabled(self.log, self.ad):
    470                 self.log.error("WFC is not available.")
    471                 return False
    472             if not is_droid_in_rat_family(self.log, self.ad, RAT_FAMILY_WLAN,
    473                                           NETWORK_SERVICE_DATA):
    474                 self.log.error("Data Rat is not iwlan.")
    475                 return False
    476         return True
    477 
    478     @TelephonyBaseTest.tel_test_wrap
    479     def test_lte_volte_wfc_wifi_preferred_to_cellular_preferred(self):
    480         """Test for WiFi Calling settings:
    481         LTE + VoLTE Enabled + WiFi Connected + WiFi Preferred,
    482         change WFC to Cellular Preferred
    483 
    484         Steps:
    485         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    486         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    487             Verify DUT WFC available, report iwlan rat.
    488         3. Change WFC setting to Cellular Preferred.
    489         4. Verify DUT report WFC not available.
    490 
    491         Expected Results:
    492         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    493         4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    494         """
    495         if not phone_setup_volte(self.log, self.ad):
    496             self.log.error("Failed to setup VoLTE.")
    497             return False
    498         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    499             WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    500             True, False,
    501             check_volte_after_wfc_disabled=True)
    502 
    503     @TelephonyBaseTest.tel_test_wrap
    504     def test_lte_wfc_wifi_preferred_to_cellular_preferred(self):
    505         """Test for WiFi Calling settings:
    506         LTE + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
    507 
    508         Steps:
    509         1. Setup DUT Idle, LTE network type, VoLTE disabled.
    510         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    511             Verify DUT WFC available, report iwlan rat.
    512         3. Change WFC setting to Cellular Preferred.
    513         4. Verify DUT report WFC not available.
    514 
    515         Expected Results:
    516         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    517         4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    518         """
    519         if not phone_setup_csfb(self.log, self.ad):
    520             self.log.error("Failed to setup LTE.")
    521             return False
    522         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    523             WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    524             True, False,
    525             check_volte_after_wfc_disabled=False)
    526 
    527     @TelephonyBaseTest.tel_test_wrap
    528     def test_3g_wfc_wifi_preferred_to_cellular_preferred(self):
    529         """Test for WiFi Calling settings:
    530         3G + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
    531 
    532         Steps:
    533         1. Setup DUT Idle, 3G network type.
    534         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    535             Verify DUT WFC available, report iwlan rat.
    536         3. Change WFC setting to Cellular Preferred.
    537         4. Verify DUT report WFC not available.
    538 
    539         Expected Results:
    540         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    541         4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    542         """
    543         if not phone_setup_voice_3g(self.log, self.ad):
    544             self.log.error("Failed to setup 3G.")
    545             return False
    546         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    547             WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    548             True, False)
    549 
    550     @TelephonyBaseTest.tel_test_wrap
    551     def test_3g_wfc_wifi_preferred_to_cellular_preferred(self):
    552         """Test for WiFi Calling settings:
    553         3G + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
    554 
    555         Steps:
    556         1. Setup DUT Idle, 3G network type.
    557         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    558             Verify DUT WFC available, report iwlan rat.
    559         3. Change WFC setting to Cellular Preferred.
    560         4. Verify DUT report WFC not available.
    561 
    562         Expected Results:
    563         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    564         4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    565         """
    566         if not phone_setup_voice_3g(self.log, self.ad):
    567             self.log.error("Failed to setup 3G.")
    568             return False
    569         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    570             WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    571             True, False)
    572 
    573     @TelephonyBaseTest.tel_test_wrap
    574     def test_apm_wfc_wifi_preferred_to_cellular_preferred(self):
    575         """Test for WiFi Calling settings:
    576         APM + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
    577 
    578         Steps:
    579         1. Setup DUT Idle, airplane mode.
    580         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    581             Verify DUT WFC available, report iwlan rat.
    582         3. Change WFC setting to Cellular Preferred.
    583         4. Verify DUT report WFC not available.
    584 
    585         Expected Results:
    586         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    587         4. DUT WiFI Calling feature bit return True, network rat is iwlan.
    588         """
    589         if not toggle_airplane_mode(self.log, self.ad, True):
    590             self.log.error("Failed to turn on airplane mode")
    591             return False
    592         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    593             WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    594             True, True)
    595 
    596     @TelephonyBaseTest.tel_test_wrap
    597     def test_lte_volte_wfc_cellular_preferred_to_wifi_preferred(self):
    598         """Test for WiFi Calling settings:
    599         LTE + VoLTE Enabled + WiFi Connected + Cellular Preferred,
    600         change WFC to WiFi Preferred
    601 
    602         Steps:
    603         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    604         2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
    605             Verify DUT WFC not available.
    606         3. Change WFC setting to WiFi Preferred.
    607         4. Verify DUT report WFC available.
    608 
    609         Expected Results:
    610         2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    611         4. DUT WiFI Calling feature bit return True, network rat is iwlan.
    612         """
    613         if not phone_setup_volte(self.log, self.ad):
    614             self.log.error("Failed to setup VoLTE.")
    615             return False
    616         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    617             WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_WIFI_PREFERRED,
    618             False, True,
    619             check_volte_after_wfc_disabled=True)
    620 
    621     @TelephonyBaseTest.tel_test_wrap
    622     def test_lte_wfc_cellular_preferred_to_wifi_preferred(self):
    623         """Test for WiFi Calling settings:
    624         LTE + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
    625 
    626         Steps:
    627         1. Setup DUT Idle, LTE network type, VoLTE disabled.
    628         2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
    629             Verify DUT WFC not available.
    630         3. Change WFC setting to WiFi Preferred.
    631         4. Verify DUT report WFC available.
    632 
    633         Expected Results:
    634         2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    635         4. DUT WiFI Calling feature bit return True, network rat is iwlan.
    636         """
    637         if not phone_setup_csfb(self.log, self.ad):
    638             self.log.error("Failed to setup LTE.")
    639             return False
    640         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    641             WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_WIFI_PREFERRED,
    642             False, True,
    643             check_volte_after_wfc_disabled=False)
    644 
    645     @TelephonyBaseTest.tel_test_wrap
    646     def test_3g_wfc_cellular_preferred_to_wifi_preferred(self):
    647         """Test for WiFi Calling settings:
    648         3G + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
    649 
    650         Steps:
    651         1. Setup DUT Idle, 3G network type.
    652         2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
    653             Verify DUT WFC not available.
    654         3. Change WFC setting to WiFi Preferred.
    655         4. Verify DUT report WFC available.
    656 
    657         Expected Results:
    658         2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    659         4. DUT WiFI Calling feature bit return True, network rat is iwlan.
    660         """
    661         if not phone_setup_voice_3g(self.log, self.ad):
    662             self.log.error("Failed to setup 3G.")
    663             return False
    664         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    665             WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_WIFI_PREFERRED,
    666             False, True)
    667 
    668     @TelephonyBaseTest.tel_test_wrap
    669     def test_apm_wfc_cellular_preferred_to_wifi_preferred(self):
    670         """Test for WiFi Calling settings:
    671         APM + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
    672 
    673         Steps:
    674         1. Setup DUT Idle, airplane mode.
    675         2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
    676             Verify DUT WFC not available.
    677         3. Change WFC setting to WiFi Preferred.
    678         4. Verify DUT report WFC available.
    679 
    680         Expected Results:
    681         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    682         4. DUT WiFI Calling feature bit return True, network rat is iwlan.
    683         """
    684         if not toggle_airplane_mode(self.log, self.ad, True):
    685             self.log.error("Failed to turn on airplane mode")
    686             return False
    687         return self._wifi_connected_set_wfc_mode_change_wfc_mode(
    688             WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_WIFI_PREFERRED,
    689             True, True)
    690 
    691     @TelephonyBaseTest.tel_test_wrap
    692     def test_apm_wfc_wifi_preferred_turn_off_apm(self):
    693         """Test for WiFi Calling settings:
    694         APM + WiFi Connected + WiFi Preferred + turn off APM
    695 
    696         Steps:
    697         1. Setup DUT Idle in Airplane mode.
    698         2. Make sure DUT WiFi connected, set WFC mode to WiFi preferred.
    699         3. verify DUT WFC available, report iwlan rat.
    700         4. Turn off airplane mode.
    701         5. Verify DUT WFC still available, report iwlan rat
    702 
    703         Expected Results:
    704         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    705         5. DUT WiFI Calling feature bit return True, network rat is iwlan.
    706         """
    707         if not toggle_airplane_mode(self.log, self.ad, True):
    708             self.log.error("Failed to turn on airplane mode")
    709             return False
    710         return self._wifi_connected_set_wfc_mode_turn_off_apm(
    711             WFC_MODE_WIFI_PREFERRED, True)
    712 
    713     @TelephonyBaseTest.tel_test_wrap
    714     def test_apm_wfc_cellular_preferred_turn_off_apm(self):
    715         """Test for WiFi Calling settings:
    716         APM + WiFi Connected + Cellular Preferred + turn off APM
    717 
    718         Steps:
    719         1. Setup DUT Idle in Airplane mode.
    720         2. Make sure DUT WiFi connected, set WFC mode to Cellular preferred.
    721         3. verify DUT WFC available, report iwlan rat.
    722         4. Turn off airplane mode.
    723         5. Verify DUT WFC not available, not report iwlan rat
    724 
    725         Expected Results:
    726         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    727         5. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    728         """
    729         if not toggle_airplane_mode(self.log, self.ad, True):
    730             self.log.error("Failed to turn on airplane mode")
    731             return False
    732         return self._wifi_connected_set_wfc_mode_turn_off_apm(
    733             WFC_MODE_CELLULAR_PREFERRED, False)
    734 
    735     @TelephonyBaseTest.tel_test_wrap
    736     def test_wfc_setup_timing(self):
    737         """ Measures the time delay in enabling WiFi calling
    738 
    739         Steps:
    740         1. Make sure DUT idle.
    741         2. Turn on Airplane Mode, Set WiFi Calling to WiFi_Preferred.
    742         3. Turn on WiFi, connect to WiFi AP and measure time delay.
    743         4. Wait for WiFi connected, verify Internet and measure time delay.
    744         5. Wait for rat to be reported as iwlan and measure time delay.
    745         6. Wait for ims registered and measure time delay.
    746         7. Wait for WiFi Calling feature bit to be True and measure time delay.
    747 
    748         Expected results:
    749         Time Delay in each step should be within pre-defined limit.
    750 
    751         Returns:
    752             Currently always return True.
    753         """
    754         # TODO: b/26338119 Set pass/fail criteria
    755         ad = self.android_devices[0]
    756 
    757         time_values = {
    758             'start': 0,
    759             'wifi_enabled': 0,
    760             'wifi_connected': 0,
    761             'wifi_data': 0,
    762             'iwlan_rat': 0,
    763             'ims_registered': 0,
    764             'wfc_enabled': 0,
    765             'mo_call_success': 0
    766         }
    767 
    768         WifiUtils.wifi_reset(self.log, ad)
    769         toggle_airplane_mode(self.log, ad, True)
    770 
    771         set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED)
    772 
    773         time_values['start'] = time.time()
    774 
    775         self.log.info("Start Time {}s".format(time_values['start']))
    776 
    777         WifiUtils.wifi_toggle_state(self.log, ad, True)
    778         time_values['wifi_enabled'] = time.time()
    779         self.log.info("WiFi Enabled After {}s".format(time_values[
    780             'wifi_enabled'] - time_values['start']))
    781 
    782         WifiUtils.wifi_connect(self.log, ad, self.wifi_network_ssid,
    783                                self.wifi_network_pass)
    784 
    785         ad.droid.wakeUpNow()
    786 
    787         if not wait_for_wifi_data_connection(self.log, ad, True,
    788                                              MAX_WAIT_TIME_WIFI_CONNECTION):
    789             self.log.error("Failed WiFi connection, aborting!")
    790             return False
    791         time_values['wifi_connected'] = time.time()
    792 
    793         self.log.info("WiFi Connected After {}s".format(time_values[
    794             'wifi_connected'] - time_values['wifi_enabled']))
    795 
    796         if not verify_http_connection(self.log, ad, 'http://www.google.com',
    797                                       100, .1):
    798             self.log.error("Failed to get user-plane traffic, aborting!")
    799             return False
    800 
    801         time_values['wifi_data'] = time.time()
    802         self.log.info("WifiData After {}s".format(time_values[
    803             'wifi_data'] - time_values['wifi_connected']))
    804 
    805         if not wait_for_network_rat(self.log,
    806                                     ad,
    807                                     RAT_FAMILY_WLAN,
    808                                     voice_or_data=NETWORK_SERVICE_DATA):
    809             self.log.error("Failed to set-up iwlan, aborting!")
    810             if is_droid_in_rat_family(self.log, ad, RAT_FAMILY_WLAN,
    811                                       NETWORK_SERVICE_DATA):
    812                 self.log.error("Never received the event, but droid in iwlan")
    813             else:
    814                 return False
    815         time_values['iwlan_rat'] = time.time()
    816         self.log.info("iWLAN Reported After {}s".format(time_values[
    817             'iwlan_rat'] - time_values['wifi_data']))
    818 
    819         if not wait_for_ims_registered(self.log, ad,
    820                                        MAX_WAIT_TIME_IMS_REGISTRATION):
    821             self.log.error("Never received IMS registered, aborting")
    822             return False
    823         time_values['ims_registered'] = time.time()
    824         self.log.info("Ims Registered After {}s".format(time_values[
    825             'ims_registered'] - time_values['iwlan_rat']))
    826 
    827         if not wait_for_wfc_enabled(self.log, ad, MAX_WAIT_TIME_WFC_ENABLED):
    828             self.log.error("Never received WFC feature, aborting")
    829             return False
    830 
    831         time_values['wfc_enabled'] = time.time()
    832         self.log.info("Wifi Calling Feature Enabled After {}s".format(
    833             time_values['wfc_enabled'] - time_values['ims_registered']))
    834 
    835         set_wfc_mode(self.log, ad, WFC_MODE_DISABLED)
    836 
    837         wait_for_not_network_rat(self.log,
    838                                  ad,
    839                                  RAT_FAMILY_WLAN,
    840                                  voice_or_data=NETWORK_SERVICE_DATA)
    841 
    842         self.log.info("\n\n------------------summary-----------------")
    843         self.log.info("WiFi Enabled After {0:.2f} s".format(time_values[
    844             'wifi_enabled'] - time_values['start']))
    845         self.log.info("WiFi Connected After {0:.2f} s".format(time_values[
    846             'wifi_connected'] - time_values['wifi_enabled']))
    847         self.log.info("WifiData After {0:.2f} s".format(time_values[
    848             'wifi_data'] - time_values['wifi_connected']))
    849         self.log.info("iWLAN Reported After {0:.2f} s".format(time_values[
    850             'iwlan_rat'] - time_values['wifi_data']))
    851         self.log.info("Ims Registered After {0:.2f} s".format(time_values[
    852             'ims_registered'] - time_values['iwlan_rat']))
    853         self.log.info("Wifi Calling Feature Enabled After {0:.2f} s".format(
    854             time_values['wfc_enabled'] - time_values['ims_registered']))
    855         self.log.info("\n\n")
    856         return True
    857 
    858     @TelephonyBaseTest.tel_test_wrap
    859     def test_lte_volte_wfc_enabled_toggle_wifi_stress(self):
    860         """Test for WiFi Calling settings:
    861         LTE + VoLTE Enabled + WFC enabled, Toggling WiFi Stress test
    862 
    863         Steps:
    864         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    865         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    866         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    867         4. DUT disconnect WiFi, verify DUT WFC unavailable, not report iwlan rat.
    868         5. Verify DUT report VoLTE available.
    869         6. Repeat steps 3~5 for N times.
    870 
    871         Expected Results:
    872         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    873         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    874         5. DUT report VoLTE available.
    875         """
    876 
    877         if not phone_setup_volte(self.log, self.ad):
    878             self.log.error("Failed to setup VoLTE")
    879             return False
    880         set_wfc_mode(self.log, self.ad, WFC_MODE_WIFI_PREFERRED)
    881 
    882         for i in range(1, self.stress_test_number + 1):
    883             self.log.info("Start Iteration {}.".format(i))
    884             result = self._wifi_connected_enable_wfc_teardown_wfc(
    885                 tear_down_operation=self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI,
    886                 initial_setup_wifi=True,
    887                 initial_setup_wfc_mode=None,
    888                 check_volte_after_wfc_disabled=True)
    889             if not result:
    890                 self.log.error("Test Failed in iteration: {}.".format(i))
    891                 return False
    892         return True
    893 
    894     @TelephonyBaseTest.tel_test_wrap
    895     def test_lte_volte_wfc_enabled_reset_wifi_stress(self):
    896         """Test for WiFi Calling settings:
    897         LTE + VoLTE Enabled + WFC enabled, Reset WiFi Stress test
    898 
    899         Steps:
    900         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    901         2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
    902         3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
    903         4. DUT Reset WiFi, verify DUT WFC unavailable, not report iwlan rat.
    904         5. Verify DUT report VoLTE available.
    905         6. Repeat steps 3~5 for N times.
    906 
    907         Expected Results:
    908         3. DUT WiFi Calling feature bit return True, network rat is iwlan.
    909         4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
    910         5. DUT report VoLTE available.
    911         """
    912 
    913         if not phone_setup_volte(self.log, self.ad):
    914             self.log.error("Failed to setup VoLTE")
    915             return False
    916         set_wfc_mode(self.log, self.ad, WFC_MODE_WIFI_PREFERRED)
    917 
    918         for i in range(1, self.stress_test_number + 1):
    919             self.log.info("Start Iteration {}.".format(i))
    920             result = self._wifi_connected_enable_wfc_teardown_wfc(
    921                 tear_down_operation=self._TEAR_DOWN_OPERATION_RESET_WIFI,
    922                 initial_setup_wifi=True,
    923                 initial_setup_wfc_mode=None,
    924                 check_volte_after_wfc_disabled=True)
    925             if not result:
    926                 self.log.error("Test Failed in iteration: {}.".format(i))
    927                 return False
    928         return True
    929 
    930     @TelephonyBaseTest.tel_test_wrap
    931     def test_lte_volte_wfc_wifi_preferred_to_cellular_preferred_stress(self):
    932         """Test for WiFi Calling settings:
    933         LTE + VoLTE Enabled + WiFi Connected + WiFi Preferred,
    934         change WFC to Cellular Preferred stress
    935 
    936         Steps:
    937         1. Setup DUT Idle, LTE network type, VoLTE enabled.
    938         2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
    939             Verify DUT WFC available, report iwlan rat.
    940         3. Change WFC setting to Cellular Preferred.
    941         4. Verify DUT report WFC not available.
    942         5. Verify DUT report VoLTE available.
    943         6. Repeat steps 3~5 for N times.
    944 
    945         Expected Results:
    946         2. DUT WiFi Calling feature bit return True, network rat is iwlan.
    947         4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
    948         5. DUT report VoLTE available.
    949         """
    950         if not phone_setup_volte(self.log, self.ad):
    951             self.log.error("Failed to setup VoLTE.")
    952             return False
    953         if not ensure_wifi_connected(
    954             self.log, self.ad, self.wifi_network_ssid, self.wifi_network_pass):
    955             self.log.error("Failed to connect WiFi")
    956             return False
    957 
    958         for i in range(1, self.stress_test_number + 1):
    959             self.log.info("Start Iteration {}.".format(i))
    960             result = self._wifi_connected_set_wfc_mode_change_wfc_mode(
    961                 WFC_MODE_WIFI_PREFERRED, WFC_MODE_CELLULAR_PREFERRED,
    962                 True, False,
    963                 initial_setup_wifi=False,
    964                 check_volte_after_wfc_disabled=True)
    965             if not result:
    966                 self.log.error("Test Failed in iteration: {}.".format(i))
    967                 return False
    968         return True
    969