def _ota_upgrade(self, ad): result = True self._set_user_profile_before_ota() config_profile_before = get_user_config_profile(ad) ad.log.info("Before OTA user config is: %s", config_profile_before) try: ota_updater.update(ad) except Exception as e: ad.log.error("OTA upgrade failed with %s", e) raise if is_sim_locked(ad): ad.log.info("After OTA, SIM keeps the locked state") elif getattr(ad, "is_sim_locked", False): ad.log.error("After OTA, SIM loses the locked state") result = False if not unlock_sim(ad): ad.log.error(ad.log, "unable to unlock SIM") if not ad.droid.connectivityCheckAirplaneMode(): if not ensure_phone_subscription(self.log, ad): ad.log.error("Subscription check failed") result = False if config_profile_before.get("WFC Enabled", False): self._check_wfc_enabled(ad) result = False config_profile_after = get_user_config_profile(ad) ad.log.info("After OTA user config is: %s", config_profile_after) if config_profile_before != config_profile_after: ad.log.error("Before: %s, After: %s", config_profile_before, config_profile_after) ad.log.error("User config profile changed after OTA") result = False return result
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
def operator_network_switch(self, ad, carrier): if ad.droid.telephonyGetSimOperatorName() == "Google Fi": for i in range(3): if self.set_active_carrier(ad, carrier): break elif i == 2: ad.log.error("Failed to switch to %s", carrier) 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
def stress_test(self, setup_func=None, network_check_func=None, test_sms=False, test_video=False): for ad in self.android_devices: #check for sim and service ensure_phone_subscription(self.log, ad) if setup_func and not setup_func(): self.log.error("Test setup %s failed", setup_func.__name__) return False fail_count = collections.defaultdict(int) for i in range(1, self.phone_call_iteration + 1): msg = "Stress Call Test %s Iteration: <%s> / <%s>" % ( self.test_name, i, self.phone_call_iteration) begin_time = get_current_epoch_time() self.log.info(msg) iteration_result = True ensure_phones_idle(self.log, self.android_devices) if not self._setup_phone_call(test_video, phone_call_duration=self.phone_call_duration): fail_count["dialing"] += 1 iteration_result = False self.log.error("%s call dialing failure.", msg) else: if network_check_func and not network_check_func( self.log, self.caller): fail_count["caller_network_check"] += 1 last_call_drop_reason(self.caller, begin_time) iteration_result = False self.log.error("%s network check %s failure.", msg, network_check_func.__name__) if network_check_func and not network_check_func( self.log, self.callee): fail_count["callee_network_check"] += 1 last_call_drop_reason(self.callee, begin_time) iteration_result = False self.log.error("%s network check failure.", msg) if not verify_incall_state(self.log, [self.caller, self.callee], True): self.log.error("%s call dropped.", msg) iteration_result = False fail_count["drop"] += 1 self._hangup_call() if test_sms and not sms_send_receive_verify( self.log, self.caller, self.callee, [rand_ascii_str(180)]): fail_count["sms"] += 1 self.log.info("%s %s", msg, iteration_result) if not iteration_result: self._take_bug_report("%s_CallNo_%s" % (self.test_name, i), begin_time) start_qxdm_loggers(self.log, self.android_devices) if self.sleep_time_between_test_iterations: self.caller.droid.goToSleepNow() self.callee.droid.goToSleepNow() time.sleep(self.sleep_time_between_test_iterations) test_result = True for failure, count in fail_count.items(): if count: self.log.error("%s: %s %s failures in %s iterations", self.test_name, count, failure, self.phone_call_iteration) test_result = False return test_result
def test_check_carrier_id(self): """Verify mobile_data_always_on can be enabled. Steps: 1. Enable mobile_data_always_on by adb. 2. Verify the mobile data_always_on state. Expected Results: mobile_data_always_on return 1. """ result = True if self.dut.adb.getprop("ro.build.version.release")[0] in ("8", "O", "7", "N"): raise signals.TestSkip("Not supported in this build") old_carrier_id = self.dut.droid.telephonyGetSimCarrierId() old_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName() self.result_detail = "carrier_id = %s, carrier_name = %s" % ( old_carrier_id, old_carrier_name) self.dut.log.info(self.result_detail) sub_id = get_outgoing_voice_sub_id(self.dut) slot_index = get_slot_index_from_subid(self.log, self.dut, sub_id) if self.dut.model in ("angler", "bullhead", "marlin", "sailfish"): msg = "Power off SIM slot is not supported" self.dut.log.warning("%s, test finished", msg) self.result_detail = "%s, %s" % (self.result_detail, msg) return result if power_off_sim(self.dut, slot_index): for i in range(3): carrier_id = self.dut.droid.telephonyGetSimCarrierId() carrier_name = self.dut.droid.telephonyGetSimCarrierIdName() msg = "After SIM power down, carrier_id = %s(expecting -1), " \ "carrier_name = %s(expecting None)" % (carrier_id, carrier_name) if carrier_id != -1 or carrier_name: if i == 2: self.dut.log.error(msg) self.result_detail = "%s, %s" % (self.result_detail, msg) result = False else: time.sleep(5) else: self.dut.log.info(msg) break else: msg = "Power off SIM slot is not working" self.dut.log.error(msg) result = False self.result_detail = "%s, %s" % (self.result_detail, msg) if not power_on_sim(self.dut, slot_index): self.dut.log.error("Fail to power up SIM") result = False setattr(self.dut, "reboot_to_recover", True) else: if is_sim_locked(self.dut): self.dut.log.info("Sim is locked") carrier_id = self.dut.droid.telephonyGetSimCarrierId() carrier_name = self.dut.droid.telephonyGetSimCarrierIdName() msg = "In locked SIM, carrier_id = %s(expecting -1), " \ "carrier_name = %s(expecting None)" % (carrier_id, carrier_name) if carrier_id != -1 or carrier_name: self.dut.log.error(msg) self.result_detail = "%s, %s" % (self.result_detail, msg) result = False else: self.dut.log.info(msg) unlock_sim(self.dut) elif getattr(self.dut, "is_sim_locked", False): self.dut.log.error( "After SIM slot power cycle, SIM in not in locked state") return False if not ensure_phone_subscription(self.log, self.dut): self.dut.log.error("Unable to find a valid subscription!") result = False new_carrier_id = self.dut.droid.telephonyGetSimCarrierId() new_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName() msg = "After SIM power up, new_carrier_id = %s, " \ "new_carrier_name = %s" % (new_carrier_id, new_carrier_name) if old_carrier_id != new_carrier_id or (old_carrier_name != new_carrier_name): self.dut.log.error(msg) self.result_detail = "%s, %s" % (self.result_detail, msg) result = False else: self.dut.log.info(msg) return result
def verify_default_ims_setting(self): result = True airplane_mode = self.dut.droid.connectivityCheckAirplaneMode() default_wfc_mode = self.carrier_configs.get( CarrierConfigs.DEFAULT_WFC_IMS_MODE_INT, WFC_MODE_DISABLED) if self.default_wfc_enabled: wait_for_wfc_enabled(self.log, self.dut) else: wait_for_wfc_disabled(self.log, self.dut) if airplane_mode: wait_for_network_rat( self.log, self.dut, RAT_UNKNOWN, voice_or_data=NETWORK_SERVICE_VOICE) else: if self.default_volte: wait_for_volte_enabled(self.log, self.dut) else: wait_for_not_network_rat( self.log, self.dut, RAT_UNKNOWN, voice_or_data=NETWORK_SERVICE_VOICE) if not ensure_phone_subscription(self.log, self.dut): ad.log.error("Failed to find valid subscription") result = False user_config_profile = get_user_config_profile(self.dut) self.dut.log.info("user_config_profile = %s ", sorted(user_config_profile.items())) if user_config_profile["VoLTE Enabled"] != self.default_volte: self.dut.log.error("VoLTE mode is not %s", self.default_volte) result = False else: self.dut.log.info("VoLTE mode is %s as expected", self.default_volte) if user_config_profile["WFC Enabled"] != self.default_wfc_enabled: self.dut.log.error("WFC enabled is not %s", default_wfc_enabled) if user_config_profile["WFC Enabled"]: if user_config_profile["WFC Mode"] != default_wfc_mode: self.dut.log.error( "WFC mode is not %s after IMS factory reset", default_wfc_mode) result = False else: self.dut.log.info("WFC mode is %s as expected", default_wfc_mode) if self.default_wfc_enabled and \ default_wfc_mode == WFC_MODE_WIFI_PREFERRED: if not self.check_call_in_wfc(): result = False elif not airplane_mode: if self.default_volte: if not self.check_call_in_volte(): result = False else: if not self.check_call(): result = False if result == False: user_config_profile = get_user_config_profile(self.dut) self.dut.log.info("user_config_profile = %s ", sorted(user_config_profile.items())) return result
def change_ims_setting(self, airplane_mode, wifi_enabled, volte_enabled, wfc_enabled, wfc_mode=None): result = True self.dut.log.info( "Setting APM %s, WIFI %s, VoLTE %s, WFC %s, WFC mode %s", airplane_mode, wifi_enabled, volte_enabled, wfc_enabled, wfc_mode) toggle_airplane_mode_by_adb(self.log, self.dut, airplane_mode) if wifi_enabled: if not ensure_wifi_connected(self.log, self.dut, self.wifi_network_ssid, self.wifi_network_pass, apm=airplane_mode): self.dut.log.error("Fail to connected to WiFi") result = False else: if not wifi_toggle_state(self.log, self.dut, False): self.dut.log.error("Failed to turn off WiFi.") result = False toggle_volte(self.log, self.dut, volte_enabled) toggle_wfc(self.log, self.dut, wfc_enabled) if wfc_mode: set_wfc_mode(self.log, self.dut, wfc_mode) wfc_mode = self.dut.droid.imsGetWfcMode() if wifi_enabled or not airplane_mode: if not ensure_phone_subscription(self.log, self.dut): self.dut.log.error("Failed to find valid subscription") result = False if airplane_mode: if (CAPABILITY_WFC in self.dut_capabilities) and (wifi_enabled and wfc_enabled): if not wait_for_wfc_enabled(self.log, self.dut): result = False elif not self.check_call_in_wfc(): result = False else: if not wait_for_state( self.dut.droid.telephonyGetCurrentVoiceNetworkType, RAT_UNKNOWN): self.dut.log.error( "Voice RAT is %s not UNKNOWN", self.dut.droid.telephonyGetCurrentVoiceNetworkType()) result = False else: self.dut.log.info("Voice RAT is in UNKKNOWN") else: if (wifi_enabled and wfc_enabled) and ( wfc_mode == WFC_MODE_WIFI_PREFERRED) and ( CAPABILITY_WFC in self.dut_capabilities): if not wait_for_wfc_enabled(self.log, self.dut): result = False if not wait_for_state( self.dut.droid.telephonyGetCurrentVoiceNetworkType, RAT_UNKNOWN): self.dut.log.error( "Voice RAT is %s, not UNKNOWN", self.dut.droid.telephonyGetCurrentVoiceNetworkType()) if not self.check_call_in_wfc(): result = False else: if not wait_for_wfc_disabled(self.log, self.dut): self.dut.log.error("WFC is not disabled") result = False if volte_enabled and CAPABILITY_VOLTE in self.dut_capabilities: if not wait_for_volte_enabled(self.log, self.dut): result = False if not self.check_call_in_volte(): result = False else: if not wait_for_not_network_rat( self.log, self.dut, RAT_LTE, voice_or_data=NETWORK_SERVICE_VOICE): self.dut.log.error( "Voice RAT is %s", self.dut.droid.telephonyGetCurrentVoiceNetworkType( )) result = False if not wait_for_voice_attach(self.log, self.dut): result = False if not self.check_call(): result = False user_config_profile = get_user_config_profile(self.dut) self.dut.log.info("user_config_profile: %s ", sorted(user_config_profile.items())) return result
def _check_subscription(self): if not ensure_phone_subscription(self.log, self.dut): self.dut.log.error("Subscription check failed") return False else: return True
def test_pre_flight_check(self): for ad in self.android_devices: #check for sim and service if not ensure_phone_subscription(self.log, ad): abort_all_tests(ad.log, "Unable to find a valid subscription!") return True