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 setup_test(self): for ad in self.android_devices: refresh_droid_config(self.log, ad) if getattr(self, "diag_logger", None): for logger in self.diag_logger: self.log.info( "Starting a diagnostic session {}".format(logger)) self.logger_sessions.append((logger, logger.start())) return ensure_phones_default_state(self.log, self.android_devices)
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 switch_sim(self, ad): """Requests switch between physical sim and esim. Args: ad: An AndroidDevice Object. timeout: (optional -- integer) the number of seconds in which a switch should be completed. Raises: Error: whenever a device is not set to the desired carrier within the timeout window. """ old_sim_operator = ad.droid.telephonyGetSimOperatorName() ad.log.info("Before SIM switch, SIM operator = %s", old_sim_operator) send_dialer_secret_code(ad, "794824746") time.sleep(10) new_sim_operator = ad.droid.telephonyGetSimOperatorName() ad.log.info("After SIM switch, SIM operator = %s", new_sim_operator) refresh_droid_config(self.log, ad) return old_sim_operator != new_sim_operator