예제 #1
0
 def _init_device(self, ad):
     synchronize_device_time(ad)
     ad.log_path = self.log_path
     print_radio_info(ad)
     unlock_sim(ad)
     ad.wakeup_screen()
     ad.adb.shell("input keyevent 82")
 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
예제 #3
0
 def setup_test(self):
     if not unlock_sim(self.dut):
         abort_all_tests(self.dut.log, "unable to unlock SIM")
     self.expected_call_result = True
예제 #4
0
    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
예제 #5
0
    def _setup_device(self, ad, sim_conf_file, qxdm_log_mask_cfg=None):
        if self.user_params.get("enable_connectivity_metrics", True):
            enable_connectivity_metrics(ad)
        if self.user_params.get("build_id_override", False):
            build_postfix = self.user_params.get("build_id_postfix", "TEST")
            build_id_override(ad,
                              new_build_id=self.user_params.get(
                                  "build_id_override_with", None),
                              postfix=build_postfix)
        if self.enable_radio_log_on:
            enable_radio_log_on(ad)
        if "sdm" in ad.model:
            if ad.adb.getprop("persist.radio.multisim.config") != "ssss":
                ad.adb.shell("setprop persist.radio.multisim.config ssss")
                reboot_device(ad)

        stop_qxdm_logger(ad)
        ad.qxdm_log = getattr(ad, "qxdm_log", self.qxdm_log)
        if ad.qxdm_log:
            qxdm_log_mask = getattr(ad, "qxdm_log_mask", None)
            if qxdm_log_mask_cfg:
                qxdm_mask_path = self.user_params.get("qxdm_log_path",
                                                      DEFAULT_QXDM_LOG_PATH)
                ad.adb.shell("mkdir %s" % qxdm_mask_path)
                ad.log.info("Push %s to %s", qxdm_log_mask_cfg, qxdm_mask_path)
                ad.adb.push("%s %s" % (qxdm_log_mask_cfg, qxdm_mask_path))
                mask_file_name = os.path.split(qxdm_log_mask_cfg)[-1]
                qxdm_log_mask = os.path.join(qxdm_mask_path, mask_file_name)
            set_qxdm_logger_command(ad, mask=qxdm_log_mask)
            start_qxdm_logger(ad, utils.get_current_epoch_time())
        else:
            disable_qxdm_logger(ad)
        if not unlock_sim(ad):
            raise signals.TestAbortClass("unable to unlock the SIM")

        if get_sim_state(ad) in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
            ad.log.info("Device has no or unknown SIM in it")
            ensure_phone_idle(self.log, ad)
        elif self.user_params.get("Attenuator"):
            ad.log.info("Device in chamber room")
            ensure_phone_idle(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)
        else:
            if not wait_for_sim_ready_by_adb(self.log, ad):
                raise signals.TestAbortClass("unable to load the SIM")
            ensure_phone_default_state(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)

        # Setup VoWiFi MDN for Verizon. b/33187374
        if get_operator_name(self.log, ad) == "vzw" and ad.is_apk_installed(
                "com.google.android.wfcactivation"):
            ad.log.info("setup VoWiFi MDN per b/33187374")
        ad.adb.shell("setprop dbg.vzw.force_wfc_nv_enabled true")
        ad.adb.shell("am start --ei EXTRA_LAUNCH_CARRIER_APP 0 -n "
                     "\"com.google.android.wfcactivation/"
                     ".VzwEmergencyAddressActivity\"")
        # Sub ID setup
        initial_set_up_for_subid_infomation(self.log, ad)

        # If device is setup already, skip the following setup procedures
        if getattr(ad, "telephony_test_setup", None):
            return True

        if "enable_wifi_verbose_logging" in self.user_params:
            ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED)

        # Disable Emergency alerts
        # Set chrome browser start with no-first-run verification and
        # disable-fre. Give permission to read from and write to storage.
        for cmd in ("pm disable com.android.cellbroadcastreceiver",
                    "pm grant com.android.chrome "
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "pm grant com.android.chrome "
                    "android.permission.WRITE_EXTERNAL_STORAGE",
                    "rm /data/local/chrome-command-line",
                    "am set-debug-app --persistent com.android.chrome",
                    'echo "chrome --no-default-browser-check --no-first-run '
                    '--disable-fre" > /data/local/tmp/chrome-command-line'):
            ad.adb.shell(cmd)

        # Curl for 2016/7 devices
        if not getattr(ad, "curl_capable", False):
            try:
                out = ad.adb.shell("/data/curl --version")
                if not out or "not found" in out:
                    if int(ad.adb.getprop("ro.product.first_api_level")) >= 25:
                        tel_data = self.user_params.get("tel_data", "tel_data")
                        if isinstance(tel_data, list):
                            tel_data = tel_data[0]
                        curl_file_path = os.path.join(tel_data, "curl")
                        if not os.path.isfile(curl_file_path):
                            curl_file_path = os.path.join(
                                self.user_params[Config.key_config_path],
                                curl_file_path)
                        if os.path.isfile(curl_file_path):
                            ad.log.info("Pushing Curl to /data dir")
                            ad.adb.push("%s /data" % (curl_file_path))
                            ad.adb.shell("chmod 777 /data/curl",
                                         ignore_status=True)
                else:
                    setattr(ad, "curl_capable", True)
            except Exception:
                ad.log.info("Failed to push curl on this device")

        # Ensure that a test class starts from a consistent state that
        # improves chances of valid network selection and facilitates
        # logging.
        try:
            if not set_phone_screen_on(self.log, ad):
                self.log.error("Failed to set phone screen-on time.")
                return False
            if not set_phone_silent_mode(self.log, ad):
                self.log.error("Failed to set phone silent mode.")
                return False
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND, True)
        except Exception as e:
            self.log.error("Failure with %s", e)
        setattr(ad, "telephony_test_setup", True)
        return True
