def _wifi_connected_set_wfc_mode_change_wfc_mode(
         self,
         initial_wfc_mode,
         new_wfc_mode,
         is_wfc_available_in_initial_wfc_mode,
         is_wfc_available_in_new_wfc_mode,
         initial_setup_wifi=True,
         check_volte_after_wfc_disabled=False):
     if initial_setup_wifi and not ensure_wifi_connected(
             self.log, self.ad, self.wifi_network_ssid,
             self.wifi_network_pass):
         self.log.error("Failed to connect WiFi")
         return False
     # Set to initial_wfc_mode first, then change to new_wfc_mode
     for (wfc_mode, is_wfc_available) in \
         [(initial_wfc_mode, is_wfc_available_in_initial_wfc_mode),
          (new_wfc_mode, is_wfc_available_in_new_wfc_mode)]:
         current_wfc_status = is_wfc_enabled(self.log, self.ad)
         self.log.info("Current WFC: {}, Set WFC to {}".format(
             current_wfc_status, wfc_mode))
         if not set_wfc_mode(self.log, self.ad, wfc_mode):
             self.log.error("Failed to set WFC mode.")
             return False
         if is_wfc_available:
             if current_wfc_status:
                 # Previous is True, after set it still need to be true
                 # wait and check if DUT WFC got disabled.
                 if wait_for_wfc_disabled(self.log, self.ad):
                     self.log.error("WFC is not available.")
                     return False
             else:
                 # Previous is False, after set it will be true,
                 # wait and check if DUT WFC got enabled.
                 if not wait_for_wfc_enabled(self.log, self.ad):
                     self.log.error("WFC is not available.")
                     return False
         else:
             if current_wfc_status:
                 # Previous is True, after set it will be false,
                 # wait and check if DUT WFC got disabled.
                 if not wait_for_wfc_disabled(self.log, self.ad):
                     self.log.error("WFC is available.")
                     return False
             else:
                 # Previous is False, after set it still need to be false
                 # Wait and check if DUT WFC got enabled.
                 if wait_for_wfc_enabled(self.log, self.ad):
                     self.log.error("WFC is available.")
                     return False
             if check_volte_after_wfc_disabled and not wait_for_volte_enabled(
                     self.log, self.ad, MAX_WAIT_TIME_VOLTE_ENABLED):
                 self.log.error("Device failed to acquire VoLTE service")
                 return False
     return True
    def _wifi_connected_enable_wfc_teardown_wfc(
            self,
            tear_down_operation,
            initial_setup_wifi=True,
            initial_setup_wfc_mode=WFC_MODE_WIFI_PREFERRED,
            check_volte_after_wfc_disabled=False):
        if initial_setup_wifi and not ensure_wifi_connected(
                self.log, self.ad, self.wifi_network_ssid,
                self.wifi_network_pass):
            self.log.error("Failed to connect WiFi")
            return False
        if initial_setup_wfc_mode and not set_wfc_mode(self.log, self.ad,
                                                       initial_setup_wfc_mode):
            self.log.error("Failed to set WFC mode.")
            return False
        if not phone_idle_iwlan(self.log, self.ad):
            self.log.error("WFC is not available.")
            return False

        # Tear Down WFC based on tear_down_operation
        if tear_down_operation == self._TEAR_DOWN_OPERATION_DISCONNECT_WIFI:
            if not WifiUtils.wifi_toggle_state(self.log, self.ad, False):
                self.log.error("Failed to turn off WiFi.")
                return False
        elif tear_down_operation == self._TEAR_DOWN_OPERATION_RESET_WIFI:
            if not WifiUtils.wifi_reset(self.log, self.ad, False):
                self.log.error("Failed to reset WiFi")
                return False
        elif tear_down_operation == self._TEAR_DOWN_OPERATION_DISABLE_WFC:
            if not set_wfc_mode(self.log, self.ad, WFC_MODE_DISABLED):
                self.log.error("Failed to turn off WFC.")
                return False
        else:
            self.log.error("No tear down operation")
            return False

        if not wait_for_not_network_rat(self.log,
                                        self.ad,
                                        RAT_FAMILY_WLAN,
                                        voice_or_data=NETWORK_SERVICE_DATA):
            self.log.error("Data Rat is still iwlan.")
            return False
        if not wait_for_wfc_disabled(self.log, self.ad):
            self.log.error("WFC is still available after turn off WFC.")
            return False

        # If VoLTE was previous available, after tear down WFC, DUT should have
        # VoLTE service.
        if check_volte_after_wfc_disabled and not wait_for_volte_enabled(
                self.log, self.ad, MAX_WAIT_TIME_VOLTE_ENABLED):
            self.log.error("Device failed to acquire VoLTE service")
            return False
        return True
