Пример #1
0
    def _rate_limit_charging_off(self, apk_type):
        """
        Args:
            apk_type: SL4A APK type - 'Q' for android Q and 'P' for android P

        Returns:
            Result True if Pass, False if Fail.
        """
        try:
            self.ad.droid.wakeUpNow()

            if not ensure_wifi_connected(self.log, self.ad,
                                         self.wifi_network_ssid,
                                         self.wifi_network_pass):
                self.ad.log.error("Failed to connect to wifi")
                return False
            """ Disable Charging """
            disable_usb_charging(self.ad)
            if apk_type == 'P':
                time_delta = self.get_all_cell_info_rate_limit(
                    CELL_INFO_UPDATE_WAIT_TIME_LOW, 'low')
            elif apk_type == 'Q':
                time_delta = self.request_cell_info_update_rate_limit(
                    CELL_INFO_UPDATE_WAIT_TIME_LOW, 'low')
            """ Enable Charging """
            enable_usb_charging(self.ad)
            if int(time_delta) == RATE_LIMIT_LOW:
                return True
            else:
                return False
        except Exception as e:
            self.log.error("Exception in rate_limit function:" + str(e))
            return False
Пример #2
0
 def _account_registration(self, ad):
     toggle_airplane_mode_by_adb(self.log, ad, new_state=False)
     for cmd in _TYCHO_VERBOSE_LOGGING_CMDS:
         ad.adb.shell(cmd)
     if hasattr(ad, "user_account"):
         if self.check_project_fi_activated(ad, retries=2):
             ad.log.info("Project Fi is activated already")
             return True
         ad.exit_setup_wizard()
         if not ad.is_apk_installed("com.google.android.tradefed.account"
                                    ) and self.user_params.get(
                                        "account_util"):
             for _ in range(2):
                 if self._install_account_util(ad):
                     break
             else:
                 ad.log.error(
                     "Fail to install com.google.android.tradefed.account")
                 return False
         ad.force_stop_apk(_TYCHO_PKG)
         if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                      self.wifi_network_pass):
             ad.log.error("Failed to connect to wifi")
             return False
         ad.log.info("Add google account")
         if not self._add_google_account(ad):
             ad.log.error("Failed to add google account")
             return False
         ad.adb.shell(
             'am instrument -w -e account "*****@*****.**" -e password '
             '"%s" -e sync true -e wait-for-checkin false '
             'com.google.android.tradefed.account/.AddAccount' %
             (ad.user_account, ad.user_password))
         ad.log.info("Enable and activate tycho apk")
         if not ad.is_apk_installed(_TYCHO_PKG):
             ad.log.info("%s is not installed", _TYCHO_PKG)
             return False
         ad.adb.shell('pm enable %s' % _TYCHO_PKG)
         #ad.adb.shell(_TYCHO_SERVER_LAB_OVERRIDE_CMD)
         for i in range(1, self.activation_attemps + 1):
             if i == self.activation_attemps:
                 ad.log.info("Reboot and try Fi activation again")
                 reboot_device(ad)
             self.activate_fi_account(ad)
             if not self.check_project_fi_activated(ad):
                 ad.log.error("Fail to activate Fi account on attempt-%s",
                              i)
                 if i == self.activation_attemps:
                     return False
             else:
                 ad.log.info("Fi account is activated successfully")
                 break
     elif "Fi Network" in ad.adb.getprop("gsm.sim.operator.alpha"):
         ad.log.error("Google account is not provided for Fi Network")
         return False
     if not ensure_phone_subscription(self.log, ad):
         ad.log.error("Unable to find a valid subscription!")
         return False
     refresh_droid_config(self.log, ad)
     return True
Пример #3
0
 def _teardown_device(self, ad):
     try:
         stop_qxdm_logger(ad)
     except Exception as e:
         self.log.error("Failure with %s", e)
     try:
         ad.droid.disableDevicePassword()
     except Exception as e:
         self.log.error("Failure with %s", e)
     if self.user_params.get("enable_connectivity_metrics", True):
         if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                      self.wifi_network_pass):
             ad.log.error("Failed to connect to wifi")
         force_connectivity_metrics_upload(ad)
         time.sleep(300)
     try:
         if "enable_wifi_verbose_logging" in self.user_params:
             ad.droid.wifiEnableVerboseLogging(
                 WIFI_VERBOSE_LOGGING_DISABLED)
     except Exception as e:
         self.log.error("Failure with %s", e)
     try:
         if self.user_params.get("build_id_override",
                                 False) and self.user_params.get(
                                     "recover_build_id", False):
             recover_build_id(ad)
     except Exception as e:
         self.log.error("Failure with %s", e)
 def connect_to_wifi(self):
     if not ensure_wifi_connected(self.log, self.dut,
                                  self.wifi_network_ssid,
                                  self.wifi_network_pass):
         self.dut.log.error("Fail to connected to WiFi")
         return False
     else:
         self.dut.log.info("Connected to WiFi")
         return True
 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
Пример #6
0
 def _idle_baseline_wifi_connected(ad):
     if not toggle_airplane_mode(self.log, ad, True):
         self.log.error("Phone failed to turn on airplane mode.")
         return False
     if not ensure_wifi_connected(self.log, ad,
                                  self.wifi_network_ssid_2g,
                                  self.wifi_network_pass_2g):
         self.log.error("WiFi connect failed")
         return False
     ad.droid.goToSleepNow()
     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
