コード例 #1
0
def wifi_tethering_cleanup(log, provider, client_list):
    """Clean up steps for WiFi Tethering.

    Make sure provider turn off tethering.
    Make sure clients reset WiFi and turn on cellular data.

    Args:
        log: log object.
        provider: android object provide WiFi tethering.
        client_list: a list of clients using tethered WiFi.

    Returns:
        True if no error happened. False otherwise.
    """
    for client in client_list:
        client.droid.telephonyToggleDataConnection(True)
        if not WifiUtils.wifi_reset(log, client):
            log.error("Reset client WiFi failed. {}".format(client.serial))
            return False
    if not provider.droid.wifiIsApEnabled():
        log.error("Provider WiFi tethering stopped.")
        return False
    if not WifiUtils.stop_wifi_tethering(log, provider):
        log.error("Provider strop WiFi tethering failed.")
        return False
    return True
コード例 #2
0
def airplane_mode_test(log, ad):
    """ Test airplane mode basic on Phone and Live SIM.

    Ensure phone attach, data on, WiFi off and verify Internet.
    Turn on airplane mode to make sure detach.
    Turn off airplane mode to make sure attach.
    Verify Internet connection.

    Args:
        log: log object.
        ad: android object.

    Returns:
        True if pass; False if fail.
    """
    if not ensure_phones_idle(log, [ad]):
        log.error("Failed to return phones to idle.")
        return False

    try:
        ad.droid.telephonyToggleDataConnection(True)
        WifiUtils.wifi_toggle_state(log, ad, False)

        log.info("Step1: ensure attach")
        if not toggle_airplane_mode(log, ad, False):
            log.error("Failed initial attach")
            return False
        if not verify_http_connection(log, ad):
            log.error("Data not available on cell.")
            return False

        log.info("Step2: enable airplane mode and ensure detach")
        if not toggle_airplane_mode(log, ad, True):
            log.error("Failed to enable Airplane Mode")
            return False
        if not wait_for_cell_data_connection(log, ad, False):
            log.error("Failed to disable cell data connection")
            return False
        if verify_http_connection(log, ad):
            log.error("Data available in airplane mode.")
            return False

        log.info("Step3: disable airplane mode and ensure attach")
        if not toggle_airplane_mode(log, ad, False):
            log.error("Failed to disable Airplane Mode")
            return False

        if not wait_for_cell_data_connection(log, ad, True):
            log.error("Failed to enable cell data connection")
            return False

        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)

        log.info("Step4 verify internet")
        return verify_http_connection(log, ad)
    finally:
        toggle_airplane_mode(log, ad, False)
    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
コード例 #4
0
    def test_smoke_data_airplane_mode_network_switch_tethering(self):
        try:
            ads = self.android_devices
            apm_result = False
            nw_switch_result = False
            tethering_result = False

            self.log.info("--------start test_smoke_data_airplane_mode_network"
                          "_switch_tethering--------")
            ensure_phones_default_state(self.log, ads)
            self.log.info("1. Verify toggle airplane mode.")
            apm_result = airplane_mode_test(self.log, ads[0])
            self.log.info("2. Verify LTE-WiFi network switch.")
            nw_switch_result = wifi_cell_switching(self.log, ads[0],
                                                   self.wifi_network_ssid,
                                                   self.wifi_network_pass,
                                                   GEN_4G)
            if ads[0].droid.carrierConfigIsTetheringModeAllowed(
                    TETHERING_MODE_WIFI,
                    MAX_WAIT_TIME_TETHERING_ENTITLEMENT_CHECK):
                self.log.info("3. Verify WiFi Tethering.")
                if ads[0].droid.wifiIsApEnabled():
                    WifiUtils.stop_wifi_tethering(self.log, ads[0])
                tethering_result = wifi_tethering_setup_teardown(
                    self.log,
                    ads[0], [ads[1]],
                    ap_band=WifiUtils.WIFI_CONFIG_APBAND_2G,
                    check_interval=10,
                    check_iteration=4)
                # check_interval=10, check_iteration=4: in this Smoke test,
                # check tethering connection for 4 times, each time delay 10s,
                # to provide a reasonable check_time (10*4=40s) and also reduce test
                # execution time. In regular test, check_iteration is set to 10.
            else:
                self.log.info("3. Skip WiFi Tethering."
                              "Tethering not allowed on SIM.")
                tethering_result = SKIP

            return (apm_result and nw_switch_result and
                    ((tethering_result is True) or (tethering_result == SKIP)))
        finally:
            self.log.info(
                "Summary for test run. Testbed:<{}>. <Data> Airplane Mode: {}, "
                "WiFi-Cell Network Switch: {}, Tethering: {}".format(
                    getattr(self, Config.ikey_testbed_name.value), apm_result,
                    nw_switch_result, tethering_result))
 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, True)
     try:
         if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                      self.wifi_network_pass):
             abort_all("WiFi connect fail.")
         if (not wait_for_wifi_data_connection(self.log, ad, True)
                 or not verify_http_connection(self.log, ad)):
             abort_all("Data not available on WiFi.")
     finally:
         WifiUtils.wifi_toggle_state(self.log, ad, False)
     # TODO: add more environment check here.
     return True