Esempio n. 3
0
def phone_setup_iwlan_cellular_preferred(log,
                                         ad,
                                         wifi_ssid=None,
                                         wifi_pwd=None):
    """Phone setup function for iwlan Non-APM CELLULAR_PREFERRED test.
    Set WFC mode according to CELLULAR_PREFERRED.
    Set airplane mode according to False.
    Make sure phone connect to WiFi. (If wifi_ssid is not None.)
    Make sure phone don't report iwlan data network type.
    Make sure phone don't report wfc enabled flag to be true.

    Args:
        log: Log object.
        ad: Android device object.
        wifi_ssid: WiFi network SSID. This is optional.
            If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi.
        wifi_pwd: WiFi network password. This is optional.

    Returns:
        True if success. False if fail.
    """
    toggle_airplane_mode(log, ad, False, strict_checking=False)
    try:
        toggle_volte(log, ad, True)
        if not wait_for_network_generation(
                log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
            if not ensure_network_generation(
                    log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
                ad.log.error("Fail to ensure data in 4G")
                return False
    except Exception as e:
        ad.log.error(e)
        ad.droid.telephonyToggleDataConnection(True)
    if wifi_ssid is not None:
        if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd):
            ad.log.error("Connect to WiFi failed.")
            return False
    if not set_wfc_mode(log, ad, WFC_MODE_CELLULAR_PREFERRED):
        ad.log.error("Set WFC mode failed.")
        return False
    if not wait_for_not_network_rat(
            log, ad, RAT_FAMILY_WLAN, voice_or_data=NETWORK_SERVICE_DATA):
        ad.log.error("Data rat in iwlan mode.")
        return False
    elif not wait_for_wfc_disabled(log, ad, MAX_WAIT_TIME_WFC_ENABLED):
        ad.log.error("Should report wifi calling disabled within %s.",
                     MAX_WAIT_TIME_WFC_ENABLED)
        return False
    return True
    def test_lte_wfc_enabled_wifi_connected_toggle_volte(self):
        """Test for WiFi Calling settings:
        LTE + VoLTE Enabled + WiFi Connected + WFC enabled, toggle VoLTE setting

        Steps:
        1. Setup DUT Idle, LTE network type, VoLTE enabled.
        2. Make sure DUT WiFi connected, WFC enabled (WiFi Preferred).
            Verify DUT WFC available, report iwlan rat.
        3. Disable VoLTE on DUT, verify in 2 minutes period,
            DUT does not lost WiFi Calling, DUT still report WFC available,
            rat iwlan.
        4. Enable VoLTE on DUT, verify in 2 minutes period,
            DUT does not lost WiFi Calling, DUT still report WFC available,
            rat iwlan.

        Expected Results:
        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
        4. DUT WiFi Calling feature bit return True, network rat is iwlan.
        """
        if not phone_setup_volte(self.log, self.ad):
            self.log.error("Failed to setup VoLTE.")
            return False
        if not phone_setup_iwlan(self.log, self.ad, False,
                                 WFC_MODE_WIFI_PREFERRED,
                                 self.wifi_network_ssid,
                                 self.wifi_network_pass):
            self.log.error("Failed to setup WFC.")
            return False
        # Turn Off VoLTE, then Turn On VoLTE
        for i in range(2):
            if not toggle_volte(self.log, self.ad):
                self.log.error("Failed to toggle VoLTE.")
                return False
            if wait_for_wfc_disabled(self.log, self.ad):
                self.log.error("WFC is not available.")
                return False
            if not is_droid_in_rat_family(self.log, self.ad, RAT_FAMILY_WLAN,
                                          NETWORK_SERVICE_DATA):
                self.log.error("Data Rat is not iwlan.")
                return False
        return True
 def _wifi_connected_set_wfc_mode_turn_off_apm(
         self, wfc_mode, is_wfc_available_after_turn_off_apm):
     if not ensure_wifi_connected(self.log, self.ad, self.wifi_network_ssid,
                                  self.wifi_network_pass):
         self.log.error("Failed to connect WiFi")
         return False
     if not set_wfc_mode(self.log, self.ad, wfc_mode):
         self.log.error("Failed to set WFC mode.")
         return False
     if not phone_idle_iwlan(self.log, self.ad):
         self.log.error("WFC is not available.")
         return False
     if not toggle_airplane_mode(self.log, self.ad, False):
         self.log.error("Failed to turn off airplane mode")
         return False
     is_wfc_not_available = wait_for_wfc_disabled(self.log, self.ad)
     if is_wfc_available_after_turn_off_apm and is_wfc_not_available:
         self.log.error("WFC is not available.")
         return False
     elif (not is_wfc_available_after_turn_off_apm
           and not is_wfc_not_available):
         self.log.error("WFC is available.")
         return False
     return True
 def verify_default_ims_setting(self):
     result = True
     airplane_mode = self.dut.droid.connectivityCheckAirplaneMode()
     default_wfc_mode = self.carrier_configs.get(
         CarrierConfigs.DEFAULT_WFC_IMS_MODE_INT, WFC_MODE_DISABLED)
     if self.default_wfc_enabled:
         wait_for_wfc_enabled(self.log, self.dut)
     else:
         wait_for_wfc_disabled(self.log, self.dut)
         if airplane_mode:
             wait_for_network_rat(
                 self.log,
                 self.dut,
                 RAT_UNKNOWN,
                 voice_or_data=NETWORK_SERVICE_VOICE)
         else:
             if self.default_volte:
                 wait_for_volte_enabled(self.log, self.dut)
             else:
                 wait_for_not_network_rat(
                     self.log,
                     self.dut,
                     RAT_UNKNOWN,
                     voice_or_data=NETWORK_SERVICE_VOICE)
     if not ensure_phone_subscription(self.log, self.dut):
         ad.log.error("Failed to find valid subscription")
         result = False
     user_config_profile = get_user_config_profile(self.dut)
     self.dut.log.info("user_config_profile = %s ",
                       sorted(user_config_profile.items()))
     if user_config_profile["VoLTE Enabled"] != self.default_volte:
         self.dut.log.error("VoLTE mode is not %s", self.default_volte)
         result = False
     else:
         self.dut.log.info("VoLTE mode is %s as expected",
                           self.default_volte)
     if user_config_profile["WFC Enabled"] != self.default_wfc_enabled:
         self.dut.log.error("WFC enabled is not %s", default_wfc_enabled)
     if user_config_profile["WFC Enabled"]:
         if user_config_profile["WFC Mode"] != default_wfc_mode:
             self.dut.log.error(
                 "WFC mode is not %s after IMS factory reset",
                 default_wfc_mode)
             result = False
         else:
             self.dut.log.info("WFC mode is %s as expected",
                               default_wfc_mode)
     if self.default_wfc_enabled and \
         default_wfc_mode == WFC_MODE_WIFI_PREFERRED:
         if not self.check_call_in_wfc():
             result = False
     elif not airplane_mode:
         if self.default_volte:
             if not self.check_call_in_volte():
                 result = False
         else:
             if not self.check_call():
                 result = False
     if result == False:
         user_config_profile = get_user_config_profile(self.dut)
         self.dut.log.info("user_config_profile = %s ",
                           sorted(user_config_profile.items()))
     return result
 def change_ims_setting(self,
                        airplane_mode,
                        wifi_enabled,
                        volte_enabled,
                        wfc_enabled,
                        wfc_mode=None):
     result = True
     self.dut.log.info(
         "Setting APM %s, WIFI %s, VoLTE %s, WFC %s, WFC mode %s",
         airplane_mode, wifi_enabled, volte_enabled, wfc_enabled, wfc_mode)
     toggle_airplane_mode_by_adb(self.log, self.dut, airplane_mode)
     if wifi_enabled:
         if not ensure_wifi_connected(self.log, self.dut,
                                      self.wifi_network_ssid,
                                      self.wifi_network_pass,
                                      apm=airplane_mode):
             self.dut.log.error("Fail to connected to WiFi")
             result = False
     else:
         if not wifi_toggle_state(self.log, self.dut, False):
             self.dut.log.error("Failed to turn off WiFi.")
             result = False
     toggle_volte(self.log, self.dut, volte_enabled)
     toggle_wfc(self.log, self.dut, wfc_enabled)
     if wfc_mode:
         set_wfc_mode(self.log, self.dut, wfc_mode)
     wfc_mode = self.dut.droid.imsGetWfcMode()
     if wifi_enabled or not airplane_mode:
         if not ensure_phone_subscription(self.log, self.dut):
             self.dut.log.error("Failed to find valid subscription")
             result = False
     if airplane_mode:
         if (CAPABILITY_WFC in self.dut_capabilities) and (wifi_enabled
                                                           and wfc_enabled):
             if not wait_for_wfc_enabled(self.log, self.dut):
                 result = False
             elif not self.check_call_in_wfc():
                 result = False
         else:
             if not wait_for_state(
                     self.dut.droid.telephonyGetCurrentVoiceNetworkType,
                     RAT_UNKNOWN):
                 self.dut.log.error(
                     "Voice RAT is %s not UNKNOWN",
                     self.dut.droid.telephonyGetCurrentVoiceNetworkType())
                 result = False
             else:
                 self.dut.log.info("Voice RAT is in UNKKNOWN")
     else:
         if (wifi_enabled and wfc_enabled) and (
                 wfc_mode == WFC_MODE_WIFI_PREFERRED) and (
                     CAPABILITY_WFC in self.dut_capabilities):
             if not wait_for_wfc_enabled(self.log, self.dut):
                 result = False
             if not wait_for_state(
                     self.dut.droid.telephonyGetCurrentVoiceNetworkType,
                     RAT_UNKNOWN):
                 self.dut.log.error(
                     "Voice RAT is %s, not UNKNOWN",
                     self.dut.droid.telephonyGetCurrentVoiceNetworkType())
             if not self.check_call_in_wfc():
                 result = False
         else:
             if not wait_for_wfc_disabled(self.log, self.dut):
                 self.dut.log.error("WFC is not disabled")
                 result = False
             if volte_enabled and CAPABILITY_VOLTE in self.dut_capabilities:
                 if not wait_for_volte_enabled(self.log, self.dut):
                     result = False
                 if not self.check_call_in_volte():
                     result = False
             else:
                 if not wait_for_not_network_rat(
                         self.log,
                         self.dut,
                         RAT_LTE,
                         voice_or_data=NETWORK_SERVICE_VOICE):
                     self.dut.log.error(
                         "Voice RAT is %s",
                         self.dut.droid.telephonyGetCurrentVoiceNetworkType(
                         ))
                     result = False
                 if not wait_for_voice_attach(self.log, self.dut):
                     result = False
                 if not self.check_call():
                     result = False
     user_config_profile = get_user_config_profile(self.dut)
     self.dut.log.info("user_config_profile: %s ",
                       sorted(user_config_profile.items()))
     return result