Пример #8
0
def phone_setup_iwlan_for_subscription(log,
                                       ad,
                                       sub_id,
                                       is_airplane_mode,
                                       wfc_mode,
                                       wifi_ssid=None,
                                       wifi_pwd=None):
    """Phone setup function for epdg call test for subscription id.
    Set WFC mode according to wfc_mode.
    Set airplane mode according to is_airplane_mode.
    Make sure phone connect to WiFi. (If wifi_ssid is not None.)
    Wait for phone to be in iwlan data network type.
    Wait for phone to report wfc enabled flag to be true.

    Args:
        log: Log object.
        ad: Android device object.
        sub_id: subscription id.
        is_airplane_mode: True to turn on airplane mode. False to turn off airplane mode.
        wfc_mode: WFC mode to set to.
        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.
    """

    # VoLTE settings are unavailable in airplane mode
    toggle_airplane_mode(log, ad, False)

    # Now that we are out of APM, toggle VoLTE if necessary
    if ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform():
        toggle_volte(log, ad, True)

    if not is_airplane_mode and not ensure_network_generation_for_subscription(
            log, ad, sub_id, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA):
        return False

    if not set_wfc_mode(log, ad, wfc_mode):
        log.error("{} set WFC mode failed.".format(ad.serial))
        return False

    if not toggle_airplane_mode(log, ad, is_airplane_mode):
        log.error("Failed to enable airplane mode on {}".format(ad.serial))
        return False

    if wifi_ssid is not None:
        if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd):
            log.error("{} connect to WiFi failed.".format(ad.serial))
            return False

    return phone_idle_iwlan_for_subscription(log, ad, sub_id)
 def _setup_wifi(self, wifi):
     if wifi == WIFI_5G:
         network_ssid = self.wifi_network_ssid_5g
         network_pass = self.wifi_network_pass_5g
     else:
         network_ssid = self.wifi_network_ssid_2g
         network_pass = self.wifi_network_pass_2g
     if not ensure_wifi_connected(
             self.log, self.ad, network_ssid, network_pass, retry=3):
         self.log.error("Wifi %s connection fails." % wifi)
         return False
     self.log.info("WIFI %s is connected successfully." % wifi)
     return True
Пример #10
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
Пример #11
0
 def test_check_environment(self):
     ad = self.android_devices[0]
     # Check WiFi environment.
     # 1. Connect to WiFi.
     # 2. Check WiFi have Internet access.
     try:
         if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                      self.wifi_network_pass):
             abort_all_tests(ad.log, "WiFi connect fail")
         if (not wait_for_wifi_data_connection(self.log, ad, True)
                 or not verify_internet_connection(self.log, ad)):
             abort_all_tests(ad.log, "Data not available on WiFi")
     finally:
         wifi_toggle_state(self.log, ad, False)
     # TODO: add more environment check here.
     return True
Пример #12
0
    def _basic_connectivity_check(self):
        """
        Set Attenuator Value for WiFi and Cell to 0
        Make sure DUT get Cell Data coverage (LTE)
        Make sure DUT WiFi is connected
        """
        toggle_airplane_mode(self.log, self.android_devices[0], False)
        if not ensure_network_generation(self.log, self.android_devices[0],
                                         GEN_4G, NETWORK_SERVICE_DATA):
            return False

        if not ensure_wifi_connected(self.log, self.android_devices[0],
                                     self.live_network_ssid,
                                     self.live_network_pwd):
            ad.log.error("%s connect WiFI failed")
            return False
        return True
    def _basic_connectivity_check(self):
        """
        Set Attenuator Value for WiFi and Cell to 0
        Make sure DUT get Cell Data coverage (LTE)
        Make sure DUT WiFi is connected
        """
        ad = self.android_devices[0]
        toggle_airplane_mode(self.log, ad, False)
        if not ensure_network_generation(self.log, ad, GEN_4G,
                                         MAX_WAIT_TIME_NW_SELECTION,
                                         NETWORK_SERVICE_DATA):
            return False

        if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                     self.wifi_network_pass):
            ad.log.error("connect WiFi failed")
            return False
        return True
 def _setup_wfc(self):
     if not ensure_wifi_connected(
             self.log,
             self.dut,
             self.wifi_network_ssid,
             self.wifi_network_pass,
             retry=3):
         self.dut.log.error("Phone Wifi connection fails.")
         return False
     self.dut.log.info("Phone WIFI is connected successfully.")
     if not set_wfc_mode(self.log, self.dut, WFC_MODE_WIFI_PREFERRED):
         self.dut.log.error("Phone failed to enable Wifi-Calling.")
         return False
     self.dut.log.info("Phone is set in Wifi-Calling successfully.")
     if not phone_idle_iwlan(self.log, self.dut):
         self.dut.log.error("Phone is not in WFC enabled state.")
         return False
     self.dut.log.info("Phone is in WFC enabled state.")
     return True
Пример #15
0
 def _setup_wfc(self):
     for ad in self.android_devices:
         if not ensure_wifi_connected(ad.log,
                                      ad,
                                      self.wifi_network_ssid,
                                      self.wifi_network_pass,
                                      retries=3):
             ad.log.error("Phone Wifi connection fails.")
             return False
         ad.log.info("Phone WIFI is connected successfully.")
         if not set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED):
             ad.log.error("Phone failed to enable Wifi-Calling.")
             return False
         ad.log.info("Phone is set in Wifi-Calling successfully.")
         if not phone_idle_iwlan(self.log, ad):
             ad.log.error("Phone is not in WFC enabled state.")
             return False
         ad.log.info("Phone is in WFC enabled state.")
     return True
