def _test_stress_cbrsdataswitch_timing(self, ad, method, validation=False):
     setattr(self, "number_of_devices", 1)
     ad.adb.shell("pm disable com.google.android.apps.scone")
     wifi_toggle_state(self.log, ad, True)
     self.cbrs_subid, self.default_subid = get_cbrs_and_default_sub_id(ad)
     toggle_airplane_mode(ad.log,
                          ad,
                          new_state=False,
                          strict_checking=False)
     if self._is_current_data_on_cbrs():
         ad.log.info("Current Data is on CBRS, proceeding with test")
     else:
         ad.log.error("Current Data not on CBRS, forcing it now..")
         ad.droid.telephonySetPreferredOpportunisticDataSubscription(
             self.cbrs_subid, False)
     ad.droid.telephonyUpdateAvailableNetworks(self.cbrs_subid)
     total_iteration = self.stress_test_number
     fail_count = collections.defaultdict(int)
     self.switch_time_dict = {
         'cbrs_default_switch': [],
         'default_cbrs_switch': []
     }
     current_iteration = 1
     for i in range(1, total_iteration + 1):
         msg = "Stress CBRS Test Iteration: <%s> / <%s>" % (i,
                                                            total_iteration)
         begin_time = get_current_epoch_time()
         self.log.info(msg)
         start_qxdm_logger(ad, begin_time)
         iteration_result = self._cbrs_default_data_switch_timing(
             ad, method, validation)
         self.log.info("Result: %s", iteration_result)
         if iteration_result:
             self.log.info(">----Iteration : %d/%d succeed.----<", i,
                           total_iteration)
         else:
             fail_count["cbrsdataswitch_fail"] += 1
             self.log.error(">----Iteration : %d/%d failed.----<", i,
                            total_iteration)
             self._take_bug_report("%s_IterNo_%s" % (self.test_name, i),
                                   begin_time)
         current_iteration += 1
         time.sleep(WAIT_TIME_BETWEEN_ITERATION)
     test_result = True
     for time_task, time_list in self.switch_time_dict.items():
         ad.log.info("%s %s", time_task, time_list)
         avg_time = self._get_list_average(time_list)
         ad.log.info("Average %s for %d iterations = %.2f seconds",
                     time_task, self.stress_test_number, avg_time)
     for failure, count in fail_count.items():
         if count:
             self.log.error("%s: %s %s failures in %s iterations",
                            self.test_name, count, failure, total_iteration)
             test_result = False
     ad.adb.shell("pm enable com.google.android.apps.scone")
     return test_result
 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
    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
        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
        }

        wifi_reset(self.log, self.dut)
        toggle_airplane_mode_by_adb(self.log, self.dut, True)

        set_wfc_mode(self.log, self.dut, WFC_MODE_WIFI_PREFERRED)

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

        self.dut.log.info("Start Time %ss", time_values['start'])

        wifi_toggle_state(self.log, self.dut, True)
        time_values['wifi_enabled'] = time.time()
        self.dut.log.info("WiFi Enabled After %ss",
                          time_values['wifi_enabled'] - time_values['start'])

        network = {WIFI_SSID_KEY: self.wifi_network_ssid}
        if self.wifi_network_pass:
            network[WIFI_PWD_KEY] = self.wifi_network_pass
        try:
            self.dut.droid.wifiConnectByConfig(network)
        except Exception:
            self.dut.log.info("Connecting to wifi by RPC wifiConnect instead")
            self.dut.droid.wifiConnect(network)
        self.dut.droid.wakeUpNow()

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

        self.dut.log.info(
            "WiFi Connected After %ss",
            time_values['wifi_connected'] - time_values['wifi_enabled'])

        if not verify_internet_connection(self.log, self.dut, retries=3):
            self.dut.log.error("Failed to get user-plane traffic, aborting!")
            return False

        time_values['wifi_data'] = time.time()
        self.dut.log.info(
            "WifiData After %ss",
            time_values['wifi_data'] - time_values['wifi_connected'])

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

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

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

        time_values['wfc_enabled'] = time.time()
        self.dut.log.info(
            "Wifi Calling Feature Enabled After %ss",
            time_values['wfc_enabled'] - time_values['ims_registered'])

        set_wfc_mode(self.log, self.dut, WFC_MODE_DISABLED)

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

        self.dut.log.info("\n\n------------------summary-----------------")
        self.dut.log.info("WiFi Enabled After %.2f seconds",
                          time_values['wifi_enabled'] - time_values['start'])
        self.dut.log.info(
            "WiFi Connected After %.2f seconds",
            time_values['wifi_connected'] - time_values['wifi_enabled'])
        self.dut.log.info(
            "WifiData After %.2f s",
            time_values['wifi_data'] - time_values['wifi_connected'])
        self.dut.log.info("iWLAN Reported After %.2f seconds",
                          time_values['iwlan_rat'] - time_values['wifi_data'])
        self.dut.log.info(
            "Ims Registered After %.2f seconds",
            time_values['ims_registered'] - time_values['iwlan_rat'])
        self.dut.log.info(
            "Wifi Calling Feature Enabled After %.2f seconds",
            time_values['wfc_enabled'] - time_values['ims_registered'])
        self.dut.log.info("\n\n")
        return True
 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_tethering_setup_teardown(log,
                                  provider,
                                  client_list,
                                  ap_band=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 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():
        provider.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))
            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 not verify_internet_connection(
                    log, client, expected_state=False):
                client.log.error("Turn off Data on client fail")
                return False

        provider.log.info(
            "Provider turn on WiFi tethering. SSID: %s, password: %s", ssid,
            password)

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

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

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

            client.log.info("Client check Internet connection.")
            if (not wait_for_wifi_data_connection(log, client, True)
                    or not verify_internet_connection(log, client)):
                client.log.error("No WiFi Data on client")
                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 airplane_mode_test(log, ad, retries=3):
    """ 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)
        wifi_toggle_state(log, ad, False)

        ad.log.info("Step1: disable airplane mode and ensure attach")
        if not toggle_airplane_mode(log, ad, False):
            ad.log.error("Failed initial attach")
            return False

        if not wait_for_state(get_service_state_by_adb, "IN_SERVICE",
                              MAX_WAIT_TIME_FOR_STATE_CHANGE,
                              WAIT_TIME_BETWEEN_STATE_CHECK, log, ad):
            ad.log.error("Current service state is not 'IN_SERVICE'.")
            return False

        time.sleep(30)
        if not ad.droid.connectivityNetworkIsConnected():
            ad.log.error("Network is NOT connected!")
            return False

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

        if not verify_internet_connection(log, ad, retries=3):
            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):
            ad.log.error("Failed to enable Airplane Mode")
            return False
        if not wait_for_cell_data_connection(log, ad, False):
            ad.log.error("Failed to disable cell data connection")
            return False

        if not verify_internet_connection(log, ad, expected_state=False):
            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):
            ad.log.error("Failed to disable Airplane Mode")
            return False

        if not wait_for_state(get_service_state_by_adb, "IN_SERVICE",
                              MAX_WAIT_TIME_FOR_STATE_CHANGE,
                              WAIT_TIME_BETWEEN_STATE_CHECK, log, ad):
            ad.log.error("Current service state is not 'IN_SERVICE'.")
            return False

        time.sleep(30)
        if not ad.droid.connectivityNetworkIsConnected():
            ad.log.warning("Network is NOT connected!")

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

        if not verify_internet_connection(log, ad, retries=3):
            ad.log.warning("Data not available on cell")
            return False
        return True
    finally:
        toggle_airplane_mode(log, ad, False)
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):
            ad.log.error("Device failed to register in %s", nw_gen)
            return False

        start_youtube_video(ad)
        # Ensure WiFi can connect to live network
        ad.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):
            ad.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)
        wifi_toggle_state(log, ad, True)
        ad.droid.telephonyToggleDataConnection(True)
        if (not wait_for_wifi_data_connection(log, ad, True)
                or not verify_internet_connection(log, ad)):
            ad.log.error("Data is not on WiFi")
            return False

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

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

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

    finally:
        ad.force_stop_apk("com.google.android.youtube")
        wifi_toggle_state(log, ad, False)
 def toggle_wifi(self):
     wifi_toggle_state(self.log, self.dut, None)
예제 #9
0
def airplane_mode_test(log, ad, retries=3):
    """ 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)
        wifi_toggle_state(log, ad, False)

        ad.log.info("Step1: disable airplane mode and ensure attach")
        if not toggle_airplane_mode(log, ad, False):
            ad.log.error("Failed initial attach")
            return False

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

        if not verify_internet_connection(log, ad, retries=3):
            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):
            ad.log.error("Failed to enable Airplane Mode")
            return False
        if not wait_for_cell_data_connection(log, ad, False):
            ad.log.error("Failed to disable cell data connection")
            return False

        if not verify_internet_connection(log, ad, expected_state=False):
            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):
            ad.log.error("Failed to disable Airplane Mode")
            return False

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

        if not verify_internet_connection(log, ad, retries=3):
            ad.log.warning("Data not available on cell")
            return False
        return True
    finally:
        toggle_airplane_mode(log, ad, False)
