def phone_setup_2g(log, ad): """Setup Phone default data sub_id data to 2G. Args: log: log object ad: android device object Returns: True if success, False if fail. """ return phone_setup_2g_for_subscription(log, ad, get_default_data_sub_id(ad))
def data_connectivity_single_bearer(log, ad, nw_gen): """Test data connection: single-bearer (no voice). Turn off airplane mode, enable Cellular Data. Ensure phone data generation is expected. Verify Internet. Disable Cellular Data, verify Internet is inaccessible. Enable Cellular Data, verify Internet. Args: log: log object. ad: android object. nw_gen: network generation the phone should on. Returns: True if success. False if failed. """ ensure_phones_idle(log, [ad]) 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 reselect in {}s.".format( MAX_WAIT_TIME_NW_SELECTION)) return False try: log.info("Step1 Airplane Off, Data On.") toggle_airplane_mode(log, ad, False) ad.droid.telephonyToggleDataConnection(True) if not wait_for_cell_data_connection(log, ad, True): log.error("Failed to enable data connection.") return False log.info("Step2 Verify internet") if not verify_http_connection(log, ad): log.error("Data not available on cell.") return False log.info("Step3 Turn off data and verify not connected.") ad.droid.telephonyToggleDataConnection(False) if not wait_for_cell_data_connection(log, ad, False): log.error("Step3 Failed to disable data connection.") return False if verify_http_connection(log, ad): log.error("Step3 Data still available when disabled.") return False log.info("Step4 Re-enable data.") ad.droid.telephonyToggleDataConnection(True) if not wait_for_cell_data_connection(log, ad, True): log.error("Step4 failed to re-enable data.") return False if not verify_http_connection(log, ad): log.error("Data not available on cell.") return False if not is_droid_in_network_generation_for_subscription( log, ad, get_default_data_sub_id(ad), nw_gen, NETWORK_SERVICE_DATA): log.error("Failed: droid is no longer on correct network") log.info("Expected:{}, Current:{}".format( nw_gen, rat_generation_from_rat( get_network_rat_for_subscription( log, ad, get_default_data_sub_id( ad), NETWORK_SERVICE_DATA)))) return False return True finally: ad.droid.telephonyToggleDataConnection(True)
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)