コード例 #6
0
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
コード例 #7
0
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)
    def test_wfc_setup_timing(self):
        """ Measures the time delay in enabling WiFi calling

        Steps:
        1. Make sure DUT idle.
        2. Turn on Airplane Mode, Set WiFi Calling to WiFi_Preferred.
        3. Turn on WiFi, connect to WiFi AP and measure time delay.
        4. Wait for WiFi connected, verify Internet and measure time delay.
        5. Wait for rat to be reported as iwlan and measure time delay.
        6. Wait for ims registered and measure time delay.
        7. Wait for WiFi Calling feature bit to be True and measure time delay.

        Expected results:
        Time Delay in each step should be within pre-defined limit.

        Returns:
            Currently always return True.
        """
        # TODO: b/26338119 Set pass/fail criteria
        ad = self.android_devices[0]

        time_values = {
            'start': 0,
            'wifi_enabled': 0,
            'wifi_connected': 0,
            'wifi_data': 0,
            'iwlan_rat': 0,
            'ims_registered': 0,
            'wfc_enabled': 0,
            'mo_call_success': 0
        }

        WifiUtils.wifi_reset(self.log, ad)
        toggle_airplane_mode(self.log, ad, True)

        set_wfc_mode(self.log, ad, WFC_MODE_WIFI_PREFERRED)

        time_values['start'] = time.time()

        self.log.info("Start Time {}s".format(time_values['start']))

        WifiUtils.wifi_toggle_state(self.log, ad, True)
        time_values['wifi_enabled'] = time.time()
        self.log.info(
            "WiFi Enabled After {}s".format(time_values['wifi_enabled'] -
                                            time_values['start']))

        WifiUtils.wifi_connect(self.log, ad, self.wifi_network_ssid,
                               self.wifi_network_pass)

        ad.droid.wakeUpNow()

        if not wait_for_wifi_data_connection(self.log, ad, True,
                                             MAX_WAIT_TIME_WIFI_CONNECTION):
            self.log.error("Failed WiFi connection, aborting!")
            return False
        time_values['wifi_connected'] = time.time()

        self.log.info(
            "WiFi Connected After {}s".format(time_values['wifi_connected'] -
                                              time_values['wifi_enabled']))

        if not verify_http_connection(self.log, ad, 'http://www.google.com',
                                      100, .1):
            self.log.error("Failed to get user-plane traffic, aborting!")
            return False

        time_values['wifi_data'] = time.time()
        self.log.info(
            "WifiData After {}s".format(time_values['wifi_data'] -
                                        time_values['wifi_connected']))

        if not wait_for_network_rat(
                self.log, ad, RAT_FAMILY_WLAN,
                voice_or_data=NETWORK_SERVICE_DATA):
            self.log.error("Failed to set-up iwlan, aborting!")
            if is_droid_in_rat_family(self.log, ad, RAT_FAMILY_WLAN,
                                      NETWORK_SERVICE_DATA):
                self.log.error("Never received the event, but droid in iwlan")
            else:
                return False
        time_values['iwlan_rat'] = time.time()
        self.log.info(
            "iWLAN Reported After {}s".format(time_values['iwlan_rat'] -
                                              time_values['wifi_data']))

        if not wait_for_ims_registered(self.log, ad,
                                       MAX_WAIT_TIME_IMS_REGISTRATION):
            self.log.error("Never received IMS registered, aborting")
            return False
        time_values['ims_registered'] = time.time()
        self.log.info(
            "Ims Registered After {}s".format(time_values['ims_registered'] -
                                              time_values['iwlan_rat']))

        if not wait_for_wfc_enabled(self.log, ad, MAX_WAIT_TIME_WFC_ENABLED):
            self.log.error("Never received WFC feature, aborting")
            return False

        time_values['wfc_enabled'] = time.time()
        self.log.info("Wifi Calling Feature Enabled After {}s".format(
            time_values['wfc_enabled'] - time_values['ims_registered']))

        set_wfc_mode(self.log, ad, WFC_MODE_DISABLED)

        wait_for_not_network_rat(self.log,
                                 ad,
                                 RAT_FAMILY_WLAN,
                                 voice_or_data=NETWORK_SERVICE_DATA)

        self.log.info("\n\n------------------summary-----------------")
        self.log.info(
            "WiFi Enabled After {0:.2f} s".format(time_values['wifi_enabled'] -
                                                  time_values['start']))
        self.log.info("WiFi Connected After {0:.2f} s".format(
            time_values['wifi_connected'] - time_values['wifi_enabled']))
        self.log.info(
            "WifiData After {0:.2f} s".format(time_values['wifi_data'] -
                                              time_values['wifi_connected']))
        self.log.info(
            "iWLAN Reported After {0:.2f} s".format(time_values['iwlan_rat'] -
                                                    time_values['wifi_data']))
        self.log.info("Ims Registered After {0:.2f} s".format(
            time_values['ims_registered'] - time_values['iwlan_rat']))
        self.log.info("Wifi Calling Feature Enabled After {0:.2f} s".format(
            time_values['wfc_enabled'] - time_values['ims_registered']))
        self.log.info("\n\n")
        return True