예제 #10
0
def airplane_mode_test(log, ad, retries=3):
    """ 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)
        wifi_toggle_state(log, ad, False)

        log.info("Step1: ensure attach")
        if not toggle_airplane_mode(log, ad, False):
            ad.log.error("Failed initial attach")
            return False
        for i in range(retries):
            if verify_internet_connection(log, ad):
                ad.log.info("Data available on cell.")
                break
            elif i == retries - 1:
                ad.log.error("Data not available on cell.")
                return False
            else:
                ad.log.warning("Attempt %d Data not available on cell" %
                               (i + 1))

        log.info("Step2: enable airplane mode and ensure detach")
        if not toggle_airplane_mode(log, ad, True):
            ad.log.error("Failed to enable Airplane Mode")
            return False
        if not wait_for_cell_data_connection(log, ad, False):
            ad.log.error("Failed to disable cell data connection")
            return False
        if verify_internet_connection(log, ad):
            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):
            ad.log.error("Failed to disable Airplane Mode")
            return False

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

        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)

        log.info("Step4 verify internet")
        for i in range(retries):
            if verify_internet_connection(log, ad):
                ad.log.info("Data available on cell.")
                break
            elif i == retries - 1:
                ad.log.error("Data not available on cell.")
                return False
            else:
                ad.log.warning("Attempt %d Data not available on cell" %
                               (i + 1))
        return True
    finally:
        toggle_airplane_mode(log, ad, False)
예제 #11
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_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)