Пример #16
0
    def test_check_environment(self):
        ad = self.android_devices[0]
        # Check WiFi environment.
        # 1. Connect to WiFi.
        # 2. Check WiFi have Internet access.
        toggle_airplane_mode(self.log, ad, False, strict_checking=False)

        try:
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                self._preflight_fail("{}: WiFi connect fail.".format(
                    ad.serial))
            if (not wait_for_wifi_data_connection(self.log, ad, True)
                    or not verify_http_connection(self.log, ad)):
                self._preflight_fail("{}: Data not available on WiFi.".format(
                    ad.serial))
        finally:
            WifiUtils.wifi_toggle_state(self.log, ad, False)
        # TODO: add more environment check here.
        return True
    def test_lte_volte_wfc_wifi_preferred_to_cellular_preferred_stress(self):
        """Test for WiFi Calling settings:
        LTE + VoLTE Enabled + WiFi Connected + WiFi Preferred,
        change WFC to Cellular Preferred stress

        Steps:
        1. Setup DUT Idle, LTE network type, VoLTE enabled.
        2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
            Verify DUT WFC available, report iwlan rat.
        3. Change WFC setting to Cellular Preferred.
        4. Verify DUT report WFC not available.
        5. Verify DUT report VoLTE available.
        6. Repeat steps 3~5 for N times.

        Expected Results:
        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
        4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
        5. DUT report VoLTE available.
        """
        if not phone_setup_volte(self.log, self.ad):
            self.log.error("Failed to setup VoLTE.")
            return False
        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

        for i in range(1, self.stress_test_number + 1):
            self.log.info("Start Iteration {}.".format(i))
            result = self._wifi_connected_set_wfc_mode_change_wfc_mode(
                WFC_MODE_WIFI_PREFERRED,
                WFC_MODE_CELLULAR_PREFERRED,
                True,
                False,
                initial_setup_wifi=False,
                check_volte_after_wfc_disabled=True)
            if not result:
                self.log.error("Test Failed in iteration: {}.".format(i))
                return False
        return True