예제 #6
0
    def _crash_recovery_test(self, process, *args):
        """Crash Recovery Test

        Arguments:
            process: the process to be killed. For example:
                "rild", "netmgrd", "com.android.phone", "imsqmidaemon",
                "imsdatadaemon", "ims_rtp_daemon",
                "com.android.ims.rcsservice", "system_server", "cnd",
                "modem"

        Expected Results:
            All Features should work as intended post crash recovery

        Returns:
            True is pass, False if fail.
        """
        self.number_of_devices = 2

        try:
            self.dut.droid.logI("======== Trigger %s crash ========" % process)
        except:
            pass
        if process == "modem":
            self.user_params["check_crash"] = False
            self.dut.log.info("======== Crash modem from kernal ========")
            trigger_modem_crash(self.dut)
        elif process == "modem-crash":
            self.user_params["check_crash"] = False
            self.dut.log.info("======== Crash modem from modem ========")
            trigger_modem_crash_by_modem(self.dut)
        elif process == "sim":
            self.dut.log.info("======== Power cycle SIM slot ========")
            self.user_params["check_crash"] = True
            sub_id = get_outgoing_voice_sub_id(self.dut)
            slot_index = get_slot_index_from_subid(self.log, self.dut, sub_id)
            if not power_off_sim(self.dut, slot_index):
                self.dut.log.warning("Fail to power off SIM")
                raise signals.TestSkip("Power cycle SIM not working")
            if not power_on_sim(self.dut, slot_index):
                self.dut.log.error("Fail to power on SIM slot")
                setattr(self.dut, "reboot_to_recover", True)
                return False
        else:
            if process == "rild":
                if int(self.dut.adb.getprop(
                        "ro.product.first_api_level")) >= 28:
                    process = "qcrild"
            self.dut.log.info("======== Killing process <%s> ========",
                              process)
            process_pid = self.dut.adb.shell("pidof %s" % process)
            self.dut.log.info("Pid of %s is %s", process, process_pid)
            if not process_pid:
                self.dut.log.error("Process %s not running", process)
                return False
            if process in ("netd", "system_server"):
                self.dut.stop_services()
            self.dut.adb.shell("kill -9 %s" % process_pid, ignore_status=True)
            self.dut.log.info("Wait %s sec for process %s come up.",
                              WAIT_TIME_AFTER_CRASH, process)
            time.sleep(WAIT_TIME_AFTER_CRASH)
            if process in ("netd", "system_server"):
                self.dut.ensure_screen_on()
                try:
                    self.dut.start_services()
                except Exception as e:
                    self.dut.log.warning(e)
            process_pid_new = self.dut.adb.shell("pidof %s" % process)
            if process_pid == process_pid_new:
                self.dut.log.error(
                    "Process %s has the same pid: old:%s new:%s", process,
                    process_pid, process_pid_new)
        try:
            self.dut.droid.logI(
                "======== Start testing after triggering %s crash ========" %
                process)
        except Exception:
            self.dut.ensure_screen_on()
            self.dut.start_services()
            if is_sim_locked(self.dut):
                unlock_sim(self.dut)

        if process == "ims_rtp_daemon":
            if not self._check_wfc_enabled:
                failed_tests = ["_check_wfc_enabled"]
            else:
                failed_tests = []
        else:
            failed_tests = []

        begin_time = get_current_epoch_time()
        failed_tests.extend(self.feature_validator(*args))
        crash_report = self.dut.check_crash_report(self.test_name,
                                                   begin_time,
                                                   log_crash_report=True)
        if failed_tests or crash_report:
            if failed_tests:
                self.dut.log.error("%s failed after %s restart", failed_tests,
                                   process)
                setattr(self.dut, "reboot_to_recover", True)
            if crash_report:
                self.dut.log.error("Crash %s found after %s restart",
                                   crash_report, process)
            return False
        else:
            return True
    def _setup_device(self, ad, sim_conf_file, qxdm_log_mask_cfg=None):
        ad.qxdm_log = getattr(ad, "qxdm_log", self.qxdm_log)
        ad.sdm_log = getattr(ad, "sdm_log", self.sdm_log)
        if self.user_params.get("enable_connectivity_metrics", False):
            enable_connectivity_metrics(ad)
        if self.user_params.get("build_id_override", False):
            build_postfix = self.user_params.get("build_id_postfix",
                                                 "LAB_TEST")
            build_id_override(
                ad,
                new_build_id=self.user_params.get("build_id_override_with",
                                                  None),
                postfix=build_postfix)
        if self.enable_radio_log_on:
            enable_radio_log_on(ad)
        list_of_models = ["sdm", "msm", "kon", "lit"]
        if any(model in ad.model for model in list_of_models):
            phone_mode = "ssss"
            if hasattr(ad, "mtp_dsds"):
                phone_mode = "dsds"
            if ad.adb.getprop("persist.radio.multisim.config") != phone_mode:
                ad.adb.shell("setprop persist.radio.multisim.config %s" \
                             % phone_mode)
                reboot_device(ad)

        stop_qxdm_logger(ad)
        if ad.qxdm_log:
            qxdm_log_mask = getattr(ad, "qxdm_log_mask", None)
            if qxdm_log_mask_cfg:
                qxdm_mask_path = self.user_params.get("qxdm_log_path",
                                                      DEFAULT_QXDM_LOG_PATH)
                ad.adb.shell("mkdir %s" % qxdm_mask_path)
                ad.log.info("Push %s to %s", qxdm_log_mask_cfg, qxdm_mask_path)
                ad.adb.push("%s %s" % (qxdm_log_mask_cfg, qxdm_mask_path))
                mask_file_name = os.path.split(qxdm_log_mask_cfg)[-1]
                qxdm_log_mask = os.path.join(qxdm_mask_path, mask_file_name)
            set_qxdm_logger_command(ad, mask=qxdm_log_mask)
            start_qxdm_logger(ad, utils.get_current_epoch_time())
        elif ad.sdm_log:
            start_sdm_logger(ad)
        else:
            disable_qxdm_logger(ad)
        if not unlock_sim(ad):
            raise signals.TestAbortClass("unable to unlock the SIM")

        # eSIM enablement
        if hasattr(ad, "fi_esim"):
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("Failed to connect to wifi")
            if check_google_fi_activated(ad):
                ad.log.info("Google Fi is already Activated")
            else:
                install_googleaccountutil_apk(ad, self.account_util)
                add_google_account(ad)
                install_googlefi_apk(ad, self.fi_util)
                if not activate_google_fi_account(ad):
                    ad.log.error("Failed to activate Fi")
                check_google_fi_activated(ad)
        if hasattr(ad, "dsds"):
            sim_mode = ad.droid.telephonyGetPhoneCount()
            if sim_mode == 1:
                ad.log.info("Phone in Single SIM Mode")
                if not phone_switch_to_msim_mode(ad):
                    ad.log.error("Failed to switch to Dual SIM Mode")
                    return False
            elif sim_mode == 2:
                ad.log.info("Phone already in Dual SIM Mode")
        if get_sim_state(ad) in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
            ad.log.info("Device has no or unknown SIM in it")
            # eSIM needs activation
            activate_esim_using_suw(ad)
            ensure_phone_idle(self.log, ad)
        elif self.user_params.get("Attenuator"):
            ad.log.info("Device in chamber room")
            ensure_phone_idle(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)
        else:
            self.wait_for_sim_ready(ad)
            ensure_phone_default_state(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)

        default_slot = getattr(ad, "default_slot", 0)
        if get_subid_from_slot_index(ad.log, ad, default_slot) != INVALID_SUB_ID:
            ad.log.info("Slot %s is the default slot.", default_slot)
            set_default_sub_for_all_services(ad, default_slot)
        else:
            ad.log.warning("Slot %s is NOT a valid slot. Slot %s will be used by default.",
                default_slot, 1-default_slot)
            set_default_sub_for_all_services(ad, 1-default_slot)

        # Activate WFC on Verizon, AT&T and Canada operators as per # b/33187374 &
        # b/122327716
        activate_wfc_on_device(self.log, ad)

        # Sub ID setup
        initial_set_up_for_subid_infomation(self.log, ad)

        # If device is setup already, skip the following setup procedures
        if getattr(ad, "telephony_test_setup", None):
            return True

        try:
            ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED)
        except Exception:
            pass

        # Disable Emergency alerts
        # Set chrome browser start with no-first-run verification and
        # disable-fre. Give permission to read from and write to storage.
        for cmd in ("pm disable com.android.cellbroadcastreceiver",
                    "pm grant com.android.chrome "
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "pm grant com.android.chrome "
                    "android.permission.WRITE_EXTERNAL_STORAGE",
                    "rm /data/local/chrome-command-line",
                    "am set-debug-app --persistent com.android.chrome",
                    'echo "chrome --no-default-browser-check --no-first-run '
                    '--disable-fre" > /data/local/tmp/chrome-command-line'):
            ad.adb.shell(cmd, ignore_status=True)

        # Curl for 2016/7 devices
        if not getattr(ad, "curl_capable", False):
            try:
                out = ad.adb.shell("/data/curl --version")
                if not out or "not found" in out:
                    if int(ad.adb.getprop("ro.product.first_api_level")) >= 25:
                        tel_data = self.user_params.get("tel_data", "tel_data")
                        if isinstance(tel_data, list):
                            tel_data = tel_data[0]
                        curl_file_path = os.path.join(tel_data, "curl")
                        if not os.path.isfile(curl_file_path):
                            curl_file_path = os.path.join(
                                self.user_params[Config.key_config_path.value],
                                curl_file_path)
                        if os.path.isfile(curl_file_path):
                            ad.log.info("Pushing Curl to /data dir")
                            ad.adb.push("%s /data" % (curl_file_path))
                            ad.adb.shell(
                                "chmod 777 /data/curl", ignore_status=True)
                else:
                    setattr(ad, "curl_capable", True)
            except Exception:
                ad.log.info("Failed to push curl on this device")

        # Ensure that a test class starts from a consistent state that
        # improves chances of valid network selection and facilitates
        # logging.
        try:
            if not set_phone_screen_on(self.log, ad):
                self.log.error("Failed to set phone screen-on time.")
                return False
            if not set_phone_silent_mode(self.log, ad):
                self.log.error("Failed to set phone silent mode.")
                return False
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING, True)
            ad.droid.telephonyAdjustPreciseCallStateListenLevel(
                PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND, True)
        except Exception as e:
            self.log.error("Failure with %s", e)
        setattr(ad, "telephony_test_setup", True)
        return True