Пример #18
0
 def _setup_phone_mobile_data_always_on(self,
                                        ad,
                                        phone_setup_func,
                                        connect_wifi,
                                        wifi_ssid=None,
                                        wifi_password=None,
                                        mobile_data_always_on=True):
     set_mobile_data_always_on(ad, mobile_data_always_on)
     if not phone_setup_func(self.log, ad):
         self.log.error("Phone failed to setup {}.".format(
             phone_setup_func.__name__))
         return False
     if (connect_wifi and not ensure_wifi_connected(self.log, ad, wifi_ssid,
                                                    wifi_password)):
         self.log.error("WiFi connect failed")
         return False
     # simulate normal user behavior -- wake up every 1 minutes and do ping
     # (transmit data)
     if not self._start_alarm():
         return False
     ad.droid.goToSleepNow()
     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 wifi_tethering_setup_teardown(log,
                                  provider,
                                  client_list,
                                  ap_band=WifiUtils.WIFI_CONFIG_APBAND_2G,
                                  check_interval=30,
                                  check_iteration=4,
                                  do_cleanup=True,
                                  ssid=None,
                                  password=None):
    """Test WiFi Tethering.

    Turn off WiFi on clients.
    Turn off data and reset WiFi on clients.
    Verify no Internet access on clients.
    Turn on WiFi tethering on provider.
    Clients connect to provider's WiFI.
    Verify Internet on provider and clients.
    Tear down WiFi tethering setup and clean up.

    Args:
        log: log object.
        provider: android object provide WiFi tethering.
        client_list: a list of clients using tethered WiFi.
        ap_band: setup WiFi tethering on 2G or 5G.
            This is optional, default value is WifiUtils.WIFI_CONFIG_APBAND_2G
        check_interval: delay time between each around of Internet connection check.
            This is optional, default value is 30 (seconds).
        check_iteration: check Internet connection for how many times in total.
            This is optional, default value is 4 (4 times).
        do_cleanup: after WiFi tethering test, do clean up to tear down tethering
            setup or not. This is optional, default value is True.
        ssid: use this string as WiFi SSID to setup tethered WiFi network.
            This is optional. Default value is None.
            If it's None, a random string will be generated.
        password: use this string as WiFi password to setup tethered WiFi network.
            This is optional. Default value is None.
            If it's None, a random string will be generated.

    Returns:
        True if no error happened. False otherwise.
    """
    log.info("--->Start wifi_tethering_setup_teardown<---")
    log.info("Provider: {}".format(provider.serial))
    if not provider.droid.connectivityIsTetheringSupported():
        log.error("Provider does not support tethering. Stop tethering test.")
        return False

    if ssid is None:
        ssid = rand_ascii_str(10)
    if password is None:
        password = rand_ascii_str(8)

    # No password
    if password == "":
        password = None

    try:
        for client in client_list:
            log.info("Client: {}".format(client.serial))
            WifiUtils.wifi_toggle_state(log, client, False)
            client.droid.telephonyToggleDataConnection(False)
        log.info("WiFI Tethering: Verify client have no Internet access.")
        for client in client_list:
            if verify_http_connection(log, client):
                log.error("Turn off Data on client fail. {}".format(
                    client.serial))
                return False

        log.info(
            "WiFI Tethering: Turn on WiFi tethering on {}. SSID: {}, password: {}".format(
                provider.serial, ssid, password))

        if not WifiUtils.start_wifi_tethering(log, provider, ssid, password,
                                              ap_band):
            log.error("Provider start WiFi tethering failed.")
            return False
        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)

        log.info("Provider {} check Internet connection.".format(
            provider.serial))
        if not verify_http_connection(log, provider):
            return False
        for client in client_list:
            log.info(
                "WiFI Tethering: {} connect to WiFi and verify AP band correct.".format(
                    client.serial))
            if not ensure_wifi_connected(log, client, ssid, password):
                log.error("Client connect to WiFi failed.")
                return False

            wifi_info = client.droid.wifiGetConnectionInfo()
            if ap_band == WifiUtils.WIFI_CONFIG_APBAND_5G:
                if wifi_info["is_24ghz"]:
                    log.error("Expected 5g network. WiFi Info: {}".format(
                        wifi_info))
                    return False
            else:
                if wifi_info["is_5ghz"]:
                    log.error("Expected 2g network. WiFi Info: {}".format(
                        wifi_info))
                    return False

            log.info("Client{} check Internet connection.".format(
                client.serial))
            if (not wait_for_wifi_data_connection(log, client, True) or
                    not verify_http_connection(log, client)):
                log.error("No WiFi Data on client: {}.".format(client.serial))
                return False

        if not tethering_check_internet_connection(
                log, provider, client_list, check_interval, check_iteration):
            return False

    finally:
        if (do_cleanup and
            (not wifi_tethering_cleanup(log, provider, client_list))):
            return False
    return True
    def test_carrier_id_update_wifi_disconnected(self):
        """Carrier Id Version Test with WiFi disconnected

        1. WiFi is connected
        2. Perform setup steps to cleanup shared_prefs
        3. Send P/H flag update to configUpdater
        4. Wait for 5 mins and keep checking for version match

        """
        try:
            result_flag = False
            time_var = 1
            ad = self.android_devices[0]
            ad.log.info("Before - CarrierId is %s", get_carrier_id_version(ad))

            # Wifi Disconnect
            cleanup_configupdater(ad)
            wifi_toggle_state(ad.log, ad, False)

            # Trigger Config Update
            ad.log.info("Triggering Config Update")
            ad.log.info("%s", CARRIER_ID_METADATA_URL)
            exe_cmd("adb -s %s shell %s" %
                    (ad.serial, CARRIER_ID_METADATA_URL))
            ad.log.info("%s", CARRIER_ID_CONTENT_URL)
            exe_cmd("adb -s %s shell %s" % (ad.serial, CARRIER_ID_CONTENT_URL))

            # Wait for 5 mins for Carrier Id version upgrade
            while (time_var < WAIT_TIME_FOR_CARRIERID_CHANGE):
                current_version = get_carrier_id_version(ad)
                if current_version == CARRIER_ID_VERSION:
                    ad.log.info("After CarrierId is %s in %s mins",
                                current_version, time_var)
                    return False
                else:
                    ad.log.debug("Carrier Id Version Not Match")
                time.sleep(60)
                time_var += 1
            time_var = 1
            ad.log.info("Success - CarrierId not upgraded during WiFi OFF")

            # WiFi Connect
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("connect WiFi failed")
                return False

            # Wait for 5 mins for Carrier Id version upgrade
            while (time_var < WAIT_TIME_FOR_CARRIERID_CHANGE):
                current_version = get_carrier_id_version(ad)
                if current_version == CARRIER_ID_VERSION:
                    ad.log.info("After CarrierId is %s in %s mins",
                                current_version, time_var)
                    result_flag = True
                    break
                else:
                    ad.log.debug("Carrier Id Version Not Match")
                time.sleep(60)
                time_var += 1

            if not result_flag:
                ad.log.info("Carrier Id Failed to Update in %s mins",
                            WAIT_TIME_FOR_CARRIERID_CHANGE)
            # pb file check
            out = ad.adb.shell("ls -l data/misc/carrierid/carrier_list.pb")
            if not out or "No such" in out:
                ad.log.error("carrier_list.pb file is missing")
                result_flag = False
            else:
                ad.log.info("carrier_list.pb file is present")
            return result_flag
        except Exception as e:
            ad.log.error(e)
            return False
        finally:
            carrier_id_path = os.path.join(self.log_path, self.test_name,
                                           "CarrierId_%s" % ad.serial)
            pull_carrier_id_files(ad, carrier_id_path)
    def test_emergency_database_update_wifi_connected(self):
        """Emergency DB Id Version Test after WiFi Connected

        1. WiFi is connected
        2. Login with whitelisted gmail credentials
        3. Wait for 5 mins and keep checking for version match

        """
        try:
            result_flag = False
            time_var = 1
            ad = self.android_devices[0]

            # Get the Emergency database Id
            ad.log.info("Before - Emergency DB Id is %s",
                        get_er_db_id_version(ad))

            # Connect to Wifi
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("connect WiFi failed")
                return False
            time.sleep(5)

            #Login with whitelisted google account
            if not install_googleaccountutil_apk(ad, self.path):
                ad.log.error("Failed to install Google Util")
                return False
            if not add_whitelisted_account(ad, self.user_account,
                                           self.user_password):
                ad.log.error("Failed to Login with Google Account")
                return False

            # Wait for 5 mins for Emergency database Id version upgrade
            while (time_var < WAIT_TIME_FOR_ER_DB_CHANGE):
                current_version = get_er_db_id_version(ad)
                if current_version == ER_DB_ID_VERSION:
                    ad.log.info("ER DB version is %s in %s mins",
                                current_version, time_var)
                    result_flag = True
                    break
                else:
                    ad.log.debug("ER Database Version Id Not Match")
                time.sleep(60)
                time_var += 1

            if not result_flag:
                ad.log.info(
                    "ER Database version Id Failed to Update in %s mins",
                    WAIT_TIME_FOR_ER_DB_CHANGE)
                return False
            # Verify Emerency Database content
            if not get_database_content(ad):
                ad.log.error("Emergency Number does not match")
                result_flag = False
                return False
            ad.log.info("Emergency Number is 54321")

        except Exception as e:
            ad.log.error(e)
            return False
        finally:
            return result_flag
Пример #23
0
def phone_setup_iwlan_for_subscription(log,
                                       ad,
                                       sub_id,
                                       is_airplane_mode,
                                       wfc_mode,
                                       wifi_ssid=None,
                                       wifi_pwd=None):
    """Phone setup function for epdg call test for subscription id.
    Set WFC mode according to wfc_mode.
    Set airplane mode according to is_airplane_mode.
    Make sure phone connect to WiFi. (If wifi_ssid is not None.)
    Wait for phone to be in iwlan data network type.
    Wait for phone to report wfc enabled flag to be true.

    Args:
        log: Log object.
        ad: Android device object.
        sub_id: subscription id.
        is_airplane_mode: True to turn on airplane mode. False to turn off airplane mode.
        wfc_mode: WFC mode to set to.
        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, is_airplane_mode, strict_checking=False)

    # check if WFC supported phones
    if wfc_mode != WFC_MODE_DISABLED and not ad.droid.imsIsWfcEnabledByPlatform(
    ):
        ad.log.error("WFC is not enabled on this device by checking "
                     "ImsManager.isWfcEnabledByPlatform")
        return False

    if wifi_ssid is not None:
        if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd):
            ad.log.error("Fail to bring up WiFi connection on %s.", wifi_ssid)
            return False

    if not set_wfc_mode(log, ad, wfc_mode):
        ad.log.error("Unable to set WFC mode to %s.", wfc_mode)
        return False

    if not wait_for_wfc_enabled(log, ad, max_time=MAX_WAIT_TIME_WFC_ENABLED):
        ad.log.error("WFC is not enabled")
        return False

    if wait_for_network_rat_for_subscription(
            log, ad, sub_id, RAT_FAMILY_WLAN,
            voice_or_data=NETWORK_SERVICE_DATA):
        ad.log.info(
            "Data rat is in iwlan mode successfully with APM %s WFC %s",
            is_airplane_mode, wfc_mode)
        return True
    else:
        ad.log.error(
            "Unable to bring data rat in iwlan mode with APM %s WFC %s",
            is_airplane_mode, wfc_mode)
        return False
 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
def wifi_cell_switching(log, ad, wifi_network_ssid, wifi_network_pass, nw_gen):
    """Test data connection network switching when phone on <nw_gen>.

    Ensure phone is on <nw_gen>
    Ensure WiFi can connect to live network,
    Airplane mode is off, data connection is on, WiFi is on.
    Turn off WiFi, verify data is on cell and browse to google.com is OK.
    Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
    Turn off WiFi, verify data is on cell and browse to google.com is OK.

    Args:
        log: log object.
        ad: android object.
        wifi_network_ssid: ssid for live wifi network.
        wifi_network_pass: password for live wifi network.
        nw_gen: network generation the phone should be camped on.

    Returns:
        True if pass.
    """
    try:

        if not ensure_network_generation_for_subscription(
                log, ad, get_default_data_sub_id(ad), nw_gen,
                MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
            log.error("Device failed to register in {}".format(nw_gen))
            return False

        # Ensure WiFi can connect to live network
        log.info("Make sure phone can connect to live network by WIFI")
        if not ensure_wifi_connected(log, ad, wifi_network_ssid,
                                     wifi_network_pass):
            log.error("WiFi connect fail.")
            return False
        log.info("Phone connected to WIFI.")

        log.info("Step1 Airplane Off, WiFi On, Data On.")
        toggle_airplane_mode(log, ad, False)
        WifiUtils.wifi_toggle_state(log, ad, True)
        ad.droid.telephonyToggleDataConnection(True)
        if (not wait_for_wifi_data_connection(log, ad, True) or
                not verify_http_connection(log, ad)):
            log.error("Data is not on WiFi")
            return False

        log.info("Step2 WiFi is Off, Data is on Cell.")
        WifiUtils.wifi_toggle_state(log, ad, False)
        if (not wait_for_cell_data_connection(log, ad, True) or
                not verify_http_connection(log, ad)):
            log.error("Data did not return to cell")
            return False

        log.info("Step3 WiFi is On, Data is on WiFi.")
        WifiUtils.wifi_toggle_state(log, ad, True)
        if (not wait_for_wifi_data_connection(log, ad, True) or
                not verify_http_connection(log, ad)):
            log.error("Data did not return to WiFi")
            return False

        log.info("Step4 WiFi is Off, Data is on Cell.")
        WifiUtils.wifi_toggle_state(log, ad, False)
        if (not wait_for_cell_data_connection(log, ad, True) or
                not verify_http_connection(log, ad)):
            log.error("Data did not return to cell")
            return False
        return True

    finally:
        WifiUtils.wifi_toggle_state(log, ad, False)
Пример #26
0
 def _make_phone_call(self, call_verification_func=None):
     ads = self.android_devices[:]
     if not self.single_phone_test:
         random.shuffle(ads)
     the_number = self.result_info["Call Total"] + 1
     duration = random.randrange(self.min_phone_call_duration,
                                 self.max_phone_call_duration)
     result = True
     test_name = "%s_No_%s_phone_call" % (self.test_name, the_number)
     log_msg = "[Test Case] %s" % test_name
     self.log.info("%s for %s seconds begin", log_msg, duration)
     begin_time = get_device_epoch_time(ads[0])
     for ad in self.android_devices:
         if self.user_params.get("turn_on_tcpdump", True):
             start_adb_tcpdump(ad, interface="any", mask="all")
         if not getattr(ad, "droid", None):
             ad.droid, ad.ed = ad.get_droid()
             ad.ed.start()
         else:
             try:
                 if not ad.droid.is_live:
                     ad.droid, ad.ed = ad.get_droid()
                     ad.ed.start()
                 else:
                     ad.ed.clear_all_events()
             except Exception:
                 ad.log.info("Create new sl4a session for phone call")
                 ad.droid, ad.ed = ad.get_droid()
                 ad.ed.start()
         ad.droid.logI("%s begin" % log_msg)
     start_qxdm_loggers(self.log, self.android_devices, begin_time)
     failure_reasons = set()
     self.dut_incall = True
     if self.single_phone_test:
         call_setup_result = initiate_call(
             self.log,
             self.dut,
             self.call_server_number,
             incall_ui_display=INCALL_UI_DISPLAY_BACKGROUND
         ) and wait_for_in_call_active(self.dut, 60, 3)
     else:
         call_setup_result = call_setup_teardown(
             self.log,
             ads[0],
             ads[1],
             ad_hangup=None,
             verify_caller_func=call_verification_func,
             verify_callee_func=call_verification_func,
             wait_time_in_call=0,
             incall_ui_display=INCALL_UI_DISPLAY_BACKGROUND)
     if not call_setup_result:
         call_logs = ads[0].search_logcat(
             "ActivityManager: START u0 {act=android.intent.action.CALL",
             begin_time)
         messaging_logs = ads[0].search_logcat(
             "com.google.android.apps.messaging/.ui.conversation.ConversationActivity",
             begin_time)
         if call_logs and messaging_logs:
             if messaging_logs[-1]["datetime_obj"] - call_logs[-1]["datetime_obj"] < 5:
                 ads[0].log.info(
                     "Call setup failure due to simultaneous activities")
                 self.result_info[
                     "Call Setup Failure With Simultaneous Activity"] += 1
                 return True
         self.log.error("%s: Setup Call failed.", log_msg)
         failure_reasons.add("Setup")
         result = False
     else:
         elapsed_time = 0
         check_interval = 5
         while (elapsed_time < duration):
             check_interval = min(check_interval, duration - elapsed_time)
             time.sleep(check_interval)
             elapsed_time += check_interval
             time_message = "at <%s>/<%s> second." % (elapsed_time,
                                                      duration)
             for ad in ads:
                 if not call_verification_func(self.log, ad):
                     ad.log.warning("Call is NOT in correct %s state at %s",
                                    call_verification_func.__name__,
                                    time_message)
                     if call_verification_func.__name__ == "is_phone_in_call_iwlan":
                         if is_phone_in_call(self.log, ad):
                             if getattr(ad, "data_rat_state_error_count",
                                        0) < 1:
                                 setattr(ad, "data_rat_state_error_count",
                                         1)
                                 continue
                     failure_reasons.add("Maintenance")
                     last_call_drop_reason(ad, begin_time)
                     hangup_call(self.log, ads[0])
                     result = False
                 else:
                     ad.log.info("Call is in correct %s state at %s",
                                 call_verification_func.__name__,
                                 time_message)
             if not result:
                 break
     if not hangup_call(self.log, ads[0]):
         failure_reasons.add("Teardown")
         result = False
     for ad in ads:
         if not wait_for_call_id_clearing(ad,
                                          []) or ad.droid.telecomIsInCall():
             ad.log.error("Fail to hang up call")
             failure_reasons.add("Teardown")
             result = False
     self.result_info["Call Total"] += 1
     for ad in self.android_devices:
         try:
             ad.droid.logI("%s end" % log_msg)
         except:
             pass
     self.log.info("%s end", log_msg)
     self.dut_incall = False
     if not result:
         self.log.info("%s failed", log_msg)
         if self.gps_log_file:
             gps_info = job.run(
                 "tail %s" % self.gps_log_file, ignore_status=True)
             if gps_info.stdout:
                 gps_log_path = os.path.join(self.log_path, test_name,
                                             "gps_logs.txt")
                 utils.create_dir(gps_log_path)
                 job.run(
                     "tail %s > %s" % (self.gps_log_file, gps_log_path),
                     ignore_status=True)
                 self.log.info("gps log:\n%s", gps_info.stdout)
             else:
                 self.log.warning("Fail to get gps log %s",
                                  self.user_params["gps_log_file"])
         for reason in failure_reasons:
             self.result_info["Call %s Failure" % reason] += 1
         for ad in ads:
             log_path = os.path.join(self.log_path, test_name,
                                     "%s_binder_logs" % ad.serial)
             utils.create_dir(log_path)
             ad.pull_files(BINDER_LOGS, log_path)
         try:
             self._take_bug_report(test_name, begin_time)
         except Exception as e:
             self.log.exception(e)
         for ad in ads:
             if ad.droid.telecomIsInCall():
                 hangup_call_by_adb(ad)
     else:
         self.log.info("%s test succeed", log_msg)
         self.result_info["Call Success"] += 1
         if self.result_info["Call Total"] % 50 == 0:
             for ad in ads:
                 synchronize_device_time(ad)
                 if not check_is_wifi_connected(self.log, ad,
                                                self.wifi_network_ssid):
                     ensure_wifi_connected(self.log, ad,
                                           self.wifi_network_ssid,
                                           self.wifi_network_pass)
                     force_connectivity_metrics_upload(ad)
                     time.sleep(300)
                     wifi_toggle_state(self.log, ad, False)
                 if self.get_binder_logs:
                     log_path = os.path.join(self.log_path,
                                             "%s_binder_logs" % test_name,
                                             "%s_binder_logs" % ad.serial)
                     utils.create_dir(log_path)
                     ad.pull_files(BINDER_LOGS, log_path)
     return result
    def test_wifi_cell_switching_stress(self):
        """Test for data switch between WiFi and Cell. DUT go in and out WiFi
        coverage for multiple times.

        Steps:
        1. Set WiFi and Cellular signal to good (attenuation value to MIN).
        2. Make sure DUT get Cell data coverage (LTE) and WiFi connected.
        3. Set WiFi RSSI to MAX (WiFi attenuator value to MIN).
        4. Verify DUT report WiFi connected and Internet access OK.
        5. Set WiFi RSSI to MIN (WiFi attenuator value to MAX).
        6. Verify DUT report Cellular Data connected and Internet access OK.
        7. Repeat Step 3~6 for stress number.

        Expected Results:
        4. DUT report WiFi connected and Internet access OK.
        6. DUT report Cellular Data connected and Internet access OK.
        7. Stress test should pass.

        Returns:
        True if Pass. False if fail.
        """
        WIFI_RSSI_CHANGE_STEP_SIZE = 2
        WIFI_RSSI_CHANGE_DELAY_PER_STEP = 1
        # Set Attenuator Value for WiFi and Cell to 0.
        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
                 MAX_RSSI_RESERVED_VALUE)
        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL], 0,
                 MAX_RSSI_RESERVED_VALUE)

        # Make sure DUT get Cell Data coverage (LTE).
        toggle_airplane_mode(self.log, self.android_devices[0], False)
        if not ensure_network_generation(self.log, self.android_devices[0],
                                         GEN_4G, NETWORK_SERVICE_DATA):
            return False

        # Make sure DUT WiFi is connected.
        if not ensure_wifi_connected(self.log, self.android_devices[0],
                                     self.live_network_ssid,
                                     self.live_network_pwd):
            self.log.error("{} connect WiFI failed".format(
                self.android_devices[0].serial))
            return False

        total_iteration = self.stress_test_number
        self.log.info("Stress test. Total iteration = {}.".format(
            total_iteration))
        current_iteration = 1
        while (current_iteration <= total_iteration):
            self.log.info(">----Current iteration = {}/{}----<".format(
                current_iteration, total_iteration))

            # Set WiFi RSSI to MAX.
            set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
                     MAX_RSSI_RESERVED_VALUE, WIFI_RSSI_CHANGE_STEP_SIZE,
                     WIFI_RSSI_CHANGE_DELAY_PER_STEP)
            # Wait for DUT report WiFi connected and Internet access OK.
            if (not wait_for_wifi_data_connection(
                    self.log, self.android_devices[0], True) or
                    not verify_http_connection(self.log,
                                               self.android_devices[0])):
                self.log.error("Data not on WiFi")
                break

            # Set WiFi RSSI to MIN (DUT lose WiFi coverage).
            set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
                     MIN_RSSI_RESERVED_VALUE, WIFI_RSSI_CHANGE_STEP_SIZE,
                     WIFI_RSSI_CHANGE_DELAY_PER_STEP)
            # Wait for DUT report Cellular Data connected and Internet access OK.
            if (not wait_for_cell_data_connection(
                    self.log, self.android_devices[0], True) or
                    not verify_http_connection(self.log,
                                               self.android_devices[0])):
                self.log.error("Data not on Cell")
                break

            self.log.info(">----Iteration : {}/{} succeed.----<".format(
                current_iteration, total_iteration))
            current_iteration += 1
        if current_iteration <= total_iteration:
            self.log.info(">----Iteration : {}/{} failed.----<".format(
                current_iteration, total_iteration))
            return False
        else:
            return True
    def test_carrier_config_version_after_fdr(self):
        """Carrier Config Version Test after FDR

        1. Disable Verity, remount, push carriersettings apk
        2. WiFi is connected
        3. Perform FDR, and re-connect WiFi
        4. Wait for 45 mins and keep checking for version match

        """
        try:
            cc_version_mapping = {
                'vzw': VZW_CARRIER_CONFIG_VERSION,
                'Verizon': VZW_CARRIER_CONFIG_VERSION,
                'att': ATT_CARRIER_CONFIG_VERSION,
            }
            result_flag = False
            time_var = 1
            ad = self.android_devices[0]
            skip_setup_wizard = True

            # CarrierSettingsApk
            carriersettingsapk = self.user_params["carriersettingsapk"]
            if isinstance(carriersettingsapk, list):
                carriersettingsapk = carriersettingsapk[0]
            ad.log.info("Using file path %s", carriersettingsapk)

            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("connect WiFi failed")
                return False

            # Setup Steps
            adb_disable_verity(ad)
            install_carriersettings_apk(ad, carriersettingsapk)

            # FDR
            ad.log.info("Performing FDR")
            fastboot_wipe(ad)
            ad.log.info("FDR Complete")
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("Connect WiFi failed")

            # Wait for 45 mins for CC version upgrade
            while (time_var < WAIT_TIME_FOR_CARRIERCONFIG_CHANGE):
                current_version = get_carrier_config_version(ad)
                if current_version == cc_version_mapping[self.dut_operator]:
                    ad.log.info("Carrier Config Version Match %s in %s mins",
                                current_version, time_var)
                    result_flag = True
                    break
                else:
                    ad.log.debug("Carrier Config Version Not Match")
                time.sleep(60)
                time_var += 1
            if not result_flag:
                ad.log.info("Carrier Config Failed to Update in %s mins",
                            WAIT_TIME_FOR_CARRIERCONFIG_CHANGE)
            return result_flag
        except Exception as e:
            ad.log.error(e)
            return False
    def _setup_device(self, ad, sim_conf_file, qxdm_log_mask_cfg=None):
        ad.qxdm_log = getattr(ad, "qxdm_log", self.qxdm_log)
        ad.sdm_log = getattr(ad, "sdm_log", self.sdm_log)
        if self.user_params.get("enable_connectivity_metrics", False):
            enable_connectivity_metrics(ad)
        if self.user_params.get("build_id_override", False):
            build_postfix = self.user_params.get("build_id_postfix",
                                                 "LAB_TEST")
            build_id_override(
                ad,
                new_build_id=self.user_params.get("build_id_override_with",
                                                  None),
                postfix=build_postfix)
        if self.enable_radio_log_on:
            enable_radio_log_on(ad)
        list_of_models = ["sdm", "msm", "kon", "lit"]
        if any(model in ad.model for model in list_of_models):
            phone_mode = "ssss"
            if hasattr(ad, "mtp_dsds"):
                phone_mode = "dsds"
            if ad.adb.getprop("persist.radio.multisim.config") != phone_mode:
                ad.adb.shell("setprop persist.radio.multisim.config %s" \
                             % phone_mode)
                reboot_device(ad)

        stop_qxdm_logger(ad)
        if ad.qxdm_log:
            qxdm_log_mask = getattr(ad, "qxdm_log_mask", None)
            if qxdm_log_mask_cfg:
                qxdm_mask_path = self.user_params.get("qxdm_log_path",
                                                      DEFAULT_QXDM_LOG_PATH)
                ad.adb.shell("mkdir %s" % qxdm_mask_path)
                ad.log.info("Push %s to %s", qxdm_log_mask_cfg, qxdm_mask_path)
                ad.adb.push("%s %s" % (qxdm_log_mask_cfg, qxdm_mask_path))
                mask_file_name = os.path.split(qxdm_log_mask_cfg)[-1]
                qxdm_log_mask = os.path.join(qxdm_mask_path, mask_file_name)
            set_qxdm_logger_command(ad, mask=qxdm_log_mask)
            start_qxdm_logger(ad, utils.get_current_epoch_time())
        elif ad.sdm_log:
            start_sdm_logger(ad)
        else:
            disable_qxdm_logger(ad)
        if not unlock_sim(ad):
            raise signals.TestAbortClass("unable to unlock the SIM")

        # eSIM enablement
        if hasattr(ad, "fi_esim"):
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("Failed to connect to wifi")
            if check_google_fi_activated(ad):
                ad.log.info("Google Fi is already Activated")
            else:
                install_googleaccountutil_apk(ad, self.account_util)
                add_google_account(ad)
                install_googlefi_apk(ad, self.fi_util)
                if not activate_google_fi_account(ad):
                    ad.log.error("Failed to activate Fi")
                check_google_fi_activated(ad)
        if hasattr(ad, "dsds"):
            sim_mode = ad.droid.telephonyGetPhoneCount()
            if sim_mode == 1:
                ad.log.info("Phone in Single SIM Mode")
                if not phone_switch_to_msim_mode(ad):
                    ad.log.error("Failed to switch to Dual SIM Mode")
                    return False
            elif sim_mode == 2:
                ad.log.info("Phone already in Dual SIM Mode")
        if get_sim_state(ad) in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
            ad.log.info("Device has no or unknown SIM in it")
            # eSIM needs activation
            activate_esim_using_suw(ad)
            ensure_phone_idle(self.log, ad)
        elif self.user_params.get("Attenuator"):
            ad.log.info("Device in chamber room")
            ensure_phone_idle(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)
        else:
            self.wait_for_sim_ready(ad)
            ensure_phone_default_state(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)

        default_slot = getattr(ad, "default_slot", 0)
        if get_subid_from_slot_index(ad.log, ad, default_slot) != INVALID_SUB_ID:
            ad.log.info("Slot %s is the default slot.", default_slot)
            set_default_sub_for_all_services(ad, default_slot)
        else:
            ad.log.warning("Slot %s is NOT a valid slot. Slot %s will be used by default.",
                default_slot, 1-default_slot)
            set_default_sub_for_all_services(ad, 1-default_slot)

        # Activate WFC on Verizon, AT&T and Canada operators as per # b/33187374 &
        # b/122327716
        activate_wfc_on_device(self.log, ad)

        # Sub ID setup
        initial_set_up_for_subid_infomation(self.log, ad)

        # If device is setup already, skip the following setup procedures
        if getattr(ad, "telephony_test_setup", None):
            return True

        try:
            ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED)
        except Exception:
            pass

        # Disable Emergency alerts
        # Set chrome browser start with no-first-run verification and
        # disable-fre. Give permission to read from and write to storage.
        for cmd in ("pm disable com.android.cellbroadcastreceiver",
                    "pm grant com.android.chrome "
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "pm grant com.android.chrome "
                    "android.permission.WRITE_EXTERNAL_STORAGE",
                    "rm /data/local/chrome-command-line",
                    "am set-debug-app --persistent com.android.chrome",
                    'echo "chrome --no-default-browser-check --no-first-run '
                    '--disable-fre" > /data/local/tmp/chrome-command-line'):
            ad.adb.shell(cmd, ignore_status=True)

        # Curl for 2016/7 devices
        if not getattr(ad, "curl_capable", False):
            try:
                out = ad.adb.shell("/data/curl --version")
                if not out or "not found" in out:
                    if int(ad.adb.getprop("ro.product.first_api_level")) >= 25:
                        tel_data = self.user_params.get("tel_data", "tel_data")
                        if isinstance(tel_data, list):
                            tel_data = tel_data[0]
                        curl_file_path = os.path.join(tel_data, "curl")
                        if not os.path.isfile(curl_file_path):
                            curl_file_path = os.path.join(
                                self.user_params[Config.key_config_path.value],
                                curl_file_path)
                        if os.path.isfile(curl_file_path):
                            ad.log.info("Pushing Curl to /data dir")
                            ad.adb.push("%s /data" % (curl_file_path))
                            ad.adb.shell(
                                "chmod 777 /data/curl", ignore_status=True)
                else:
                    setattr(ad, "curl_capable", True)
            except Exception:
                ad.log.info("Failed to push curl on this device")

        # Ensure that a test class starts from a consistent state that
        # improves chances of valid network selection and facilitates
        # logging.
        try:
            if not set_phone_screen_on(self.log, ad):
                self.log.error("Failed to set phone screen-on time.")
                return False
            if not set_phone_silent_mode(self.log, ad):
                self.log.error("Failed to set phone silent mode.")
                return False
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND, True)
        except Exception as e:
            self.log.error("Failure with %s", e)
        setattr(ad, "telephony_test_setup", True)
        return True